Skip to content

P1: Bind terminal sessions to the current worktree and clean up removed threads #1183

Closed

Description

@currentbits

Audit #1180, 2026-09-10. Baseline: checkout 9fc8645; fetched origin/main bf6fb02 has identical relevant implementation. This is implementation backlog, not a shipped fix.

Evidence

electron/terminal.js returns an existing live session by threadId before comparing the requested root. A fake-child check of the real module called open(id, '/tmp/old') then open(id, '/tmp/new'); the second call still reported '/tmp/old'.

electron/ipc.js resolves worktreePath || project.path on every terminal call. A shell opened before materialization can keep running in the main checkout after its thread acquires a worktree.

Source tracing found no terminal cleanup in electron/services.js purgeThread/deleteThread or Store.removeThread. Pane unmount preserves sessions. After permanent deletion terminal:close rejects Unknown thread, leaving cleanup until app exit. Root reuse was reproduced with a fake child; deletion leakage is source-confirmed, not measured against live user processes.

Change

Bind sessions to thread plus execution root/host. On root change, make stale ownership visible and require safe reattachment before accepting another command. Do not silently kill a running job or silently continue in the old checkout. Use a shared permanent-removal cleanup path for thread deletion, project removal and retention. Preserve ordinary pane hide/show reattachment. Expose Close session separately from Restart.

Acceptance

  • Opening before worktree materialization cannot silently execute later commands in the main checkout.
  • Merge/reclaim cannot leave a seemingly valid terminal attached to a removed directory.
  • Permanent removal releases owned shells and descendants with correct platform handling.
  • Closing a pane may retain the session; Close session explicitly terminates it.
  • Cover root changes, reattachment, deletion and project removal; never signal unrelated processes.

Coordinate with #147's session manager and the PTY upgrade under #1180.

Activity

  1. added a commit that references this issue on Oct 6, 2026
  2. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    Gap pass #1532 checked this against main @24d3c36b (v0.24.0). It is mostly shipped:

    Keeping this open for two gaps:

    1. A stale shell only gets a warning. terminal:write still accepts input (electron/terminal.js:485), so the "require safe reattachment before accepting another command" requirement is not met.
    2. On WSL the shell starts in the project root, not the worktree (terminal.js:357), so it can run commands in the main checkout.
  3. added
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Oct 9, 2026
  4. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    Fixed: open reports a stale root and supports moving to the current worktree (terminal.js:328-337), and trashing a thread kills its terminals (services-threads.js:1176). Closing in the 2026-10-09 board cleanup (#1532).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions