Repository navigation
fix(native-chat): settle a structured send the provider proves it received after the ack window - #19140
Conversation
…eived after the ack window A send waits a bounded window for the provider to echo the message it was given. On timeout the dispatch resolves `unknown`. The echo that arrives later IS matched — `recoverLateIdentity` uses it to repair the session's turn identity — but nothing tells the journal, and `unknown` is terminal there. The submission stays unknown for the life of the session. Two consequences, both reachable on any ordinary session: - The composer renders "Message delivery is unconfirmed." with a Retry, forever, for a message that was delivered and answered. - Retry redispatches, because the host only replays a recorded outcome unless `retryUnknown` is set, which that button is the only thing that sets. So the banner is a duplicate delivery armed and waiting for a click — and a user who believes the banner and resends is doing exactly that by hand. Every send made while a turn is already running takes this path: the provider does not echo a queued message until the running turn ends, which is far past the 10s ack window. Sends made while idle are unaffected, which is why this reads as intermittent. Carry the `clientMessageId` on the dispatch waiter and settle the journal submission `accepted` when the late echo proves delivery. Deliberately unfenced against the dispatch sequence: that fence decides which turn owns the identity, while delivery is settled either way. Already-terminal rows are untouched.
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (9)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughClaude replay handling now retains the originating client message ID and reports late provider-confirmed delivery. The structured agent-session host resolves the corresponding unknown journal submission as accepted and publishes the updated journal. Runtime adapters forward the settlement callback and report asynchronous errors. Tests cover late replay correlation, superseded dispatches, accepted submissions, and missing sessions. Merge Risk: ⚪ Minimal · up to Late provider-confirmed deliveries now update previously unknown submissions to accepted without redispatching or changing active-turn ownership. The covered settlement path is ready to merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the bug, impact, implementation, and verification clearly. However, it omits required template sections and information, including the linked issue ( Resolution Add the missing template sections. Include a valid linked issue, provide visual proof or state ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Carry
clientMessageIdon the dispatch waiter —ClaudeDispatchWaitergainsclientMessageIdso a replay that lands after the ack window can name the exact journal submission it proves delivered. - Fire a settlement callback from
recoverLateIdentity— invoked before thedispatchSequencefence check, deliberately unfenced so a superseded dispatch's message is still settledacceptedeven though it no longer owns the turn. - Wire the callback through the adapter, runtime, and host —
resolveClaudeReplayWaiter→acquireClaudeSession(onDispatchSettledLate) → runtime →host.settleLateDispatch, all in-process with no wire or schema change. - New host mutation
settleStructuredAgentSessionLateDispatch— serializesjournal.resolveDispatch({ state: 'accepted', providerIdentity, fence: session.fence })with the session's other writes; a no-op on already-settled rows because the reducer treatsaccepted/rejectedas terminal. - Tests at both layers — exact assertions in
claude-structured-dispatch.test.ts(timed-out replay settles; superseded dispatch settles without claiming the turn) andstructured-agent-session-late-settlement.test.ts(durableunknown→acceptedwith no second dispatch; terminal rows untouched; non-held session ignored).
The fix is well-scoped and correct. The settlement's providerIdentity is byte-for-byte the same shape the normal accept path produces, so alias/dedup and acceptance-receipt semantics stay consistent, and delivery is only settled after the frame matches a retired waiter by correlation (user_message_uuid/uuid) or the single-candidate content fallback — genuine proof, not a guess. session.fence cannot diverge from the dispatch fence in practice because the fence only advances on release/handoff/re-attach, each of which tears down the ClaudeSession and its retired waiters. Tests pass (pnpm vitest run on both files: 23/23).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Drop host-queue serialization from late-dispatch settlement —
settleStructuredAgentSessionLateDispatchnow callssession.journal.resolveDispatchdirectly instead of wrapping it incontext.serialize, so a receipt arriving while the provider child is closing persists instead of being deferred past teardown and dropped. The journal's ownJournalWriteQueuestill serializes the write. - New pending/close coverage — two tests: a settlement landing while the send is still
pendingpublishesacceptedand suppresses any laterretryUnknownre-dispatch, and a receipt fired duringcloseSessionsurviveshost.closeand reappears asacceptedafterrevealSession. Teardown moved from a vestigialjournals.closeAll()tohost.close(SESSION).
The change is correct. The eviction steps stop the provider child (closeSession) before forget-session closes the journal, and a write enqueued during that window is ordered ahead of markClosed/close, so the settlement is durable. Bypassing the host queue is safe because journal writes are serialized at the journal layer and applyDispatch treats accepted/rejected as terminal, so the send's later unknown from its ack timeout cannot reopen a settled row. A failed direct write surfaces through the runtime's existing onDispatchSettledLate .catch(onError) rather than being swallowed. Both changed files' tests pass (25/25).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Grok Electron QA report — PR #19140#19140 Identity
Session: ScenariosS2 idle send (control) — passComposer send while idle: "Reply with exactly the word pong…". No unconfirmed banner at 1s/3s/6s/11s. Journal row accepted in ~2s with provider identity S1 late echo clears unconfirmed — pass (rendered + journal)Idle composer first: Long essay turn started through composer; sidebar and tab showed Working; tools running. Mid-turn follow-up Journal at that moment: follow-up After the running turn finished, banner gone, Retry gone, follow-up once, assistant replied OKAY. Late settlement timing for FOLLOWUP-2:
S4 stacked composer send — pass with FIFO noteWhile FOLLOWUP-2 was unconfirmed, typed/sent S6 Retry absence + new send — passAfter settlement, Retry was gone (Send button present). New message Dispatch vs submissionFive journal submissions, five distinct provider item UUIDs, one submission per TopologyLocal execution host only. Renderer Not exercised
Logs / secretsScreenshots inspected: no tokens, keys, or CleanupPlaywright session closed. Electron launch PID 96782 (this worktree |
|
Review complete on
Coverage limits: live Windows/Linux/WSL, SSH/remote runtimes, mobile/older clients, explicit Retry while unknown, and genuine rejected-send UI were not exercised. Close-during-echo and no-redispatch are proven by deterministic tests; live transport send-frame count was not instrumented. These are unverified paths, not observed regressions. QA app and disposable profile/workspace were cleaned up; evidence was preserved outside the diff. |
…eived after the ack window (stablyai#19140) * fix(native-chat): settle a structured send the provider proves it received after the ack window A send waits a bounded window for the provider to echo the message it was given. On timeout the dispatch resolves `unknown`. The echo that arrives later IS matched — `recoverLateIdentity` uses it to repair the session's turn identity — but nothing tells the journal, and `unknown` is terminal there. The submission stays unknown for the life of the session. Two consequences, both reachable on any ordinary session: - The composer renders "Message delivery is unconfirmed." with a Retry, forever, for a message that was delivered and answered. - Retry redispatches, because the host only replays a recorded outcome unless `retryUnknown` is set, which that button is the only thing that sets. So the banner is a duplicate delivery armed and waiting for a click — and a user who believes the banner and resends is doing exactly that by hand. Every send made while a turn is already running takes this path: the provider does not echo a queued message until the running turn ends, which is far past the 10s ack window. Sends made while idle are unaffected, which is why this reads as intermittent. Carry the `clientMessageId` on the dispatch waiter and settle the journal submission `accepted` when the late echo proves delivery. Deliberately unfenced against the dispatch sequence: that fence decides which turn owns the identity, while delivery is settled either way. Already-terminal rows are untouched. * fix(native-chat): persist late dispatch receipts before session close --------- Co-authored-by: Merge Sim <sim@local>






What you see
"Message delivery is unconfirmed." with a Retry, under a turn that is running normally — for a message that was in fact delivered and answered. It never clears.
Why it happens
A send waits a bounded window (10s) for the provider to echo the message it was given. On timeout the dispatch resolves
unknown.The echo that arrives later is matched —
recoverLateIdentityuses it to repair the session's turn identity — but nothing tells the journal, andunknownis terminal there (applyDispatchonly advances out ofpending). So the submission staysunknownfor the life of the session.Every send made while a turn is already running takes this path, because the provider does not echo a queued message until the running turn ends, which is far past the ack window. Sends made while idle are unaffected, which is why this reads as intermittent rather than as the deterministic bug it is.
Why it matters beyond the banner
performSendreplays a recorded outcome unlessretryUnknownis set, and the composer's Retry button is the only thing that sets it. So a stuck unconfirmed bubble is a duplicate delivery armed and waiting for a click — and a user who believes the banner and resends by hand is doing the same thing manually. This was reported by a user who had resent several messages for exactly that reason.The change
Carry the
clientMessageIdon the dispatch waiter, and settle the journal submissionacceptedwhen the late echo proves delivery.Deliberately unfenced against the dispatch sequence: that fence decides which turn owns the identity, and a superseded dispatch must not claim the active turn — but the message it names still landed, so its delivery is settled either way. Rows already
acceptedorrejectedare untouched, since the reducer treats both as terminal.The settlement lives beside the other journal effects in
structured-agent-session-host-mutations.tsand is serialized with the session's other writes.Verification
Live structured Claude session, same scripted journey both ways: send a long prompt, wait 4s, send a second message mid-turn, sample every 3s.
The transient appearance is correct and kept: until the provider echoes, delivery genuinely is unconfirmed. What is fixed is that it no longer stays wrong forever.
Unit coverage at both layers, each ablation-verified red: the dispatch waiter reports the settlement (including for a superseded dispatch that must not claim the turn), and the host moves a durable
unknowntoacceptedwithout a second dispatch.pnpm tcandoxlintclean.