Skip to content

fix(telegram): make reaction handling soft-fail and message-id resilient#20236

Merged
vincentkoc merged 4 commits intoopenclaw:mainfrom
PeterShanxin:pr/draft-telegram-reliability
Feb 23, 2026
Merged

fix(telegram): make reaction handling soft-fail and message-id resilient#20236
vincentkoc merged 4 commits intoopenclaw:mainfrom
PeterShanxin:pr/draft-telegram-reliability

Conversation

@PeterShanxin
Copy link
Contributor

@PeterShanxin PeterShanxin commented Feb 18, 2026

Summary

This PR hardens Telegram reaction handling to fail softly and improves message-id compatibility/fallback routing.

Problem

Hard errors in reaction paths can trigger provider re-generation loops and duplicate content. Also, real-world payloads may use message_id and reaction targets may be omitted.

Changes

  • Accept snake_case message_id aliases in reaction input parsing.
  • Return structured soft failures (ok:false) for reaction failure cases:
    • disabled via reaction policy/gates
    • missing token
    • invalid emoji
    • transport/API failures
  • Fallback reaction target to current inbound message context when messageId is omitted.
  • Thread currentMessageId through tool context/dispatch.
  • Align Telegram reaction e2e expectations with soft-fail behavior.

Risk

Medium-low. User-facing behavior change is intentional and scoped to Telegram reaction/dispatch flow.

Validation

  • Updated Telegram e2e tests and related parsing tests.
  • Behavior goals:
    • no hard throw/re-generation loop for reaction failures
    • stable reaction targeting from inbound context fallback.

Greptile Summary

This PR hardens Telegram reaction handling by converting hard errors (exceptions) into soft failures (structured ok:false responses), preventing agent re-generation loops that cause duplicate content. It also improves message-id compatibility by accepting snake_case message_id aliases and automatically falling back to the current inbound message ID when messageId is omitted.

Key changes:

  • Telegram reaction failures (disabled policy, missing token, invalid emoji, API errors) now return jsonResult({ok: false, reason, hint}) instead of throwing exceptions
  • Added automatic camelCase → snake_case fallback in param readers (readParamRaw in common.ts:56-71) for LLM tool-call flexibility
  • Thread currentMessageId from inbound context through runtime → tools → action handlers
  • Telegram dock now extracts currentMessageId from context.CurrentMessageId and passes it to tool context
  • Schema adds message_id field as LLM-facing alias (see inline comment at message-tool.ts:249)
  • Tests updated to verify soft-fail behavior (no more rejects.toThrow assertions for reaction errors)

Confidence Score: 4/5

  • This PR is safe to merge with low risk - the changes are well-scoped to Telegram reaction flow with comprehensive test coverage
  • Score reflects solid implementation with thorough test coverage validating soft-fail behavior. The changes are intentional user-facing improvements (reaction stability) with backward-compatible param reading. Minor deduction because the snake_case fallback is broad (affects all param readers) and the messageId-required error at telegram.ts:128 still throws hard despite soft-fail goal, though this is a reasonable edge case for truly missing IDs.
  • No files require special attention - the implementation is consistent and well-tested

Last reviewed commit: 8901940

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: M labels Feb 18, 2026
@PeterShanxin PeterShanxin force-pushed the pr/draft-telegram-reliability branch from 97b4735 to 664e822 Compare February 18, 2026 18:51
@openclaw-barnacle openclaw-barnacle bot added the channel: telegram Channel integration: telegram label Feb 18, 2026
@PeterShanxin PeterShanxin marked this pull request as ready for review February 18, 2026 19:40
Copilot AI review requested due to automatic review settings February 18, 2026 19:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Telegram reaction handling robustness by implementing soft-fail error handling to prevent LLM re-generation loops, adds snake_case parameter alias support for better API compatibility, and introduces message-id fallback capabilities for more resilient reaction targeting.

Changes:

  • Converted Telegram reaction errors from hard throws to soft-fail JSON results to prevent Gemini Flash re-generation loops
  • Added snake_case (message_id) alias support alongside camelCase (messageId) for parameter parsing
  • Threaded currentMessageId through tool context to enable fallback reaction targeting when messageId is omitted

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/infra/shell-env.test.ts Added Windows platform checks to skip shell environment tests (unrelated fix)
src/channels/plugins/types.core.ts Added CurrentMessageId to threading context types
src/channels/plugins/actions/telegram.ts Added currentMessageId fallback for reaction targeting
src/channels/dock.ts Removed ReplyToId fallback for threadId; added currentMessageId extraction
src/auto-reply/reply/agent-runner-utils.ts Threaded currentMessageId through tool context building
src/agents/tools/telegram-actions.ts Converted reaction errors to soft-fail results instead of throwing
src/agents/tools/telegram-actions.e2e.test.ts Updated tests to expect soft-fail results; added snake_case alias test
src/agents/tools/message-tool.ts Added message_id schema field as snake_case alias
src/agents/tools/common.ts Implemented snake_case parameter alias support via toSnakeCaseKey
src/agents/tools/common.e2e.test.ts Added tests for snake_case alias support
src/agents/pi-tools.ts Added currentMessageId parameter threading
src/agents/pi-embedded-runner/run/params.ts Added currentMessageId to run parameters
src/agents/pi-embedded-runner/run/attempt.ts Threaded currentMessageId to tool creation
src/agents/pi-embedded-runner/run.ts Threaded currentMessageId through agent execution
src/agents/openclaw-tools.ts Added currentMessageId to tool options
extensions/telegram/src/channel.ts Added safeParseTelegramReplyToMessageId with fallback implementation

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@PeterShanxin PeterShanxin force-pushed the pr/draft-telegram-reliability branch from 5995554 to a01377e Compare February 19, 2026 04:57
@PeterShanxin
Copy link
Contributor Author

Addressed review feedback in a01377eb2 and rebased branch onto latest upstream/main.

  • Aligned safeParseTelegramReplyToMessageId fallback semantics with core parser behavior (removed positivity guard; finite-number check only).
  • Kept message_id schema alias intentionally for tool-schema discoverability, and documented that intent inline.
  • Kept the Windows shell-env test guard as an intentional CI-stability fix (can split to infra-only follow-up if maintainers prefer).

I resolved the outdated review threads after the push.

@PeterShanxin
Copy link
Contributor Author

Update: all review feedback has been addressed and all CI checks are green. This PR is ready for maintainer review/merge.

@PeterShanxin PeterShanxin force-pushed the pr/draft-telegram-reliability branch from a01377e to 14cb34b Compare February 19, 2026 13:22
@PeterShanxin
Copy link
Contributor Author

Rebased to latest main and resolved the merge conflict.

Current red CI is from upstream formatting drift in files outside this PR scope (same pnpm check/oxfmt --check failure observed on main). Once baseline formatting is fixed upstream, this PR should be re-runnable cleanly.

@vincentkoc
Copy link
Member

This looks like a strong candidate for the reaction-handling track.

Before merge, please rebase and confirm DM-specific reaction behavior against the open DM reaction report lineage (for example #21001) so we can tie closure evidence directly.

If you can add one explicit DM reaction regression test in the rebased branch, it will make merge/closure much easier.

@vincentkoc vincentkoc force-pushed the pr/draft-telegram-reliability branch from 14cb34b to 705a38c Compare February 23, 2026 15:06
@vincentkoc
Copy link
Member

Rebased and refreshed this PR with a focused reaction-resilience patch set:

  • soft-fail Telegram reaction error paths (disabled, missing_token, invalid emoji/API failures) to avoid regenerate loops
  • snake_case input alias support for message_id / other camelCase params
  • currentMessageId threaded through tool context and used as Telegram reaction fallback when explicit messageId is omitted
  • Telegram threading context updated to avoid treating ReplyToId as message_thread_id in DMs
  • added regression coverage for:
    • snake_case reaction IDs
    • DM/inbound-message fallback reaction targeting (toolContext.currentMessageId)
    • Telegram dock threading behavior in DMs

Validation run locally:

  • pnpm test src/agents/tools/common.params.test.ts src/agents/tools/telegram-actions.test.ts src/channels/plugins/actions/actions.test.ts src/channels/dock.test.ts
  • pnpm check

I also added the unreleased changelog fix entry with contributor credit.

@openclaw-barnacle openclaw-barnacle bot removed the channel: telegram Channel integration: telegram label Feb 23, 2026
@vincentkoc
Copy link
Member

@greptile review

@vincentkoc
Copy link
Member

Follow-up to review feedback:

  • Removed the hard throw for missing messageId in Telegram action adapter.
  • Added soft-fail handling in handleTelegramAction for missing/invalid messageId with reason: "missing_message_id".
  • Added regression tests for both layers:
    • tool-level soft-fail when messageId is absent
    • plugin adapter forwarding missing ID to lower-layer soft-fail path (no hard throw)

Validation:

  • pnpm test src/agents/tools/telegram-actions.test.ts src/channels/plugins/actions/actions.test.ts
  • pnpm check

@vincentkoc vincentkoc merged commit c1b75ab into openclaw:main Feb 23, 2026
6 checks passed
jaydiamond42 pushed a commit to jaydiamond42/bloomtbot that referenced this pull request Feb 23, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
carlosrivera pushed a commit to myascendai/meshiclaw that referenced this pull request Feb 23, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Yuyang-0 pushed a commit to Yuyang-0/openclaw that referenced this pull request Feb 26, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…ent (openclaw#20236)

* Telegram: soft-fail reactions and fallback to inbound message id

* Telegram: soft-fail missing reaction message id

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants