Repository navigation
fix(agent-trust): bound the remaining Codex trust writes a launch waits on - #23380
Conversation
There was a problem hiding this comment.
Important
The bound added at the two startup-prep call sites does not actually bound the launch: each one awaits a same-lane hook install right after the bounded write, and that install has no deadline. The ELI5's "starts the agent anyway" and the new gate oracle hold only because the new tests mock the hook service to resolve instantly. Details inline.
Reviewed changes
- Bound three more Codex trust writes —
markLocalWorktreeTrusted,prepareCodexRuntimeHomeForLaunchandprepareCodexSessionResumeForLaunchnow routemarkCodexProjectTrustedthroughawaitAgentTrustWriteWithinDeadline(20s race, named warning, rejection adoption) instead of a bareawait. - Reliability gate updated —
agent-session.trust-preflight-completionnow lists all five bounded call sites, rewrites the invariant/oracle/coverage notes, and adds the new suites to its command, test list and evidence. - New tests —
src/main/startup/codex-launch-trust-write-deadline.test.ts(5 cases: bound + ordering for quick-launch and resume prep, contained rejection) plus one never-settling bound case inruntime-worktree-agent-startup.test.ts. The never-settling cases have teeth (they hang to the vitest timeout against a bareawait).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughCodex launch preparation, session resume preparation, and local worktree startup now use a deadline-bounded helper for trust writes. New tests cover timeout handling, call ordering, warning behavior, timer cleanup, and resume outcomes. The reliability gate now includes these paths and records six suites with 53 passing tests. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to This change can proceed after normal checks. It limits the three targeted waits, but does not guarantee that quick launch or resume completes when later hook work stalls. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 2 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (1 skipped: 1 unsupported.)
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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 84ab770e-b9a7-4e7d-83f7-35c3e0f7e3a4
📥 Commits
Reviewing files that changed from the base of the PR and between 6504ef0 and ecd26579824e16807b20cd156699f693fbf43a00.
📒 Files selected for processing (1)
config/reliability-gates.jsonc
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — the gate now correctly scopes the 20s deadline to the trust write. One invariant wording point inline.
Reviewed changes
- Reliability gate stopped claiming a bounded launch —
agent-session.trust-preflight-completion'sinvariant,oracle,coverageNotes,performanceBudget.evidenceandknownGapsnow state that the deadline bounds the trust write rather than the whole launch, and name the two launch-prep sites whose next same-lane hook step can still stall the launch.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ts on #23148 capped the trust write on the agentTrust:markTrusted IPC handler and the worktree-remote startup path, but three call sites still awaited markCodexProjectTrusted with no bound: the main-process worktree startup used by orchestration worker-start, Codex quick-launch preparation, and Codex session resume preparation. All three share the per-config.toml lane with hook installs and app-server trust grants, which has no cap on queue depth, and the SSH writer adds a resolveHome round trip plus unbounded SFTP over a possibly half-open link. A wedged lane left the user clicking "start agent" with nothing happening and no error. Each site now routes through the existing awaitAgentTrustWriteWithinDeadline helper with unchanged semantics for its two current callers. Abandoning at the deadline never cancels the write, writes nothing else, and never substitutes a local fallback, so the workspace stays untrusted and Codex raises its own trust prompt. The await still sits ahead of the runtime-home resolution and hook repair that the PTY spawn waits on, so the ordering #23148 established is kept. Reliability only; there is no speed gain. The win is that a launch cannot hang. Verified with 2,755 agent-trust/Codex/startup/runtime tests, the 53-test reliability-gate command, the gate manifest check, typecheck:node, changed-code quality, oxlint and oxfmt. Red-green: with the three sites reverted to a bare await the new bounding tests hang to the 30s vitest timeout (3 fail/14 pass); restored, 17 pass. Co-Authored-By: Claude <[email protected]>
…nded launch The gate's performance budget said a stuck predecessor "degrades to the agent's own trust prompt instead of an indefinite caller wait." That is false at two of this branch's three new sites. In startup/codex-launch-preparation.ts the next awaited call after the abandoned write is codexHookService.prepareRuntimeHomeForLaunch; in startup/codex-session-resume-launch.ts it is installForLaunchPrep or refreshRuntimeUserHooksForLaunchPrep. Both reach runExclusivelyForRuntimeAndSystemTrustConfig, which takes the same runExclusivelyForCodexTrustConfig queue - FIFO per config.toml, no depth cap and no timeout - on the runtime home and on ~/.codex/config.toml that markCodexProjectTrusted itself takes. A wedged lane still stalls those two launches one step later, with the abandoned write holding its queue slot ahead of the hook step. Only markLocalWorktreeTrusted has nothing after its Codex branch and so is bounded end to end. The budget, invariant, oracle and coverage notes now say what is true: all five markCodexProjectTrusted call sites are bounded, so no trust write hangs a caller indefinitely, but the bound is on the write and not on the launch. A new knownGaps entry records the residual stall and that the new launch-prep tests mock codexHookService wholesale, so nothing in these suites can catch it. The already-complete-write case stays labelled a timer control, not a red. Wording only; no production code, test or count changed. The cited command still reports 6 files / 53 tests, and the gate manifest check passes for 138 gates. Co-Authored-By: Claude <[email protected]>
…ook-service call The trust-preflight gate cited codexHookService.prepareRuntimeHomeForLaunch as the immediate next step after the abandoned write in startup/codex-launch-preparation.ts. Tracing the module, the first awaited step is ensureRealHomeHooksIfSelected. It is conditional: only when the target is not WSL and runtimeHome.isHostSystemDefaultRealHomeSelected(launchEnv) is true does it call ensureRealHomeCodexHookState, which chains behind that module's own serial ensure promise and then acquires runExclusivelyForCodexTrustConfig directly on ~/.codex/config.toml - the same lane markCodexProjectTrusted's inner acquire takes. When the real home is not selected that call returns without awaiting the lane, runtimeHome.prepareForCodexLaunchAsync is synchronous on the non-WSL path, and only then is prepareRuntimeHomeForLaunch the first re-entry. So the gate could miss a launch stall one step earlier than the one it named. startup/codex-session-resume-launch.ts had the same omission: its hook branch takes ensureRealHomeCodexHookState when the resume home is ~/.codex, and only otherwise installForLaunchPrep or refreshRuntimeUserHooksForLaunchPrep. The coverage notes also understated the mocking - codex-launch-trust-write-deadline mocks ensureRealHomeCodexHookState as well as codexHookService and defaults the real-home selection to false, so neither lane is driven by any suite here. The performance budget, coverage notes and the residual-stall knownGap now name the first re-entry on each path and say when it applies, rather than only the later hook-service call. Wording only; no production code, test or count changed. The cited command still reports 6 files / 53 tests, and the gate manifest check passes for 138 gates. Co-Authored-By: Claude <[email protected]>
8ce3ef4 to
50b8db8
Compare
…ocal writes The invariant claimed every Codex trust write a launch waits on is bounded or abandoned at a deadline. The entry's own knownGaps contradicted that: the remote write reached through markRemoteWorktreeTrusted in runtime/runtime-worktree-agent-startup.ts is awaited with no timer, and it is a Codex write, not an adjacent one - it reads TUI_AGENT_CONFIG[agent].preflightTrust, which is 'codex' for the codex agent, and markRemoteAgentWorkspaceTrusted then branches into markRemoteCodexProjectTrusted. Its one production caller, markRemoteWorkspaceTrustedForAgent, is reached with a connectionId from seven launch entry points; five await it directly before the createTerminal that spawns the agent, and two gate the launch command they hand back for their caller to spawn. It chains a session.resolveHome round trip plus SFTP realpath/read/mkdir/ write, none with a timeout, over a possibly half-open link - the same hang this branch bounds locally. The invariant now claims only the five local markCodexProjectTrusted sites and names the remote exception inline instead of leaving it to knownGaps. Audited the rest of the entry against the code in the same pass: performanceBudget said "no trust write can hold its caller indefinitely" (now scoped to those five); the "all five awaited Codex trust writes" tally is now "all five awaited local" and points at the unbounded sixth; the remote gap no longer calls that path merely "preset-agnostic and out of Codex scope"; oracle and coverageNotes now record that nothing here drives markRemoteWorktreeTrusted, since the remote-preset suite only checks what markRemoteAgentWorkspaceTrusted writes, never how long it may take; and surfaces gains the remote writer that suite actually covers. Re-verified the rest rather than assuming it: the launch-prep re-entry chain, the FIFO no-cap no-timeout trust-config queue, the IPC handler capping both its remote and local writes with no cross-branch fallback, and that upsertProjectTrustLevel and upsertProjectTrustLevelInContent remain the only producers of a project trust_level, so no further writer needs covering. The already-complete-write case stays labelled a timer control, not a red. Wording only; no production code, test or count changed. The cited command still reports 6 files / 53 tests, and the gate manifest check passes for 140 gates. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Scoped the trust-preflight
invariantto local writes —agent-session.trust-preflight-completionnow claims only the five localmarkCodexProjectTrustedcall sites, and names the unbounded remotemarkRemoteWorktreeTrustedwrite as a second explicit limit alongside the "bounds the write, not the launch" caveat. - Recorded the remote gap in the gate —
oracle,coverageNotes,performanceBudget.evidenceand a newknownGapsentry now state that the remote Codex write fronting an SSH launch is unbounded and unmeasured, and thesurfaceslist gainsremote (SSH) agent workspace trust writer. - Verified against source —
markRemoteWorktreeTrusted(src/main/runtime/runtime-worktree-agent-startup.ts:221) readsTUI_AGENT_CONFIG[agent].preflightTrust,markRemoteAgentWorkspaceTrustedbranches intomarkRemoteCodexProjectTrusted(src/main/remote-agent-trust-presets.ts:23), and the write is awaited viamarkRemoteWorkspaceTrustedForAgent(src/main/runtime/orca-runtime-activate-managed-worktree.ts:188), so the invariant's exception is accurate and matchesknownGaps.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When you start Codex in a folder it has never seen, Orca quietly writes a small "this folder is fine" note so Codex does not stop and ask you first. Writing that note takes a turn in a queue, and if something ahead of it in the queue gets stuck, the note never finishes.
Before this change, three of the places that write the note would wait for it forever. You pressed "start agent" and nothing happened at all — no agent, no error, no prompt.
Now every one of those waits has a 20-second limit, so no single note can hold up its caller forever. That is the whole of what this change promises. It is not the same as "the agent always starts":
Fixing the queue itself is a separate, larger change. This PR removes the part where a single note write can hang a caller with nothing to show for it, and it says plainly on the reliability gate which launches are still exposed.
What Changed
PR #23148 fixed this hang in two places: the
agentTrust:markTrustedIPC handler and the worktree-remote startup path. It addedsrc/main/agent-trust-write-deadline.ts, which waits on a trust write for at most 20 seconds.Three call sites were still waiting with no limit. This PR routes all three through that same helper:
src/main/runtime/runtime-worktree-agent-startup.ts—markLocalWorktreeTrusted, the pathorchestration worker-starttakes.src/main/startup/codex-launch-preparation.ts— quick-launch preparation, which runs before every recognized Codex spawn.src/main/startup/codex-session-resume-launch.ts— resuming an existing Codex session.Before, as a user: with the shared config lane wedged (a hook install or an app-server trust grant holding it, or an SSH write stalled on a half-open link), launching or resuming Codex from any of those three paths produced a pane that never started. Nothing timed out, nothing was logged, and the only way out was to quit.
After: no trust write can hold its caller past 20 seconds. Each site logs one named warning and moves on. What that buys differs by site, and the difference matters:
runtime-worktree-agent-startup.ts— the launch completes. Its Codex branch has nothing after the trust write, so when the wait is abandoned the startup path finishes and the agent starts. This is the one end-to-end bounded launch here.config.tomlqueue the abandoned write is still sitting in. A reviewer should read this as "the wait is now attributable and logged", not "the pane always starts".Mechanism: each site previously did
await markCodexProjectTrusted(path). That write takesrunExclusivelyForCodexTrustConfigon the runtimeconfig.tomland then on~/.codex/config.toml— a FIFO lane per file, shared with hook installs and app-server trust grants (10s native / 30s WSL each), with no cap on how many are already queued. The SSH writer adds asession.resolveHomeround trip plus unbounded SFTP calls. The write is not self-bounding, so the caller was not either. The call is now wrapped inawaitAgentTrustWriteWithinDeadline, which races the write against onesetTimeout, cleared in afinally, and adopts the write promise so a rejection arriving after the deadline stays handled rather than surfacing unhandled.Why the two launch paths are still exposed, traced in the modules:
codex-launch-preparation.tsthe first awaited step after the write isensureRealHomeHooksIfSelected. That step is conditional — only when the target is not WSL andruntimeHome.isHostSystemDefaultRealHomeSelected(launchEnv)is true does it callensureRealHomeCodexHookState, which acquires the lane directly on~/.codex/config.toml. When the real home is not selected it returns without awaiting the lane, and sinceprepareForCodexLaunchAsyncis synchronous on this non-WSL path, the first re-entry is thencodexHookService.prepareRuntimeHomeForLaunch.codex-session-resume-launch.tsthe first awaited step is the hook branch:ensureRealHomeCodexHookStatewhen the resume home is~/.codex, otherwiseinstallForLaunchPreporrefreshRuntimeUserHooksForLaunchPrep.~/.codex/config.tomllane, either directly or as the inner acquire ofrunExclusivelyForRuntimeAndSystemTrustConfig. The abandoned write also keeps its queue slot ahead of that step.Two properties are deliberately preserved:
prepareForCodexLaunchAsync(whose return value is theCODEX_HOMEthe spawn needs), and in resume prep it precedes the hook repair inside the resolver whose return value the PTY waits on. Both orderings have a test.The reliability gate
agent-session.trust-preflight-completioninconfig/reliability-gates.jsoncis updated to match. Its invariant now states that the deadline bounds the write and not the whole launch. ItsknownGapspreviously recorded these three sites as unbounded; it now records all five as bounded plus the four things that genuinely remain:codexHookServiceandensureRealHomeCodexHookStatewholesale and default the real-home selection to false, so no suite here drives either lane — nothing in this PR is evidence about whether a launch as a whole is bounded.ipc/worktree-remote.tssite is bounded but still has no test in these suites.markRemoteWorktreeTrustedis still unbounded, which is out of this change's Codex scope.Evidence counts were re-measured, not copied.
Why
The problem is a user-visible hang with no error, on the main path for starting and resuming Codex.
Alternatives considered:
config.toml. That needs its own change with its own evidence. The deadline sits in the caller, so it changes only how long a caller is willing to wait, never what gets written.There is no speed gain here. In the normal case the write settles in milliseconds and nothing changes. The win is narrower than "a launch cannot hang": no trust write can hang its caller indefinitely, one launch path is bounded end to end, and for the other two the remaining stall is now written down on the gate instead of being assumed away.
Linked Issue
Follow-up to #23148. No separate issue.
Fixes #
Visual Proof
N/A— there is no UI change. The only user-visible difference appears when a trust write stalls past 20 seconds: on the worktree-startup path, the agent starts and Codex shows its own trust prompt instead of the pane never starting. On quick-launch and resume the pane can still stall on the following hook step, so there is no reliable "after" to record. Reproducing any of it on a real machine needs a wedged config lane, which is why it is covered by unit tests that hold the write open under fake timers rather than by a recording.Testing
macOS, local. Not run on Linux, Windows, WSL or against a live SSH host; the remote writer is mocked in these suites.
ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-trust-presets.test.ts src/main/remote-agent-trust-presets.test.ts tests/e2e/agent-trust-completion.unit.test.ts src/main/codex src/main/startup src/main/runtime/runtime-worktree-agent-startup.test.ts— 2,755 passed, 20 skipped.node config/scripts/check-reliability-gates.mjs— passed for 138 gates.pnpm tc:node,pnpm run check:code-quality:changed,oxlint,oxfmt --check— all clean (includingconfig/reliability-gates.jsonc, formatted with oxfmt, not prettier).Red-green, to show the new tests have teeth: with the three call sites reverted to a bare unbounded
awaitand the tests unchanged, all three never-settling cases fail by hanging to the 30s vitest timeout (3 fail / 14 pass). Restored, 17 pass in 0.46s. Note that the gate's existing "admits an already-complete write without waiting for any timer" case passes against an unbounded implementation too — it is a timer control, not evidence of bounding.What the tests do not show: because they mock
codexHookServiceandensureRealHomeCodexHookState, nothing here exercises the realconfig.tomllane, so no test in this PR speaks to whether a quick-launch or a resume completes when that lane is wedged.New tests:
src/main/startup/codex-launch-trust-write-deadline.test.ts(5 cases covering both startup prep sites: the bound, the ordering, and a contained rejection) and one case added tosrc/main/runtime/runtime-worktree-agent-startup.test.ts.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
docs/reference/ssh-execution-boundary.md.setTimeoutper call, cleared on settlement. The cap is per call site, not global, so two launches racing the same wedged lane each wait their own deadline.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Co-Authored-By: Claude [email protected]