Skip to content

fix(runtime): keep remote servers usable when one saved record can't be read - #27685

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-a4-tolerant-environment-store
Oct 12, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-a4-tolerant-environment-store

Conversation

@nwparker

@nwparker nwparker commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​478 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​478
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​230 $\color{#cf222e}{\Huge{\mathbf{−}}}$​62 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​168

ELI5

Orca keeps a list of your remote servers in one file. Before, if a single entry in that file was damaged or written by a newer Orca, every remote server vanished. Now Orca skips just that entry, keeps it safe on disk, and everything else keeps working.

What Changed

  • Before: one unreadable record in orca-environments.json made the whole list fail to parse — every remote server disappeared and the list call failed.
  • After: only the outer { version: 1, environments: [] } shape is strict. Each record is parsed on its own (new src/shared/runtime-environment-store-records.ts). Unreadable or newer-format records are skipped with one deduplicated console.warn, and every write re-reads the file and puts them back verbatim, in their original order. A write that would add a readable record under an unreadable record's id is refused.
  • Records that carry a kind field are treated as unreadable, so a future record type can't be loaded as a plain pairing and lose its kind on the next save.
  • Unknown keys on readable records are still stripped (keeping them would leak them to the renderer through redactRuntimeEnvironment).
  • Sidecar orca-environment-sidecar.json (SSH access links, managed-server links, migration timestamps, pairing revision floors): unreadable entries are kept verbatim and never pruned. The matching server is hidden — not connectable, removable or re-pairable — direct access throws "needs a newer version of Orca", and removeManagedOrcadEnvironment checks before writing.
  • Whole-file failures (invalid JSON, a different version) still fail closed.

No RPC parameters, stream frames or published content changed; this is local file parsing only.

Why

Failing per record keeps the blast radius to the one server that's actually broken. Dropping unreadable records would silently destroy data a newer Orca wrote; keeping them verbatim lets a downgrade-then-upgrade round trip lose nothing. Hiding servers with unreadable sidecar entries (instead of loading them without their pins) means an SSH host fingerprint or device token is never bypassed.

Linked Issue

None. Related: #18766 (whole-file corruption — still fails closed, not fixed here)

Visual Proof

N/A — no UI change; a hidden server only produces a log line.

Testing

  • pnpm tc; oxlint on changed files; pnpm run check:code-quality:changed

  • pnpm test src/shared/runtime-environment*.test.ts src/main/ephemeral-vm-runtime-environment-release.test.ts src/main/ssh src/main/ipc src/cli — all pass

  • New src/shared/runtime-environment-store-unreadable-records.test.ts: verbatim/in-order rewrite, id-collision refusal, sidecar entry kept across another server's writes, hidden-not-unpinned, never pruned/orphaned.

  • New src/shared/runtime-environment-store-unreadable-records-interleaving.test.ts: seeded random interleavings (40 seeds x 40 steps, ~1s) of two stale read-modify-write writers, a newer build appending or converting records, and unreadable/foreign sidecar entries. After every step: no readable record lost or duplicated beyond last-writer-wins, unreadable records kept verbatim and in order, unreadable sidecar entries and links owned by unreadable records never pruned, and a server with an unreadable link never listed, resolvable, or readable. Each of six guards in the fix, removed one at a time, makes it fail.

  • Real profile files (read-only copies: two macOS profiles with 4 and 3 servers plus a managed-server sidecar, and a Windows profile with secrets replaced by hashes): this branch's reader returns exactly what main's does; a no-change rewrite of the store and the sidecar is byte-identical to main's rewrite and to the original file on macOS, and stays byte-stable over repeated read/write cycles.

  • Downgrade: a file this branch writes from a valid profile reads identically on main. A file carrying an unreadable record is rejected whole by main's reader both before and after this branch rewrites it, so mixed versions behave as they do today; this branch only ever re-writes such records, it never introduces them.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: sidecar pins (SSH target fingerprint, loopback endpoint/device token/public key) are never skipped; an unreadable entry hides its server rather than loading it unpinned.
  • Compatibility: protects this build going forward. Builds already shipped will still strip kind and fail the whole file on a bad record.
  • SSH / cross-platform: file-format handling only; same on all platforms.
  • Follow-ups: no UI explanation yet for a hidden server; ephemeral-vm-runtime-store has the same whole-file failure mode.

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)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in 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: e2ef7099-3079-4f97-951c-7c2c494c470a


📥 Commits

Reviewing files that changed from the base of the PR and between 462cece05ca6227071f2db81db85296260ab72a1 and 6aa041b.



📒 Files selected for processing (1)
  • src/shared/runtime-environment-store-unreadable-records-interleaving.test.ts


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




📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds record-level reading for the runtime environment store. It retains unreadable records and sidecar entries during writes, hides environments with unreadable sidecar entries, and blocks operations that target those entries. New tests cover record and sidecar preservation, listing behavior, ID collisions, and blocked operations.



Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 6aa04

Adding a managed server whose ID matches an unreadable saved record is refused, but its existing sidecar pin data may be overwritten first. This is a narrow edge case worth fixing or accepting before merge. The CI lint failure is no longer present.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.91% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the primary change: preserving usability when a saved runtime-environment record cannot be read.
Description check Passed The description is mostly complete. It includes the user impact, implementation details, rationale, testing evidence, security and compatibility notes, and checklist status. The Linked Issue section h…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR





  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc2df86a-ae34-4e08-aae1-8de64e3b0ac2
📥 Commits

Reviewing files that changed from the base of the PR and between cfb63dc and f4dc878f3953398c3b48f1953cf260414afd3591.

📒 Files selected for processing (5)
  • src/shared/runtime-environment-managed-orcad-store.ts
  • src/shared/runtime-environment-sidecar.ts
  • src/shared/runtime-environment-store-file.ts
  • src/shared/runtime-environment-store-records.ts
  • src/shared/runtime-environment-store-unreadable-records.test.ts

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

Comment on lines +204 to +207
// Servers whose main record this build cannot read still own their entries.
const foreignOwners = new Set(
readEnvironmentStoreRecords(userDataPath).unreadable.map((record) => record.id)
)

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Refuse a sidecar write that targets an ID owned by an unreadable store record.

foreignOwners protects only the entries of other IDs. The loop skips id === environment.id, so a readable sidecar entry that belongs to an unreadable store record is dropped or replaced when environment.id equals that record's ID.

Here is how addManagedOrcadEnvironment reaches this path:

  1. It checks args.id only against readEnvironmentStore, and that function excludes unreadable store records.
  2. It writes the sidecar first.
  3. Only then does writeEnvironmentStore throw the new ID-collision error.

Result: the newer build's SSH pin or deployment link is already overwritten in the sidecar. The store record still exists, but its sidecar entry is lost.

Refuse the write before the sidecar is changed. environments already contains the new environment, so check readable from disk instead.

Proposed fix
-  const foreignOwners = new Set(
-    readEnvironmentStoreRecords(userDataPath).unreadable.map((record) => record.id)
-  )
+  const onDisk = readEnvironmentStoreRecords(userDataPath)
+  const foreignOwners = new Set(onDisk.unreadable.map((record) => record.id))
+  if (
+    foreignOwners.has(environment.id) &&
+    !onDisk.environments.some((candidate) => candidate.id === environment.id)
+  ) {
+    throw new RuntimeEnvironmentSidecarInvalidError(
+      getRuntimeEnvironmentSidecarPath(userDataPath),
+      environment.id
+    )
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Servers whose main record this build cannot read still own their entries.
const foreignOwners = new Set(
readEnvironmentStoreRecords(userDataPath).unreadable.map((record) => record.id)
)
// Servers whose main record this build cannot read still own their entries.
const onDisk = readEnvironmentStoreRecords(userDataPath)
const foreignOwners = new Set(onDisk.unreadable.map((record) => record.id))
if (
foreignOwners.has(environment.id) &&
!onDisk.environments.some((candidate) => candidate.id === environment.id)
) {
throw new RuntimeEnvironmentSidecarInvalidError(
getRuntimeEnvironmentSidecarPath(userDataPath),
environment.id
)
}

… dropping them

One corrupt or newer-format record in orca-environments.json or the
environment sidecar made every server unlistable. Each file now parses
per record: readable records load, unreadable ones are rewritten
verbatim on every write. A server whose sidecar entry cannot be read is
hidden and refused for edits, so it never connects or is rewritten
without its SSH access or deployment link.
@nwparker
nwparker force-pushed the nwparker/wsl-a4-tolerant-environment-store branch from f4dc878 to 462cece Compare October 12, 2026 01:50

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e7b6243d-1b66-41a7-ab2a-ea1e5a88b6f5
📥 Commits

Reviewing files that changed from the base of the PR and between f4dc878f3953398c3b48f1953cf260414afd3591 and 462cece05ca6227071f2db81db85296260ab72a1.

📒 Files selected for processing (1)
  • src/shared/runtime-environment-store-unreadable-records-interleaving.test.ts

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

Comment on lines +72 to +79
const shapes: unknown[] = [
{ ...persisted(id, 1), kind: 'wsl-distro', distro: { name: 'Ubuntu' } },
{ id, name: 'Broken', endpoints: 'not-an-array' },
{ name: 'no id', kind: 'future' },
'not-an-object',
null
]
return shapes[Math.floor(rand() * shapes.length)]

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Rename shapes to fix the failing anti-slop lint check.

The CI static-analysis job fails on Line 72. The anti-slop rule rejects the name shapes. The pipeline runs with --deny-warnings, so this one name blocks the PR. Use a name that says what the values are, for example unreadableVariants.

Proposed fix
--- "a/src/shared/runtime-environment-store-unreadable-records-interleaving.test.ts"
+++ "b/src/shared/runtime-environment-store-unreadable-records-interleaving.test.ts"
@@ -69,14 +69,14 @@
 }
 
 function unreadableRecord(rand: () => number, id: string): unknown {
-  const shapes: unknown[] = [
+  const unreadableVariants: unknown[] = [
     { ...persisted(id, 1), kind: 'wsl-distro', distro: { name: 'Ubuntu' } },
     { id, name: 'Broken', endpoints: 'not-an-array' },
     { name: 'no id', kind: 'future' },
     'not-an-object',
     null
   ]
-  return shapes[Math.floor(rand() * shapes.length)]
+  return unreadableVariants[Math.floor(rand() * unreadableVariants.length)]
 }
 
 describe('runtime environment store under interleaved writers and unreadable records', () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const shapes: unknown[] = [
{ ...persisted(id, 1), kind: 'wsl-distro', distro: { name: 'Ubuntu' } },
{ id, name: 'Broken', endpoints: 'not-an-array' },
{ name: 'no id', kind: 'future' },
'not-an-object',
null
]
return shapes[Math.floor(rand() * shapes.length)]
const unreadableVariants: unknown[] = [
{ ...persisted(id, 1), kind: 'wsl-distro', distro: { name: 'Ubuntu' } },
{ id, name: 'Broken', endpoints: 'not-an-array' },
{ name: 'no id', kind: 'future' },
'not-an-object',
null
]
return unreadableVariants[Math.floor(rand() * unreadableVariants.length)]
🧰 Tools
🪛 GitHub Actions: PR 27685 | source e9abcc5a1f007f3b75361707726788989d760cc2 | workflow e9abcc5a1f007f3b75361707726788989d760cc2 | unit full / static analysis and typecheck

[error] 72-72: Oxlint anti-slop check failed: rename the symbol "shapes" to reflect its domain role; "shape" describes structure rather than ownership. Command: bun --smol node_modules/oxlint/bin/oxlint --config config/oxlint-anti-slop.json src config tests mobile --deny-warnings

Source: Pipeline failures

@nwparker
nwparker force-pushed the nwparker/wsl-a4-tolerant-environment-store branch from 462cece to 6aa041b Compare October 12, 2026 01:57
@nwparker
nwparker merged commit a3e9718 into main Oct 12, 2026
32 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.

1 participant