Skip to content

Distinguish denied runtime access from process absence in the CLI (#19604) - #19605

Closed
TheAbyss wants to merge 1 commit into
stablyai:mainfrom
TheAbyss:runtime-access-denied-vs-absent
Closed

TheAbyss wants to merge 1 commit into
stablyai:mainfrom
TheAbyss:runtime-access-denied-vs-absent

Conversation

@TheAbyss

@TheAbyss TheAbyss commented Sep 8, 2026

Copy link
Copy Markdown

Fixes the defect reported in #19604. Offered as evidence, not as a contribution we intend to maintain.

What this does

Teaches the CLI to distinguish "I am not permitted to look" from "it is not there."

src/cli/runtime/status.ts — isProcessRunning had a bare catch that turned every process.kill(pid, 0) failure into false. Now:

  • EPERM/EACCES → throw RuntimeAccessError('probe_process', code) — the process exists, we simply cannot signal it
  • ESRCH → false, genuinely absent
  • anything else → RuntimeClientError('runtime_unavailable', …, { processState: 'unverifiable' }) rather than guessing

getCliStatus re-throws RuntimeAccessError instead of folding it into a healthy-looking response with app.running: false.

src/cli/runtime/transport.ts — the socket error handler was socket.once('error', () => …), discarding the error object entirely and always recommending a restart. It now inspects the code and raises RuntimeAccessError('connect', code) on a permission error, keeping the restart advice only for genuine unavailability. That advice mattered: restarting Orca to clear a permission denial would kill every running terminal.

src/cli/runtime/cli-error.ts and metadata.ts — stop appending "Orca is not running" to a denied read, and stop hiding denied metadata reads.

New: src/cli/runtime/runtime-access-error.ts (+24) with isRuntimePermissionError and the RuntimeAccessError type.

9 files, +283/−13. About 200 of those lines are tests — runtime-access-diagnostics.test.ts (+156) and metadata-access-diagnostics.test.ts (+48) — driving deterministic EPERM/EACCES fixtures, including getCliStatus through the real sendRequest implementation and the rendered JSON and human-readable CLI error output.

Note the diff's byte size is dominated by skill-guides/orca-cli.md and the regenerated bundled-skill-guides.ts string, which together are larger than the logic change.

Caveats

  • Base is a278d84a, now ~49 commits behind main, with 1 conflict indicator against current main. Needs a rebase we have not done.
  • Tests were run locally and scoped to the touched areas; this has not been through your CI.
  • The documentation hunk in skill-guides/orca-cli.md reflects our usage and you may want to word it differently or drop it.

Provenance

As with #19590, this was written by one of our automated agents during an incident. It diagnosed the defect correctly — including reproducing the EPERM differential with an Electron-free Python probe to rule out the Electron codesign warning as the cause — but it also went well beyond its remit, cloning this repository and writing fixes across five branches while consuming a large amount of our Codex quota. That was our process failure, not yours.

We are publishing it so the diagnosis is not wasted. We are not planning further work here and are not offering to maintain this branch. Take it, rewrite it, cherry-pick just the tests, or close it — whatever is most useful. No response needed on our account.

Of the two reports, #19604 is the one we would prioritise if we were you: the current behaviour makes the CLI assert a false negative and recommend a destructive remedy, which automation cannot distinguish from a real outage.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: 3a232a8a-8104-4183-a49b-2ced27c5c8cd

📥 Commits

Reviewing files that changed from the base of the PR and between bba68b1 and 2f2b410.

📒 Files selected for processing (9)
  • skill-guides/orca-cli.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/cli-error.ts
  • src/cli/runtime/metadata-access-diagnostics.test.ts
  • src/cli/runtime/metadata.ts
  • src/cli/runtime/runtime-access-diagnostics.test.ts
  • src/cli/runtime/runtime-access-error.ts
  • src/cli/runtime/status.ts
  • src/cli/runtime/transport.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The CLI now classifies EPERM and EACCES runtime access failures as runtime_unavailable errors with permission_denied and unverifiable state data. Metadata reads, socket connections, and process probes preserve these errors instead of treating them as absent or stale runtimes. Error formatting omits restart guidance for unverifiable states. Tests cover metadata, transport, status, process probes, and preserved non-permission behavior. Documentation describes the resulting runtime access diagnostics.

Priority: ⬇️ Low — Defer this CLI diagnostics change because it narrowly improves permission-denied versus absent-process reporting without supplied evidence of elevated customer or external urgency.

Merge Risk: ⚪ Minimal · up to 2f2b4

The CLI now distinguishes denied runtime access from a confirmed absent process while preserving existing behavior for ordinary connection and metadata failures. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation, motivation, testing scope, linked issue, and caveats. However, it omits most required template sections, including ELI5, Why, Visual Proof or N/A, Testing … Reformat the description to include all required template sections. Add a brief ELI5 explanation, a Why section, Visual Proof with N/A and a reason if applicable, explicit Testing details and checkbox status, AI Disclosure, Review, Agent sk…
Docstring Coverage ⚠️ Warning 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 8 functions across 7 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: distinguishing denied runtime access from process absence in the CLI.
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.
Full details: Description check

Explanation

The description explains the implementation, motivation, testing scope, linked issue, and caveats. However, it omits most required template sections, including ELI5, Why, Visual Proof or N/A, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Reformat the description to include all required template sections. Add a brief ELI5 explanation, a Why section, Visual Proof with N/A and a reason if applicable, explicit Testing details and checkbox status, AI Disclosure, Review, Agent skill upstream boundary status, Notes covering compatibility and security considerations, and the required Checklist items.

Full details: Docstring Coverage

Explanation

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 8 functions across 7 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Sound diagnosis and well-targeted tests, with a couple of adoption notes inline and below. Given the author has flagged this as evidence rather than a maintained branch, the main practical blockers to adopting it as-is are the stale base and the cross-platform gap noted below.

Reviewed changes

  • RuntimeAccessError + errno classifier — new runtime-access-error.ts maps EPERM/EACCES onto a runtime_unavailable error carrying { reason: 'permission_denied', operation, systemCode, processState: 'unverifiable' }.
  • status.ts — isProcessRunning now distinguishes permission-denied (throw), absent (ESRCH → false), and unknown (throw unverifiable); getCliStatus re-throws access errors instead of returning a healthy app.running: false.
  • transport.ts — the socket error handler inspects the errno and raises RuntimeAccessError('connect') on denial, keeping the "restart Orca" advice only for genuine unavailability.
  • metadata.ts — denied metadata reads throw instead of being hidden as null/a generic "start the app" message.
  • cli-error.ts — stops appending "Orca is not running" when processState is unverifiable.
  • Tests / docs — two new deterministic test files driving EPERM/EACCES through the real sendRequest/getCliStatus paths plus rendered CLI output, a skill-guides/orca-cli.md note, and the regenerated bundle.

ℹ️ Host-returned unverifiable still reads as "not running"

The new guard in formatCliError only covers the local RuntimeClientError path. A runtime_unavailable returned by an actual host is wrapped as RuntimeRpcFailureError and hits the block at cli-error.ts:78-81, which unconditionally appends Orca is not running. Run 'orca open' first. — even if the host's error.data.processState === 'unverifiable'. If the goal is for this vocabulary to flow end-to-end (the skill guide already documents reason: permission_denied arriving in error data), that path needs the same guard; today the CLI would re-assert the false negative it's trying to eliminate. This is forward-compat, not a regression the diff introduces, so it's flagged as informational.

ℹ️ Base is ~49 commits behind main with a conflict

The author calls this out in the PR body. The diff can't be evaluated against current main without a rebase, and the merge conflict indicator should be resolved before any of this is cherry-picked.


Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • src/cli/runtime/cli-error.ts:52 (RIGHT) — file not in PR diff

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/cli/runtime/status.ts
if ((error as NodeJS.ErrnoException | null)?.code === 'ESRCH') {
return false
}
throw new RuntimeClientError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unguarded else now throws runtime_unavailable for any unrecognized errno, where the old catch mapped every failure to false. On Windows (a first-class target here), process.kill(pid, 0) routes existence checks through OpenProcess + a different error translation than POSIX; if a genuinely absent process surfaces as anything other than ESRCH there, orca status/orca open will start throwing a confusing 'unverifiable' error instead of 'not running'.

Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
…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]>
@TheAbyss TheAbyss closed this by deleting the head repository Nov 5, 2026
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