Skip to content

fix(native-chat): a Codex chat is Working only while Codex holds the send - #29922

Merged
brennanb2025 merged 10 commits into
mainfrom
brennanb2025/send-lifecycle-codex-held
Oct 17, 2026
Merged

brennanb2025 merged 10 commits into
mainfrom
brennanb2025/send-lifecycle-codex-held

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​466 $\color{#cf222e}{\Huge{\mathbf{−}}}$​124 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​342
Prod 34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​480 $\color{#cf222e}{\Huge{\mathbf{−}}}$​173 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​307

ELI5

A Codex chat could stay on "Working" forever after Codex had finished: Stop stayed up, every session list said Working, queued messages never sent, and /compact was refused. It only cleared when the Codex process exited. This happened whenever Orca was waiting for a signal about a message that never came. Now "Working" means only what it should: Codex is running a turn, or Codex still has a message it hasn't finished with.

What Changed

Before (what you saw): you send a message to a Codex chat. A hook refuses it (or Codex answers without naming a turn, or the send times out and Codex goes idle before Orca records that). Codex is done, but the chat keeps showing Working, the Stop button stays, the queue never drains, and /compact says the chat is busy. Restarting the agent was the only way out. Orca has fixed this one case at a time at least nine times since September.

After: the chat stops showing Working as soon as Codex no longer holds the message, on the desktop, the phone and every session list, including older desktop and phone versions. Nothing about delivery changes: a message whose fate is unknown still reads as an ordinary sent message, and Codex's own echo still marks it delivered if it comes later. Nothing is resent.

One case changes visibly beyond the stuck state: if Orca's request to start a Codex turn times out while Codex is idle, the chat no longer stays on Working with a Stop button that ends the agent. It reads as not working, with the message shown as sent (Orca can't confirm it, as today). If Codex does start that turn later, the chat shows Working again and Stop works as usual.

Mechanism. The root cause was one rule: a chat was Working while any message was still "pending delivery", so every missed or late event kept it Working. This PR separates "is the agent working?" from "was the message delivered?":

  • Codex's adapter now reports the messages it still holds (heldSends): ones Codex hasn't answered yet, ones it answered into a turn that hasn't ended, and ones it answered into no turn while a status Codex reported after that answer says the thread is running. A turn that ends releases its messages whether or not their echo came.
  • Codex's replies and status notifications are ordered as they are read off its output (a synchronous onReply stamp on the request), so a status Codex sent before it answered can never release a newer message.
  • The host's current-work projection counts a handed-over message as work only while the child holds it, or while the host itself is still handing it over (a short window from the pending row until the adapter answers, so a send never flashes "not working").
  • A message the child no longer holds is published to clients as undecided (unknown, recovered) on every page and frame, so older clients that compute Working themselves agree, and the host republishes whenever the held set changes without a journal row.
  • The host's own readers (the queue's "a send is still opening its turn" gate, the send-result wait, the status projection, the restart-resume check) read the same corrected values.
  • Removed: the Codex "thread went idle" latch and the release it triggered, which rewrote messages only for one of the ways this could happen.

Why

This is the first step of a planned refactor of how native chats track sends, which has had the same class of stuck-Working bug fixed repeatedly. The common pattern in other chat clients keeps "the agent is running" (driven by turn start and end) separate from "this input was confirmed" (an exact receipt), and never lets a missing confirmation keep the agent running. This PR adopts that separation for Codex. Claude, Pi and ACP agents keep today's rule until the next step, which moves them onto the same heldSends question (labelled temporary below).

Alternatives considered:

  • Another targeted fix for each missing event (what the last nine fixes did): rejected, the class keeps coming back.
  • Asking Codex for the thread's status (thread/read) when in doubt: rejected. Codex only marks a thread running once it handles the turn's start, so a read in the normal window between Codex's answer and the turn starting reads idle and would release a message Codex is about to run.
Difference from the common pattern Label Why
The host keeps a short "handing over" set so a send reads as held before the adapter is called intended Orca writes the pending row before the adapter call so a crash never loses a message; one host serves several clients and SSH
Older clients get the corrected send values restated on every page and frame intended mixed client and host versions are normal; old clients compute Working themselves
Claude, Pi and ACP still count every unanswered send as held temporary the next PR in this series gives them the same per-message answer and removes their idle releases
The 256-message cap on Codex's in-flight index stays temporary a later PR in this series makes that index a bounded, disposable cache

Linked Issue

Tracked in #28630 (closed in favour of this series).

Visual Proof

Merged-head verification, 2026-10-17: 5c53b0aef9408198c87ca08d1bfe9e0ee1268408 is the previously reviewed caa4616f33fdb973b1cd93ccad1b1c9474837bc4 plus a clean merge of main 98d8257b02d52a6d93e3bde4eebed2a4308d828e. Narrow merge review found no P0/P1: changes within this PR's prior files are main's queue-publication projection, existing-method typing and main's compatibility-test version. The queue projection runs before phone frame sizing and tracks canonical queue identity independently; it does not change execution ownership, the command handover window, or bounded submission restatements. The full PR workflow, including PR checks passed, is green on this exact head; GitHub reports CLEAN, out of draft and no unresolved threads.

Merged-head real Electron QA used qa-gate ticket 189 on macOS, with signed-in Codex and Claude. Codex drove all six cases after Grok stalled during setup. This was a PR-arm-only recheck against round two's PR results, with no new main arm: a minute-long Codex turn, normal compact and a follow-up, immediate compact, active-shell Stop then compact, a Claude turn, and final status all matched. For immediate compact, Enter was requested 114 ms after observed Done and the keypress finished at 214 ms; compact cleared its composer and completed without an error or unconfirmed-command notice. Stop removed the control promptly, background monitoring settled between 119.503–119.702 seconds, and subsequent compact succeeded. Every chat finished Done or idle.

The earlier limits below remain: no live no-echo reproduction, queue/card Steer, indexed native-session-list status or phone proof. The notification-permission warning recurred on the PR and remains unattributed against main. The new fixture has no setup script, so its “Add a setup script” card is a fixture difference; setup was not retested. All owned rig/driver processes and listeners were verified stopped and ticket 189 was released. Protected hooks/settings/Orca files and authentication metadata remained unchanged; the same shared-machine Codex/Claude bookkeeping categories changed with no established writer.

Merged-head check Whole-window screenshot
Codex running Codex running
Normal compact completed Normal compact completed
Immediate compact completed Immediate compact completed
Stop settled Stop settled
Post-Stop compact completed Post-Stop compact completed
Real Claude completed Real Claude completed

Earlier main-versus-PR comparison, before the main merge:

Real Electron QA on the final head and frozen main used signed-in Codex and Claude with Grok on qa-gate ticket 140 (macOS). Ordinary turns, Enter steering, active-tool Stop, compact including the observed 198ms completion boundary, setup/default tabs and Claude succeeded. The original no-echo failure was not reproduced live; queue controls were absent, indexed history status was not proven, and phone was not run. Main also compacted successfully. A notification-permission warning seen on the PR remains unattributed after an inconclusive main recheck. These are qualified regression results, not live proof of the original failure.

Flow Main This PR
Setup and default tabs Main: Setup and default tabs PR: Setup and default tabs
Codex Working Main: Codex Working PR: Codex Working
Enter steer accepted Main: Enter steer accepted PR: Enter steer accepted
Stop: Interrupted Main: Stop: Interrupted PR: Stop: Interrupted
Compact after completed send: Working Main: Compact after completed send: Working PR: Compact after completed send: Working
Compact after completed send: idle Main: Compact after completed send: idle PR: Compact after completed send: idle
Compact after Stop: idle Main: Compact after Stop: idle PR: Compact after Stop: idle
Real Claude completed Main: Real Claude completed PR: Real Claude completed
Final sidebar: all Done Main: Final sidebar: all Done PR: Final sidebar: all Done

Testing

  • structured-agent-session-codex-held-sends.test.ts (new): through the real host, journal and Codex adapter with a fake Codex child. A turn completes without echoing the prompt: the chat stops Working with no delivery row written, and a client that was already subscribed is sent the message as undecided (so an older client also stops reading Working). A normal send stays Working until its turn ends, and its echo still marks it delivered.

  • codex-structured-dispatch-echo.test.ts: the hold rule. Held from the write until the turn it was answered into ends, echo or not; a message answered into no turn is held only while a status read after its answer says running; a status read before the answer decides nothing.

  • Removed the tests of the deleted idle latch.

  • CI runs lint, typecheck and the full test suite.

  • Real Electron QA completed on the final head (coverage and limits above)

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Remote and mixed versions: no new wire field, opcode or saved field. Older clients receive corrected values of existing fields. Newer clients already prefer the host's working field.
  • SSH: the held set lives on the host that runs the agent, like the rest of current work.
  • No timers decide anything; nothing is resent.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Main/branch screenshots attached, with reproduction limits above
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Full PR workflow passed on the final head: static analysis/typecheck, tests, compatibility and packaging

…send

Working read 'a send still pending delivery', so any echo or idle signal
that never arrived (a hook-blocked prompt, an answer naming no turn, idle
before a timed-out send was written) kept the chat Working, Stop up, the
queue frozen and /compact refused until the agent exited.

Codex now reports which sends it still holds: unanswered, answered into a
turn that has not ended, or answered into none while a status read after
that answer says the thread runs. Replies and statuses are ordered as they
are read, so a stale status cannot release a newer send. The host reads
that set (plus the short window while it hands a send over) for Working,
publishes a send the child stopped holding as in doubt on every page and
frame so older clients agree, and republishes when the set changes with no
row. The Codex idle latch and its release are removed.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 17, 2026 02:27
@coderabbitai

coderabbitai Bot commented Oct 17, 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: 6b4d173c-2b75-4ab0-a2bf-45539c1b91da
📥 Commits

Reviewing files that changed from the base of the PR and between caa4616 and 5c53b0a.

📒 Files selected for processing: 2
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-subscribers.ts

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

📝 Walkthrough

The change tracks when Codex still holds a send using request reply timing, turn events, and primary-thread status. Structured sessions use held-send and handover state to calculate current work and restate unanswered submissions. Subscriber delivery refreshes published work in bounded batches. The change also updates Codex and session tests for held sends, publication, and subscriber delivery.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 5c53b

The command handler retains its controller binding, and subscribers receive snapshots before bounded work updates. No concrete user-facing regression is established in these changes; normal checks are sufficient.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 45 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 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 identifies the main change: Codex chats now remain Working only while Codex still holds the send.
Description check Passed The description is detailed and covers the required explanation, user-visible behavior, mechanism, rationale, linked issue, visual proof, testing, review notes, compatibility considerations, and check…
Full details: Description check

Explanation

The description is detailed and covers the required explanation, user-visible behavior, mechanism, rationale, linked issue, visual proof, testing, review notes, compatibility considerations, and checklist. It also documents known test limitations. The issue is referenced as #28630, although the template's Fixes # field remains unfilled.

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

…at's work; run the held-sends test with the database runtime
…ecycle-codex-held

# Conflicts:
#	src/main/native-chat/agent-session-wire/structured-agent-session-command-turn.ts
#	src/main/native-chat/agent-session-wire/structured-agent-session-delivery-loop.ts
#	src/main/native-chat/agent-session-wire/structured-agent-session-host-delivery.ts
@brennanb2025

brennanb2025 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

A Codex chat could keep showing Working after Codex finished because Orca counted a missing message confirmation as unfinished execution. This change reads the work Codex still owns separately from delivery, so the chat becomes idle, queued work can proceed and /compact can run; a later confirmation still updates delivery, and nothing is resent.

The review found and fixed three problems: unloading an idle thread could restore Working, phone updates could exceed the subscription frame limit, and command handover could report /compact as unconfirmed or reject it after a completed send with no echo. The fixes use positive active status, complete byte-budgeted update batches and the existing host handover window for commands. Two review rounds, an independent architecture challenge and a unanimous design-panel ruling kept the approved design; the final main merge was checked separately.

Merged-head verification, 2026-10-17: 5c53b0aef9408198c87ca08d1bfe9e0ee1268408 is the previously reviewed caa4616f33fdb973b1cd93ccad1b1c9474837bc4 plus a clean merge of main 98d8257b02d52a6d93e3bde4eebed2a4308d828e. Narrow merge review found no P0/P1: changes within this PR's prior files are main's queue-publication projection, existing-method typing and main's compatibility-test version. The queue projection runs before phone frame sizing and tracks canonical queue identity independently; it does not change execution ownership, the command handover window, or bounded submission restatements. The full PR workflow, including PR checks passed, is green on this exact head; GitHub reports CLEAN, out of draft and no unresolved threads.

Merged-head real Electron QA used qa-gate ticket 189 on macOS, with signed-in Codex and Claude. Codex drove all six cases after Grok stalled during setup. This was a PR-arm-only recheck against round two's PR results, with no new main arm: a minute-long Codex turn, normal compact and a follow-up, immediate compact, active-shell Stop then compact, a Claude turn, and final status all matched. For immediate compact, Enter was requested 114 ms after observed Done and the keypress finished at 214 ms; compact cleared its composer and completed without an error or unconfirmed-command notice. Stop removed the control promptly, background monitoring settled between 119.503–119.702 seconds, and subsequent compact succeeded. Every chat finished Done or idle.

The earlier limits below remain: no live no-echo reproduction, queue/card Steer, indexed native-session-list status or phone proof. The notification-permission warning recurred on the PR and remains unattributed against main. The new fixture has no setup script, so its “Add a setup script” card is a fixture difference; setup was not retested. All owned rig/driver processes and listeners were verified stopped and ticket 189 was released. Protected hooks/settings/Orca files and authentication metadata remained unchanged; the same shared-machine Codex/Claude bookkeeping categories changed with no established writer.

Earlier full comparison on caa4616f33fdb973b1cd93ccad1b1c9474837bc4:

  • Full PR workflow passed, including its PR checks passed aggregate, static analysis/typecheck, all five unit shards, compatibility tests, relay integration and Windows/Linux packaging. The PR is out of draft, CLEAN, with no unresolved review threads.
  • Real Electron QA used Grok and signed-in Codex/Claude on macOS, admitted by qa-gate ticket 140 after remote-machine attempts were blocked. Frozen main 2d33cd965f34af6d058cb62765924ff60c09d0ef and the final PR head were tested sequentially with isolated app homes. Setup/default tabs, ordinary one-minute Codex turns, Enter steering, active-tool Stop, normal compact, compact after Stop and a Claude turn succeeded on both. All live chats finished idle/Done. The PR also accepted compact 198 ms after the first observed completed-send sample, cleared its composer, showed Working/Stop and returned to idle without an error or unconfirmed-command notice. Main's successful direct compact was slower to submit, so it is not an equally fast comparison.
  • Limits: the original missing-echo failure was not reproduced live; that behavior is covered by host/adapter regression tests. Queue and card Steer controls were absent on both builds, so queue draining was not exercised. Indexed Session History contained synthetic title jobs rather than native chats; its status was not proven. Phone was not run. Main also compacted successfully: these screenshots show the requested PR behavior, not a reproduced before/after failure.
  • User-surprise observations: a macOS notification-permission toast appeared on the PR; main's initial transition was missed and its recheck was inconclusive. The fallback and delivery code are identical at both heads and show this warning once per renderer session, but that does not establish why main's warning was not observed. Treat it as unattributed, not an intended PR difference. Empty Claude model labels loaded from Sonnet to Opus, and synthetic history title jobs reported missing login despite successful real Claude turns. Stop retained background-task monitoring before settling on both arms; main's transition was sampled between 65–113 seconds, not timed exactly. Post-Stop compact retained Interrupted until a normal send on both arms. Complete transient-toast coverage for Claude was not established.

All rig/driver processes and allocated-port listeners were verified stopped. Hooks, Claude settings and Orca settings hashes stayed unchanged; Codex authentication metadata stayed unchanged. Codex configuration and Claude bookkeeping changed on the shared machine, with coordinator approval and no established writer; this is not a claim that every real-home file was unchanged.

Deferred concerns: repeated reconstruction of the bounded ownership set has no measured latency impact; the existing restart marker can select an older send when child work remains, with no wrong continuation established. Individually oversized legacy submission records and aggregate phone backpressure remain unverified residual cases. No new stored field or protocol operation was added. The intentional host ownership window supports multiple clients and SSH; other providers' ownership and the existing Codex correlation cap remain temporary differences described in the PR.

For Brennan's review

Merged-head recheck:

Merged-head check Whole-window screenshot
Codex running Codex running
Normal compact completed Normal compact completed
Immediate compact completed Immediate compact completed
Stop settled Stop settled
Post-Stop compact completed Post-Stop compact completed
Real Claude completed Real Claude completed

Earlier main-versus-PR comparison (before the main merge):

Main and PR whole-window comparisons follow. Different reply wording, transcript lengths and sampled tool phases are not controlled; the rapid compact boundary was measured on the PR only.

Flow Main This PR
Setup and default tabs Main: Setup and default tabs PR: Setup and default tabs
Codex Working Main: Codex Working PR: Codex Working
Enter steer accepted Main: Enter steer accepted PR: Enter steer accepted
Stop: Interrupted Main: Stop: Interrupted PR: Stop: Interrupted
Compact after completed send: Working Main: Compact after completed send: Working PR: Compact after completed send: Working
Compact after completed send: idle Main: Compact after completed send: idle PR: Compact after completed send: idle
Compact after Stop: idle Main: Compact after Stop: idle PR: Compact after Stop: idle
Real Claude completed Main: Real Claude completed PR: Real Claude completed
Final sidebar: all Done Main: Final sidebar: all Done PR: Final sidebar: all Done

Three places where judgment matters: the execution-ownership rule, the short host handover window and complete bounded updates to older clients. The three judgment points are the ownership rule, command handover, and bounded updates.

…ecycle-codex-held

Takes main's cross-version harness fix (#30000) in place of this branch's copy.
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