Skip to content

fix: recover deleted Active Server defaults and preserve editor hosts - #25938

Merged
nwparker merged 2 commits into
mainfrom
nwparker/bug-runtimeenvironments-call-runtimeenvironments
Oct 6, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/bug-runtimeenvironments-call-runtimeenvironments

Conversation

@nwparker

@nwparker nwparker commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​401 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​398
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​142 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123

ELI5

Deleting a saved server could leave Orca trying to use its old ID, so unrelated panes failed with “Unknown environment.” This clears the deleted default and keeps editor files and tabs attached to the machine that owns them when focus changes.

What Changed

  • Repair a removed Active Server before asynchronous or synchronous settings reads, on host-list refresh, and after CLI registry writes. Notify open windows through the existing settings listener. Only a successfully validated registry can prove removal; offline hosts and unreadable registries preserve the preference.
  • Create editable tabs with their backing file's captured host. Resolve editor ownership from catalog records instead of unrelated workspace focus. For same-ID folder workspaces, a host qualifier must match a catalog owner; later checks retain the captured owner and still reject real ownership changes.

Why

Repairing the saved preference fixes both existing stale defaults at startup and live CLI removal. Resetting to Local desktop avoids guessing which replacement server the user intended. Explicit remote file operations keep their own host and never fall back to executing locally. Editor routing reuses the existing ownership resolver instead of introducing another owner store.

Linked Issue

Refs #21489 for the reproduced deleted-default and editor-focus paths. Historical terminal/session corruption described in the comments is outside this change; see Review and Notes.

Visual Proof

Before: the deleted server ID remains selected, leaving the Active Server control blank.

Before: stale Active Server selection

After: CLI removal automatically resets the selection to Local desktop. The server list was refreshed for this screenshot.

After: Active Server recovered

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Used orca host list --json to inspect available hosts. In an isolated macOS app profile, added a disposable loopback server, seeded its saved Active Server preference through settings IPC, and removed it with orca environment rm. Before the fix, the retained selector reproduced the exact runtimeEnvironments:call / RuntimeEnvironmentStoreError: Unknown environment error. The rebuilt hidden app reset the running renderer automatically, restored Local desktop, and repaired a stale preference at restart.

Also opened a real fixture file with a conflicting focused host: before, its file owner was local and its tab owner was the other runtime; after, both were local and the editor rendered the file contents. App identity was verified through CDP. Production host registrations were untouched; a Windows peer was checked read-only, not used for a full Windows-client/WSL reproduction.

Validation:

  • 221 tests passed across 20 affected settings, registry, routing, subscription, editor, and palette suites.
  • New regressions failed before the corresponding fixes, including watcher installation failure and same-ID folders on two hosts.
  • After rebasing onto main, pnpm tc:node, pnpm tc:web, full pnpm exec oxlint, the changed-code quality gate, formatting, and git diff --check pass. The 221 affected tests still pass; 17 shared live-turn tests pass after correcting two pre-existing fixture calls to the newer { items } API in a separate test-only commit.
  • pnpm build passed on the original base, including desktop, relay/CLI, web/mobile bundles, and macOS native builds. The separate mobile workspace required its frozen-lockfile dependency install first. Full repository lint/test coverage is left to CI.

Review

Adversarial self-review found and fixed two P2 issues: watcher installation errors could abort runtime IPC registration (runtime-environment-preference.ts), and suppressing folder focus without catalog disambiguation rejected valid same-ID folders on different hosts (editor-file-operation-owner.ts). Regressions demonstrate both failures and their recovery. Checked same-name replacement, unavailable/corrupt registries, offline saved hosts, SSH and nested runtime ownership, pairing-generation changes, and settings notifications.

Contributor references:

No unresolved correctness finding remains in the reviewed scope.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer material is copied or translated.

Notes

No remote protocol changes. Folder workspaces and SSH routes are covered. Full native Windows/Linux runs and the original Windows-client/WSL pairing flow remain untested locally. Existing terminal bindings, duplicated historical editor records, and abandoned saved host partitions are not migrated by this PR. If a native registry watcher fails, settings reads and host-list refresh still repair the preference.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Targeted lint/typecheck/test validation passed; full repository lint/test coverage will run in CI

Recovery and merge scope

Existing broken Active Server preferences are repaired automatically; existing mis-owned terminals, duplicate editor records, and orphan host partitions are not migrated. #23349 is the only contributor PR superseded here. #9514, #21175, #21048, #21124, and #21125 remain separate work. #23749 / #23785 remain separate terminal-identity fixes.

The first CI runs failed on the unchanged mobile turn-disclosure test exceeding its line limit. Main fixed that in #25933; this branch is rebased onto that fix. Rebase also exposed two pre-existing shared live-turn fixture calls still using the old argument shape: their regression failed before correction, and both typechecks plus all 17 tests pass after correction. That repair is isolated in a test-only commit. Refreshed CI is green at 2faf2ce9378c: static analysis/typechecks, both packaging jobs, all five unit shards, relay integration and the aggregate gates passed. One unchanged relay subprocess test initially timed out in CI; its 28-test local suite and the failed-job rerun passed. The original Windows-client/WSL pairing flow remains untested locally.

Current merge recommendation: merge this as a partial fix; refreshed CI is green. Keep #21489 open until historical host ownership drift and removed-host recovery are addressed. The implementation is contained and does not migrate historical saved-session records; local verification is green after rebase and the separate fixture correction. The original Windows-client/WSL pairing flow remains a validation gap.

Remaining root-fix review

Follow-up #25954 reproduces and prevents one server snapshot removing or rebinding another server’s terminal, including collisions across workspaces. It prevents new corruption and does not migrate old records. The rendered evidence uses synthetic hosts, not the reporter’s complete Windows/WSL pairing sequence.

#21125 needs further work before adoption: its exact recovered-draft parking function retained only 10 of 12 divergent drafts in a bounded reproduction; the reopen stack is also not durable across restart. Historical recovery must preserve all unsaved drafts before changing owners or deduplicating. #21124 remains a separate document-identity/deduplication fix.

#9514 and #21175 still address persisted partition retirement, with differing startup/ownership policies; #21175 also depends on #21113. #21048 still addresses transport retirement after CLI removal. None is superseded here. #23749/#23785 remain separate first-mount PTY identity work and retain their failed Linux validation gates. In #23749’s referenced log, the two ledger entries include a --help probe and the actual launch; this needs an oracle review, not an assumption that two agents launched.

Series status

#25954 now includes broader visibility-resume coverage: 320 tests across 42 suites pass, including stale-frame fencing and owner-confirmed removal. Its refreshed CI is the follow-up merge gate.

#25958 fixes a separately reproduced publication source: a local server advertised a paired host’s files and cold/legacy terminals as its own. In the production renderer, that advertisement created duplicate file records and replaced a WSL editor with a Mac-owned tab. The new producer-to-client regression preserves the original owner. Nine focused cases fail on the old publisher; 465 tests across 61 suites pass with the fix. This is prevention, not historical migration, and the complete original Windows/WSL pairing sequence remains unproved.

The remaining resolution gates for #21489 are safe recovery of historical records (including every divergent unsaved draft), reconciliation of partition retirement (#9514/#21175/#21113), transport retirement after CLI removal (#21048), and the original native Windows/WSL pairing journey. #21124’s document deduplication and #23749/#23785’s first-mount PTY identity work remain separate. No additional contributor PR is superseded by the follow-ups.

Final merge review

Recommend merging this PR at 2faf2ce9378c; its CI is green and GitHub reports it clean/mergeable. It repairs existing stale Active Server preferences and prevents the reproduced editor focus drift, while leaving historical session migration untouched.

Hold draft follow-ups #25954 and #25958. Full #25954 CI exposed 12 deterministic returning-pane status failures when different hosts reuse a terminal ID; all 12 reproduce locally, including on the dependent publication branch. The receiver’s collision guard needs identity-scoping work before adoption. These findings do not touch this PR’s settings/editor implementation.

@coderabbitai

coderabbitai Bot commented Oct 6, 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: 75381456-51df-4b22-8f27-b67a0ea5ad8e
📥 Commits

Reviewing files that changed from the base of the PR and between 4c35ea8 and 2faf2ce.

📒 Files selected for processing (1)
  • src/shared/structured-agent-session-live-turn.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

Settings reads now reconcile the active runtime-environment preference with the saved environment registry. A registry watcher checks for removed environments, and environment listing reads settings before returning results. Editor operations now resolve routes using captured execution-host information, and editor tabs receive the matching open file’s execution-host ID.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 2faf2

Some folder-based editor operations can target the wrong folder when duplicate workspace IDs exist across hosts; resolve this pairing before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The changes in src/shared/structured-agent-session-live-turn.test.ts update two unrelated test calls to use the { items } API. Those tests cover structured-agent session turns, not deleted Active … Remove the unrelated structured-agent test fixture edits from this PR, or move them to a separate change.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #21489 reports runtimeEnvironments:call failing with Unknown environment. runtime-environment-preference.ts clears a saved Active Server ID only when a successfully read registry confirms …
Title check ✅ Passed The title clearly summarizes the two main changes: recovering deleted Active Server defaults and preserving editor host ownership.
Description check ✅ Passed The description covers the required sections with clear change details, rationale, linked issue context, visual proof, testing, review notes, and checklist status. It uses “Refs #21489” rather than “F…
Full details: Out of Scope Changes check

Explanation

The changes in src/shared/structured-agent-session-live-turn.test.ts update two unrelated test calls to use the { items } API. Those tests cover structured-agent session turns, not deleted Active Server preferences or editor host ownership. The PR description says the edits fix pre-existing fixture calls exposed by the rebase, but that does not connect them to issue #21489.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Select the folder path from the resolved owner. · editor-file-operation-owner.ts:194-196

src/renderer/src/lib/editor-file-operation-owner.ts:194-196
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Select the folder path from the resolved owner.

If two folder records share an ID but have different hosts and paths, resolveEditorOwnerRoute can select the second record by host. When worktreePath is null, this lookup still returns the first record's folderPath. getEditorFileOperationContext then pairs one host's route with another host's path. Use the same host-qualified folder owner for both values, and test same-ID folders with different paths.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 963c8691-e254-41e8-8ed6-a19c13617fd3
📥 Commits

Reviewing files that changed from the base of the PR and between 07981bd and b4cbc5c2dcc5828fec8bde0a44d65048e46743cd.

📒 Files selected for processing (11)
  • src/main/ipc/runtime-environment-connectivity-handlers.ts
  • src/main/ipc/runtime-environment-preference.test.ts
  • src/main/ipc/runtime-environment-preference.ts
  • src/main/ipc/runtime-environments.ts
  • src/main/ipc/settings.test.ts
  • src/main/ipc/settings.ts
  • src/renderer/src/lib/editor-file-operation-owner.ts
  • src/renderer/src/lib/unified-tab-host-ownership.ts
  • src/renderer/src/store/slices/editor-tab-host-ownership.test.ts
  • src/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts
  • src/shared/runtime-environment-store.ts

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

Co-authored-by: Chen <zwq19980411@gmail.com>
@nwparker
nwparker force-pushed the nwparker/bug-runtimeenvironments-call-runtimeenvironments branch from b4cbc5c to 4c35ea8 Compare October 6, 2026 19:07
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