Repository navigation
fix(runtime): keep remote servers usable when one saved record can't be read - #27685
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to 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 |
|
There was a problem hiding this comment.
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.tssrc/shared/runtime-environment-sidecar.tssrc/shared/runtime-environment-store-file.tssrc/shared/runtime-environment-store-records.tssrc/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.
| // Servers whose main record this build cannot read still own their entries. | ||
| const foreignOwners = new Set( | ||
| readEnvironmentStoreRecords(userDataPath).unreadable.map((record) => record.id) | ||
| ) |
There was a problem hiding this comment.
🗄️ 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:
- It checks
args.idonly againstreadEnvironmentStore, and that function excludes unreadable store records. - It writes the sidecar first.
- Only then does
writeEnvironmentStorethrow 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.
| // 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.
f4dc878 to
462cece
Compare
There was a problem hiding this comment.
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.
| 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)] |
There was a problem hiding this comment.
📐 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.
| 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
462cece to
6aa041b
Compare
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
orca-environments.jsonmade the whole list fail to parse — every remote server disappeared and the list call failed.{ version: 1, environments: [] }shape is strict. Each record is parsed on its own (newsrc/shared/runtime-environment-store-records.ts). Unreadable or newer-format records are skipped with one deduplicatedconsole.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.kindfield are treated as unreadable, so a future record type can't be loaded as a plain pairing and lose itskindon the next save.redactRuntimeEnvironment).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", andremoveManagedOrcadEnvironmentchecks before writing.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;oxlinton changed files;pnpm run check:code-quality:changedpnpm 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 passNew
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 tomain'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 bymain'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
Notes
kindand fail the whole file on a bad record.ephemeral-vm-runtime-storehas the same whole-file failure mode.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)