agentHost: use proper sdk-provided forking/truncation methods#309669
Merged
connor4312 merged 2 commits intomainfrom Apr 14, 2026
Merged
agentHost: use proper sdk-provided forking/truncation methods#309669connor4312 merged 2 commits intomainfrom
connor4312 merged 2 commits intomainfrom
Conversation
Also adds logic to migrate our metadata DB, which we weren't doing before.
Contributor
Screenshot ChangesBase: Changed (17) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Agent Host session forking/truncation to use Copilot SDK RPCs instead of manipulating Copilot CLI on-disk session data, and extends the per-session SQLite DB to track SDK event IDs needed for those RPCs.
Changes:
- Pass
turnIdthrough the forking/truncation flow (protocol → agent service → provider) and remove the legacyforkSessionprovider API. - Add
turns.event_idtracking (with DB migration) plus helper APIs to look up truncation/fork boundaries and remap turn IDs after forking. - Switch Copilot provider implementation to
sessions.fork/history.truncate, copying/remapping the session DB for forked sessions.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts | Include turnId when requesting a forked session. |
| src/vs/platform/agentHost/test/node/mockAgent.ts | Update mock agent truncation signature; remove legacy forking hook. |
| src/vs/platform/agentHost/test/node/copilotAgentForking.test.ts | Remove tests for the deleted legacy on-disk forking/truncation implementation. |
| src/vs/platform/agentHost/test/common/sessionTestHelpers.ts | Extend test DB stub to satisfy new ISessionDatabase API surface. |
| src/vs/platform/agentHost/node/sessionDatabase.ts | Add event_id migration and new turn/event-id + truncation/remap helpers. |
| src/vs/platform/agentHost/node/sessionDataService.ts | Use shared SESSION_DB_FILENAME constant. |
| src/vs/platform/agentHost/node/protocolServerHandler.ts | Resolve fork turnId → turnIndex and pass both to the service layer. |
| src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts | Capture SDK user.message event IDs and expose helper methods for truncation/forking. |
| src/vs/platform/agentHost/node/copilot/copilotAgentForking.ts | Delete legacy filesystem/DB forking & truncation logic. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Use SDK fork/truncate RPCs; copy/remap per-session DB for forked sessions. |
| src/vs/platform/agentHost/node/agentSideEffects.ts | Call provider truncation using turnId instead of turnIndex. |
| src/vs/platform/agentHost/node/agentService.ts | Generate a turnId remapping map for forks and seed forked session state accordingly. |
| src/vs/platform/agentHost/common/sessionDataService.ts | Add SESSION_DB_FILENAME and expand ISessionDatabase with turn/event-id/truncation/remap APIs. |
| src/vs/platform/agentHost/common/agentService.ts | Update fork/truncation types to use turnId and remove legacy forking API. |
Copilot's findings
Comments suppressed due to low confidence (2)
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts:456
- The
onUserMessagehandler calls the asyncsetTurnEventId()without awaiting or handling errors. Please ensure the returned promise is handled (e.g.void ... .catch(...)) to avoid unhandled promise rejections from event callbacks.
this._register(wrapper.onUserMessage(e => {
if (this._turnId) {
this._databaseRef.object.setTurnEventId(this._turnId, e.id);
}
}));
src/vs/platform/agentHost/node/sessionDatabase.ts:290
- New turn/event-id and truncation support in
SessionDatabase(event_id migration + getNext/getFirst/deleteTurnsAfter/deleteAllTurns/remapTurnIds) is not covered by the existingSessionDatabaseunit tests. Adding focused tests would help catch regressions around event-id ordering, deletion boundaries, and ID remapping after forks.
async getFirstTurnEventId(): Promise<string | undefined> {
const db = await this._ensureDb();
const row = await dbGet(db, 'SELECT event_id FROM turns ORDER BY rowid LIMIT 1', []);
return row?.event_id as string | undefined ?? undefined;
}
- Files reviewed: 14/14 changed files
- Comments generated: 3
roblourens
approved these changes
Apr 14, 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.
Also adds logic to migrate our metadata DB, which we weren't doing before.