Skip to content

fix(telegram): preserve forward origins in debounce batches - #108985

Merged
steipete merged 3 commits into
openclaw:mainfrom
aspalagin:fix/telegram-debounce-forward-origin
Jul 17, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
aspalagin:fix/telegram-debounce-forward-origin

Conversation

@aspalagin

@aspalagin aspalagin commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #108466

What Problem This Solves

Fixes an issue where Telegram users forwarding multiple messages within one inbound debounce window would lose per-message source attribution. Mixed and multi-origin batches could be presented to the agent as the forwarding user's own text or be attributed entirely to the first forwarded source.

Why This Change Was Made

The Telegram debounce path now carries the original messages into the Telegram context owner, which formats each segment with its own visible forward origin. Forward-origin visibility is evaluated per segment, the synthetic batch no longer inherits the first message's origin, and single-message debounce flushes retain their existing structured forwarding metadata. The agent-facing body is built from those attributed segments while the command body remains plain.

User Impact

Agents can distinguish ordinary text from forwarded content and identify each visible source correctly, including forwarded media-only segments. Group context-visibility rules continue to redact origins that are not allowed.

Evidence

Redacted live Telegram proof

Candidate 19d0e34bb247c610e9bd0411fb1820fd2ff81903 was run with a temporary BotFather bot, an isolated candidate gateway/state/config/workspace, and a localhost-only deterministic OpenAI Responses mock. Two real text-only Telegram forwards from distinct public origins were sent in one burst.

Observed pipeline:

2 real Bot API updates (38 ms apart) -> 1 debounce batch -> 1 dispatch -> 1 model POST -> 2 distinct forward origins in the current agent-facing turn

Redacted runtime facts:

  • Both real Bot API updates were observed exactly once.
  • One Telegram inbound/queue item/run and one model POST were observed; debounce failures: zero.
  • Fresh-state transcript inspection found exactly two [Forwarded from ...] segments with two distinct origins in the current user turn, not history.
  • The agent-facing turn did not contain the untrusted-metadata envelope.
  • Source contents, temporary bot username, and token were redacted.
  • The temporary bot was deleted through BotFather, its token file was removed, and all isolated processes were stopped. No production bot or gateway was modified.

After the proof, the branch was rebased onto current main 0903ebe4fa5f4643aaf83e3d59cc5518f80db448. git range-diff marks both commits unchanged (=), the combined patch-id remains 1dd854185e513d08949795a1749bf549112cef1d, and the six-file numstat is identical. Current head: 472af1a2beb6f3d15fc767cb5df2a5052ef6bc39.

Automated verification on current head

  • node scripts/run-vitest.mjs extensions/telegram/src/bot-message-context.forwarded-batch.test.ts extensions/telegram/src/bot.create-telegram-bot.test.ts
    • 2 test files passed, 124 tests passed.
    • Covers two distinct origins, mixed ordinary/forwarded text, group visibility redaction, media-only forwards, single-forward debounce, and the downstream agent-facing body while preserving a plain command body.
  • pnpm check:test-types passed all three phases (core-test, extensions-test, root-test).
  • git diff --check origin/main...HEAD passed.
  • Local Codex autoreview completed with findings: [], patch correct, confidence 0.88.

AI-assisted: yes, implemented and reviewed with Codex. I reviewed the resulting code and understand the behavior and security boundary.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M labels Jul 16, 2026
@aspalagin
aspalagin force-pushed the fix/telegram-debounce-forward-origin branch from 9a658b1 to 7c45116 Compare July 16, 2026 12:20
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 1:40 PM ET / 17:40 UTC.

Summary
The PR carries each original Telegram message through multi-entry debounce processing and renders visible forward attribution per segment while keeping command text plain.

PR surface: Source +50, Tests +273. Total +323 across 6 files.

Reproducibility: yes. On current main, enable Telegram inbound debounce and forward multiple messages with different origins within one window; source inspection shows the multi-entry synthetic message cannot retain those per-message origins, matching the linked report.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #108466
Summary: This PR is the focused candidate fix for the linked Telegram debounce forward-origin bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • No automated repair is needed; the PR has no actionable finding and can proceed through the normal exact-head merge and check gates.

Security
Cleared: The patch does not broaden permissions or expose denied origins; it reuses the existing supplemental-context visibility decision independently for each forwarded segment.

Review details

Best possible solution:

Keep single-message forwarding metadata unchanged, but have multi-entry debounce batches preserve their ordered source messages and let the Telegram context owner apply per-segment visibility and attribution, as this patch does.

Do we have a high-confidence way to reproduce the issue?

Yes. On current main, enable Telegram inbound debounce and forward multiple messages with different origins within one window; source inspection shows the multi-entry synthetic message cannot retain those per-message origins, matching the linked report.

Is this the best way to solve the issue?

Yes. Passing original messages to the existing Telegram context owner is safer than prefixing text inside the debounce runtime because it preserves ordering, media placeholders, visibility filtering, and plain command parsing in their existing ownership boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cb84dc76fc05.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides redacted after-fix live Telegram output with real Bot API updates, one debounce dispatch, and two distinct forward origins in the current agent-facing turn, resolving the earlier proof request.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides redacted after-fix live Telegram output with real Bot API updates, one debounce dispatch, and two distinct forward origins in the current agent-facing turn, resolving the earlier proof request.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes incorrect Telegram agent context for users who opt into inbound debounce, with meaningful but limited channel-specific blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides redacted after-fix live Telegram output with real Bot API updates, one debounce dispatch, and two distinct forward origins in the current agent-facing turn, resolving the earlier proof request.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides redacted after-fix live Telegram output with real Bot API updates, one debounce dispatch, and two distinct forward origins in the current agent-facing turn, resolving the earlier proof request.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The change affects observable attribution produced from real Telegram forwards and is suitable for Telegram-visible proof, which the contributor has now supplied.
Evidence reviewed

PR surface:

Source +50, Tests +273. Total +323 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 66 16 +50
Tests 2 273 0 +273
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 339 16 +323

What I checked:

  • Current-main reproduction path: Current main derives forwarding context from the single synthetic message and sends plain bodyText as the agent-facing body; the debounce multi-entry path therefore has no representation for each original message’s distinct forward origin. (extensions/telegram/src/bot-message-context.session.ts:239, cb84dc76fc05)
  • Owner-boundary fix: The branch strips the misleading inherited origin from the synthetic batch and passes the ordered original Telegram messages into the Telegram context owner, where visibility and formatting already belong. (extensions/telegram/src/bot-handlers.inbound-debounce.runtime.ts:154, 472af1a2beb6)
  • Per-segment regression coverage: New context tests cover mixed ordinary and forwarded text, distinct origins, group visibility redaction, and media-only forwards; bot-level tests also preserve the existing structured metadata for a single forwarded debounce entry. (extensions/telegram/src/bot-message-context.forwarded-batch.test.ts:1, 472af1a2beb6)
  • Real Telegram behavior proof: The updated PR body reports two real Bot API forwards from distinct public origins arriving 38 ms apart, one debounce batch and model request, and two distinct redacted forward-attribution segments in the current agent-facing turn; the branch was subsequently rebased with an unchanged patch-id. (472af1a2beb6)
  • Validation state: Focused Telegram tests report 124 passing tests, test type checks and diff checks passed, and the current-head CI gate, channel boundary, security, and real-behavior-proof checks are successful. (extensions/telegram/src/bot.create-telegram-bot.test.ts:1496, 472af1a2beb6)
  • Feature history: The relevant current-main file history includes shared supplemental-context work, forwarded-timestamp handling, Telegram inbound-context construction, and recent Telegram-local type refactoring, providing clear routing candidates. (extensions/telegram/src/bot-message-context.session.ts:1, 1507a9701b83)

Likely related people:

  • obviyus: Repeatedly maintained Telegram inbound context, group-history, ambient-context, and dispatch behavior in the central session module. (role: recent area contributor; confidence: high; commits: 5841087cb9ab, 63cbb35, 3ad465d; files: extensions/telegram/src/bot-message-context.session.ts)
  • steipete: Introduced and refactored the shared inbound supplemental-context and visibility path that owns forward-origin filtering and rendering. (role: shared context-path introducer; confidence: high; commits: 1507a9701b83, 0185d0d2acc8, 9aa4684; files: extensions/telegram/src/bot-message-context.session.ts)
  • vincentkoc: Recently localized Telegram implementation types and maintained nearby prompt-media and inbound metadata behavior. (role: recent adjacent owner; confidence: medium; commits: e311943700ae, ba36291, 003d310; files: extensions/telegram/src/bot-message-context.session.ts, extensions/telegram/src/bot-message-context.types.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-16T12:29:50.545Z sha 7c451163814d6532cd4398e4cd5f1151d2ae0d7a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T16:58:04.756Z sha 472af1a2beb6f3d15fc767cb5df2a5052ef6bc39 :: needs maintainer review before merge. :: none

@aspalagin
aspalagin force-pushed the fix/telegram-debounce-forward-origin branch 2 times, most recently from 19d0e34 to 472af1a Compare July 16, 2026 16:51
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 16, 2026
@steipete steipete self-assigned this Jul 17, 2026
@steipete
steipete force-pushed the fix/telegram-debounce-forward-origin branch from 472af1a to b18e238 Compare July 17, 2026 05:39
@steipete
steipete merged commit 5e13f45 into openclaw:main Jul 17, 2026
112 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…#108985)

* fix(telegram): preserve forward origins in debounce batches

* fix(telegram): deliver batched forward origins to agent

* refactor(telegram): keep debounce forward cleanup local

Co-authored-by: Arseniy Palagin <[email protected]>

---------

Co-authored-by: Arseniy Palagin <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
obviyus pushed a commit to iridescentWen/openclaw that referenced this pull request Aug 14, 2026
When multiple Telegram messages arrive during an active agent turn, the
inbound debounce spool merges them into one synthetic message built from
the first entry, so only that entry's reply_to_message/quote survived.
A quote-reply sent as a follow-up was silently dropped from the prompt.

Give reply-target visibility a single owner and apply it to every buffered
message, appending recovered targets to the reply chain keyed by message id.
This mirrors the per-entry handling forward origins already received in
openclaw#108985 in the same function.

Closes openclaw#121765

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…#108985)

* fix(telegram): preserve forward origins in debounce batches

* fix(telegram): deliver batched forward origins to agent

* refactor(telegram): keep debounce forward cleanup local

Co-authored-by: Arseniy Palagin <[email protected]>

---------

Co-authored-by: Arseniy Palagin <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram debounce coalescer drops forward-origin metadata when batching forwarded messages

2 participants