agentHost: implement Claude truncateSession (Phase 6.7 — Restore Checkpoint + Start Over)#323197
Merged
Merged
Conversation
…kpoint + Start Over) Implements IAgent.truncateSession for the Claude agent host so the workbench "Restore Checkpoint" and "Start Over" actions work end-to-end: - Point-restore (turnId): truncates the conversation in place on the same SDK session id / protocol URI via the SDK's `resumeSessionAt` option. The protocol turn is resolved to its SDK assistant-envelope uuid and staged as a one-shot anchor the next turn's rebuild applies (lazy — full history is preserved if the user restores then walks away). - Remove-all (no turnId, "Start Over"): tears down the live subprocess, deletes the on-disk transcript, and recreates a fresh provisional under the same id, preserving the model/agent/permissionMode overlay. Teardown awaits the subprocess's actual exit (Query.return() -> the SDK's memoized cleanup -> transport.waitForExit()) before deleting + respawning the same `--session-id`, fixing a "Session ID ... is already in use" race. Also fixes a pre-existing rebind consumer-loop handoff race surfaced by truncation (post-restore turn could hang), and simplifies the pipeline's query handles (single `_query` mirroring the warm subprocess; `_needsRebind` as the sole health signal). Unit + integration green (427 Claude tests); both flows live-E2E verified against real Claude. See node/claude/phase6.7-plan.md for the implementation log and node/claude/roadmap.md (Phase 6.7) marked done. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Implements IAgent.truncateSession for the Claude agent host so the workbench’s Restore Checkpoint (point restore) and Start Over (remove-all) actions work end-to-end for Claude-backed sessions, aligning Claude with Copilot’s existing truncate behavior while preserving the same protocol session URI.
Changes:
- Plumbs
resumeSessionAtthrough Claude SDK options and stages a one-shot truncation anchor onClaudeAgentSessionto apply on the next rebuild. - Adds a
deleteSessionSDK binding and implements remove-all truncation by tearing down the live subprocess, deleting the transcript, and recreating a fresh session under the same id/URI. - Hardens the Claude SDK pipeline lifecycle (deterministic teardown + consumer-loop rebind handoff) and adds extensive regression tests + roadmap/plan documentation.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/claude/claudeAgent.ts | Implements truncateSession (turnId restore + remove-all) and same-id recreation flow. |
| src/vs/platform/agentHost/node/claude/claudeAgentSdkService.ts | Adds deleteSession to the Claude SDK service surface and passthrough bindings. |
| src/vs/platform/agentHost/node/claude/claudeAgentSession.ts | Adds pending resumeSessionAt anchor + DB pruning helpers and forces rebind when anchor is staged. |
| src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts | Adds resumeSessionAt to buildOptions projection (resume-only). |
| src/vs/platform/agentHost/node/claude/claudeSdkPipeline.ts | Adds deterministic shutdownAndWait, separates _needsRebind health, and fixes consumer-loop handoff across rebind. |
| src/vs/platform/agentHost/test/node/claudeAgent.test.ts | Adds truncation test coverage (warm/cold restore, remove-all, teardown ordering, one-shot anchor). |
| src/vs/platform/agentHost/test/node/claudeAgent.integrationTest.ts | Updates integration fake to include deleteSession stub. |
| src/vs/platform/agentHost/test/node/claudeSdkOptions.test.ts | Adds tests validating resumeSessionAt option projection behavior. |
| src/vs/platform/agentHost/test/node/claudeSdkPipeline.test.ts | Adds regression tests for rebind handoff and post-abort steering buffering. |
| src/vs/platform/agentHost/test/node/claudeSubagentResolver.test.ts | Updates SDK fake to include deleteSession stub. |
| src/vs/platform/agentHost/test/common/sessionTestHelpers.ts | Makes TestSessionDatabase record pruning calls for assertions. |
| src/vs/platform/agentHost/node/claude/roadmap.md | Documents Phase 6.7 completion and supersedes earlier “no truncateSession” rationale. |
| src/vs/platform/agentHost/node/claude/phase6.7-plan.md | Adds the Phase 6.7 implementation plan/retrospective documentation. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 4
- Review effort level: Low
- claudeAgentSession: retain the pending truncation anchor until a rebuild succeeds (read it without clearing, clear only after materialize / rebuild installs the pipeline). A throw/cancel after reading no longer silently drops `resumeSessionAt`, so the next send retries the checkpoint restore. + regression test. - claudeSdkPipeline: `_ensureQueryBound` now honors `_needsRebind` (rebuilds via the rematerializer like `send()` does) so pre-flight helpers (reloadPlugins / snapshotResolvedCustomizations) never operate on a dead stream after an abort/crash. - claudeAgent: cold remove-all fails fast when no working directory is available (SDK cwd absent and no live session), mirroring `_resumeSession` and the fork path, instead of recreating a provisional that fails later. - claudeSdkPipeline: pass the error object to the logger in shutdownAndWait instead of stringifying it, preserving stack traces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dmitrivMS
approved these changes
Jun 26, 2026
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.
What
Implements
IAgent.truncateSessionfor the Claude agent host, so the workbench's Restore Checkpoint and Start Over actions work end-to-end for Claude sessions (previously a no-op — only Copilot supported it).This is Phase 6.7 of the Claude agent-host roadmap. Full implementation log:
src/vs/platform/agentHost/node/claude/phase6.7-plan.md; roadmap entry marked done insrc/vs/platform/agentHost/node/claude/roadmap.md.How
Two flows, both keeping the same SDK session id / protocol URI (unlike fork, which mints a new id):
turnId) — truncates the conversation in place via the SDK'sresumeSessionAtoption. The protocol turn is resolved to its SDK assistant-envelope uuid (reusing Phase 6.5'sresolveForkAnchorUuid) and staged as a one-shot anchor the next turn's rebuild applies. The write is lazy: if the user restores then walks away without sending, the full pre-restore history is preserved.turnId) — tears down the live subprocess, deletes the on-disk transcript, and recreates a fresh provisional under the same id, preserving the model/agent/permissionMode overlay.Notable sub-fixes
Query.return()→ the SDK's memoizedcleanup()→transport.waitForExit()) before deleting + respawning the same--session-id. Without this, the dying process re-flushed<id>.jsonland the respawn failed withSession ID … is already in use._warm(subprocess),_query(the stream bound to it, lifetime mirrors_warm), and_needsRebindas the sole health signal.Testing
resumeSessionAtprojection, warm + cold point-restore, warm + cold remove-all, teardown ordering, the rebind handoff, and the post-abort steering guard).already in use/stream ended/exit-1/crashederrors across an 8-turn session.🤖 Generated with Copilot CLI