Skip to content

fix(native-chat): settle a structured send the provider proves it received after the ack window - #19140

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/structured-late-dispatch-settlement
Sep 6, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/structured-late-dispatch-settlement

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​278 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​278
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77

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 — recoverLateIdentity uses it to repair the session's turn identity — but nothing tells the journal, and unknown is terminal there (applyDispatch only advances out of pending). So the submission stays unknown for 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

performSend replays a recorded outcome unless retryUnknown is 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 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, 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 accepted or rejected are untouched, since the reducer treats both as terminal.

The settlement lives beside the other journal effects in structured-agent-session-host-mutations.ts and 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.

banner appears banner clears
before t+16s never (still showing past turn completion at t+52s)
after t+16s t+61s, when the first turn ends and the provider echoes

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 unknown to accepted without a second dispatch.

pnpm tc and oxlint clean.

…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.
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: ed4ed656-e773-424b-8b01-b3860c751f45

📥 Commits

Reviewing files that changed from the base of the PR and between e8470e1 and ba32236.

📒 Files selected for processing (2)
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 4ea5ae24-a6f3-4a40-b549-777a8e5f28e9

📥 Commits

Reviewing files that changed from the base of the PR and between 5a46703 and e8470e1.

📒 Files selected for processing (9)
  • src/main/claude/claude-structured-dispatch.test.ts
  • src/main/claude/claude-structured-dispatch.ts
  • src/main/claude/claude-structured-session-acquisition.ts
  • src/main/claude/claude-structured-session-state.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-late-settlement.test.ts
  • src/main/runtime/structured-agent-session-runtime.ts
  • src/main/runtime/structured-claude-runtime-adapter.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Claude 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 e8470

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, impact, implementation, and verification clearly. However, it omits required template sections and information, including the linked issue (Fixes #), explicit visua… Add the missing template sections. Include a valid linked issue, provide visual proof or state N/A with a reason, document testing steps and platforms, complete applicable disclosure and checklist items, and address the required compatibi…
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: settling structured sends after the provider confirms delivery beyond the acknowledgment window.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the bug, impact, implementation, and verification clearly. However, it omits required template sections and information, including the linked issue (Fixes #), explicit visual proof or N/A justification, the Testing section, AI Disclosure, Review, boundary declaration, Notes, and Checklist confirmations.

Resolution

Add the missing template sections. Include a valid linked issue, provide visual proof or state N/A with a reason, document testing steps and platforms, complete applicable disclosure and checklist items, and address the required compatibility and review notes.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Carry clientMessageId on the dispatch waiter — ClaudeDispatchWaiter gains clientMessageId so 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 the dispatchSequence fence check, deliberately unfenced so a superseded dispatch's message is still settled accepted even 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 — serializes journal.resolveDispatch({ state: 'accepted', providerIdentity, fence: session.fence }) with the session's other writes; a no-op on already-settled rows because the reducer treats accepted/rejected as terminal.
  • Tests at both layers — exact assertions in claude-structured-dispatch.test.ts (timed-out replay settles; superseded dispatch settles without claiming the turn) and structured-agent-session-late-settlement.test.ts (durable unknown → accepted with 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).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Drop host-queue serialization from late-dispatch settlement — settleStructuredAgentSessionLateDispatch now calls session.journal.resolveDispatch directly instead of wrapping it in context.serialize, so a receipt arriving while the provider child is closing persists instead of being deferred past teardown and dropped. The journal's own JournalWriteQueue still serializes the write.
  • New pending/close coverage — two tests: a settlement landing while the send is still pending publishes accepted and suppresses any later retryUnknown re-dispatch, and a receipt fired during closeSession survives host.close and reappears as accepted after revealSession. Teardown moved from a vestigial journals.closeAll() to host.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).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Grok Electron QA report — PR #19140

#19140
SHA: ba32236c69e4133f1db4bd3fa7a148600fd5cd49
Worktree: /Users/brennanbenson/orca/workspaces/orca/fix-native-chat-settle-a-structured-send-the-pro
Branch: brennanb2025/structured-late-dispatch-settlement

Identity

window.api.app.getIdentity():

  • name: Orca: brennanb2025/structured-late-dispatch-settlement
  • isDev: true
  • devWorktreeName: fix-native-chat-settle-a-structured-send-the-pro
  • devBranch: brennanb2025/structured-late-dispatch-settlement
  • CDP: 127.0.0.1:9335 renderer 127.0.0.1:5177
  • Isolated ORCA_DEV_USER_DATA_PATH=/tmp/orca-electron-profile-qa19140.YI3HJ6
  • ORCA_BACKGROUND_LAUNCH=1; Resource Manager showed 0 terminal sessions throughout
  • Local runtime capabilities included agent-session.structured.v1

Session: claude_3e99ecd2_540d_4be2_954a_fa982e8f5a49 on folder workspace /tmp/orca-qa-19140-workspace (not the orca repo). Launched from New tab → Claude.

Scenarios

S2 idle send (control) — pass

Composer 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 …:13c6e1d1-48ed-4a1a-b958-a906a9c21458. Visible pong; tab Done.

s2-idle-send-accepted.png

S1 late echo clears unconfirmed — pass (rendered + journal)

Idle composer first:

s1a-idle-composer.png

Long essay turn started through composer; sidebar and tab showed Working; tools running. Mid-turn follow-up QA19140-FOLLOWUP-2 sent with Enter (Send button is Stop while working). After ack window: visible Message delivery is unconfirmed. + Retry while still Working/Thinking.

s1b-unconfirmed-while-running.png

Journal at that moment: follow-up 1788736930098-5b2a0c1d7403493394537ca8c917c480 was unknown with no provider identity.

After the running turn finished, banner gone, Retry gone, follow-up once, assistant replied OKAY.

s1c-banner-cleared.png

Late settlement timing for FOLLOWUP-2:

  • submittedAt 1788736930430
  • resolvedAt 1788736988268
  • 57.8s submission-to-acceptance (not time spent unknown; unknown starts after the 10s ack window)
  • providerItemId claude:b19709f5-ef2d-464d-b95f-af8f0b6c5764:b06b1885-729d-406f-8c50-f88520e63a90
  • one journal submission for that clientMessageId; no duplicate user bubbles. Transport send-frame count was not instrumented; unit tests prove late settlement does not call dispatch again.

S4 stacked composer send — pass with FIFO note

While FOLLOWUP-2 was unconfirmed, typed/sent QA19140-FOLLOWUP-3 through the composer. Visible once after settlement. Host submittedAt for FOLLOWUP-3 is 1788736988297 — immediately after FOLLOWUP-2 resolved — so the client outbox parked it behind the unknown head, then dispatched it. Accepted in ~1.6s with unique provider uuid 535de09e-4ffb-4038-bec5-e2fc8767920c. Both follow-ups appear once; replies OKAY and STACKED. This is the real UI stacked-send path, not two concurrent host unknowns.

S6 Retry absence + new send — pass

After settlement, Retry was gone (Send button present). New message QA19140-S6 created a new clientMessageId 1788737088909-2f65e10eeaa94fc7a92db6358aaa8859, accepted with a fifth unique provider uuid. Follow-up 2/3 still count 1 each.

s6-post-settlement-new-send.png

Dispatch vs submission

Five journal submissions, five distinct provider item UUIDs, one submission per clientMessageId. FOLLOWUP-2 remained a single submission across unknown→accepted. No duplicate user bubbles were observed. Electron/dev logs had no structured-agent-session-late-settlement errors. Per-frame Claude send dumps were not in the dev log, so live transport send count is unverified; host unit tests prove settlement does not redispatch. Submission-to-acceptance for FOLLOWUP-2 was 57.8s.

Topology

Local execution host only. Renderer callRuntimeRpc can target {kind:'environment'} remote runtimes, and those hosts can install the same structured session runtime. Remote/SSH/Windows/mobile UI were not exercised. Diff does not change src/main/ssh/ or src/relay/; no new stream opcode. SSH-specific brennan-test-ssh not applicable; remote generic runtime path remains unverified.

Not exercised

  • S3: explicit Retry while unknown (coordinator: pre-existing duplicate-on-retry; do not treat as regression)
  • S5: genuine rejected / "Message was not sent."
  • Close-during-echo persistence (unit-tested on this SHA; not a feasible live-UI case)
  • Mobile UI, Windows, SSH/remote structured Claude

Logs / secrets

Screenshots inspected: no tokens, keys, or .env values. Playwright console: React DevTools info + tooltip controlled/uncontrolled warning only. File listing cancelled on empty workspace is unrelated. Screenshots were not committed.

Cleanup

Playwright session closed. Electron launch PID 96782 (this worktree run-electron-vite-dev.mjs + temp vite config) stopped. Isolated profile and /tmp/orca-qa-19140-workspace are disposable leftovers.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review complete on ba32236c69e4133f1db4bd3fa7a148600fd5cd49: no proven in-scope issues remain. No merge performed.

  • Two review rounds with GPT-6 Astra / medium, matching the coordinator. Pushed ba32236c69 to fix a reproduced shutdown race: late receipts now enter the existing journal write queue before teardown closes it. Also corrected test journal cleanup. No product scope expansion.
  • Initial and final eight-category readiness audits completed. The final audit independently checked the fix and passed 72 focused tests with zero findings. Performance review found no added polling, subprocesses, timers, or unbounded state; existing waiter retention remains capped at 64.
  • Reviewer validation: 160 tests across eight files, full pnpm tc, targeted lint and formatting passed. The shutdown regression failed before the fix; disabling the original late-settlement callback also made its regression tests fail. All 18 applicable final-head CI checks passed, none pending.
  • Grok exercised real structured Claude chat through background Electron/CDP on a disposable macOS folder workspace. A mid-turn send displayed unconfirmed + Retry, then the same submission became accepted 57.8 seconds after submission and the banner cleared. Idle, queued follow-up, and post-settlement new-send scenarios also passed. Uncropped screenshots and detailed evidence.

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.

@brennanb2025
brennanb2025 merged commit ad4dc35 into main Sep 6, 2026
28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant