Skip to content

fix(native-chat): Claude, Pi and ACP chats are Working only while the agent holds the send - #30134

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/send-lifecycle-agent-held-sends
Oct 18, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/send-lifecycle-agent-held-sends

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201 $\color{#cf222e}{\Huge{\mathbf{−}}}$​213 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12
Prod 34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​168 $\color{#cf222e}{\Huge{\mathbf{−}}}$​126 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

ELI5

A Claude, Pi or ACP chat (Grok, OpenCode and other ACP agents) could keep saying "Working" after the agent had finished. This happened when Orca never got to save the agent's answer about a message. Now these chats show Working only while the agent is running a turn or still holding a message, the same rule Codex chats have followed since #29922.

What Changed

Before:

  • Orca counted any message without a saved answer ("received", "refused" or "couldn't confirm") as work the agent still owed.
  • If that answer arrived but saving it failed, the chat kept showing Working, with Stop up and queued messages stuck behind it. It cleared only when the agent next went idle, and only if that save also worked.
  • If the save failed while the agent was already idle, the chat stayed Working until the agent exited.

After:

  • Each agent tells Orca which messages it still holds, from state it already keeps:
    • Claude: its list of messages waiting for the CLI to reply.
    • Pi: each message from handover until Pi accepts or refuses it.
    • ACP: the prompt and queued steers it hasn't settled.
  • Once the agent holds nothing and no turn is running, the chat stops showing Working everywhere: tab, sidebar, session list and phone.
  • A message whose answer couldn't be saved reads as "couldn't confirm" right away, instead of keeping the chat busy.

Mechanism:

  • Each adapter reports heldSends, reusing the host plumbing fix(native-chat): a Codex chat is Working only while Codex holds the send #29922 added for Codex.

  • The host keeps counting a message as held while its late answer is being written: the answer's write runs inside the existing handover window. That window now counts per message, because a late answer can land while the same message is still being handed over (ACP accepts at turn open). Without the count, the message would briefly read as doubt.

  • Clients are republished to only when that write fails; a successful write already republishes.

  • Removed: the "release unanswered messages when the agent goes idle" mechanism and every caller of it (Claude's idle hook, Pi's onIdle, the host delegate and its file). Owned state replaces it.

  • Claude: a completed lifecycle frame with no started before it now releases that message as doubt, never as received. The CLI finished with it without saying it ran.

  • Reopening the same live agent keeps its original in-memory child record and event stream, so recovery still reaches that agent if a final save fails during the reopen.

  • Unexpected-exit reporting also uses the agent's execution ownership captured before teardown. A completed, idle conversation no longer gets a false "response was in progress" error because an earlier send remained uncertain. Actual interrupted responses still report the interruption.

What counts as "received" is unchanged for every agent. This PR changes ownership and uses that same evidence for interruption reporting.

Why

The old rule ("any unanswered message is the agent's work") ties Working to bookkeeping: one failed save keeps a chat busy. The structural fix is to ask the agent what it holds. The agent already tracks it, and a missing save can't fake it.

The common pattern marks a thread busy when a send starts and clears it on the agent's final turn event. That mechanism fails when that event never arrives; a send that times out can leave a thread active indefinitely. Deriving Working from the agent's existing execution state removes the extra idle-recovery write that could fail. Each adapter still has to release its own input when that input is settled. It also keeps older clients right, because they read Working from the published sends.

Differences from the common pattern:

  • Ownership comes from the live agent, not from a stored busy flag. Intended: the flag strands when its clearing event is lost, and Orca must stay correct for older paired clients.
  • A message whose answer couldn't be saved stays "couldn't confirm" until the agent process ends, instead of being cleared at the agent's next idle. Intended: it matches Codex since fix(native-chat): a Codex chat is Working only while Codex holds the send #29922, and clients see the doubt immediately. An old uncertain message does not make a later idle exit report an interrupted response. Interruption reporting uses a running turn or a message the agent actually held before teardown, including Codex chats.
  • Pi and ACP keep their existing receipt rules. Temporary: a later send-lifecycle change will revise when delivery is confirmed; this PR deliberately preserves those rules.

Linked Issue

Part of the native-chat send lifecycle work, after #29922. Not a GitHub issue.

Visual Proof

Fresh main (ce2d6083) versus final branch (5a0654ee) on a separate Mac, with the same repository, setup, settings and inputs. Whole-window screenshots below show the real host queue waiting before drain, a genuine active Claude process failure, and Grok after Stop. All exercised flows matched main. Queue creation used the host RPC because the shipped queue controls are disabled by capability on both versions; this does not claim coverage of shipped queue creation.

Main — host queue waiting

Branch — host queue waiting

Main — active Claude process failure

Branch — active Claude process failure

Main — Grok after Stop

Branch — Grok after running-tool Stop

Testing

  • Manually exercised the changed flows on a separate Mac through hidden-renderer CDP
  • Automated tests added/updated

The full PR workflow, including its aggregate gate, passed on 5a0654eedcff59585099cbff3ecb0345d953f244. Two targeted host files also passed all 38 tests remotely. The safe, name-filtered real-Claude subset passed 2 tests with 12 skipped; the full real-Claude suites were not run because their excluded cases disable hooks or require a signed-out home.

Real Claude and ACP Grok QA covered normal send, rapid follow-up, Stop while a tool was running, and ending without Working. Claude additionally covered host queue waiting/drain, quiet process exit after a completed turn, and a real active-process failure showing the agent-specific error. Grok's native rapid follow-up replaces the active turn on both versions; it is separate from host queue coverage. A premature branch Stop observation was excluded and repeated successfully after the tool was confirmed running.

Blocked coverage: Pi is below the supported installed version; native Codex cannot authenticate through the isolated runtime route; a genuine kept reattach requires the original successful ensure request, which the UI flow did not retain. No credentials were copied, and nothing was installed or signed in. Deterministic host regressions cover old uncertain sends, final-write failure, and reattach overlapping failed event recovery; these races were not injected into the real-agent smoke run. SSH, historical desktop/phone binaries, Windows and Linux were reviewed in source but not exercised here.

AI Disclosure

Internal contribution; not applicable.

Review

Full review path: ownership, lifecycle, ordering and cross-version publication. Two adversarial rounds, architecture challenge, independent design checks and final source readiness review completed. Both proven high-priority findings were fixed: old uncertain sends falsely implying an interrupted response on idle exit, and kept reattach replacing recovery's child identity. No open proven P0/P1 findings remain. Test additions exceed production additions because the existing host fixture now pins the real final-write/reattach failure sequence.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer material is copied or translated.

Notes

No new saved field, wire operation, receipt rule, automatic resend, or version floor. Older clients continue to derive Working from existing published fields. The implementation is platform-neutral; remote contact loss remains unverifiable rather than proof of process exit.

Inherited QA observations on both versions: the configured default tab was absent, generated conversation titles changed despite automatic titles being off, and startup logged a listener-count warning. The setup marker ran successfully. These observations are reported for follow-up, not attributed to this change. All owned QA processes were stopped, ports released, and real config hashes/credential metadata were unchanged.

Checklist

  • This PR is focused on send ownership and its interruption-reporting consequence
  • Explained the user-facing before/after, mechanism and alternatives
  • Before/after screenshots attached
  • Self-reviewed for correctness, security and performance
  • Cross-platform, SSH/remote and mixed-version behavior considered
  • Full CI gates passed on the final commit

… agent holds the send

Each adapter reports the sends it still holds (Claude's dispatch waiters, Pi's sends until
settlement, ACP's unsettled prompt and steers). A late settlement's write runs inside the
per-send handover window, so a send reads held until its row lands, and a failed write
reads as doubt at once. Removes the idle-release API and its callers.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 17, 2026 23:56
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b218931-af89-45db-801c-8b28abc31fb0
📥 Commits

Reviewing files that changed from the base of the PR and between 1f481fb and 5a0654e.

📒 Files selected for processing: 1
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-stop-exit-ends-record.test.ts

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

📝 Walkthrough

Provider adapters now expose held-send IDs and record held sends with exit observation times. Claude handles completion events that arrive before a send starts. Late dispatch settlement uses counted handover windows and publishes a work-changed notification if settlement fails. Idle callbacks no longer release unanswered dispatches, and the related helper and wiring are removed. Tests cover held-send behavior, settlement failures, exit recovery, and lifecycle events.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 5a065

No merge-blocking issue is established. Run the changed regression test as part of normal validation.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 38 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description covers the user impact, implementation, rationale, testing, visual proof, review scope, and checklist. However, the required Linked Issue section does not provide an actual issue and e… Add the actual linked issue reference under Fixes # or provide the required pre-existing issue link. Do not leave the Linked Issue section stating that no GitHub issue exists unless the repository maintainer explicitly approves an excepti…
Passed Passed checks: 3 passed
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: Claude, Pi, and ACP chats remain Working only while the agent holds the send.
Full details: Description check

Explanation

The description covers the user impact, implementation, rationale, testing, visual proof, review scope, and checklist. However, the required Linked Issue section does not provide an actual issue and explicitly states that this PR is not linked to one.

Resolution

Add the actual linked issue reference under Fixes # or provide the required pre-existing issue link. Do not leave the Linked Issue section stating that no GitHub issue exists unless the repository maintainer explicitly approves an exception.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ba891c54-00e8-4b19-90d9-37000b6e38a0
📥 Commits

Reviewing files that changed from the base of the PR and between 1cd5554 and bf79f47.

📒 Files selected for processing: 21
  • src/main/acp/acp-structured-acquire.ts
  • src/main/acp/acp-structured-session.ts
  • src/main/claude/claude-structured-session-adapter.ts
  • src/main/claude/claude-structured-session-close.ts
  • src/main/claude/claude-structured-session-exit-lifecycle.ts
  • src/main/claude/claude-structured-session-state.ts
  • src/main/codex/codex-structured-session-acquire.ts
  • src/main/codex/codex-structured-session-close.ts
  • src/main/codex/codex-structured-session-state.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-orchestration.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-child-exit.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-stop-exit-ends-record.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-event-recovery.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-event-sink.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-exit-observation.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-types.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-unexpected-exit.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-unfinished-work.ts
  • src/main/pi/rpc-session.ts
  • src/main/runtime/claude-structured-idle-releases-unknown.test.ts
  • src/main/runtime/structured-agent-session-codex-held-sends.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment thread src/main/acp/acp-structured-acquire.ts Resolved
@brennanb2025

Copy link
Copy Markdown
Contributor Author

A chat could keep showing Working after its agent released a message because saving the delivery result failed. This change derives Working from the agent's live turn and held messages, so failed bookkeeping no longer keeps Stop visible or blocks queued work. Delivery-confirmation rules are unchanged.

The full review completed in two rounds at 5a0654eedcff59585099cbff3ecb0345d953f244, with architecture and independent source checks. Fixed both proven high-priority findings: an old uncertain send falsely producing a response-in-progress error after a later completed turn, and reopening the same live agent replacing the child identity needed by failed-event recovery. No open proven P0/P1 findings remain.

Verified:

  • Full PR workflow and aggregate gate passed on this exact commit; the branch is out of draft, CLEAN, and has no unresolved review threads.
  • A separate Mac compared main ce2d6083 with this branch using the same setup, settings and inputs. Real Claude and ACP Grok passed normal send, rapid follow-up, running-tool Stop, and final nonworking state. Claude also passed quiet completed-idle process exit and genuine active-process failure with the expected agent-specific error.
  • Supplemental real-host queue coverage showed a waiting receipt and rendered card before the active tool finished, exactly one drain/reply, then card removal and Done. Shipped queue creation is disabled by capability on both versions, so this is explicitly host RPC coverage. Grok's native rapid follow-up replaces the active turn on both versions and is not queue coverage.
  • Targeted host tests: 38 passed. Safe filtered real-Claude cases: 2 passed, 12 skipped; not the full real-Claude suites. Full-window CDP evidence retained; all owned processes stopped, assigned ports released, real config hashes and credential metadata unchanged.

Coverage gaps: installed Pi is below the supported version; native Codex authentication through the isolated runtime is blocked; genuine kept reattach could not be exercised without the original successful ensure request. Old-doubt/final-write/reattach failure races are covered by deterministic host regressions and source review, not real-agent fault injection. Historical desktop/phone clients, SSH, Windows and Linux were not run.

Deferred without a proven regression: Pi's silent unacknowledged-input case and a resume-marker choice involving an older uncertain send. Inherited observations on both main and branch: configured default tab absent, generated titles despite automatic titles being off, and a startup listener-count warning. No behavior difference was found in exercised cases beyond variable timing/title text. An early Stop observation before the tool started was excluded and repeated successfully after a running tool was confirmed.

For Brennan's review

Main — host queue waiting

Branch — host queue waiting

Main — active Claude process failure

Branch — active Claude process failure

Main — Grok after Stop

Branch — Grok after running-tool Stop

Two places worth human attention:

  • Interruption evidence: only execution the exiting agent actually owned can make an uncertain send count as interrupted work.
  • Kept acquisition identity: reopening the same live agent retains its child record and original event observation.

@brennanb2025
brennanb2025 merged commit fc925c3 into main Oct 18, 2026
37 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/send-lifecycle-agent-held-sends branch October 18, 2026 07:40
brennanb2025 added a commit that referenced this pull request Oct 19, 2026
…hile the agent holds the send (#30134)"

This reverts commit fc925c3.
brennanb2025 added a commit that referenced this pull request Oct 19, 2026
…hile the agent holds the send (#30134)" (#30572)

This reverts commit fc925c3 until the real fix for STA-11160 lands.
With it, `orca orchestration worker-start --agent claude` shuts a new Claude
chat worker down right after Claude acknowledges its task: between the echo
and the accepted row the send reads as no longer held, settlement reports it
unknown, and worker-start tears the session down.

Conflicts with #29150 were formatting only; resolved to the pre-#30134 code.
brennanb2025 added a commit that referenced this pull request Oct 19, 2026
…while the agent holds the send (#30134)" (#30572)

This reverts commit 3ef5a46.
brennanb2025 added a commit that referenced this pull request Oct 19, 2026
…ity, held-send revert

Sleep (#28445) closes a workspace's chats through the same abort a close gives a
registered start, re-aborts a start registered while it waited for the lane, and
judges its receipt once the start it aborted has settled, so only a newer start
reads as later work. Each adapter's owned-acquisition check covers the child it
owns between acquire and open. Main's Sleep cases from the deleted surface
lifetime suite move to the workspace Sleep suite, plus one for a starting agent.

Codex (#30406): the split open sends the chat's command env overrides when it
opens the thread; the adapter test keeps that assertion on the open's request.

Revert of #30134 (#30572): the event sink, exit observation, Pi held-send wrapper
and adapter heldSends overrides go with it; Pi dispatch submits through its
turns again and its idle report is wired back.
brennanb2025 added a commit that referenced this pull request Oct 21, 2026
… shutting down Claude chat workers (#30577)

* fix(native-chat): a Claude chat worker keeps running after Claude acknowledges its task

Claude's adapter dropped an echoed send from the sends it holds before
reporting the send's answer to the host, and emitting the echo's turn
can publish at once. That publish read the still-pending send as held
by nobody, so it read as "couldn't confirm": orchestration worker-start
then closed the new Claude worker, and every other answer wait and
client saw a one-frame doubt.

A frame's settled sends now stay held until their answers are reported,
when the host's handover window takes them over; a Stop's rejected
sends are released and reported one at a time, as Pi and ACP already do.

Tracked in STA-11160.

* test(native-chat): assert the settled send's dispatch state through the send result

* Reapply "fix(native-chat): Claude, Pi and ACP chats are Working only while the agent holds the send (#30134)" (#30572)

This reverts commit 3ef5a46.

* fix(native-chat): a Claude send stays held until its settlement reaches the host, on the reapplied held-sends read

* fix(native-chat): a Claude send stays Working, not in doubt, while a Stop is still ending its CLI

* test(pi): drop the removed idle-release dependency from the adapter fixture
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