Skip to content

fix: restore terminal ownership on reload to prevent cross-worktree contamination #113

Merged
amandal0903 merged 2 commits intomainfrom
terminal-persistence
Apr 13, 2026
Merged

fix: restore terminal ownership on reload to prevent cross-worktree contamination #113
amandal0903 merged 2 commits intomainfrom
terminal-persistence

Conversation

@amandal0903
Copy link
Copy Markdown
Collaborator

Summary

  • Fix terminal ownership not being restored on window reload, causing all terminals to be assigned to the active worktree regardless of which worktree they belonged to
  • _restoreOwnership() was gated on activeWorktree being available at construction time — it wasn't, so the persisted PID→worktree map was never loaded
  • Add _persistedOwnershipByPid map so late-arriving restored terminals reclaim their correct worktree from storage instead of falling through to _activeKey

…ontamination

On window reload, _restoreOwnership() was gated inside if (activeWorktree)
which was null at construction time. This meant the persisted PID-to-worktree
map was never loaded, causing all restored terminals to be blindly assigned
to whichever worktree happened to be active — terminals from background
worktrees would appear in the wrong worktree.

Fix: call _restoreOwnership() unconditionally before seeding _activeKey.
Add _persistedOwnershipByPid map so late-arriving restored terminals
(via onDidCreateInstance) reclaim their correct worktree from persisted
storage instead of falling through to _activeKey. Also match terminals
by attachPersistentProcess.id which is available before process manager
reconnects.

Additional hardening from code review:
- Guard against re-entrancy in onDidCreateInstance (skip already-owned)
- Clean up _savedActiveEditors on worktree removal
@amandal0903 amandal0903 merged commit 3c7f829 into main Apr 13, 2026
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