Skip to content

fix(runtime): stop paired hosts from echoing mirrored editor tabs - #25877

Closed
BearMett wants to merge 22 commits into
stablyai:mainfrom
BearMett:ym-wt/pr4-mirror-echo-republication
Closed

BearMett wants to merge 22 commits into
stablyai:mainfrom
BearMett:ym-wt/pr4-mirror-echo-republication

Conversation

@BearMett

@BearMett BearMett commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When two Orca desktops are paired with each other, each one shows the other's open editor tabs. Before this change, a desktop also told its peer about the tabs it was only showing for that peer. Mirrored tabs were republished, which could echo tabs back to their originating host, and a closed tab could come back because the peer sent it again. Now a desktop only announces the tabs it actually opened itself.

What Changed

Before: desktops A and B are paired in both directions. A file opened on A shows up on B as a mirrored tab. B announces it to A as one of B's own tabs, and A can show it again. The same file can appear as more than one tab, and a closed tab can come back when a peer reconnects.

After: B shows A's tab but never announces it. Each updated host publishes only the tabs it owns, so between two updated peers a close holds for rows that carry the mirror marker.

How it works (10 production lines in 7 files):

  • isMobilePublishableOpenFile skips rows with mirroredFromRuntimeSession === true. That flag already marked tabs received from another host, but publishing ignored it. The flag is also added to the open-files sync projection, so changing it re-runs publishing.
  • The flag survives a restart. It is saved with the session (only when true), accepted by the load-time schema and the shared workspace-layout field table (workspace-layout-disk-fields.ts), and copied back when the session loads. Without this, a restored mirror came back unmarked and was republished after every relaunch.
  • A worktree holding only mirrored editor tabs keeps publishing an empty snapshot (tabs: []) instead of disappearing. Worktrees holding only mirrored terminals already behave this way.
  • config/scripts/pr-code-change-scope.mjs now runs the cross-version CI job when the publishing, mirror-apply, editor-schema or salvage modules change.

Rebase notes:

Why

The host already knows exactly which rows it received from a peer, so filtering on that marker is precise. Two alternatives were rejected:

  • Inferring "mirrored" from runtimeEnvironmentId. That id is also set on files a host really owns (SSH-owned files, and files opened through the focused-environment path). This approach would hide legitimate tabs.
  • Publishing only tabs whose path exists locally. Same problem for SSH and folder workspaces.

No capability gate is needed: receivers already treat a missing tab as closed, and no field, frame or opcode is added on the wire.

Linked Issue

Fixes #27984

Related to #21121, which absorbed the closed report #17778. Field evidence: this measurement on #23967 shows this loop. Not fixed here: older peers echoing under the host's own tab id (see Notes).

Visual Proof

Nothing new is drawn on screen; the difference is which tabs a paired desktop publishes. From mirrored-editor-tab-republication.test.ts and mirrored-editor-tab-persistence.test.ts: host A has /repo/app.ts open as tab host-file-tab, and peer B applies A's snapshot.

Before (main, pinned by the characterization test in c2bb84ddf7), B's published snapshot for that worktree:

tabs: [{ type: 'file', id: 'host-file-tab', filePath: '/repo/app.ts' }]

After, both right after the snapshot and after B saves, reloads, and applies A's snapshot again:

tabs: []

Hidden Electron checks on the refreshed head verify reciprocal pairing, final close, and real restart. CDP screenshots and hidden native-window receipts are preserved in the audit evidence. Attachment upload is unavailable in this environment without a browser session token.

Testing

Current head 39ce049d5b69 merges main 816fcee74214 while preserving the contributor implementation. This includes the already-merged fixes for the old calendar-dependent scanner and socket-backpressure CI fixtures. One cross-version fixture now initializes editorBuffers: {} to match the current sync state; there are no new production changes in this refresh.

  • 112 focused and adjacent tests across 16 files pass, including mirror publication/persistence, old-release compatibility, buffer ownership/hydration, schema coverage, and both formerly failing CI fixtures.
  • All four core typecheck projects pass: Node, renderer, CLI, and process-host tests. Changed-code quality reports zero new findings across 22 files; patch whitespace passes.
  • The Electron E2E app and CLI build pass. Hidden Electron reciprocal-pairing and real quit/restart checks pass (2 passed; the opt-in three-host ring is skipped). Both native windows remained hidden and unfocused. The restart test proves a resumed host subscription, marker persistence, and a closed-mirror soak.
  • Folder liveness controls pass, but the folder-only no-echo oracle was vacuous because that peer lacked the source folder. The Git-worktree mirror and persistence assertions were nonvacuous.

Local validation used macOS. Linux/Windows and live SSH acceptance remain for CI or follow-up. The supplemental broad E2E tooling typecheck has 252 diagnostics, including missing separately installed cloud dependencies and other test errors; none name the 22 PR paths. No full baseline comparison or global E2E typecheck success is claimed.

Fresh CI is required for this head; the old 40ba2edd run does not validate the refresh. Main advanced by an unrelated watcher change after the pinned merge, with no changes in the 22 PR paths.

AI Disclosure

Written with Codex (gpt-6-astra) and Claude Code (Claude Opus 5.5).

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.

Notes

  • Wire compatibility: this is a change to what a host publishes, not to the wire format. A host stops publishing editor tabs it only mirrored from another host. No RPC field, stream opcode or protocol version changes. An older client that was showing an echoed tab relayed by this host will see it close, the same as any host-side close today.
  • Non-goal: older peers echoing the same tab id. Echo suppression and close finality hold only when every reciprocally paired host runs this change. An older peer builds its mirror tab with the tab id it received (checked in the v1.4.204 builder source), so its echo carries the host's own tab id. In that case the host keeps its own file record, but its own tab is moved into the peer-sync group, stamped as owned by the older peer, and still published; it stays that way after the older peer closes the mirror. The cross-version test case 3 pins this.
  • Legacy rows: rows saved before this change carry no marker. runtimeEnvironmentId alone cannot tell them apart from local files, so they are still republished after a restart. Nothing in this PR re-marks them.
  • Downgrade: an older build reading the same profile drops the marker (cross-version case 5), so after a downgrade a restored mirror is treated as the old build's own file.
  • True-only marker: by design. The writer only saves mirroredFromRuntimeSession: true, and the schema accepts only true. A hand-written false row is dropped by the salvage path (case 5).
  • SSH and folder workspaces: the filter is on the received-from-peer marker only. SSH-owned and folder-workspace files a host really owns still publish.

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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). Typecheck, changed-code quality and the related suites pass locally. Full lint, the full test suite and the build are left to CI.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: bcabd984-1300-4f89-9f44-9287376274df
📥 Commits

Reviewing files that changed from the base of the PR and between 3bc7c849f7a275aa167b518f1912fc293069ce0d and e0dc7f54075b37d2b8ef1869e9f41cda3ca92937.

📒 Files selected for processing (3)
  • tests/e2e/helpers/localhost-ssh-target-preflight.ts
  • tests/e2e/helpers/localhost-ssh-target.ts
  • tests/e2e/ssh-localhost.spec.ts

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

Walkthrough

The change persists and restores the mirroredFromRuntimeSession marker and excludes marked files from mobile-session publication. Tests cover snapshot application, cross-version exchanges, paired-runtime behavior, restart restoration, and SSH worktrees.

Priority: Normal

Merge Risk: Minimal · up to e0dc7

An empty SSH host override no longer causes the opt-in test to probe an invalid destination. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning For [#21121], this PR excludes marked mirrored tabs from publication and preserves the marker through save and restore. Its tests cover echo prevention and restart behavior. The issue also proposes wr… Implement the remaining applicable #21121 repairs, or narrow the linked issue to the mirrored-tab republication work covered by this PR.
Docstring Coverage Warning Docstring coverage is 37.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 58 functions across 23 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Out of Scope Changes check Passed The publication, persistence, and projection changes support mirrored-tab suppression. The unit, cross-version, paired-Electron, and SSH tests verify that behavior and its ownership and compatibility …
Title check Passed The title clearly and concisely describes the main change: preventing paired hosts from echoing mirrored editor tabs.
Description check Passed The description is complete and aligned with the template. It explains the problem, implementation, rationale, linked issue, testing, compatibility limits, and remaining known cases. The visual-proof …
Full details: Out of Scope Changes check

Explanation

The publication, persistence, and projection changes support mirrored-tab suppression. The unit, cross-version, paired-Electron, and SSH tests verify that behavior and its ownership and compatibility boundaries. The test-job routing and SSH helper extraction support those tests. The change summary shows no unrelated changes.

Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the problem, implementation, rationale, linked issue, testing, compatibility limits, and remaining known cases. The visual-proof section does not use the exact requested N/A wording, and several checklist items remain unchecked, but these are minor issues because the description explains the non-visual behavior and testing status in detail.

Full details: Linked Issues check

Explanation

For [#21121], this PR excludes marked mirrored tabs from publication and preserves the marker through save and restore. Its tests cover echo prevention and restart behavior. The issue also proposes write-path record deduplication, hydration ownership and ID repair, orphan pruning, atomic close and guarded activation, owner derivation from the worktree route, and missing-file handling. The change summary shows none of those repairs. The PR therefore addresses the mirrored-tab republication symptom but does not meet the broader coding scope of the active linked issue.

Resolution

Implement the remaining applicable #21121 repairs, or narrow the linked issue to the mirrored-tab republication work covered by this PR.

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

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: e89e1652-6122-481f-8105-279a4d97d649
📥 Commits

Reviewing files that changed from the base of the PR and between 5cf3585 and 3bc7c849f7a275aa167b518f1912fc293069ce0d.

📒 Files selected for processing (21)
  • config/scripts/pr-code-change-scope-cross-version-editor-mirror.test.mjs
  • config/scripts/pr-code-change-scope.mjs
  • src/renderer/src/lib/workspace-session.ts
  • src/renderer/src/runtime/sync-runtime-graph-projection-hot-path.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/mirrored-editor-tab-persistence.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/mirrored-editor-tab-republication.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/mobile-session-surfaces.ts
  • src/renderer/src/runtime/sync-runtime-graph/sync-projections.ts
  • src/renderer/src/store/slices/editor/actions/hydrate-editor-session.ts
  • src/shared/workspace-session-editor-schema.ts
  • src/shared/workspace-session-schema-field-coverage.test.ts
  • src/shared/workspace-session-state-types.ts
  • tests/e2e/cross-version-wire/cross-version-session-tabs-editor-mirror.unit.test.ts
  • tests/e2e/helpers/editor-mirror-peer-setup.ts
  • tests/e2e/helpers/editor-mirror-persisted-partitions.ts
  • tests/e2e/helpers/editor-mirror-renderer-store.ts
  • tests/e2e/helpers/editor-mirror-session-inventory.ts
  • tests/e2e/helpers/editor-mirror-soak.ts
  • tests/e2e/helpers/localhost-ssh-target-preflight.ts
  • tests/e2e/paired-editor-mirror-echo-reciprocal.spec.ts
  • tests/e2e/paired-editor-mirror-echo-restart-ssh.spec.ts

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

… peer echoes it

Main now retains a local editor row and tab when a peer frame claims the same
id, so the old-peer echo characterization no longer expects the local row to be
duplicated or its tab dropped.
…h a host pin

Since stablyai#26593 the mirror resolver reuses an existing row for the same owner, so a
row restored from the profile keeps its owned editor: id when the host's
snapshot lands; the bare-path id the spec waited for can no longer appear. The
host now pins its tab after the relaunch and the client must show the pin on the
tab backed by its restored row. The ids-seen list is reported at failure time
instead of being captured empty before polling.
@DaveDev42

Copy link
Copy Markdown
Contributor

Hit this on 1.4.237 with a Mac and a Windows desktop paired both ways. In my profile-state.db one file had 5 tabs with the same sourceFileId and path, differing only in the environment segment of the tab id. Cleaning the db didn't stick, the copies came back within seconds. That matches the republish loop this PR cuts.

One gap I think this leaves: a peer still on an older build keeps republishing, and saved layouts that already carry the variants keep sending them. I opened #31984 to collapse those on the receiving side. It doesn't touch anything this PR changes, so either can land first.

…epublishes mirrors

Main's stablyai#31984 fixture published a mirrored row, which this branch no longer republishes.
@nwparker

Copy link
Copy Markdown
Contributor

Maintainer refresh: merged current main (2a20d2d) into this branch, no textual conflicts. After the merge, main's #31984 test mirrors one tab when a snapshot lists the same file under several environment variants failed, because its publisher fixture published a mirrored row and this PR now drops those. I changed that fixture to publish an older peer's unmarked row (test only, d622f77). Production code is unchanged. Local: 3722 tests pass across editor/runtime/shared workspace-session suites; oxlint clean.

@nwparker

Copy link
Copy Markdown
Contributor

Follow-up (a4f83a0): the refreshed head failed the oxlint max-lines gate, because pr-code-change-scope.mjs reached 603 counted lines (limit 600) after the merge. I moved the tail of CROSS_VERSION_WIRE_PREFIXES (the orchestration-db group plus this PR's editor-mirror group) verbatim into config/scripts/pr-cross-version-wire-paths.mjs and spread it back into the list. Routing is unchanged, and the 113 pr-code-change-scope tests pass.

…de-change-scope under its line budget"

This reverts commit a4f83a0.
@nwparker

Copy link
Copy Markdown
Contributor

I reverted the split (bee99f9). PR Checks sparse-checks out config/scripts from an explicit list in pr.yml, and mobile.yml and its tests keep their own lists, so a new routing module would need workflow and route-test edits that go beyond a mechanical refresh.

Still blocking: after merging current main, config/scripts/pr-code-change-scope.mjs is at 603 counted lines, over the 600-line oxlint max-lines gate. This PR's four new CROSS_VERSION_WIRE_PREFIXES entries pushed main's 599 over. Options:

  • Drop the routing addition and its test from this PR.
  • Split the prefix list into a module and wire it into the workflow sparse-checkout lists.

Maintainer decision needed. The production fix and the test-fixture update (d622f77) are unaffected.

nwparker added a commit that referenced this pull request Oct 24, 2026
…33259)

* fix(runtime): stop paired desktops republishing mirrored editor tabs

When two desktops pair both ways, B mirrored A's editor tabs and then
published them in its own session inventory as if B had opened them. A
then applied B's copy, which took over A's own tab.

isMobilePublishableOpenFile now skips rows marked
mirroredFromRuntimeSession, the marker is part of the open-files sync
projection so a flip republishes, and the marker is saved with the
session and restored so a relaunched client does not republish its
restored mirrors before the host's first snapshot.

Based on #25877 by BearMett.

Co-authored-by: BearMett <[email protected]>

* fix(runtime): keep restored mirrors through unpublished frames and out of headless publication

A restored mirror now carries its marker, so an unpublished host frame
must not cull it (and its recovered draft). The windowless publication
skips persisted mirrored rows for the same reason the window does.

Co-authored-by: BearMett <[email protected]>

---------

Co-authored-by: BearMett <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Thank you @BearMett, and sorry this sat open for so long. Your diagnosis was right. When two desktops pair both ways, each one republished the editor tabs it was only mirroring, and the host then took them back as if the peer had opened them. We reproduced it on current main using your reciprocal two-desktop spec. Desktop B listed A's src/index.ts as its own tab, and A's own tab got re-attributed to B. With your change applied, your reciprocal spec and your restart spec both pass.

We've landed the fix in #33259, with you as co-author, and we're closing this PR in favour of it. From your work we kept:

  • Production change: your fix, as you wrote it:
    • the mirroredFromRuntimeSession check in isMobilePublishableOpenFile;
    • the flag in the open-files sync projection;
    • saving the flag when it is true, through the session save, the load schema, the layout disk-field table and hydration.
  • Tests: your republication unit tests, trimmed to the core cases, and your persistence round-trip test.
  • Fixtures: your updates to the projection hot-path, layout fact-location and old-peer editor-tab tests.

We also added two follow-ups your change exposed:

  • A restored mirror is no longer culled by a host frame that hasn't been published yet. That cull could lose an unsaved draft.
  • The windowless host publication skips mirrored rows too.

We didn't check in the e2e specs and helpers, the cross-version release-checkout suite or the CI routing change. They were very valuable for verifying the fix. They're long and soak-heavy to keep in CI, though, and the unit tests catch the same regression deterministically. Thanks again for such a careful, well-evidenced write-up.

@nwparker nwparker closed this Oct 24, 2026
@BearMett

Copy link
Copy Markdown
Contributor Author

Thanks, @nwparker, and no worries about the wait. Glad the reciprocal and restart specs reproduced it on current main, and the two follow-ups cover the remaining gaps.

The cross-version release-checkout suite really helped me confirm the bug across versions, but I'd already been concerned that it would be too heavy to use directly in CI. So I fully agree with keeping the unit tests in CI and leaving that suite out. Appreciate the co-author credit.

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]: Paired desktops republish mirrored editor tabs, including after restart

3 participants