Skip to content

fix(terminals): remap stale worktree ids on restore - #8063

Closed
bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:fix/reattach-remap-stale-worktree-id
Closed

bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:fix/reattach-remap-stale-worktree-id

Conversation

@bbingz

@bbingz bbingz commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

fix(terminals): remap stale worktree ids on restore

Summary

When hydrating a workspace session, remap persisted terminal worktree IDs onto the current worktree catalog by normalized path + execution host, so restored tabs keep daemon PTY identity after worktree ID regeneration (app update, SSH reconnect rediscovery, etc.).

Residual / status (2026-07-23)

  • Rebased onto latest main; 1 commit
  • Does not depend on closeLifecycle / transport recovery / orchestration PRs
  • Main still lacks this reconciliation module

Solution

  • reconcileWorkspaceSessionWorktreeIds(...) before hydrate validity filtering
  • Merge colliding session maps when two old IDs map to one live worktree
  • Preserve active repo selection when possible

Test plan

  • Unit tests for path/host remapping and collision merge
  • Manual: restore session after worktree id change — tabs not “Unknown”
  • Remote runtime worktree still reattaches same daemon PTY when path matches

Reviewer note

Community PR — cannot merge. Safe independent land.

ELI5

Restored terminal tabs could lose their daemon PTY after worktree IDs changed (app update, SSH rediscovery). On hydrate, old worktree IDs are remapped by path and host so sessions reattach to the right place.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds reconcileWorkspaceSessionWorktreeIds to match stale persisted worktree IDs using normalized paths and execution hosts. The reconciliation recursively updates session keys and values, merges collisions, and adjusts the active repository ID. Session hydration now supplies repositories, worktrees, and runtime host mappings to the reconciliation function. Tests cover unique and ambiguous matches, local fallback behavior, host isolation, SSH mappings, tabs, sleeping agents, and terminal PTY mappings.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

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.
Description check ⚠️ Warning The description covers summary and tests, but it omits required screenshots, AI review report, security audit, and notes sections. Add the missing template sections, including screenshots/no visual change, AI review with cross-platform checks, security audit, and notes.
✅ Passed checks (3 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 matches the main change: remapping stale worktree IDs on session restore.

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.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Restack + review guide (community, awaiting maintainer)

Rebased onto latest main (force-with-lease). Squashed to 1 unique commit (dropped stale merge noise from old tip). Conflict resolved: kept main’s terminal-tab-retirement imports and hydrate-time worktree-id reconciliation.

What this PR still uniquely does

On hydrateWorkspaceSession, remap stale persisted worktree IDs to current catalog IDs by normalized path + execution host (preserving daemon PTY bindings where possible).

Main has no workspace-session-worktree-id-reconciliation module.

Files

  • src/renderer/src/lib/workspace-session-worktree-id-reconciliation.ts (+ tests)
  • wire-up in terminals.ts hydrate path only

Depends on

Tests (local)

  • reconciliation unit tests — 5 passed

Ready for upstream review; community author cannot merge.

@bbingz
bbingz force-pushed the fix/reattach-remap-stale-worktree-id branch from fab6ad9 to 0cb2a65 Compare July 24, 2026 08:17
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@bbingz

bbingz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of fork PR backlog cleanup. Long-conflicted against current main; reopen or recreate if still needed.

@bbingz bbingz closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants