Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Codex review: needs real behavior proof before merge. Reviewed August 28, 2026, 6:44 AM ET / 10:44 UTC. ClawSweeper reviewWhat this changesThe branch records a successful Telegram durable send and uses that attempt-bound fact when deciding whether a retryable processing failure may replay the inbound message. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 4 items remain The patch is not on current main and plausibly fixes the deferred ambient-frame read; it remains human-blocked because its Telegram delivery/replay behavior has only mock-style proof. Priority: P1 Review scores
Verification
How this fits togetherTelegram ingress creates per-update processing state before dispatching a reply turn. The turn is either durably adopted for agent execution or abandoned for replay; reply delivery informs whether replay would duplicate a user-visible answer. flowchart LR
A[Telegram update] --> B[Ingress processing frame]
B --> C[Reply dispatch]
C --> D{Adopt or abandon}
D -->|adopt| E[Agent reply delivery]
D -->|abandon| F[Replay decision]
E --> G[Visible send fact]
G --> F
Before merge
Agent review detailsSecurityNone. PR surfaceSource +49, Tests +242. Total +291 across 5 files. View PR surface stats
Review metrics
Proof path suggestionA redacted Telegram Desktop run would directly establish whether a timed-out/retried update produces exactly one final reply. Mantis is proof-only, so it must not be asked to change code or mutate GitHub state. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep the captured-frame repair, add a crash-window or restart-replay test that performs the actual send, and attach redacted after-fix Telegram or mock-gateway evidence. Do we have a high-confidence way to reproduce the issue? No: the checked-in tests establish source-level behavior, but no high-confidence after-fix Telegram delivery/replay reproduction is supplied. Is this the best way to solve the issue? Yes, provisionally: capturing the processing frame before deferred settlement directly addresses the ambient-read flaw, subject to transport-boundary proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against df905a6cb652. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
A spooled update whose turn exceeds the 5-minute adoption watchdog settles failed-retryable and releases its dispatch-dedupe claim, so the spool redelivers it. If that attempt had already sent a reply, the retry ran the whole turn again and replied a second time. Observed in a live group, one source message answered twice: 14:19:08 outbound send ok messageId=13018 replyToMessageId=12949 14:19:20 outbound send ok messageId=13020 replyToMessageId=12949 Record the visible-delivery fact where it is known - the single chokepoint that fires on a confirmed successful send - and read it at settlement. A retryable failure that already spoke now commits the replay guard instead of releasing it, so the redelivery is duplicate-suppressed. The default is deliberately false when no update frame is active: a false negative costs a duplicate reply, a false positive would silently drop the user's message, and silent loss is the worse failure. This is the invariant openclaw#127090 does not cover. That commit guards against entering the reply pipeline after the ingress owner fences an attempt; it does not prevent re-running a turn that already completed a visible dispatch. Tests: 4 new frame-level cases covering record/read, nested-middleware sharing, cross-update isolation, and the no-frame default. 193/193 existing telegram tests still pass. (cherry picked from commit 1db5e14)
ClawSweeper's P1 on 630973362846, reproduced: the delivery mark was read ambiently at settlement, so it was wrong on both sides. It missed its own target case. Settlement is reached from bot-message.ts:439-446, the retained onAbandoned callback invoked by the reply queue at src/auto-reply/reply/queue/types.ts:348, outside the update frame -- and that is the deferred-phase watchdog path this change exists to fix. The read returned false there and the guard still released. It could also drop a message, which the previous body wrongly ruled out. Because getStore() resolves at call time, update A's settlement running inside update B's frame reads B's mark; if B replied and A did not, A's guard commits and A is silently dropped. Reachable: the reply-queue drain never detaches its async context (drain.ts:1267-1272 swaps only the callback, self-reschedules from its own finally at :1535/:1538/:1548), so one starter's context spans drain cycles. captureTelegramVisibleReplyDelivered() is called during dispatch setup while the attempt's own frame is current and returns a closure over that frame object, so settlement performs no getStore() at all. Not ClawSweeper's suggested shape, deliberately. getTelegramSpooledReplayDeferredParticipant() (bot-processing-outcome.ts:216) is itself an AsyncLocalStorage read on a second store; both stores are entered around the same bot.handleUpdate region and have identical async lifetime, so moving the fact between them changes nothing about which attempt is read. Settlement lifetime was not the missing property. Neutralize cycle, re-derived independently: 10/10 pass -> 3 failed / 7 passed -> 10/10 pass, restored byte-identical. The three that go red: suppresses the redelivery of an attempt that replied before the queue abandoned it redelivers an abandoned attempt that never replied, even while another update's frame is current answers for its own update while another update's frame is current 298/298 across the changed files plus bot.test.ts and bot.create-telegram-bot.test.ts. Also fixes "behaviour" in shipped code and corrects the comment that asserted the refuted false-negatives-only safety property. Known gap, not closed here: bot/delivery.send.ts:115 confirms sends without recording the fact, so a reply through that funnel still leaves the guard blind. Production +9, tests +197.
6309733 to
7b48abc
Compare
|
Thanks @amittell — I rechecked this on current Proof: I delayed the first model turn, sent a second Telegram DM into the same session, and shortened the adoption watchdog. The watchdog fired for the queued input. That input made zero provider calls and produced zero Telegram replies. It was lost, not answered twice. I also held an accepted Bot API response across an owned Gateway restart; that run made one provider call and delivered one visible reply.
Closing because the duplicate-reply claim is not reproducible on current |
What Problem This Solves
A Telegram turn that has already replied can be replayed from the durable ingress spool and run again, so the user receives the same answer twice.
The trigger is the ingress adoption watchdog. An attempt that does not reach adoption within 5 minutes is settled
failed-retryableand its dispatch-replay claim is released, so the spool redelivers the update. That is correct for an attempt that never reached the user. It is wrong for one that already spoke.Captured on a live gateway, the watchdog naming itself:
300003ms is
DEFAULT_INGRESS_ADOPTION_STALL_MS(src/channels/message/ingress-drain.ts:51, pinned by an existing assertion atingress-drain.test.ts:965), overridable viaOPENCLAW_TELEGRAM_SPOOLED_HANDLER_TIMEOUT_MS(extensions/telegram/src/telegram-ingress-drain.ts:45).Why This Change Was Made
Nothing at the settlement decision knew whether a reply had gone out, so this records the fact where it is known and reads it where it is needed.
logTelegramOutboundSendOk(extensions/telegram/src/send-context.ts:61) is the durable funnel's confirmation point and marks the active update-processing frame; settlement reads that mark and commits the replay guard instead of releasing it.The first revision of this PR read that fact ambiently, and did not work. The ClawSweeper P1 was correct and I have fixed it rather than argued with it.
The mark lives on an
AsyncLocalStorageframe entered aroundbot.handleUpdate(bot-processing-outcome.ts:48, entered attelegram-ingress-drain-factory.ts:68). Settlement is reached two ways:bot-message.ts:455-465and:525, the handler's own await path, inside the frame. The read worked.bot-message.ts:439-446, the retainedonAbandonedcallback invoked by the reply queue atsrc/auto-reply/reply/queue/types.ts:348, outside it. The read returnedfalse.The second is the deferred-phase watchdog case, which is the case this PR exists to fix. So the original patch missed its own target.
It was also unsafe in the other direction, which contradicts what the first revision of this body claimed. Because
getStore()resolves at call time, update A's settlement running inside update B's frame reads B's mark. If B replied and A did not, A's guard commits and A is silently dropped. That is reachable, not theoretical: the reply-queue drain never detaches its async context (src/auto-reply/reply/queue/drain.ts:1267-1272swaps only the callback and self-reschedules from its ownfinallyat:1535,:1538,:1548), so one starter's context propagates across drain cycles and updates.The fix binds the frame instead of resolving it later.
captureTelegramVisibleReplyDelivered()is called during dispatch setup, while the attempt's own frame is current, and returns a closure over that frame object:There is no
getStore()at settlement, so the deferred route reads the right frame and the foreign-frame read becomes unrepresentable.On the review's suggested shape - storing the fact with the deferred participant - I did not take it, and I want to be explicit about why.
getTelegramSpooledReplayDeferredParticipant()(bot-processing-outcome.ts:216) is itself anAsyncLocalStorageread:There are two stores, declared at
:48and:49, entered attelegram-ingress-drain.ts:335andtelegram-ingress-drain-factory.ts:68around the samebot.handleUpdateregion. They have identical async lifetime, so moving the fact between them changes nothing about which attempt a settlement reads. Settlement lifetime was not the missing property: the frame is alive and reachable whenonAbandonedruns, andgetStore()simply returns a different one. Both shapes fix the read; neither fixes the write. Happy to switch if that reasoning is wrong.Only the replay guard is committed. The spool row still follows its own retry and dead-letter policy, and the drain contract is untouched.
User Impact
Users stop seeing the bot repeat itself when a turn outruns the 5 minute watchdog. A message whose turn fails before replying still retries exactly as before, so this does not trade duplicates for lost messages - and with this revision it also no longer risks dropping an unanswered message from an unrelated update.
Operators on tool-heavy or long-context workloads see the largest difference, because those are the turns that outrun the watchdog.
Evidence
Three-beat proof, in the shape the review asked for. Neutralizing the capture back to an ambient read reproduces both production failure modes as ordered traces:
Neutralize cycle, re-derived independently rather than taken on report:
The three that go red, by name:
The middle one is the silent-drop guard, covering the failure the first revision of this body wrongly ruled out.
Suite. 4 files, 298 passed:
bot-processing-outcome.test.ts, the newbot-handlers.message-pipeline.replay-guard.test.ts, plusbot.test.tsandbot.create-telegram-bot.test.ts- the last two included deliberately because a sibling Telegram change broke exactly those with pinned-date fixtures.pnpm check:changed. 18 of 19 lanes green, includingtypecheck extensions,format changed files,plugin boundaries, the dead-export scan and the max-lines ratchet. The 19th,typecheck extension tests, fails on two pre-existing errors inextensions/qa-lab/src/*.cleanup.test.ts(providerReadinessArtifactPathmissing). Those test files were last touched in #127715 and the type requiring the property in #106039; this branch changes no qa-lab file. I could not re-execute that lane on the untouched base to prove it independently - the run was OOM-killed on this machine, which is not a build host - so this is provenance and file-scope rather than a clean re-run, and CI is the better arbiter.Rebased onto current
main(849e35ce36d) from 1,351 commits behind, no conflicts. Suite re-run after the rebase: 299 passed, one more than before, from an upstream test added in the interval.Real-behavior proof: I could not produce one, and the reason is specific rather than a shortage of effort. I wrote a QA Lab scenario for this path (driving the real Telegram plugin over Crabline), ran it in three states with the shipped bundle content verified each time, and it passes with the fix neutralized - so it does not cover the fix and I am not offering it as proof.
The blocker is an ordering fact, not scenario authoring. The claim-to-adoption stall watchdog only fires while the drain claim is
dispatchingordeferred(src/channels/message/ingress-drain.ts:391-422);onAdoptedclears that timer (:449-465) and fires at run start, before the model emits anything (src/auto-reply/reply/agent-runner-execute.ts:294). So no agent answer for a claim can precede that claim's own watchdog, and the confirmed-send arm is unreachable end to end. Genuinely pre-adoption durable sends do exist (dispatch-from-config.finalize.ts:127,get-reply-run-queue.ts:38-46), but the drain adopts callback-free immediately afterwards (ingress-drain.ts:602-608), so landing the watchdog in that window is a race and would be flaky by construction.What would unblock it is what the plugin's own e2e test already has: a controllable Bot API fault after the first visible send (
telegram-ingress-coalescing.e2e.test.ts:356-390stallsgetFilewith a 429). Crabline records provider traffic but exposes no fault-injection seam to a YAML scenario. That is a bounded qa-lab change and explicitly not a production seam. I have not made it here - happy to, if that is the preferred route to closing this checkbox.Size. Production +9, tests +197 over the previous revision of this branch.
A gap this does not close, stated rather than discovered later.
logTelegramOutboundSendOkis not the only confirmation point.extensions/telegram/src/bot/delivery.send.ts:115logstelegram text delivery okand does not record the fact, so a reply delivered through that funnel still leaves the guard blind and the duplicate remains possible on that path. Fixing it is a one-line call in the same shape; I have left it out of this PR because it is a second delivery surface with its own tests and it should not ride in on a P1 repair.Corrections to the first revision of this body. It said no related issue existed - four overlap: #127090 (merged, the direct predecessor that introduced the retry disposition), #128042 (closed, same symptom, mirror mechanism), #127229 (open, same watchdog release path, opposite outcome), and this PR. It reported core ingress at 97/97; the real figure is 100/100 across 7 files. It rendered the log line as
claim->adoption; the shipped string uses a real arrow (src/channels/message/ingress-drain.ts:400). It also claimed the guard could only ever produce a duplicate and never a drop, which is refuted above.Not verified. No live-channel or mock-gateway run for this revision; the traces are from the regression harness driving the real dispatch-dedupe guard, not from a production replay. The originally reported duplicate was observed in production but I did not reproduce that end to end under test. A separate 2-3s double dispatch on the same host, with no
keeping for retryin the window, is not this bug and is not fixed here.Claude assisted with the AsyncLocalStorage analysis and the regression harness. The submitter owns the conclusions and final review.