Skip to content

fix(telegram): chain over-limit stream previews#74508

Merged
obviyus merged 1 commit into
openclaw:mainfrom
anagnorisis2peripeteia:fix/telegram-reasoning-overflow
May 8, 2026
Merged

fix(telegram): chain over-limit stream previews#74508
obviyus merged 1 commit into
openclaw:mainfrom
anagnorisis2peripeteia:fix/telegram-reasoning-overflow

Conversation

@anagnorisis2peripeteia

@anagnorisis2peripeteia anagnorisis2peripeteia commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Chain over-limit Telegram draft previews into continuation messages instead of stopping the stream.
  • Retain completed overflow preview pages while stale race-superseded previews still get cleaned up.
  • Rebase onto current main and drop the unrelated throttling, QQBot, CLI, and generated-baseline changes.

Verification

  • pnpm test extensions/telegram/src/draft-stream.test.ts extensions/telegram/src/bot-message-dispatch.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md extensions/telegram/src/draft-stream.ts extensions/telegram/src/draft-stream.test.ts extensions/telegram/src/bot-message-dispatch.ts extensions/telegram/src/bot-message-dispatch.test.ts
  • pnpm check:changed

Real behavior proof

  • Behavior addressed: Telegram draft stream previews that cross Telegram's 4096-character message limit should continue in a new Telegram message instead of stopping the stream.
  • Real environment tested: Real Telegram private group using the skill-local SUT and driver bot credentials against this PR branch at d2ac4ea.
  • Exact steps or command run after this patch: Ran a local Node/tsx live probe that imports this PR's extensions/telegram/src/draft-stream.ts, wires it to real Telegram Bot API sendMessage, editMessageText, and deleteMessage, sends a 4050-character first preview, then updates to 5050 characters in the live group.
  • Evidence after fix: Terminal output from the live probe:
{
  "ok": true,
  "runMarker": "PR74508-mowx7yo3",
  "firstUpdateLength": 4050,
  "overflowUpdateLength": 5050,
  "sentMessages": [
    { "messageId": 5422, "length": 4050 },
    { "messageId": 5423, "length": 1000 }
  ],
  "retained": [{ "messageId": 5422, "length": 4050, "retain": true }],
  "warnMessages": [],
  "cleanup": [
    { "messageId": 5422, "ok": true },
    { "messageId": 5423, "ok": true }
  ]
}
  • Observed result after fix: Real Telegram accepted two SUT messages for the overflowing preview, the first completed preview page was retained, no over-limit warning fired, and both probe messages were deleted afterward.
  • What was not tested: Strict driver-observed bot-to-bot reply detection, because the driver bot saw zero updates even while the SUT sent messages. The changed real Telegram draft-stream transport behavior was tested directly.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS labels Apr 29, 2026
@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
Review failed before ClawSweeper could summarize the requested change.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Real behavior proof
Not applicable: Real behavior proof was not assessed because the Codex review failed.

Next step before merge
Review did not complete, so no work-lane recommendation was made.

Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)

Remaining risk / open question:

  • No close action taken because the review did not complete.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 30e079dd89b4.

@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from 69cf98b to b07fa2c Compare April 29, 2026 22:51
@openclaw-barnacle openclaw-barnacle Bot added size: L agents Agent runtime and tooling and removed size: M labels Apr 30, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from e1f14a1 to d71b634 Compare May 1, 2026 09:29
@anagnorisis2peripeteia
anagnorisis2peripeteia marked this pull request as ready for review May 1, 2026 09:45
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from d62caa9 to dfb9139 Compare May 1, 2026 10:33
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from dfb9139 to c9eba64 Compare May 1, 2026 11:07
@anagnorisis2peripeteia
anagnorisis2peripeteia marked this pull request as draft May 1, 2026 12:01
@anagnorisis2peripeteia

anagnorisis2peripeteia commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Scope change -- pivoting to per-account API queue

Marking as draft while this is overhauled.

Original approach: chain overflow reasoning messages and halve draft stream edit frequency when the Telegram message length limit is hit.

Why that's insufficient: the 1000ms throttle (and any reduction) operates per-dispatch. Ten concurrent sessions on the same bot account each behave individually but collectively can still burst past Telegram's ~30 req/sec account-level limit. Throttling per-message doesn't fix a per-account resource.

New approach: per-account token bucket queue wrapping all mutating Telegram API calls (editMessageText, sendMessage, sendChatAction) for a given bot account:

  • ~25 tokens/sec (conservative under the 30/sec global cap)
  • On 429, enforce the retry_after delay account-wide -- all concurrent sessions pause together since it's a shared limit
  • Streaming edits continue to coalesce before entering the queue (existing throttle handles that), so an active stream contributes ~1-2 queue entries/sec
  • Natural backpressure: overflow behaviour (message chaining) becomes a fallback for when a single message hits the 4096 char limit, not a rate-limit workaround

The existing draftLaneEventQueue already serialises correctly within a single dispatch. The gap is that it's not shared across concurrent dispatches on the same account. This change lifts that coordination to the account layer.


Update (May 7): Per-account queue is future work. Current HEAD (6687524823) addresses immediate ClawSweeper findings:

Fixed: adaptive throttle wired into send gate (getAdaptiveThrottleMs()), direct pausedUntil hard block before gate (fixes bypass via fresh chats with lastSentAt: 0), config baseline hashes regenerated.

Remaining: P2 per-account scoping (acknowledged, out of scope for this PR), P2 stale hashes (rebase concern, will regenerate before merge), P3 gate retry timing (low priority). All 35 tests pass.

@anagnorisis2peripeteia anagnorisis2peripeteia changed the title fix(telegram): chain reasoning messages on overflow instead of stopping fix(telegram): share per-token API throttler across polling and CLI; handle reasoning overflow May 1, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia marked this pull request as ready for review May 1, 2026 12:38
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup. channel: qqbot labels May 1, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from a390eec to efce48e Compare May 1, 2026 21:15
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label May 1, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from d78a974 to dd845b5 Compare May 4, 2026 00:41
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from dd845b5 to 928083f Compare May 4, 2026 00:59
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label May 4, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia marked this pull request as draft May 4, 2026 10:57
@anagnorisis2peripeteia
anagnorisis2peripeteia marked this pull request as ready for review May 4, 2026 11:58
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from 55c084a to 0b72bbd Compare May 4, 2026 12:27
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label May 4, 2026
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the fix/telegram-reasoning-overflow branch from ab2c26b to 159ca85 Compare May 6, 2026 23:06
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 6, 2026
@anagnorisis2peripeteia anagnorisis2peripeteia changed the title fix(telegram): share per-token API throttler across polling and CLI; handle reasoning overflow fix(telegram): reasoning overflow chaining, per-token throttler, QQBot SSRF guard May 6, 2026
@anagnorisis2peripeteia

Copy link
Copy Markdown
Contributor Author

Combined test branch available: 5.6+claude-cli-telegram-reasoning based on v2026.5.6 with both #71817 and #74508 cherry-picked on top.

If you'd like to try both fixes together:

npm install -g anagnorisis2peripeteia/openclaw#5.6+claude-cli-telegram-reasoning

What's included:

  • reasoningDefault config now respected for Telegram/Feishu -- set "reasoningDefault": "stream" in openclaw.json and Claude's extended thinking streams in channel replies without needing /reasoning stream per session
  • Reasoning overflow chains to a new message instead of truncating
  • Adaptive throttle with account-wide 429 backoff propagation
  • QQBot SSRF guard on API endpoints

Feedback welcome -- especially on how the reasoning stream behaves during long thinking blocks and whether the overflow chaining feels natural.

@obviyus

obviyus commented May 8, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Scoped tests: pnpm test extensions/telegram/src/draft-stream.test.ts extensions/telegram/src/bot-message-dispatch.test.ts; pnpm check:changed; git diff --check
  • Live proof: Telegram draft-stream overflow probe via skill credentials, 4050-char preview plus 1000-char chained continuation, no Telegram over-limit warning
  • Changelog: CHANGELOG.md updated
  • Land commit: d2ac4ea
  • Merge commit: 10bbed8

Thanks @anagnorisis2peripeteia!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram proof: supplied External PR includes structured after-fix real behavior proof. size: S triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants