Skip to content

fix(editor): translate mirrored editor-tab owners into the receiver frame - #10926

Closed
rodboev wants to merge 1 commit into
stablyai:mainfrom
rodboev:pr/mirrored-editor-owner-translation
Closed

rodboev wants to merge 1 commit into
stablyai:mainfrom
rodboev:pr/mirrored-editor-owner-translation

Conversation

@rodboev

@rodboev rodboev commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10859. Mirrored editor tabs were carrying the sender's perspective-relative runtimeEnvironmentId across paired Orca instances unchanged. When the receiver owned that worktree locally, Orca still routed local editor reads and diffs back to the peer, which had never heard of the worktree. The same overloaded field also drove close and cull behavior, so mirrored tabs could reappear or multiply after sync.

This change splits those meanings and keeps the fix renderer-local:

  • runtimeEnvironmentId becomes the receiver-frame routing owner for the file.
  • New runtime-only mirroredFromRuntimeEnvironmentId records which remote runtime mirrored the tab to this receiver.
  • Hydration and live mirror ingest translate incoming owners only when the receiver has concrete ownership for that worktree.
  • Live mirror dedupe keys off the translated owner, while cull and close use the mirror-host provenance.

The result is that paired machines still mirror editor tabs, but a machine that owns the worktree routes its own file operations locally and can close mirrored tabs authoritatively across the link.

Closes #10859.

Screenshots

No visual change.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/worktree-runtime-owner.test.ts src/renderer/src/store/slices/editor.test.ts src/renderer/src/runtime/web-session-tabs-sync.test.ts src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • pnpm run typecheck:web
  • pnpm exec oxlint on changed files
  • pnpm exec oxfmt --check on changed files

Focused coverage:

  • Hydration re-owns mirrored local-worktree tabs into the receiver frame.
  • The shared owner-translation helper preserves peer-only and explicit-remote worktrees.
  • Live mirror sync dedupes by translated owner and culls by mirror-host provenance.
  • Mirrored close routes to the mirror host, with a fallback for pre-fix mirrored rows.

AI Review Report

Adversarial review found three P1s, all fixed on the final branch and revalidated locally:

  • Hydration initially decided whether to use an owned file ID from the persisted owner, not the translated receiver-frame owner. That could diverge from live sync when a local snapshot translated into an explicit remote owner. The final branch now forces the owned ID whenever translation changes ownership.
  • Live sync initially retained an earlier mirror-host copy when a second host published the same translated editor ID. The final branch now replaces any preexisting mirrored file with the same translated ID before appending the new host copy.
  • Live sync still let a receiver-local tab with the same translated owned ID survive beside the mirrored replacement. The final branch now coalesces canonical-ID collisions against local entries too, so the mirrored copy becomes the single authoritative tab and carries the host provenance for close and cull.

Final local revalidation after those fixes:

  • Focused Vitest: 4 passed, 283 tests
  • pnpm run typecheck:web
  • changed-file oxlint
  • changed-file oxfmt --check

Review focus covered the explicit-owner boundary, shared owned-ID construction across hydration and live sync, mirror-host keyed cull/close, and stripping runtime-only mirror provenance from persisted or reopened tabs.

Security Audit

No new RPC, IPC, or cross-process trust boundary. The fix tightens routing by keeping receiver-owned local file operations on the receiver instead of sending them to a peer runtime that does not own the worktree. Owner translation is guarded by concrete receiver-side records, and peer-only worktrees remain peer-owned.

Notes

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds runtime-environment translation for mirrored editor worktrees and uses translated owned editor IDs during web-session synchronization. Mirrored open files now retain sender environment provenance for equality checks and snapshot reconciliation. Editor hydration translates persisted ownership, detects owner changes, and updates hydrated IDs. Closed-tab snapshots omit sender provenance, reopened tabs clear mirrored fields, and host close notifications use stored mirrored environment IDs when available. Tests cover translation, synchronization, hydration, replacement, removal, closing, and reopening behavior.

🚥 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%. 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 summarizes the main change: translating mirrored editor-tab owners into the receiver frame.
Description check ✅ Passed The description covers the required sections and provides substantive summary, testing, review, security, and notes details.
Linked Issues check ✅ Passed Changes address #10859 by translating mirrored editor-tab owners, deduping sync, and making close/cull authoritative in the receiver frame.
Out of Scope Changes check ✅ Passed All code and tests are aligned with the editor-mirroring fix; no unrelated scope is evident.

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.

🧹 Nitpick comments (1)
src/renderer/src/runtime/web-session-tabs-sync.ts (1)

883-914: 📐 Maintainability & Code Quality | 🔵 Trivial

Unsafe double-cast bypasses the type contract needed for translation.

state as unknown as WorktreeRuntimeOwnerState forces the cast, but WebSessionTabsSyncState is Pick<AppState, 'activeBrowserTabId' | ... | 'sortEpoch'> & Partial<Pick<AppState, 'automaticAgentResumeClaimsByTabId' | 'pendingStartupByTabId'>> and does not structurally include repos, worktreesByRepo, detectedWorktreesByRepo, or folderWorkspaces — the fields translateMirroredEditorRuntimeEnvironmentId actually reads. Production is fine today because callers always pass the full store state (which happens to carry those extra properties), but the type no longer documents/enforces that dependency, and a caller constructing a genuinely narrow WebSessionTabsSyncState would silently get hasConcreteRecord === false and skip translation (the tests already need Object.assign(state, { repos, worktreesByRepo }) to backfill this). close-mirrored-editor-tab.ts's MirroredEditorCloseState = WorktreeRuntimeOwnerState & {...} intersection pattern is the safer approach used elsewhere in this same PR.

♻️ Suggested type-safe alternative
-import type { WorktreeRuntimeOwnerState } from '`@/lib/worktree-runtime-owner`'
+import type { WorktreeRuntimeOwnerState } from '`@/lib/worktree-runtime-owner`'
...
-export type WebSessionTabsSyncState = Pick<
-  AppState,
-  ...
-> &
-  Partial<Pick<AppState, 'automaticAgentResumeClaimsByTabId' | 'pendingStartupByTabId'>>
+export type WebSessionTabsSyncState = Pick<
+  AppState,
+  ...
+> &
+  Partial<Pick<AppState, 'automaticAgentResumeClaimsByTabId' | 'pendingStartupByTabId'>> &
+  WorktreeRuntimeOwnerState

Then drop the as unknown as WorktreeRuntimeOwnerState cast at the call site.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 58e9cf6f-db49-4ef3-ae6e-ef0dcab493e9

📥 Commits

Reviewing files that changed from the base of the PR and between 94009f6 and b2c1c84.

📒 Files selected for processing (8)
  • src/renderer/src/lib/worktree-runtime-owner.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants