Repository navigation
fix(vscode): retain terminal ownership across restart and teardown - #14774
marius-kilocode merged 8 commits into
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The follow-up commit ( Files Reviewed (4 files)
Previous Review Summary (commit 0913273)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 0913273)Status: No Issues Found | Recommendation: Merge The retry/ownership rework in Files Reviewed (3 files)
Reviewed by deepseek-v4.1-flash · Input: 80.4K · Output: 25.9K · Cached: 690.8K Review guidance: REVIEW.md from base branch |
marius-kilocode
left a comment
There was a problem hiding this comment.
The core revision and identity fix is correct, but cleanup ownership is still lost across the production router lifecycle. Please address these two cases before merging.
- Keep late-cleanup ownership reachable after router disposal.
TerminalRouter.dispose() replaces manager M1 with M2 immediately. M1.dispose() intentionally returns without waiting for a pending replacement create. If pty-2 then arrives and its removal fails, M1 retains it in owned, but nothing references M1 after the restart promise settles. Later disposal calls only M2, so pty-2 cannot be retried and remains alive until kilo serve exits. This contradicts the retryable-cleanup goal.
Please either retain retired managers in TerminalRouter until they have no owned PTYs or pending restarts, and retry them during later cleanup, or use an equivalent retry mechanism that survives manager replacement. Do not make disposal wait for a stalled create request.
- Include detached ownership in directory cleanup.
TerminalManager.closeDirectory() scans entries, while close() correctly scans owned. After a late replacement cleanup fails, the entry is detached from entries but remains in owned, so worktree cleanup can report success without retrying that PTY. Directory cleanup should operate on owned entries for the target directory.
Please add regression coverage at the router boundary:
- Hold a replacement create, dispose the router, release the replacement, fail its first removal, trigger cleanup again, and assert that the replacement is removed and the retired manager can be released.
- Leave a failed late replacement only in
owned, callcloseDirectory(), allow removal to succeed, and assert that no PTY remains.
I reproduced the first case through TerminalRouter: after the failed late removal and a second dispose(), the live set is still ["pty-2"]. The existing manager-level retry test reuses the same manager, so it does not cover this production lifecycle.
|
@marius-kilocode both points should be fixed in fc6ad12: retired managers get retried on later dispose()/closeDirectory(), and closeDirectory() now walks owned. |
marius-kilocode
left a comment
There was a problem hiding this comment.
Both cleanup issues from my previous review are fixed. Retired managers remain available for cleanup retries, and directory cleanup includes detached ownership. All 157 focused tests, compilation, lint, and typechecks pass. I also tested terminal restart and terminal/panel teardown in isolated VS Code and confirmed the shell processes were removed. Thanks for addressing this and adding the router regressions!
Issue
Fixes #14772
Follows up on the restart cleanup finding in #12812.
Context
A restarted PTY can finish creating after its terminal closes or its panel reloads. The restart then updates a detached entry, leaving the replacement outside cleanup bookkeeping. Setup failures can leave the same gap.
Implementation
Keep PTY ownership until removal succeeds, and invalidate the entry revision when teardown begins. Check identity and revision after asynchronous setup and cleanup so an obsolete restart cannot return a stale URL or replace a newer entry.
Close/dispose clean up known PTYs without waiting for pending create/resize requests. Late allocations are removed when their requests settle. The router retains retired managers until their PTYs and pending requests are settled, so later disposal and directory cleanup can retry failed removals after a panel reload. Directory cleanup includes detached ownership and stays scoped to the target directory. Only a matching typed
PtyNotFoundErrorcounts as already removed. Ordinary restart and concurrent-restart deduplication are preserved.Screenshots / Video
N/A: no visual changes.
How to Test
Manual/local verification
Agent-executed with Bun 1.3.14:
git diff --checkandbun run check-kilocode-changepassed.git diff --checkandbun run check-kilocode-changepassed.Reviewer test steps
From
packages/kilo-vscode:bun test tests/unit/agent-manager-terminal-manager.test.ts tests/unit/agent-manager-terminal-routing.test.ts tests/unit/terminal-architecture.test.ts tests/unit/script-terminal-manager.test.ts tests/unit/pty-cleanup.test.ts tests/unit/agent-manager-arch.test.tsThe regression suite holds create/resize responses until after close/dispose completes, then checks late cleanup. It also covers setup failure, repeated/deduplicated restart, terminal ID reuse, typed not-found responses and partial cleanup recovery.
Blocked checks and substitute verification
Dependencies were installed with the frozen lockfile. Typecheck, lint, format, Knip and the focused architecture/PTY suites all ran successfully. Live VS Code extension/backend verification remains pending.
Checklist