Skip to content

fix(ssh): don't overwrite remote agent config after a failed read - #22644

Merged
brennanb2025 merged 2 commits into
stablyai:mainfrom
AmoabaKelvin:AmoabaKelvin/fix-ssh-read-bug
Sep 28, 2026
Merged

brennanb2025 merged 2 commits into
stablyai:mainfrom
AmoabaKelvin:AmoabaKelvin/fix-ssh-read-bug

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

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.toml or ~/.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.ts returns 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's code when 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:

  • a failed remote read leaves the Codex and Copilot configs untouched
  • a binary read leaves both configs untouched
  • a missing file (reported the way the relay reports it, message only) still creates a fresh Codex config

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

A flaky read was treated as an empty file, wiping the user's config.

Fixes stablyai#22638
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 9aab5bbb-114b-47fb-9660-518ba65de200

📥 Commits

Reviewing files that changed from the base of the PR and between daddb22 and b6eecda.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime-test-mocks/setup.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-05.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Remote 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 b6eec

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 Summary

Architecture risk: 🔵 Low · up to b6eec

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/main/remote-agent-trust-presets.test.ts: Adds a parameterized test over the codex and copilot presets asserting that when readFile throws, markRemoteAgentWorkspaceTrusted rejects and writeFile is not called.
  • observed — Modified behavior in src/main/remote-agent-trust-presets.test.ts: Adds a parameterized test over the codex and copilot presets asserting that when readFile returns binary content (isBinary: true), markRemoteAgentWorkspaceTrusted rejects and writeFile is not called.
  • observed — Modified behavior in src/main/remote-agent-trust-presets.test.ts: Adds a test asserting that when readFile throws an ENOENT error message, the function writes the Codex config at /home/u/.codex/config.toml with content [projects."/real/repo"]\ntrust_level = "trusted"\n.
  • observed — Modified behavior in src/main/remote-agent-trust-presets.ts: Added imports for FileReadResult type and the isENOENT guard, replacing the prior import of only IFilesystemProvider from ./providers/types and ./ipc/filesystem-path-containment.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main SSH fix: preventing remote agent configuration from being overwritten after a failed read.
Description check ✅ Passed The description explains the user impact, behavior before and after the change, rationale, linked issue, testing coverage, visual-proof status, and checklist items. It omits some template headings, in…
Linked Issues check ✅ Passed The changes satisfy the coding requirements in issue #22638. readRemoteTextFile returns empty content only for a confirmed ENOENT error. It rethrows other read errors and rejects binary responses.…
Out of Scope Changes check ✅ Passed The changes stay within issue #22638. The source change protects remote Codex and Copilot configuration reads and trust writes. The test changes support these read-error and missing-file cases. No unr…
  • 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.

✅ 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 — readRemoteTextFile returns 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.

Pullfrog  | View workflow run | Using 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.
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks @AmoabaKelvin, good catch. Verified over a real SSH host: when the remote config can't be read, main rewrote it to just the trust entry; this branch leaves it alone and still creates a missing one.

I pushed one test-only commit on top. This change broke two existing tests in orca-runtime.test.ts: they faked a missing config with a generic error, and the test harness stubbed isENOENT as code-only, so they only passed under the old "any error = empty" behaviour. They now use the real isENOENT and the relay's actual missing-file error.

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Fixes remote agent config handling on read failures.

The PR appears safe to merge; no actionable regression was identified.

Summary

The PR prevents SSH Codex and Copilot trust setup from replacing an existing config when its read fails or returns binary content.

  • Only a recognized missing-file error starts from an empty config.
  • Tests cover failed reads, binary results, and message-only missing-file errors.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Read remote config] --> B{Result}
  B -->|Text| C[Update trust entry]
  B -->|ENOENT| D[Start empty config]
  B -->|Other error or binary| E[Skip write]
  D --> C
Loading

Reviews (1) · Last reviewed commit: "test(runtime): model remote missing-conf..."

@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.

ℹ️ 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 readFile with the message-only ENOENT: no such file or directory, stat '…' shape the relay actually delivers, so the trust write still runs under the new isENOENT check.
  • Shared harness switches to the real isENOENT — the runtime mock for filesystem-path-containment now delegates to vi.importActual instead of a .code-only stub, matching production's message fallback.

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

Comment on lines +424 to +430
// 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 }
})

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 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.

@brennanb2025
brennanb2025 merged commit 64569a8 into stablyai:main Sep 28, 2026
43 checks passed
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.

[Bug]: Trusting an SSH workspace can wipe the remote Codex and Copilot config

2 participants