Repository navigation
fix(agent-status): recover Codex subagent state after restart (STA-5329) - #16336
brennanb2025 wants to merge 20 commits into
Conversation
|
QA evidence for exact head Before: https://github.com/user-attachments/assets/9584b418-99fc-4b3a-a877-d75b894b02c8 |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds Codex transcript reconciliation after main-server and relay restarts. Persisted status cache entries are hydrated, validated, sanitized, and replayed. Reconciliation restores subagent state, tracks parent terminal status, retries unreadable transcripts, and persists unverifiable diagnostics. Diagnostic fields propagate through hook payloads, relay envelopes, SSH forwarding, and status snapshots. Relay HTTP handling, event application, cache persistence, and lifecycle cleanup use dedicated helpers. Tests cover recovery, cache hydration, diagnostic retention, authority transfer, and remote forwarding. Merge Risk: 🟡 Moderate · up to Restart recovery now rebuilds Codex subagent status from persisted data, but the current implementation can retain agents from a previous transcript and present stale or misleading status after a path change. Reconciliation diagnostics may also be lost in mirrored panes, while related recovery edge cases remain open, so owner follow-up is needed before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is mostly complete and covers the change, rationale, linked issue STA-5329, visual proof rationale, and scope. Testing details are limited, and the AI Disclosure, Agent skill upstream boundary, and checklist sections are not completed.
✨ 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.
Actionable comments posted: 6
🧹 Nitpick comments (2)
src/relay/agent-hook-status-cache.ts (1)
184-195: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider debouncing the synchronous full-cache write.
persistRelayHookStatusCacheserializes the wholelastStatusByPaneKeymap and performs a synchronouswriteFileSyncplusrenameSync.applyRelayHookEventcalls it on every hook event, andclearPaneStatecalls it once per evicted pane. Codex and Claude emitPostToolUseper tool call, so a busy pane triggers repeated whole-file writes on the relay event loop. With the 256-pane cap the payload can be large.A short debounce (or a write only when the serialized content changes) keeps the durability guarantee and removes the per-event I/O.
src/relay/relay-http-listener.ts (1)
8-23: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winClose the server when startup fails.
onErrorrejects the promise but leaves thenet.Serverobject with its internal state untouched.RelayAgentHookServer.start()reacts toEADDRINUSEby callinglistenOn(0), which creates a second server, so the first one is abandoned without aclose(). Callserver.close()before you reject, so the failed instance releases its handle deterministically.♻️ Proposed cleanup
const onError = (error: Error): void => { server.off('listening', onListening) + server.close() reject(error) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c6ed1b81-17a7-4666-8233-71fb2a5464c3
📒 Files selected for processing (19)
src/main/agent-hooks/server-codex-subagent-transcript.test.tssrc/main/agent-hooks/server.tssrc/main/ssh/ssh-relay-session-agent-hooks.integration.test.tssrc/main/ssh/ssh-relay-session.tssrc/relay/agent-hook-envelope-build.tssrc/relay/agent-hook-server-codex-subagent-transcript.test.tssrc/relay/agent-hook-server.test.tssrc/relay/agent-hook-server.tssrc/relay/agent-hook-status-cache.test.tssrc/relay/agent-hook-status-cache.tssrc/relay/relay-http-listener.tssrc/renderer/src/hooks/useIpcEvents.tssrc/shared/agent-hook-listener.tssrc/shared/agent-hook-relay.tssrc/shared/agent-reconcile-diagnostic.tssrc/shared/agent-status-observation.tssrc/shared/codex-subagent-transcript-seeding.tssrc/shared/codex-subagent-transcript.test.tssrc/shared/codex-subagent-transcript.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Review verification for exact head
Verification only; this is not a merge-ready claim. GitHub currently reports the PR as |
49fee97 to
acc7d1c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Review verification for exact head
|
|
QA / evidence for exact head
|
Exact-head review verificationFinal head reviewed: Review outcome
Silent-revert check
Settled CI and verdictSettled rollup: 26 success, 8 skipped, 1 failure, 0 pending. The two previously failing test shards are green. The remaining red check is That E2E failure is base-owned, not caused by STA-5329. A clean Linux/amd64 Node 24.20.0 reproduction from untouched Verdict: not merge-ready while the base-owned E2E check remains red. |
Exact-head QA evidenceFinal head under test: Electron restart validationValidation used the
Before restart — live parent and child: After restart — completed child removed, parent retained: After second restart — missed parent completion restored: The renderer reported 0 console errors throughout the flow. Live Linux SSH changed-flow validationThe throwaway host was reachable with: ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -i /tmp/pr16336-ssh-key -p 61951 [email protected]It was Linux ARM64 with Node 22.23.1. Its installed relay version The isolated restored profile no longer owned the historical remote pane after its app restarts, so I do not claim a rendered SSH row; the live Linux transport, exact-head relay replacement, transcript reread, and authoritative cache transitions are the evidence for the SSH arm. Electron rendering is proven separately above. CI attributionAll 16 Node 24/26 test shards pass at this head. The remaining QA verdict: the exact-head local and live-Linux restart flows pass, but the PR is not merge-ready while the base-owned E2E check is red. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/agent-hooks/server.ts (1)
1722-1724: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRecord unreadable parent transcripts.
When
readJsonlCursor(state.parent)returnsundefined,reconcileCodexSubagentTranscriptconverts it to[]. The final retry check only inspects childunresolvedSincevalues. A missing parent transcript with no child records therefore leaves the restored entry without atranscript-unreadablediagnostic. Track parent readability and add a restart test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 061144b9-7e97-499b-9011-bec648b952ea
📒 Files selected for processing (7)
src/main/agent-hooks/server-codex-subagent-transcript.test.tssrc/main/agent-hooks/server.tssrc/relay/agent-hook-server.test.tssrc/relay/agent-hook-status-cache.test.tssrc/relay/agent-hook-status-cache.tssrc/shared/agent-hook-listener-relay-dependency.test.tssrc/shared/codex-subagent-transcript.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
…-rebase-review-r1 # Conflicts: # src/relay/agent-hook-server.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/agent-hooks/server.ts (2)
1692-1695: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winReject empty relay IDs before local reconciliation.
sanitizeHydratedEntrypreservesconnectionId: ""as a string, but this truthiness check treats it as local. A hydrated remote Codex entry can therefore make the main server readproviderSession.transcriptPathon the SSH execution host's behalf and emit a local reconciliation result ortranscript-unreadablediagnostic. Reject empty or whitespace connection IDs during hydration, and use an explicitentry.connectionId === nullcheck for local reconciliation.As per coding guidelines: all
src/**/*.{ts,tsx}changes must consider SSH; the execution host owns everything that touches execution.Source: Coding guidelines
1742-1749: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winClear stale diagnostics after a successful transcript re-read.
When
reconcileCodexSubagentTranscriptreads a previously unreadable child successfully butnextPayloadis unchanged, the update branch does not run. The persistedtranscript-unreadablediagnostic remains visible. Clear the diagnostic when readability is restored and add a regression test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e27c33e3-e714-4a72-8d9c-094229fefa1e
📒 Files selected for processing (5)
src/main/agent-hooks/server.tssrc/relay/agent-hook-request.tssrc/relay/agent-hook-server-cache-hydration.test.tssrc/relay/agent-hook-server.tssrc/shared/agent-hook-listener-relay-dependency.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 181562c3-dfef-4140-9df2-380a4dc146f5
📒 Files selected for processing (17)
src/main/agent-hooks/server-codex-subagent-transcript.test.tssrc/main/agent-hooks/server.tssrc/relay/agent-hook-event-application.tssrc/relay/agent-hook-server-cache-hydration.test.tssrc/relay/agent-hook-server.tssrc/relay/agent-hook-status-cache.test.tssrc/relay/agent-hook-status-cache.tssrc/renderer/src/hooks/ipc-events-agent-status-store-test-fixtures.tssrc/renderer/src/hooks/ipc-events/agent-status-event-applicator.tssrc/renderer/src/hooks/ipc-events/agent-status-reconcile-diagnostic.test.tssrc/renderer/src/runtime/web-session-tabs-sync-agent-status.test.tssrc/renderer/src/runtime/web-session-tabs-sync.tssrc/renderer/src/store/slices/agent-status.tssrc/shared/codex-subagent-transcript-paths.tssrc/shared/codex-subagent-transcript-seeding.tssrc/shared/codex-subagent-transcript.test.tssrc/shared/codex-subagent-transcript.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/relay/agent-hook-event-application.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
Independent exact-head review —
|
|
Exact-head CI follow-up for
The focused exact-head recovery matrix remains green (172/172 affected tests, including 49/49 lifecycle tests), along with |
Independent exact-head review — content
|
Resolves src/relay/agent-hook-server.ts against #17012, which landed on main after this branch extracted applyEvent/handleRequest into their own modules. Main's retired-pane-surface gate lived in the extracted body, so a plain 'keep ours' resolution would have dropped it: applyRelayEvent now takes isPaneSurfaceRetired and drops a retired pane before caching or forwarding, and agent-hook-event-application.test.ts pins it at its new home. Options types move to agent-hook-server-options.ts to keep the server file under max-lines.
Re-based onto current
|
Greptile SummaryThis PR adds restart recovery for Codex parent and subagent status by reconciling persisted relay and main-process state against rollout transcripts.
Confidence Score: 5/5The PR appears safe to merge based on the reviewed restart, replay, transcript-reconciliation, and renderer propagation paths. No concrete changed-code failure with a realistic reachable trigger and actionable consequence remained after checking pane-state migration, relay shedding, restart fencing, and status propagation.
|
| Filename | Overview |
|---|---|
| src/main/agent-hooks/server.ts | Adds local persisted-status reconciliation, generation fencing, diagnostic propagation, and remote authoritative-state ingestion. |
| src/relay/agent-hook-server.ts | Integrates durable relay cache hydration and schedules Codex reconciliation for restored events. |
| src/relay/agent-hook-status-cache.ts | Implements relay status-cache validation, persistence, hydration, and restart reconciliation scheduling. |
| src/relay/agent-hook-codex-reconciliation.ts | Reconstructs authoritative Codex parent and child state from transcript evidence. |
| src/shared/codex-subagent-transcript.ts | Extends bounded transcript parsing and child-rollout reconciliation for restart recovery. |
| src/shared/agent-hook-relay.ts | Extends the relay contract with authoritative Codex state, diagnostics, replay provenance, and safe shed-field markers. |
| src/renderer/src/runtime/web-session-tabs-sync.ts | Carries restored-state and reconciliation diagnostics through mirrored session status merging. |
| src/renderer/src/store/slices/agent-status.ts | Stores reconciliation diagnostics alongside existing agent-status restoration metadata. |
| src/main/ssh/ssh-relay-session.ts | Forwards the new relay reconciliation fields into main-process remote status ingestion. |
Sequence Diagram
sequenceDiagram
participant C as Codex
participant H as Hook listener
participant R as Relay cache
participant M as Main process
participant T as Transcript
participant U as Renderer
C->>H: Lifecycle hook
H->>R: Cache normalized status
R--xM: Restart or connection interruption
R->>T: Reconcile parent and child rollout state
T-->>R: Authoritative state and diagnostics
R->>M: Replay reconciled envelope
M->>M: Validate identity and reconcile status
M->>U: Publish restored status
C->>H: Subsequent live hook
H->>M: Confirm current state
M->>U: Clear restored uncertainty
Reviews (1): Last reviewed commit: "Merge branch 'main' into brennanb2025/st..." | Re-trigger Greptile
|
Missed status messages now recover after a restart through #16685. The remaining case with no new status message needs checking in current code, so this older implementation can be retired while the recovery problem stays tracked. |



ELI5
When Orca restarts during Codex work, relay hook events can be missed and subagent status can remain stale. This restores the state from relay/cache and transcript data so the status can recover.
Put plainly: each Orca terminal tab shows a little status for the agent inside it — working, waiting
on you, done — and for Codex it also lists the subagents that run spawned. That status is kept up to
date by live event messages. If Orca quits or restarts while a Codex run is in flight, the messages
sent while Orca was away are simply lost, and when Orca comes back the tab keeps showing whatever it
last saw: a finished run still marked "working", a run waiting on your input looking idle, an empty
subagent list for a run that has five.
Now, on the way back up, Orca rebuilds that status from Codex's own transcript file and from cached
records instead of waiting for events that will never arrive.
User-facing before / after
When it bites
Codex users, on local machines and SSH hosts alike, whenever Orca restarts — quit and reopen, an app
update, a crash — while a Codex run is still going.
What Changed
Why
A restart can interrupt hook delivery; rehydrating and reconciling persisted state keeps subagent status truthful after the app returns.
Linked Issue
STA-5329 (Linear)
Visual Proof
N/A — no new UI surface; this fixes relay/state reconciliation behavior.
Testing
No additional validation was run in this handoff; CI should run the branch tests.
Review
No QA evidence or screenshots attached.
Notes
The change is scoped to Codex subagent relay/state recovery and its focused coverage.