Skip to content

Isolate code editor text and Undo history by execution host - #25174

Merged
nwparker merged 5 commits into
mainfrom
nwparker/editor-host-model-isolation
Oct 4, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/editor-host-model-isolation

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Files with the same path on different hosts now keep their text and Undo history separate.

What Changed

The code editor previously identified a document by its path alone. Its model identity now includes the execution host, using the file's captured owner and existing host resolver. Synchronization and closed-tab cleanup use that same identity. Late owner resolution snapshots the caret and scroll before the widget changes. Tabs for the same local file still share one model.

Why

Opening a remote file after editing a local file with the same path could expose the local text through Undo. Scoping the existing model registry preserves Undo and tab reopening without rebuilding every model or clearing useful history.

Linked Issue

Found during the editor integration review; no linked issue.

Visual Proof

Edit the local file, open the same path under a different host identity, then Undo. Before, Undo reveals LOCAL_MARKER in the remote tab. After, it restores REMOTE_MARKER, and the local edit remains intact.

Before After
Remote Undo exposes local text Remote Undo retains remote text

Actual SSH workspace after the remote save, followed by the retained local draft at the identical path. Actual SSH integration receipts.

Remote save Retained local draft
Actual SSH file remains remote Local draft remains local

Testing

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

Native Windows passes 136/136 tests across 17 files on head 17adc1f8ce21d5be016ac0f02662f6f41699be84. Exact-head Windows receipts.

The real editor wrapper regression fails before the owner-change cleanup fix and passes after it: the dirty draft, selection on lines 80–82, and scroll position survive; Undo remains isolated. A positive user-edit control verifies that the content-change callback is reachable. Remote-owner close/reopen tests cover POSIX, Windows drive, and UNC paths.

A hidden macOS Electron app connected through Orca's actual SSH provider to Linux. A local folder and remote Git workspace used the identical absolute file path. Actual reads, independent dirty drafts and Undo, remote save with independent SSH readback, and the unchanged local file all pass. The temporary target, app, and owned fixture directories were removed. The earlier rendered baseline reproduces the local-text leak.

The combined macOS editor suite passes 2,272 tests in 304 files, with three tests skipped. Full pnpm tc, full pnpm lint, the changed-code quality gate, and a fresh background Electron build pass on main plus these three changes. All three PRs are rebased onto main at 6c0757004053; their owned source files match that tested integration. Current-head CI is green, including static analysis/typecheck, all five full-unit shards, the Linux rendered regression, packaging, and final verification.

Native window focus was not exercised. Global E2E typecheck has existing unrelated errors; the changed editor spec has no diagnostics.

Review

Checked authoritative file ownership, unresolved-owner isolation, model disposal, shared local tabs, Undo, and synchronization during owner changes, including late catalog-only resolution and deferred cleanup after detach.

Agent skill upstream boundary

  • Not applicable; no agent skill changes.

Notes

Resolving a previously unknown owner remounts the editor under the correct host. The current unsaved draft, selected range, and scroll position are preserved. Earlier Undo history and Find state may reset. Tabs for the same local file still share their model and Undo history.

Uses existing host routing for remote and folder workspaces. No wire format changes or new platform-specific commands.

Checklist

  • Focused change; before/after, mechanism, and approach explained.
  • Before/after screenshots attached.
  • Self-reviewed for correctness, security, performance, and cross-platform/remote behavior.
  • Native Windows tests, the macOS editor suite, full typecheck/lint, fresh build, changed-code quality, and real SSH integration pass. Current-head CI is green, including static analysis/typecheck, all five full-unit shards, the Linux rendered regression, packaging, and final verification.

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 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: e9fa6065-7f73-459d-8d15-83f05a6e6a4a
📥 Commits

Reviewing files that changed from the base of the PR and between b432dd43bf5679f2d71287a8da32032b71e6a8b4 and 17adc1f.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/MonacoEditor.content-owner.test.tsx
  • src/renderer/src/components/editor/MonacoEditor.owner-view-state.test.tsx

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


📝 Walkthrough

Walkthrough

Editor model URIs now include an owner key derived from file and worktree route state. Monaco content synchronization and closed-tab cleanup use owner-specific model identities. Added tests cover same-path model separation, synchronization, undo history, and model disposal across ownership routes.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 17adc

No actionable issue is established in these changes; they are mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 17adc

The change strengthens separation between files opened on different execution hosts. No introduced security regression was established in the reviewed flows, but incomplete coverage leaves some residual uncertainty.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly affected confidentiality boundary is retained text and Undo history for same-path files belonging to different execution hosts within a renderer's model registry. This identity change does not itself establish stronger operating-system or remote-service authorization.

Trust Boundaries and Controls

  • observed — Content-change callbacks and external-content reconciliation require the live model URI to match the expected owner-specific identity. Programmatic synchronization uses that same identity and releases suppression in finally blocks, including during mount reconciliation.

Resilience and Maintainability Implications

  • observed — Deferred disposal retains the previous owner identity, rechecks currently open owner-specific URIs, limits disposal to captured model objects, and defers attached models until detachment. Generation and active-state fences invalidate stale work during registry changes and shutdown.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 18 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 summarizes the main change: separating editor text and Undo history by execution host.
Description check ✅ Passed The description covers the change, user impact, rationale, visual proof, testing, review, compatibility notes, and checklist. It states that no issue is linked, although the template requires one for …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • 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.

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

✅ No new issues found.

Reviewed changes

This run read the complete diff (16 files, 1 commit) at 24c6399.

  • Owner-scoped model identity — toEditorModelUri now appends the execution-host owner key as the URI fragment, so equal paths on different hosts get distinct Monaco models while local files keep the legacy path-only model.
  • Owner derivation and isolation — new editor-model-owner.ts derives a stable [runtimeEnvironmentId, executionHostId] key from captured provenance or the worktree/folder route, with a per-file unresolved key so an unplaceable tab cannot borrow another host's retained text.
  • Threaded through sync and cleanup — MonacoEditor.tsx, use-monaco-editor-mount.ts, the closed-tab controller/disposal, and the programmatic-sync suppression map all key by the owner-scoped model URI; the controller subscription now also reacts to owner-affecting catalog changes.
  • Tests — unit, component, and Electron/CDP e2e coverage for same-host sharing, cross-host isolation, owner changes, disposal, and Windows drive/UNC URI round-trips.

ℹ️ Editor view state is still keyed by path, not by owner

Text and Undo are now isolated per host, but scroll and cursor view state is not: editorViewStateKey is the raw activeFile.filePath (EditorContent.tsx:96-99), and scrollTopCache/editorSelectionCache entries are keyed by path, so same-path local and remote tabs restore each other's position and closing one clears the other's cached entry. This is outside the PR's stated scope (text and Undo), and the codebase already scopes durable PDF zoom per owner via buildPdfScalePreferenceKey, so it reads as a candidate follow-up rather than a blocker.

Technical details
# Editor view state not owner-scoped

## Affected sites
- `src/renderer/src/components/editor/EditorContent.tsx:96-99` — `editorViewStateKey` is `activeFile.filePath` (or `...::scope`).
- `src/renderer/src/components/editor/closed-editor-tab-disposal.ts:98-104` — deletes `scrollTopCache`/`editorSelectionCache` by `closedFile.filePath`, shared across same-path owners.
- Contrast `src/renderer/src/components/editor/EditorContent.tsx:111-113` — `buildPdfScalePreferenceKey(activeFile)` already scopes PDF zoom by owner.

## Open questions for the human
- Is view-state sharing across same-path hosts intentional (harmless convenience), or an oversight to fix in a follow-up?

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/editor-host-model-isolation branch 2 times, most recently from 188d7fb to 108ed7a Compare October 4, 2026 20:06

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

ℹ️ No critical issues — minor suggestions inline.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review at 24c6399: commit 188d7fb (Verify editor owner resolution and Windows model path isolation), which changes only tests.

  • Ownership-resolution remount test — mocked the editor to record mount/unmount transitions and added a component test that drives an unresolved tab to a resolved local owner, asserting the widget remounts onto a new model while keeping the latest draft.
  • Windows-shaped path coverage — parameterized the host-isolation test over a POSIX path, a Windows drive path, and a UNC path.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

expect(editorProps.current?.defaultValue).toBe('latest dirty draft')
expect(editorProps.mounts).toEqual([unresolvedModel, resolvedModel])
expect(editorProps.unmounts).toEqual([unresolvedModel])
expect(onContentChange).not.toHaveBeenCalled()

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.

The mock Editor never invokes onChange (or onMount), so onContentChange has no reachable call site in this test and this assertion can never fail — it cannot catch the spurious-dirty regression it looks like it guards. Either have MockEditor emit a change after the remount, or drop the assertion so the suite doesn't imply coverage it lacks.

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

✅ No new issues found.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review (188d7fb): commit 108ed7a (Respect native model line endings in content sync history coverage), a test-only change.

  • Line-ending-aware assertion — the read-only live-tail undo test now compares against ['first line', 'appended'].join(model.getEOL()) instead of a hard-coded \n, so it holds on native CRLF hosts too.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/editor-host-model-isolation branch 2 times, most recently from 1391fb2 to b432dd4 Compare October 4, 2026 21:45
@nwparker
nwparker force-pushed the nwparker/editor-host-model-isolation branch from b432dd4 to 17adc1f Compare October 4, 2026 21:54
@nwparker
nwparker merged commit a753aff into main Oct 4, 2026
36 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