Repository navigation
fix(ssh): don't overwrite remote agent config after a failed read - #22644
Conversation
A flaky read was treated as an empty file, wiping the user's config. Fixes stablyai#22638
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 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 (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughRemote trust config reads now treat ENOENT as an empty config. Other read errors are rethrown, and binary config files are rejected. Tests verify that read errors and binary content do not trigger writes for Codex and Copilot presets, while ENOENT creates the Codex config with the trust entry. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Remote trust updates now initialize only confirmed-missing files and refuse unreadable or binary configs. The supplied evidence shows no material merge-blocking risk. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 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.
✅ No new issues found.
Reviewed changes
Reviewed the SSH remote agent-trust read path and its new tests in this run.
- Remote config reads now fail closed —
readRemoteTextFilereturns an empty string only when the relay reports the file missing (isENOENT), rethrows any other read failure, and refuses to rewrite a config the relay classifies as binary. - Indeterminate reads no longer overwrite user config — the Codex and Copilot callers previously treated any failed read as an empty file and wrote back only the trust entry; they now abort that best-effort write, which both entry points already swallow.
- Regression tests added — a failed read and a binary read leave both configs untouched, and a relay-reported missing file still seeds a fresh Codex config.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The runtime harness stubbed isENOENT as code-only, and the remote Codex startup specs rejected with a generic error that only passed while any read failure seeded an empty config. Use the real isENOENT and the message-only shape the relay actually delivers.
|
Thanks @AmoabaKelvin, good catch. Verified over a real SSH host: when the remote config can't be read, I pushed one test-only commit on top. This change broke two existing tests in |
|
There was a problem hiding this comment.
ℹ️ No critical issues — one minor test-harness fidelity note inline.
Reviewed changes
Reviewed the delta since the prior pullfrog review (daddb2260e..b6eecdab1d) — a test-only commit that aligns the runtime harness with the new fail-closed remote read behavior.
- Runtime trust specs model a real relay ENOENT — the two remote Codex startup specs now reject
readFilewith the message-onlyENOENT: no such file or directory, stat '…'shape the relay actually delivers, so the trust write still runs under the newisENOENTcheck. - Shared harness switches to the real
isENOENT— the runtime mock forfilesystem-path-containmentnow delegates tovi.importActualinstead of a.code-only stub, matching production's message fallback.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why: the real check also matches relay-rebuilt errors, which carry only the ENOENT message. | ||
| vi.mock('../../ipc/filesystem-path-containment', async () => { | ||
| const actual = await vi.importActual<typeof FilesystemPathContainmentModule>( | ||
| '../../ipc/filesystem-path-containment' | ||
| ) | ||
| return { isENOENT: actual.isENOENT } | ||
| }) |
There was a problem hiding this comment.
This mock now uses the real isENOENT, but the sibling filesystem-auth mock above (lines 413-418) still stubs a .code-only isENOENT, even though filesystem-auth only re-exports it (src/main/ipc/filesystem-auth.ts:16). Runtime modules that import isENOENT from filesystem-auth (e.g. runtime-repository-registration-controller.ts:13, runtime-worktree-filesystem.ts:7) therefore still get code-only behavior in this harness, diverging from production for relay-delivered message-only ENOENT. Consider having that mock delegate to the real isENOENT as well.

ELI5
When Orca sets up Codex or Copilot on an SSH machine, it adds one line to their config file on that machine. If reading the file failed for a moment, Orca assumed it was empty and wrote back just that one line, erasing everything else. Now it only starts from an empty file when the file really doesn't exist.
What Changed
Before: any failed read of the remote
~/.codex/config.tomlor~/.copilot/config.json(timeout, busy relay, permission error) was treated as an empty file. The trust write then replaced the user's config with only the trust entry, so their model settings, MCP servers and everything else were gone.After: the shared remote read helper in
remote-agent-trust-presets.tsreturns an empty file only when the relay reports the file as missing (ENOENT). Any other failure, or a file that comes back as binary, cancels the write. Both callers already treat the trust write as best-effort, so the worst case is that the user sees the agent's trust prompt once.Why
A failed read means we don't know what's in the file, not that it's empty. The local Codex path got the same fix in #15417; the SSH copy never did.
Missing-file detection reuses
isENOENT, which already matches the relay's error message. The relay drops Node'scodewhen it forwards errors, so checking the code alone would treat every missing remote file as a failure and never write the trust entry.Fixes #22638
Visual Proof
N/A. No UI change; this only affects what gets written to a config file on the SSH host.
Testing
Added tests in
src/main/remote-agent-trust-presets.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.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)