Repository navigation
fix(channels): preserve messages stalled before adoption - #132409
PollyBot13 wants to merge 4 commits into
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, 3:10 PM ET / 19:10 UTC (Revision 18). ClawSweeper reviewWhat this changesThe branch preserves stalled incoming messages until dispatch and deferred bookkeeping settle, keeps owner-aborted Telegram updates replayable, and retires watchdog waits during disposal. Merge readiness✅ Ready for maintainer review This remains a useful landing candidate: current main and v2026.9.8 still lack the dispatch-settlement fence. No concrete introduced defect was found, and the recorded production-path proof remains relevant to the reconciled implementation. Priority: P1 Review scores
Verification
How this fits togetherChannel transports durably queue incoming messages before the shared ingress drain dispatches them to agent turns. Claim settlement and Telegram replay bookkeeping determine whether stalled messages remain recoverable or become completed records. flowchart LR
A[Incoming channel message] --> B[Durable ingress queue]
B --> C[Claim and dispatch]
C --> D{Turn adopted?}
D -->|Yes| E[Complete claim]
D -->|Watchdog expires| F[Wait for old dispatch]
F --> G[Release for ordered retry]
F -->|Monitor stops| H[Retain for successor recovery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +250, Tests +498. Total +748 across 17 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep one shared settlement owner that safely retries quiescent attempts, preserves unfinished claims for successor recovery, and allows unrelated conversations to progress. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the race: hold a pre-adoption dispatch beyond the watchdog and current main releases its claim before that dispatch settles. This read-only review did not execute a failing current-main run. Is this the best way to solve the issue? Yes. The patch repairs the shared settlement owner and Telegram tracker at their existing boundaries while retaining the canonical retry policy and restart recovery path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bdd44c5260d1. 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 (17 earlier review cycles; latest 8 shown)
|
7db767c to
3cdb9d5
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Preserve terminal quiescence before retry while retaining upstream joined shutdown settlement.
|
Reconciled this PR with current This update is also in response to the stale notice. I cannot remove the |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
We've been running this fix in production on a self-hosted multi-agent gateway (Discord + Telegram, ~20 agents) since 2026.9.5, and it's still needed on v2026.9.7. In stock 9.7, We rebased the PR onto v2026.9.7 (c074824). Three things needed adjusting for 9.7, in case it helps the rebase here:
Gate: 2× Happy to share the rebased diff if it's useful. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
Carries openclaw#132409 ("fix(channels): preserve messages stalled before adoption", open; issue openclaw#127229, P1 message loss) onto the 9.6 carry. Applied as diff(9a4114b..217ef6a), the PR's own base to its Sept 10 head, by 3-way merge onto 1d5d6c8. Why that head and not the Sept 27 merge head cc8f0d0: the 9.6 tag's ingress files equal main of 2026-09-22 (814a7e7). cc8f0d0 merges main of 09-27 and integrates the PR with openclaw#158637's claim custody through settlement, which the tag does not have; applied here it conflicts in 4 production files. 217ef6a predates openclaw#158637, applies with one import conflict, and has a green hosted CI run (34543782080). The 09-27 head adds an abort-aware quiescence wait and idle-wake accessors that only openclaw#158637's retained owner and main's reworked monitor use. On this tree the owner is deregistered at abort, so a replacement drain recovers the claim at once; settleStalledClaim checks isStopped() only between attempts, so an attempt already waiting for quiescence still makes its one release write after stop, and the claim token fences that write. What it fixes on the bots: a second update from the same chat waits in grammY sequentialize behind a deferred handler with no heartbeat. At the 300 s adoption watchdog the drain released it for retry while the first callback was still blocked; the retry met the in-process update tracker as a duplicate, returned no outcome, and the row was completed without a recorded processing outcome (rh-bot, updates 735980139 and 735980143, 2026-09-29). Now the stalled claim keeps its lease and heartbeat until the old dispatch and deferred bookkeeping quiesce, then settles the retry; a separate stall-settlement wake repumps the monitor; Telegram's tracker records an owner-aborted deferred update as incomplete. Conflict resolution: - ingress-monitor.ts: import-only; the fork's split imports kept, the wake scheduler import added. - ingress-drain.watchdog.test.ts: main's two tests added after 09-08 kept; in the PR's rewritten "rearms a live deferred wait" test the tag's 1_666 ms heartbeat-cadence assertion is kept (cc8f0d0 dropped it). - polling-session.test.ts: the PR's hunk for "requeues buffered spooled claims when deferred processing times out" is not applied. At the tag the deferred participant settles itself on owner abort (openclaw#150080), so the claim is released at the stall without a manual settle; main later deleted the test (openclaw#155040). ingress-drain.ts equals 217ef6a plus exactly the tag's own 09-08..09-22 drift; drain-state, drain-wake, drain.test, zalouser and mattermost tests are byte-identical to 217ef6a. Original implementation by PollyBot13, with the maintainer fixup in 217ef6a; see openclaw#132409. Drop this commit when an upstream equivalent reaches the fork's base tag.
…-cap ratchet check:line-cap-ratchet --base 1d5d6c8 refused the carry: the PR's test changes grew three files that are already over the cap here (upstream main has since shrunk them). bot.create-telegram-bot.test.ts 5953 -> 5994, polling-session.test.ts 3889 -> 3895, webhook.test.ts 2839 -> 2841. - The PR's new update-tracker test moves unchanged into bot.create-telegram-bot.spooled-owner-abort.test.ts, on the same harness; bot.create-telegram-bot.test.ts is back to its 1d5d6c8 blob. - polling-session.test.ts drops its local copy of waitForAbortSignal for the SDK's (openclaw/plugin-sdk/runtime, same behavior). - webhook.test.ts builds its message fixture with the spool test-support's directUpdate(id, 111, text), the same fields, and drops its local type. No test is removed or weakened. Ratchet OK; webhook 111/111, polling-session 81/81, bot.create-telegram-bot 163/163, the new file 1/1.
A dated section for the four commits on top of the deployed 1d5d6c8: why version-3 carriers lost the Telegram body in the 9.6 pull-forward of openclaw#151099 and what carrierText changes; why openclaw#132409 is carried at its 09-10 head 217ef6a and not cc8f0d0, with the conflict resolutions and the held-lane behavior change on channels that hold the lane; the line-cap ratchet fix; the review findings fixed and left; and the validation on this tree, including the two changed-gate failures shown byte-identical at 1d5d6c8. Records rh-bot's unbuilt ad67756 and the local variant branch that carries the same four commits onto it.
|
I am experiencing this same bug in 9.2 as well |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
Merge current main while retaining dispatch/deferred quiescence and token-fenced settlement. Retire watchdog-owned release waits on direct disposal and recheck drain authority immediately before delayed retry release. Preserve main's finalization and early ownership registration, remove the unused monitor import, and adapt the inspection fixture to retained claim ownership. Extract cohesive private watchdog and Telegram test helpers to satisfy current file-growth ratchets without dropping coverage or changing suite fixture order. Validated with 346 focused tests, post-extraction core/transport cases, the failing-before direct-disposal regression, changed-file gates and independent ownership review. No queue schema, dependencies or runtime deployment changes.
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
…un found Upstream tests that fail alone on the base a1ccb69 and pass alone on bare v2026.10.5 because they assert behaviour the fork changes on purpose. Each pin passes here and fails with the fork code reverted to 10.5's. - main-session-recovery-yield: the kept dead-generation fence rule (Alex, 2026-10-21) settles the other-generation fence, so the claim is not_required. - ingress-monitor.admission: openclaw#132409 keeps the claim fenced through the stall watchdog. 10.5 moved this test here from the deleted ingress-monitor.inspection.test.ts, whose fork pin the carry dropped. - server.health-store-scheduling: openclaw#89526 re-collects health when a config publication lands mid-collection; the test waits for in-flight collections before counting reads. - telegram-recovery-notice-send: fork #13 claims a restart only for a cycle with cause gateway_restart. - gateway-tool.assembly: a non-owner turn sees a refusing gateway stub (owner-only tool stubs); the real tool stays off its authorized surface. - run.plugin-runtime-refresh: the fork's silent-stop nudge adds a third attempt for message-tool-only turns; media and provenance assertions are unchanged.
…claim hold telegram-ingress-coalescing.e2e.test.ts > "keeps a timed-out update retryable while its original middleware is still waiting" fails on the stack, on 3eefd13 and on the deployed 11.1 carry (eee763b), and passes on bare v2026.11.2. Upstream added it with openclaw#169202 (6d624f3, 2026-10-15). There the stall watchdog re-queues a timed-out update as pending with handler-timeout while its original middleware still waits, and the retry records "Telegram update processing is still pending" until the original returns. The fork carries upstream openclaw#132409 (closed upstream unmerged; carried since da9b206fc93, now through 1e127ad). Its stall watchdog (ingress-drain-watchdog.ts) releases the timed-out claim only once the original dispatch has quiesced (beforeRetryRelease -> waitForQuiescenceOrStop). The test pinned openclaw#169202's in-between state, so it cannot pass with openclaw#132409. Alex chose to keep openclaw#132409, so the upstream test is replaced by a pin of the fork's behavior, marked FORK DIVERGENCE (openclaw#132409): "holds a timed-out update's claim until its original middleware returns, then retries it once". The pin lives in a new fork-only file, extensions/telegram/src/telegram-ingress-claim-hold.e2e.test.ts, with the subset of the coalescing harness a text-only case needs (the same mocks, fixture and import order). The upstream file was already over the 1,000-line test cap at the tag (1,014 counted lines, so oxlint max-lines fails on it). Moving the replaced case out brings it to 928, and later upstream merges of that file only see the case removed. The assertions are what an instrumented run measured on the stack: - at 300 s the watchdog has fired, and 802 is still claimed with attempts 0 and no lastError. It is not pending and not failed. - 803, admitted then, stays pending behind it, and 802 is not handed to handleUpdate again. - after 801 finishes and the drain runs, handleUpdate has seen 802, 802, 803 (the original, then the one retry), and the downstream turns are "busy turn", "deliver this later", "deliver after the retry". - nothing is left pending, claimed or failed, both updates are tombstoned, and a redelivered 802 is skipped. The same measurement shows no message loss: the update is processed once, and in order. Proof (M4, Node 26.12.1, node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts <file>), on 1daeda2 plus this commit: - telegram-ingress-coalescing.e2e.test.ts 20/20 passed. telegram-ingress-claim-hold.e2e.test.ts 1/1 passed. - Red check (throwaway commit): with the watchdog's quiescence wait skipped (env toggle), the pin fails at the 300 s assertion, because 802 is already pending with lastError "Channel ingress claim->adoption stalled for event 802 ... (handler-timeout)". Without the toggle it passes. - Gates: check-line-cap-ratchet --base v2026.11.2 rc 0, run-oxlint on both files rc 0, check-test-mock-exports --base v2026.11.2 rc 0 (the new file's three isolating mocks carry mock-isolation reasons), tsgo:extensions:test rc 0, and oxfmt --check on both files rc 0.
Related: #127229
Supersedes #120419 with @Grynn’s agreement.
What Problem This Solves
Fixes silently lost channel messages when delivery stalls before turn adoption and retry races the original dispatch or deferred transport bookkeeping.
User Impact
Stalled messages remain recoverable and replay in lane order. Unrelated conversations continue, and monitor shutdown leaves an unfinished claim recoverable by its successor. An abort-ignoring participant can still hold its own lane until it settles or the monitor restarts: this is the preservation-first policy accepted by @Patrick-Erichsen on September 10, not a new policy in this reconciliation.
Why This Change Was Made
The shared drain retains claim ownership and heartbeat until dispatch/deferred bookkeeping quiesces. Dispatch-idle observation stays separate from watchdog settlement. Telegram treats an owner-aborted deferred update as incomplete rather than consuming its replay watermark.
The October 3 reconciliation merges main without rewriting contributor/maintainer history. It preserves main’s adoption finalization, early ownership registration, token-fenced writes and joined disposal. It also cancels a watchdog-owned wait on direct disposal and checks live drain authority immediately before delayed retry release; ordinary late terminal settlements retain their existing contract. Retry backoff remains measured from durable release, not from the watchdog deadline.
No queue schema, dependencies, routing or production Gateway changes. Cohesive private helper/test-support extractions satisfy current main’s file-growth ratchets without removing coverage or changing suite fixture order; the existing polling state-wait helper moves unchanged into its test-support module.
Evidence
Current reconciliation
606f04bfa59b744c17b5ec26679de940442904d6; integrated main:66cbf25fa6243566a1965c4a4906f588af7c8e3b.queue.releaseonce. Both pass after the fix, with the durable row still claimed and its attempt count unchanged. Tests cover no external signal and a still-live external signal, while existing late-terminal-settlement tests remain green.reviewer_unavailable/engine failure and is not represented as completed review coverage.Historical isolated Gateway proof (not this head)
At
4250c7a56bed066a5b1a52977c18f4ccf0a5dfd6, an ephemeral built Gateway exercised production Telegram ingress against a loopback Bot API and repository mock OpenAI provider. A 1,000 ms watchdog fired at 1,002 ms; provider admission and outgoing replies were ordered first, recovered stalled message, follower, with the stalled marker admitted exactly once. Gateway cleanup completed; no real Telegram account or production service was used.{ "head": "4250c7a56bed066a5b1a52977c18f4ccf0a5dfd6", "passed": true, "transport": "loopback Telegram Bot API", "runtime": "ephemeral Gateway, repository mock OpenAI provider", "watchdogObserved": true, "providerMarkerOrder": ["PR132409-FIRST-DONE", "PR132409-STALLED-RECOVERED", "PR132409-FOLLOWER-DONE"], "outboundTexts": ["PR132409-FIRST-DONE", "PR132409-STALLED-RECOVERED", "PR132409-FOLLOWER-DONE"] }This historical full-Gateway proof is not an exact-head or authenticated Telegram service claim. Current reconciliation proof is the actual shared-drain/monitor and transport boundary tests above; fresh hosted CI/review and maintainer landing remain separate gates.
Owner acceptance
AI-assisted implementation and validation under human authorization. Original implementation: @PollyBot13. Maintainer compatibility work: @steipete and @Kimiyu-186; contributor ancestry retained.
Historical maintainer collaboration: existing review session.