Repository navigation
Shared Codex servers survive an Orca restart and update - #51093
Conversation
…lists every loaded thread
…ack; held chats keep their server and cuts
…chat cutoff; bounded unresolved roots and retries
…per server; recovery scans bounded
…floor and drops stay off the chat count; cleanup inside the read limit; partial-listing expiry cuts
…use an unconfirmed interrupt; kept-chat loss markers survive eviction; drops visit each group once; listing stops on a repeated cursor
…ored chats hear unknown loss once
… history; an overflowing restored backlog is let go with a cut
Perf scan: shared Codex servers survive restart (#51093)Head Verdict: NOT READY. One P1 retention finding. FindingP1: a reattached shared server whose chats don't all reopen is never idle-stopped, for the rest of the app session and (at quit) for up to 24 h in the daemon
Coverage by trigger
Regression classes touched
Six questions
Residual (not inspected at runtime): first-reopen reattach latency at fleet thread counts. Daemon-side wakeups for an attached shared relay. |
…ng; a delete whose commands aren't proven gone drains the server
… a shed during reopen keeps its requests; quit keeps a server any chat was handed off on; bots share the app server where nothing is kept; drop stray lockfile churn
…emon with every chat's open work, keeping recovery's owners and cuts for its next attach (rev 8)
Perf re-scan: shared Codex servers survive restart (#51093), head 7202469Head Verdict: NOT READY. The earlier P1 is closed. The fix adds a new P1 on the per-line path. Earlier P1 (a kept server that never idle-stops): closed
New findingP1: every completed command on a shared server is JSON-parsed a second time, in full, on Electron main
Changed triggers
Classes touched
Six questions:
Residual: I didn't measure reattach latency at fleet thread counts or real Codex command-output sizes. |
…rsed, never a line again
Perf re-scan: head b74d9f8Head Verdict: PASS. Both earlier P1s are closed and this diff adds no new perf finding.
Nothing new was added: no timers, no per-line work and no retained state. |
…uit hands off the server's own open work; open work ends visit only their thread's tasks
Perf re-scan: head b26ea69Head Verdict: PASS. No perf findings are open.
Not perf, for whoever reviews correctness: |
…for exit proof; a retry that finds an unheld ancestor re-roots the family on it
Perf re-scan: head 4c4974dHead Verdict: PASS. No perf findings are open.
Nothing new: no timers, no per-line or per-notification work, and no new retained state. |
…at's kept server can't be tied to a chat; rechecked right before the delete commits
Perf re-scan: head de5c2fdHead Verdict: PASS. No perf findings are open.
Nothing new: no timers, no per-line or per-frame work, and no new retained state. |
…lete waits until its commands are proven gone; a chat with no part left on an attached server reads as gone; a released helper stays held until interrupted
Perf re-scan: head 2a1ea9cHead Verdict: PASS. No perf findings are open.
Nothing new: no timers, no per-line or per-frame work, and no new retained state beyond the capped recovery. |
Perf re-scan: head 6d5d077Head Verdict: PASS. The P1 from
|
… daemon's idle stop (no app keeps its output); acks stay held from the read, so the daemon counts every start and end
Perf scan: adbfc21 (shared Codex servers survive restart)Verdict: PASS. No perf regression at this head. The open concern from the previous scan (6d5d077), idle shared servers lingering up to the 24 h detached cap because unread output held the daemon's idle stop, is fixed for the hand-back path. Static scan only: no tests, builds or runtime were run. What changed
Is an idle handed-back server stopped promptly? YesTimeline for one idle server: the last lease leaves, the pool waits A quit detach ( Can servers accumulate per key? No
Work by trigger
Idle wakeups (daemon / main / renderer): none added. A handed-back idle relay now gets one 60 s one-shot timer, then stops and calls Regression classes touched
Six questions
Remaining risk (not changed here)
|
… lines a reopen rebuilds or never shows (replies, turn and item frames, status); plan updates, goals and errors still hold it
…ach (before the spool files them) and as each later line arrives, so an empty scan's replies don't hold its idle stop
…ok, a denied review) still hold a handed-back server's idle stop
Perf scan: 90bdb79 (diff
|
| Work | Trigger | Population | Bound |
|---|---|---|---|
isProviderRelayKeptLine in ProviderRelayIdleStop.observeAgentLine (provider-relay-idle-stop.ts:225) |
Each agent stdout line while the relay is armed (detached with an open-work policy), has a forgettable list, and keptUnread is still false |
Only shared Codex servers handed back to the daemon. The pool keeps one per launch key (codex version, home, skill roots), so a few per app, not one per chat or worktree. Attach, spawn and quit policies have no forgettable, so other relays skip the branch with a null check. |
slice(0, 4096), then leadingJsonEnvelope with stopAtContainer and 32 fields max. It returns at the first method/type/result/error key. A Codex frame is {"jsonrpc":"2.0","method":"…","params":{ (or the reply equivalent), so it does about 2–3 fields, about 60 chars and 1–2 small JSON.parse calls. Worst case is 4096 chars. It latches off at the first kept line. It runs on every line only while all output is forgettable, such as a detached turn streaming item/agentMessage/delta or reasoning deltas. Then the rate is that turn's frame rate, on the daemon, for the few handed-back servers. |
Unacked scan in arm() (idle-stop.ts:178–183) |
Once per detach that carries forgettable (a hand-back) |
Same handed-back servers | The .some stops at the first kept line, over spool.unacked(). That covers the lines since acks were held for the open-work read, capped by the 1 MiB spool memory cap. It returns null, which counts as kept, once spilled. It repeats the walk openWorkAtDetach already does. Runs once per detach. |
readProviderRelayDetachPolicy forgettable validation (detach-policy.ts:133) |
Each spawn, attach or detach RPC that carries a policy | Per relay RPC | At most 256 names of at most 128 chars each, so ≤ 32 KiB checked. The app's hand-back list is ~62 names. |
FORGETTABLE_ON_HAND_BACK (codex-shared-server-keep.ts:31) |
Module load, once | App main | ~67 table entries filtered into a deduped array of ~62. Never recomputed. |
policyFor copy, plus new Set(policy.forgettable) in adopt |
Each hand-back detach | One per hand-back | ~62 strings copied and serialized (~1.5 KB on the detach RPC), plus one Set per relay. |
Requested checks
- Idle hand-back stops promptly. When every line after the detach is a reply or a forgettable name (turn/item frames, agent and reasoning deltas, status chrome, benign notices),
check()reachesunreadKept() === falseand stops the server 60 s after its last line.keptUnreadlatches true for a plan update, goal, error or warning,hook/completed,guardianWarning,item/autoApprovalReview/completed, a file-change or process/exec output delta,process/exited, a server request, or an unparseable line. In those cases the server waits for the 24 h detached cap or a reattach, which is the behavior noted in the previous scan. Before this span every unacked line held it, so the set of lines that can hold a server only got smaller. A turn that edits files or updates its plan after the hand-back still lingers until the cap. That is intended (that output can't be rebuilt by a reopen), and the population is the few handed-back servers. - Per-key accumulation. None that outlives its owner. Each relay gets one
forgettableSet (~62 strings, replaced on eachadopt) and one boolean, freed with the relay. The span removesCodexSharedServerTurns.starts. It adds no Map or Set keyed by chat, worktree or host. - Timers. None new.
schedule()and the detached cap's single timer are unchanged. Idle wakeups per second on main, renderer and daemon match the base: 0 added.
Regression classes touched
- Hot-path rescans: matched and disproved. The per-line scan is a bounded prefix scan that latches off and is gated to handed-back relays. It is a second envelope scan next to the work reader's
scannedName, but it is O(envelope) and not O(line). - Per-entity state outlives the entity: matched and disproved (relay-scoped fields only).
- Fixed-cadence poll and new idle wakeups: no matching code.
- Unbounded queues or fan-out: no matching code. Both the policy list and the scan are capped.
Six questions
- Unused work before the gate: reviewed. The scan is gated on
armed && forgettable && !keptUnreadbefore any slicing. - Ownership multiplication: reviewed. One idle stop per relay, and a few handed-back servers per app.
- Thread and storage: daemon thread, CPU only. No fs, SQLite or subprocesses.
- Growth and progress: reviewed. The scan is bounded per line and stops at the first kept line. The arm scan is bounded by the 1 MiB spool memory cap. The policy list is capped at 256.
- Execution host: not applicable. Pure string work, the same on every platform and on remote daemons.
- Obsolete work stops: reviewed.
disarmclearsarmed, which ends the scan, and the nextarmrecomputeskeptUnread. Idle stop and the cap both still end the server.
Residual note (not a finding)
If the codex frame classification table grows past ~256 status or benign names, readProviderRelayDetachPolicy rejects the whole hand-back policy. The relay then detaches unarmed and waits for the 24 h cap. Today there are ~62 names, about 4x headroom.
Perf scan: shared Codex app-servers survive a restart (head 90bdb79)Static scan of the whole PR diff ( Verdict: blocked, one P1. FindingP1. A restored pooled chat's reopen scans its whole tool-call history a second time.
Work inventory (trigger, population, bound)
Listener census and send rates
Steady-idle wakeups per process: Electron main 0 → 0, daemon 0 → 0, renderer untouched. Handed-back servers do now live on in the daemon while the app runs, where the app used to stop them itself. A handed-back server adds ≤1 lazy idle check per 60 s until its work ends and it stops. That check fires only after activity, so it is not a fixed idle cadence. Regression classes touched
The six questions
Residual (not inspected at runtime): foreground metadata-read latency behind a startup burst on one 4-permit server, and real Codex page sizes for |
…d as running, through the unsettled-row index, not every tool row in its history
[High impact] The latest changes appear safe to merge; no new blocking failure was established. SummaryShared Codex servers can stay under the terminal daemon across Orca restarts on macOS and Linux. Reopened chats recover their history and running work from Codex.
|
Perf scan of the whole PR at
|
| trigger | population | bound | |
|---|---|---|---|
| before | every reopen of a chat on a rebuilt shared server | every tool-call row in the chat's history (tens of thousands) | grew with history |
| after | same, once per reopen | rows still unsettled in the chat's epoch | the number of unsettled rows, the same set the reopen's existing unsettled-row timeline reads already walk |
The cost no longer grows with history. Body reads (readItemsByKindPage) happen only for the rows chosen. Only the bodies of commands still open, or of history-import commands, are read again afterwards (seedCarriedKeptCodexCommands, 1–2 itemBody reads per open command).
All work the PR adds, with trigger, population and bound
| Work | Trigger | Population | Bound |
|---|---|---|---|
codexPooledRunOf / providerRelayPlacedRunOf (codex-structured-connection-opener.ts, codex-shared-server-pool.ts:98) |
building an opener, and each pooled open | 1 record | an in-memory records.get (agent-session-record-store.ts:134), O(1) |
ownRunMayBeKept and codexPooledRunGate |
a chat open whose last run was relayed (pooled: only until its kept server is attached, after which byRelay short-circuits it) |
1 daemon listing per open | concurrent cold opens share one in-flight listing (instanceListing). This is the same per-open gate that a chat's own relayed agent already pays |
kept.serverFor / reattachServer |
a pooled open after a restart | the servers kept per relay | one attach per relay, whatever the chat count (byRelay is set synchronously after the gate) |
readProcessStartTimeMs (codex-shared-server-start.ts) |
each relayed shared-server spawn | 1 pid | one /proc read or one ps per server start, one time only |
inspectMacProcessCodeIdentity (provider-relay-spawn-request.ts, anyFolder) |
each new relayed shared-server spawn on macOS (a reattach skips it) | 1 codesign child | async; concurrent probes for the same pid are shared; one time per server |
readCodexSharedOpenWork |
hand-back after the 60 s idle timer, or at quit | the server's loaded threads, each with thread/read plus a background-terminal list |
at most 4 in flight per server (PrioritySemaphore), 64 pages, 5 s timeouts; once per hand-back |
keptRunThreads / seedRunningCodexTurns (codex-shared-server-writer-stop.ts) |
closing a restored lease | the lease's threads, one thread/turns/list (limit 1) each |
at most 4 at once, once per close attempt |
Retry for a release whose reads failed (codex-shared-server.ts:124) |
only when that close's reads failed | stuck closing leases | backs off 30 s → 60 → 120 → 240 → 300 s. It ends when the server exits, a turn or chat changes, or a retry succeeds. A healthy idle run has no timer |
REBUILT_BY_RESUME.has plus replayed() per notification (codex-shared-server-start.ts) |
every frame from a shared server | 1 | O(1) |
CodexSharedServerRequests admit/takeFor/answer/resolved |
server requests only (approvals, token refresh): human- or tool-paced | requests Codex is waiting on | pending drains on answer or serverRequest/resolved. settled stores ids as ranges; ranges only multiply where gaps are left, and the set dies with the server |
RelayedProviderConsumption.lineSeqs |
every relayed line | a queue parallel to after |
the same compaction as after (head > 1024 and more than half the queue) |
CodexJournalItems activeItems.get per item event |
Codex item events | 1 | an O(1) map lookup |
readCodexHistoryJournalView openScopes / turnOfRow |
the existing full catch-up visit (base cost) | adds O(1) per row; turnOfRow holds one entry per turn during the read |
freed when the read ends; sameCodexHistoryJournalView serializes only openTools (turns with a running tool) |
Daemon ProviderRelayIdleStop: isProviderRelayKeptLine |
at a hand-back detach (once over the unacked lines), then per incoming line only while handed back and every line so far is forgettable | each line | at most 4,096 characters of envelope scan; it stops at the first kept line. The cost per line is constant and of the same size as the existing work-marker read |
relayedPlacement (agent-session-lease-transitions.ts) |
each relayed process commit | 1 | builds one object; pure |
installProviderRelayRecords (structured-agent-session-host-assembly.ts) |
journal install | 1 | runs once. list is installed but nothing calls it |
Subscriptions and publications (listener census)
| Subscription | Listeners | Idle send rate | Loaded send rate |
|---|---|---|---|
onProviderRelayQuit (pool constructor) |
1 per process | 0/s | once per quit |
onCodexSharedRelayChats holder |
1 (a getter the daemon gate reads, not a stream) | 0/s | read per relay-gate call, O(1) |
registerPooledProviderRelayChat registry |
1 entry per open pooled lease, removed in finish/endQuietly |
0/s | read at quit (pooledProviderRelayChatsPresent: one pass over the open leases) |
Shared child once('exit') / once(RELAYED_CHILD_HANDED_OFF) (provider-relay-attached-agents.ts:track) |
2 per attached shared relay child (a few per app) | 0/s | once per child exit or hand-off |
CodexSharedServerTurns waiters (existing) |
1 per closing lease | 0/s | on turn or lease change |
New timers are all one-shot and event-driven: the router's server-wide deadline refusal (100 ms or 10 s), the pool's existing 60 s idle timer (now followed by a hand-back), the daemon's 60 s idle stop after a hand-back, and the backoff for failed reads. Healthy steady idle adds 0 wakeups per second on main, the renderer and the daemon, so before and after are both 0.
Regression classes the diff touches
- Re-reading unchanged input / growth with history. This was a finding at
90bdb793971. It is fixed here because the read now goes through the unsettled-row index. - Fixed-cadence poll that never settles. Matched by the retry for failed reads, and disproved: it only exists in a failure state, has exponential backoff with a 5-minute cap, and ends when the server exits, the lease changes or a retry succeeds. The hang watch retires hung servers.
thread/loaded/listis already used by the existing kept-thread path, so it is not a permanently unsupported call. - New steady-idle wakeups. Disproved: there is no interval and every timer is one-shot.
- Subprocess per item. Disproved: codesign and the start-time read run once per server spawn, not per chat or per event.
- Unbounded fan-out. Disproved: every Codex metadata read goes through a 4-permit semaphore per server, and listings are capped at 64 pages.
- Per-entity state outlives the entity. Disproved. The pooled registry,
byRelay,handingandsharedAttachedHereall have deletes in the same teardown. The per-serverendedChatsandsettleddie with the server.handedOffAtQuitandreattachedFromLastRunare bounded by chat count per app session. - Hot-path rescans. Disproved.
SettledRequestIds.hasis linear in the number of ranges, but it runs only for request frames.takeForonly runs per thread claim. - Expensive code reachable past a gate. Disproved. Kept-state reads run only when
relay.rebuiltis set.ownRunMayBeKeptand the pooled-run gate are the existing per-open gate that a chat's own relayed agent already pays.
The six scan questions
- Unused work before the skip gate. Reviewed. Saved rows are read only when
rebuilt === true, helper threads only with a running row, and command bodies only for open commands. - Ownership multiplying work. Reviewed. There is one kept attach per relay and one open-work read per server hand-back, however many chats the server carries.
- Which thread pays. Reviewed. SQLite reads run on the journal's worker, paged. The Codex RPCs are async through the permit semaphore. Main does O(1) work per frame.
- Growth and progress. Reviewed. The blocker was cost growing with history; it now scales with unsettled rows. Failed reads back off and still move forward on any change.
- Execution host. Reviewed. Windows never relays shared servers. The macOS codesign probe runs only on a new spawn. Linux reads the start time from
/proc. Remote hosts are untouched, because the relay gate requires a local execution host. - Obsolete work stops. Reviewed. Hand-back moves timing to the daemon's idle stop.
endQuietlyunregisters and drains the lease queue (take). Fenced acks clear throughunfenceor the hand-back result.
Gaps: this was a static scan only, so there are no timing, CPU or heap measurements. The work counts above come from the source.
…nds it off instead of stopping it, so chats not reopened keep their work
|
Perf scan: 62fe073 (quit hands off a kept shared server still reattaching) — clean, no findings. Scope: Servers that stay up at quit. The only new case is a server reattached from the last run ( Quit latency. It's the same tracked-work slot as before: Repeated work. None. Regression classes: the diff matches no listed class. There's no new timer, poll, subscription or idle wakeup, nothing loops per item, and no gate is removed. The widened condition only takes effect at quit. Six questions: (1) no work before a skip gate. (2) one hand-off per server. (3) main thread does an O(1) map lookup plus one async RPC. (4) nothing grows. (5) no host-specific probes, and Windows still doesn't relay. (6) the lifetime of the abandoned reattach is bounded by the daemon's idle stop or its 24 h cap. This was a static scan; nothing was run. |
QA on the final code: crash and quit, Claude and CodexLinux, shared Codex servers on. A Codex command restored after a crash. It reads Working, with Stop, and keeps every line shown before the crash: Stop ends it, and the row keeps its title and all its output: A Codex chat that finished while Orca was down shows its output once, in order: Claude chats. After a graceful quit the chat has one run and no duplicate rows, and Send replies normally: After a crash, the same: Stop interrupts a new Claude command after the crash relaunch: The Codex chat in the same workspace keeps its history and command rows: With every chat closed, the terminal daemon stopped the shared Codex server 60 s after it was handed back. |
…odex-servers-survive-restart # Conflicts: # src/main/codex/app-server/codex-app-server-connection.ts # src/main/codex/structured/acquisition/codex-structured-connection-opener.ts # src/main/provider-relay/app-provider-relays.ts # src/main/provider-relay/provider-relay-launch-inventory.ts # src/main/provider-relay/provider-relay-run-liveness.ts
|
Perf scan of the merge with main at 031e7fe: no findings. This covers only what the merge adds: the combined diff and the 10 files both sides changed, compared with each parent. What I checked, on the paths that repeat:
Six questions: no work is paid for before a gate, no owner multiplies work, the main thread pays only constant map work, and nothing grows with chats, relays or records past the listings that already existed. The execution host doesn't matter here (no new probes). The pin and refused sets are released at commit or capped. I didn't measure runtime; this was a static scan. |
…n's front (a bot's) runs on its own relayed app-server, so its run and tools survive a restart
|
Perf scan: c9a1304 (follows the clean scan at 031e7fe). Verdict: clean, no P0/P1. Scope: the opener ( App-server process count. With sharing on, a chat whose launch was given a daemon front no longer shares a server: a bot chat, or a non-bot chat with a relayed host MCP server. Each one now runs its own relayed app-server, one per such open chat. That is the same count as sharing off at base, and the existing detached cap and idle stop limit them the same way. Chats without a front still share. The extra processes grow with the number of open fronted chats, not with worktrees, turns or history, and keeping their runs alive is the point of the change. Cost per launch. Resolution now passes
So there are at most two local daemon round trips, once per launch (start or resume), never per turn or event. Repeated work. None found. Regression classes screened:
Not measured: real launch latency of the two RPCs on a busy daemon (static scan only). |
…, so that chat still shares a server
Combined QA on the final head 8499574: bots, shared servers, restart, update, crashLinux, shared Codex servers on. Chats:
Steps, while all four were working:
Result: pass.
All four chats after the update, still Working: The Codex bot after the update: the restart message, then working tool calls: The Codex bot after the graceful restart: The Claude bot after the update: the restart message, then working tool calls: The subagent's command still running after the update, its output kept: Stop on a restored ordinary chat after the crash: |
… its tools now end with the app, so its open never lands on a second server
…h the app is still rebuilt as kept, so its running turn reads Working
…pooled placement, so a crash before it ends still reopens it on its server
…en its tools now end with the app, instead of special-casing that run's quit, close and rebuild





ELI5
With shared Codex servers turned on, quitting or updating Orca used to stop every chat's work: replies Codex was still writing, commands it was running and questions waiting for your answer were all cut off. Now, on macOS and Linux, that work keeps going while Orca is closed, and each chat picks up where it was when you open it again, reading its history back from Codex. Text Codex wrote while Orca was closed appears once that reply or command finishes. On Windows nothing changes yet. Chats run by bots are the exception: their work still stops when Orca quits, for now.
What Changed
codex-shared), on macOS and Linux. Windows and an older daemon stay as today. A new custom command takes effect once a chat's kept pooled run has ended.Why
Shared servers were spawned directly by the app, so they ended with it.
Linked Issue
N/A (maintainer).
Visual Proof
N/A: no UI change. Verified by quit/relaunch QA on Linux (see Testing).
Testing
Performance
At a hand-off, one loaded-thread listing and two reads per loaded thread, at most 4 at once. Requests waiting for a chat are bounded by the daemon's cap; settled request ids are kept as ranges. Per frame, nothing is added beyond today's routing.
Risk
Level: High. This touches routing, quit and reopen for shared servers. Known limits:
Back out with a plain revert.
Agent skill upstream boundary