Repository navigation
fix(cli): classify a permission-denied runtime connect instead of reporting "starting" - #13583
Flamingpuffins wants to merge 4 commits into
Conversation
…ting starting `orca status` reported `runtimeState: starting` whenever the local runtime socket was unreachable and the recorded pid was still alive. A guarded endpoint - wrong owner, restrictive mode bits, or a named-pipe ACL - lands in exactly that state, so the CLI advertised progress that could never arrive. Two losses of information stacked. The socket error handler in transport.ts took no error parameter at all, discarding err.code and collapsing every connect failure into runtime_unavailable, whose advice is to restart Orca. status.ts then used a bare catch, leaving nothing to branch on before the starting/stale_bootstrap fallback. EACCES/EPERM now surface as a distinct permission_denied runtime state with a message naming the endpoint. graph.state reports unavailable rather than not_running, since a live pid disproves that the graph stopped. Tests fake the connect rather than creating a genuinely permission-denied socket, which is not reproducible across platforms: a root CI user bypasses Unix mode bits and Windows guards named pipes by ACL. They therefore run on Windows too, unlike the existing socket suites in this directory. Co-Authored-By: Claude Opus 5 <[email protected]>
…denied on it Review of the previous commit surfaced two behavioral gaps. isProcessRunning collapsed every process.kill(pid, 0) failure into "not running". EPERM means the process exists but is owned by another user, so a healthy runtime observed from a sandbox was reported dead, and the new permission_denied branch emitted app.running false with a null pid alongside it. Only ESRCH proves death. This is the macOS half of the same defect (stablyai#12528), where the symptom was stale_bootstrap rather than starting. The permission_denied branch also ran before the pid-dependent fallback, so a guarded endpoint behind a provably dead pid silently overrode stale_bootstrap. It is now gated on liveness and the pre-existing fallback keeps precedence. Adds regression tests for both errno paths, each verified to fail against the unfixed code. Corrects two comments that claimed the endpoint "answered" when the OS refuses the connection before the runtime ever sees it, and records that the test mocks Node's error classification rather than any real named-pipe ACL. Co-Authored-By: Claude Opus 5 <[email protected]>
…e proves Comment-only follow-up from review. No behaviour change. EACCES on connect does not prove the endpoint exists - it can equally reflect denied traversal of the directory holding the socket - so the rationale now says the OS denied access to the transport path rather than asserting the endpoint is present and guarded. "Only ESRCH proves death" described a policy broader than the code, which treats every non-EPERM errno as absent. The comment now states the actual contract: EPERM means present, ESRCH means absent, and any other errno is handled conservatively as absent. Co-Authored-By: Claude Opus 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe runtime types add permission-denied error classification and a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
🧹 Nitpick comments (1)
src/cli/runtime/status.ts (1)
65-71: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReduce the new comment blocks.
Keep only the non-obvious reason at each site. Use one concise line where possible.
src/cli/runtime/status.ts#L65-L71: replace the branch explanation with one line that states why a live denied endpoint cannot remainstarting.src/cli/runtime/status.ts#L139-L143: replace the errno explanation with one line that states thatEPERMmeans the process exists but is inaccessible.src/cli/runtime/permission-denied-classification.test.ts#L8-L19: reduce the mock rationale to one concise statement about portable permission-error simulation.As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6db55db0-a875-45c9-905b-5c51b3cb96e7
📒 Files selected for processing (5)
src/cli/runtime/permission-denied-classification.test.tssrc/cli/runtime/status.tssrc/cli/runtime/transport.tssrc/cli/runtime/types.tssrc/shared/runtime-types.ts
AGENTS.md asks for concise, non-obvious comments, one line where possible. The blocks added by this branch ran to four and seven lines and read as narration. Every rationale is now one to three lines with no multi-paragraph blocks, keeping the facts that earlier review asked for: that EACCES reflects a denied transport path rather than a proven endpoint, that EPERM means present and any other errno is treated as absent, and that the faked connect covers errno classification rather than real OS enforcement. No behaviour change; comments only. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Thanks — condensed the comment blocks in Kept the specifics earlier review asked for: that Left the docstring-coverage warning as-is deliberately — Comments only, no behaviour change: typecheck, oxlint, and the |
macOS measurement:
|
| Probe | Inside seatbelt sandbox | Outside (control) |
|---|---|---|
stat() on endpoint |
succeeds — mode 600, uid 501, gid 20 |
same |
access(W_OK) |
EPERM |
ok |
process.kill(pid, 0) |
EPERM |
alive |
net.connect() |
EPERM, syscall: "connect" |
connected |
Raw probe line from inside the sandbox:
PROBE {"stat":{"mode":"600","uid":501,"gid":20},"access":"EPERM","kill":"EPERM","connect":"EPERM","syscall":"connect","errno":-1}
What the unpatched CLI reported at that moment, inside the sandbox:
{ "app": { "running": false, "pid": null },
"runtime": { "state": "stale_bootstrap", "reachable": false, "runtimeId": null },
"graph": { "state": "not_running" } }{ "ok": false,
"error": { "code": "runtime_unavailable",
"message": "Could not connect to the running app. Restart and try again." } }Outside the sandbox, same minute, same runtime: runtime.state: "ready", reachable: true, pid present.
The caller and the socket owner are the same uid
Worth separating from the Windows case in #13539, where the sandbox runs as a distinct account (CodexSandboxOffline / CodexSandboxOnline).
On macOS the sandboxed process runs as uid 501, and the socket is owned by uid 501 with mode 600. Ownership and mode bits are already correct and the connect is still denied — seatbelt denies the syscall itself, above the filesystem permission check.
The practical consequence: any classification that inspects endpoint ownership or mode to decide whether a denial is plausible will conclude "this should work" on macOS. The errno is the only available signal, which is what this PR keys on.
Mapping to the three changes here
| Change in this PR | Measured errno it keys on |
|---|---|
transport.ts — pass err into the 'error' handler, classify EACCES/EPERM as runtime_permission_denied |
connect → EPERM |
isProcessRunning — treat EPERM as alive rather than absent |
kill(pid, 0) → EPERM |
status.ts — running && permission-denied → permission_denied, graph unavailable |
both of the above, together |
macOS lands on the EPERM liveness branch, which is the case your treats an EPERM liveness probe as alive, not as a dead pid test already covers. So on this evidence macOS moves from stale_bootstrap to permission_denied under this PR, for the same reason Windows moves off starting.
Scope limit
I measured errnos against unpatched upstream code; I did not build and run this PR's branch. The claim here is only that the inputs your classification depends on are present on macOS with the values it expects — not an end-to-end verification of the patched output.
Why the current output is worse than merely unhelpful
runtime_unavailable carries "restart and try again". In the sandbox that advice is not just useless, it is actively wrong: restarting recreates the endpoint with identical permissions while the sandbox denial is unchanged. A caller told permission_denied can recover immediately — drop the sandbox for that one call, or route the lifecycle message another way. A caller told stale_bootstrap or starting has no reason to do either.
Happy to re-run the probe with any variation that would help — different sandbox modes, the websocket transport, or a build of this branch.
|
Follow-up to my errno measurement above — the failure then happened to me for real, and one detail is directly about this PR's reach. Full writeup on #12528: #12528 (comment) A plain The part worth flagging here: the text the worker actually saw was two layers, not one. The second line comes from I traced whether this PR reaches that second layer, rather than assuming it. It does: Also worth noting for scope: Offer stands — I can re-run this end-to-end against a build of this branch if a before/after on the real orchestration path would help before merge. |
…22341) * fix(cli): report a denied runtime connection instead of a dead Orca Inside Codex's macOS Seatbelt sandbox, connect() on the runtime socket fails with EPERM. The CLI dropped the errno and reported "Could not connect ... Restart Orca", appended "Orca is not running. Run 'orca open' first.", and `orca status` answered ok:true with `starting` (its pid probe also gets EPERM). An agent following that advice restarts a healthy app, which cannot help. EPERM/EACCES on the metadata read or the socket/pipe connect now fails with a CLI-local `runtime_access_denied` error: ok:false, non-zero exit, operation/systemCode/processState:"unverifiable"/retryable:false and nextSteps that say to re-run with escalated permissions and not restart. CODEX_SANDBOX only picks the wording. `orca open` stops before launching. The status pid probe is unchanged: a refused or missing socket proves the caller reached the endpoint, so a later EPERM probe is another uid and keeps #20098's `starting`. Missing, refused, stale-pid and timeout paths are unchanged. Adapted from the diagnosis and tests in #20487 (and #19605, #13583). Co-authored-by: lifeodyssey <[email protected]> * docs(skills): tell agents runtime_access_denied means escalate, not restart The shared CLI-resolution block told every bundled skill to run `orca open` when a command says Orca is not running. Add the counterpart for the new access-denied code so sandboxed agents re-run with escalated permissions instead of launching or restarting Orca. Regenerated stubs and manifest. * refactor(cli): classify only a denied runtime connect, with a leaner error A denied metadata read was never observed under a sandbox, and it turned an unreadable user-data path (the Linux launch contract's root-owned HOME) into runtime_access_denied instead of "Orca is not running". Keep metadata reads as on main and classify only the socket/pipe connect. One helper now maps a socket errno to the error or null; the error data keeps only systemCode and nextSteps. Tests drop cases already pinned by status.test.ts. * fix(cli): give not-running advice when a denied socket belongs to a dead Orca A crashed Orca leaves its metadata and socket file behind, and a sandbox denies the connect with EPERM before the CLI can see ECONNREFUSED. The sandbox still reports ESRCH for a gone pid, so a denied connect now probes the metadata pid and falls through to the ordinary unavailable path when the pid is proven gone. isProcessRunning moves to its own module so transport and status share it. * refactor(cli): inline the runtime_access_denied code like other CLI error codes --------- Co-authored-by: lifeodyssey <[email protected]>
|
Thanks for this! The bug it targets (#12528) has since been fixed on main by another change, so I'm closing this as superseded. Appreciate the contribution. |
Addresses Defect 2 only of #13539 (
Defect 2 — permission-denied connect is mapped to permanent "starting"). Deliberately notCloses #13539: Defect 1, the named-pipeDACL that excludes the Codex sandbox principal, is untouched and needs a native
CreateNamedPipeWsecurity descriptor. That issue notes Defect 2 "could landindependently of Defect 1", which is what this PR does.
It also improves the liveness classification relevant to #12528 (the macOS counterpart) via
the liveness-probe change below. Stated deliberately narrowly: that issue shows the pid
probe is permission-limited under sandbox, but I have not reproduced on macOS whether the
socket
connect()there also returnsEACCES/EPERM, so I am not claiming this resolvesthat issue's classification outright.
This does not restore connectivity. Inside the Codex sandbox,
orcacommands that needthe runtime —
orchestration send --type worker_doneamong them — still cannot connect.What changes is how the failure is described, and that differs by command:
orca statusreturnsruntime.state: permission_deniedwhere it previously returnedstarting, so a caller polling it is no longer told to keep waiting for a state thatwill never arrive.
runtime_permission_deniedwith the endpoint named,where it previously threw
runtime_unavailableand its "restart Orca" advice. Thesecommands never reported
startingthemselves — they failed with misleading guidance.Summary
orca statusreportedruntimeState: startingwhenever it could not reach the localruntime socket and the recorded pid was still visible. A permission problem on the endpoint
— wrong owner, restrictive mode bits, or a named-pipe ACL — lands in exactly that state, so
the CLI advertised progress that could never arrive.
startingis indistinguishable from aruntime that is genuinely still booting, so the correct client behaviour (keep waiting) is
precisely the behaviour that hangs forever.
Three changes:
EACCES/EPERMon connect now surfaces as a distinctpermission_deniedruntime state with a message naming the endpoint, instead of beingcollapsed into
runtime_unavailable— whose advice, "restart Orca", recreates theendpoint with the same permissions.
process.kill(pid, 0)throwingEPERMmeans theprocess is present but owned by another user;
ESRCHmeans absent. Any other errno isstill treated conservatively as absent. This is the probe behaviour CLI reports stale_bootstrap for healthy runtime inside Codex sandbox on macOS #12528 describes on
macOS, where a present-but-inaccessible process was read as gone.
permission_deniedrequires a live pid. A permission-deniedconnect behind a provably dead pid is a leftover, so the pre-existing
stale_bootstrapanswer keeps precedence.
Screenshots
No visual change— CLI output only.Testing
pnpm typecheckpnpm lint— exits 0. One caveat worth reporting: on Windows the chain first fails atverify:skill-bundle-manifest, claimingresources/skills/{current-manifest,snapshot-registry,release-mapping}.jsonarestale. This is not caused by this PR — it reproduces on a pristine checkout of
current
mainwith zero changes. Root cause is line endings:.gitattributespinseol=lffor byte-compared paths such as/resources/plugins/**, but not forresources/skills/*.json, so withcore.autocrlf=truethey are checked out CRLFwhile the generator writes LF and the comparison fails. Converting those three files
to LF makes the gate pass and the whole chain exit 0, which is the result recorded
here. The artifacts are deliberately not regenerated in this PR. A one-line
.gitattributesentry would fix it for Windows contributors; happy to send thatseparately if useful.
pnpm test— not a clean signal locally. The full run completes in ~20 min on therebased branch: 48,438 passed, 229 failed across 79 files, 643 skipped. Zero of the
failures are under
src/cli, where every behavioural change in this PR lives. Theyare overwhelmingly
EPERM: operation not permitted, symlink(Windows requiresDeveloper Mode to create symlinks) and
spawn /bin/sh ENOENT, clustered insrc/main/{ipc,git,ssh,ai-vault},src/relay, andconfig/scripts. These areenvironmental rather than related to this change, but CI remains the
supported-environment signal, so I cannot tick this box from here. Targeted evidence
instead:
src/cli— 732 passed, 28 skipped.pnpm buildTests
New
src/cli/runtime/permission-denied-classification.test.ts, six cases. Each was verifiedto fail against the unfixed code by reverting the relevant hunk:
EACCES→runtime_permission_deniedruntime_unavailableEPERM→runtime_permission_deniedruntime_unavailablestartingon a live pidstartingEPERMliveness probe treated as alivestale_bootstrapESRCHliveness probe keepsstale_bootstrappermission_deniedECONNREFUSED→ stillruntime_unavailableThe connect is faked rather than genuinely permission-denied, because that is not
reproducible across platforms — a root CI user bypasses Unix mode bits and Windows guards
named pipes by ACL. Scope caveat: this exercises how Node's errno is classified, not the
OS enforcement that produces it. It does not prove anything about a real named-pipe DACL,
and it is not a test for Defect 1. The fake emits
errorthenclosein Node's real order,pinning the double-settle guard so the close handler cannot overwrite the classified error.
AI Review Report
Reviewed with Claude. Risks checked, and what came of each:
EACCES/EPERMare the codes both Unixdomain sockets and Windows named pipes raise for a permission-denied transport path;
libuv's Windows error mapping produces both. No path strings are constructed — the
endpoint is echoed from existing metadata — so no separator assumptions. No shortcuts,
labels, shell
invocation, or Electron-specific surface is touched. The new tests run on all three
platforms, unlike the existing socket suites in this directory, which are
skipIf(win32).EPERMinto "dead",so on macOS the new branch would have reported
permission_deniedalongsideapp.running: falseandpid: null— incoherent, and the probe behaviour CLI reports stale_bootstrap for healthy runtime inside Codex sandbox on macOS #12528describes; (b) the permission branch originally ran before the pid-dependent
fallback, silently overriding
stale_bootstrapfor a dead pid; (c) several comments claimed more than the code or thesyscalls support — that the endpoint "answered" (the OS refuses before the runtime sees
the connection), that
EACCESproves the endpoint exists (it can equally mean deniedpath traversal), and that "only ESRCH proves death" (the implementation treats every
non-
EPERMerrno as absent). All are corrected, and (a) and (b) now have dedicatedregression tests.
unix/named-pipetransport. The remotepairing branch in
client.tsreturns before this code, and the remote path(
websocket-transport.ts,remote-runtime-client-error-classification.ts) is untouched —its agreement corpus still passes. The new code is deliberately not added to
RECOVERABLE_CODES: retrying never clears a permission problem.behavior involved.
Setlookup on an already-failing connect. Nothing in a hot path.CliRuntimeStatehas no exhaustive switch ori18n mapping — its two consumers (
cli/format.ts,ssh-remote-cli-format.ts) interpolatethe raw string — so the localization gates are unaffected.
CliStatusResultis built client-side from thestatus.getresult; the classification derives from a local socket error and never crosses the wire,
so no host/client capability negotiation is involved.
Security Audit
changes how an already-failing connect is described. A caller denied by the OS is still
denied;
metadata.authTokenremains the RPC authority and is untouched.already present in
orca-runtime.jsonreadable by the same principal, and is shown to thelocal user who just tried to open it. No token, credential, payload, or RPC data is added
to the message. The existing
redactOrchestrationCompatibilitySecretspath for structurederror data is unchanged.
err.code, compared against a fixed two-elementallowlist. No parsing, no interpolation into a shell or path.
process.kill(pid, 0)is asignal-0 liveness probe that was already there; the change only reads the errno it throws
rather than discarding it. No new IPC surface.
actual security-relevant decision lives — any DACL work there should grant only duplex
client rights, and specifically not
WRITE_DAC,WRITE_OWNER, orFILE_CREATE_PIPE_INSTANCE, per the analysis in [Bug][Windows]: Codex sandbox cannot connect to Orca runtime named pipe (EPERM); status reportsstartingforever #13539.Notes
pid, so it yields
starting), but the fix is platform-independent. CLI reports stale_bootstrap for healthy runtime inside Codex sandbox on macOS #12528 describes themacOS side, where an
EPERMliveness probe yieldsstale_bootstrap; change 2 above makesthat probe accurate, but I have not reproduced that issue on this branch and am not
claiming it resolves it.
EPERMliveness probe as alive alsoaffects the pre-existing non-permission fallback — a runtime owned by another user that is
unreachable for some other reason now reports
startingrather thanstale_bootstrap.That is the more accurate answer, but it is a visible change outside the permission path
and worth a maintainer's eye.
RuntimeClient.openOrca()pollsgetCliStatus()for up to15s and then reports
runtime_open_timeout. Apermission_deniedendpoint could now bailout of that loop early with a useful message. Left out to keep this PR to a single topic;
behavior there is unchanged by this patch.
resources/skills/*.jsonare byte-compared byverify:skill-bundle-manifestbut have noeol=lfrule in.gitattributes, sopnpm lintfails for any Windows contributor withcore.autocrlf=true. Not touched here.main(a63df9179) before submitting.X: @Flamingpuffins