Repository navigation
fix(telegram): photo albums split into several replies when the Gateway is under CPU load - #163863
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 6:56 PM ET / 22:56 UTC (Revision 6). ClawSweeper reviewWhat this changesThe branch adds bounded checks for queued Telegram album and forward-burst members so slow local processing does not split them into separate replies. Merge readiness✅ Ready for maintainer review This fix remains necessary: current main still flushes albums without checking queued members, and the merged ordering repair addresses a different failure. The live Telegram evidence supports the change, and no blocking introduced defect was found. Priority: P1 Review scores
Verification
How this fits togetherTelegram updates enter a durable queue before the core drain hands them to the plugin. The plugin collects related messages into one agent turn, which produces the chat reply. flowchart TD
A[Telegram updates] --> B[Durable ingress queue]
B --> C[Core conversation drain]
C --> D[Album and forward buffers]
D --> E{Matching members still queued?}
E -->|Yes, before deadline| D
E -->|No, or deadline reached| F[One collected agent turn]
F --> G[Telegram reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +182, Tests +465, Docs +13. Total +660 across 14 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep collection timing in Telegram and expose queued-member facts through the existing core drain, preserving delivery windows and bounded flush deadlines. Do we have a high-confidence way to reproduce the issue? Yes: queue a matching member before the quiet timer expires while delaying its local dispatch. Current-main source flushes the earlier member, and the supplied live base run demonstrates the same failure under CPU contention; this reviewer did not execute it. Is this the best way to solve the issue? Yes: checking already-durable matching input addresses the local-processing delay directly, while enlarging quiet windows would add latency and continue chasing host load. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8db9539ee84a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
f3040d5 to
75d7507
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
33ac7f4 to
75d7507
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
… are pending Albums and multi-message forwards could split into multiple turns when local per-member ingress work exceeded their quiet windows, even though the next members were already durably queued. Expose a pure same-lane backlog read on the core dispatch lifecycle through the existing monitor and plugin SDK types. Telegram replay participants retain that reader so album and forward buffers can match their own pending updates before flushing. The generic debouncer owns asynchronous hold checks, append supersession, and its existing fixed deadline and forced-flush behavior. Keep the 500 ms album and 1 s forward quiet windows. Stop extending album holds after the first member's 20 s hold deadline without shortening its quiet window. Cover durable coalescing, unrelated queued text, backlog filtering, and asynchronous debounce races.
A stalled lane-backlog read could keep an album buffered beyond its fixed 20-second hold deadline. Arm the deadline while reading and fence its flush by the current buffer entry and revision. Clear it when the read settles; member joins retain their fresh quiet timer and late results are ignored. Exercise the real ingress queue with a gated backlog read, proving the buffered member flushes at the deadline and a late result adds no turn.
A matching backlog read resolving near the album hold deadline re-armed a full quiet window, allowing the hold to exceed its bound. Cap that hold re-arm at the remaining deadline, as the SDK debouncer already does. Keep the full delivery quiet window for newly joined members. Extend the existing ingress deadline regression with a matching read released one millisecond before the deadline.
Move deferred-turn and timer setup into the existing coalescing fixture support after combining the album hold and same-sender queue regressions. Preserve every test assertion and keep the E2E file within its line limit.
75d7507 to
2d3e64a
Compare
|
Merged via squash.
|
…ay is under CPU load (openclaw#163863) * fix(telegram): hold album and forward flushes while same-lane members are pending Albums and multi-message forwards could split into multiple turns when local per-member ingress work exceeded their quiet windows, even though the next members were already durably queued. Expose a pure same-lane backlog read on the core dispatch lifecycle through the existing monitor and plugin SDK types. Telegram replay participants retain that reader so album and forward buffers can match their own pending updates before flushing. The generic debouncer owns asynchronous hold checks, append supersession, and its existing fixed deadline and forced-flush behavior. Keep the 500 ms album and 1 s forward quiet windows. Stop extending album holds after the first member's 20 s hold deadline without shortening its quiet window. Cover durable coalescing, unrelated queued text, backlog filtering, and asynchronous debounce races. * fix(telegram): bound album holds while the backlog read is pending A stalled lane-backlog read could keep an album buffered beyond its fixed 20-second hold deadline. Arm the deadline while reading and fence its flush by the current buffer entry and revision. Clear it when the read settles; member joins retain their fresh quiet timer and late results are ignored. Exercise the real ingress queue with a gated backlog read, proving the buffered member flushes at the deadline and a late result adds no turn. * fix(telegram): cap album hold re-arm at the hold deadline A matching backlog read resolving near the album hold deadline re-armed a full quiet window, allowing the hold to exceed its bound. Cap that hold re-arm at the remaining deadline, as the SDK debouncer already does. Keep the full delivery quiet window for newly joined members. Extend the existing ingress deadline regression with a matching read released one millisecond before the deadline. * test(telegram): share deferred ingress fixture setup Move deferred-turn and timer setup into the existing coalescing fixture support after combining the album hold and same-sender queue regressions. Preserve every test assertion and keep the E2E file within its line limit.
What Problem This Solves
Fixes: Telegram photo albums and multi-message forwards split into several agent turns and replies when the Gateway host is under heavy CPU load, even though Telegram delivered every member in a single
getUpdatesresponse.User Impact
User impact: a photo album or forward burst reaches the agent as one turn with one reply on a busy or slow host, as it already does on an idle one. Quiet windows are unchanged (500 ms for albums, 1 s for forwards), so latency on a healthy host is unchanged. There is no new config, storage, or payload change.
Why This Change Was Made
The album and forward quiet timers start at each member's local buffer entry. Members reach the buffer one at a time through the serialized ingress lane: a drain claim pass, then per-member authorize, session state, dispatch-dedupe claim, and reply-chain record. Under CPU starvation those stretched to 0.6–1.7 s per member.
Live probes showed that in 47 of 48 starved member transitions, the next member was already durably spooled before the previous member even entered the buffer. The window was measuring the Gateway's local lane pace, not Telegram's delivery gaps, so enlarging it would only chase load.
Now, when a quiet timer fires, the buffer asks the lane's owner whether a matching member is still pending, and holds instead of flushing if so:
readLaneBacklog()on the dispatch lifecycle. It returns same-lane durable rows not yet handed off. The drain stays the single owner of lane state.createInboundDebouncergains an optionalshouldHoldFlush(items)hook. It is consulted only on quiet-timer expiry before the existing deadline. Appends supersede an in-flight check, explicit flushes bypass it, and a failing check flushes.media_group_idand chat is pending. A fixed 20 s deadline bounds holds, including a stalled read and a hold re-arm. It never shortens the normal window for a member Telegram just delivered.This branch is rebased over #163926, which keeps queued albums alive and ordered per conversation. Its album flush now closes the album's already-reserved collection (
collectionClosed) instead of enqueueing, so both changes compose: holds decide when collection closes, and #163926 owns queue order and claim liveness.Release note context: Telegram photo albums and multi-message forwards no longer split into several replies when the Gateway host is under heavy CPU load.
Evidence
Live Telegram Test Server, DM lane, clawstudio.
send.photosandforwardBurstactions, with unique small photos per album.taskpolicy -b, plus background-band CPU burners that only contend for efficiency cores.Tests. Each new regression fails against the previous production code. The forced-flush and unrelated-backlog controls pass on both.
src/channels/message/ingress-drain-lanes.test.ts, 7 tests). Covers ordering, plus exclusion of self, other lanes, retry-delayed rows, and released claims. Vitest suite 2.8 s on Testbox.src/auto-reply/inbound-debounce.test.ts, 27 tests). Covers re-arm, append supersession, the deadline with resolved and pending checks, and explicit flush bypass. Suite 0.1 s on Testbox. The groupedpnpm test <both files> --maxWorkers=1command took 24.9 s of wall time.extensions/telegram/src/telegram-ingress-coalescing.e2e.test.ts, 21 cases after the rebase, including fix(telegram): back-to-back photo albums replay or arrive out of order while the agent is busy #163926's; command 39.3 s on Testbox before the shared harness moved intotelegram-ingress-coalescing-fixture.test-support.tsto satisfy max-lines). Covers album and forward holds, an unrelated plain-text control, a deadline that bounds a stalled backlog read, and a deadline that caps a hold re-arm.extensions/telegram/src/bot.create-telegram-bot.channel-post-media.test.ts, 20 tests). Adapted to asynchronous queue admission after the backlog read. Suite 1.8 s on Testbox, run withbot.create-telegram-bot.test.tsin a 77.4 s command.CI notes.
QA Smoke CI (profile 2/4)failed insubagent-empty-completion-recovery(subagent finalization, untouched here). It passed on the rebased head.checks-ui-e2efailed on the rebased head, and on unrelated PRs, inboard-mcp-app.e2e.test.ts. That was red main from fix(ui): confirm app messages inside the app view instead of a native dialog #164493: a board-leveldisplay: blockcollapsed the fullscreen MCP App frame. It was fixed directly on main in 11515ce, and this PR touches no UI files.Gates.
tsgo:core,tsgo:extensions, oxlint, oxfmt,plugin-sdk:check-exports, andplugin-sdk:surface:checkpass.plugin-sdk:api:diffshows no entrypoint additions or removals; the change is an additive optional member and an optional hook.