fix: restore terminal ownership on reload to prevent cross-worktree contamination #113
Merged
amandal0903 merged 2 commits intomainfrom Apr 13, 2026
Merged
fix: restore terminal ownership on reload to prevent cross-worktree contamination #113amandal0903 merged 2 commits intomainfrom
amandal0903 merged 2 commits intomainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_restoreOwnership()was gated onactiveWorktreebeing available at construction time — it wasn't, so the persisted PID→worktree map was never loaded_persistedOwnershipByPidmap so late-arriving restored terminals reclaim their correct worktree from storage instead of falling through to_activeKey