Skip to content

agentHost: use proper sdk-provided forking/truncation methods#309669

Merged
connor4312 merged 2 commits intomainfrom
connor4312/proper-forking
Apr 14, 2026
Merged

agentHost: use proper sdk-provided forking/truncation methods#309669
connor4312 merged 2 commits intomainfrom
connor4312/proper-forking

Conversation

@connor4312
Copy link
Copy Markdown
Member

Also adds logic to migrate our metadata DB, which we weren't doing before.

Also adds logic to migrate our metadata DB, which we weren't doing before.
Copilot AI review requested due to automatic review settings April 13, 2026 23:25
@connor4312 connor4312 self-assigned this Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Screenshot Changes

Base: 11018d92 Current: 01bddc8e

Changed (17)

editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after
agentSessionsViewer/CompletedRead/Dark
Before After
before after
agentSessionsViewer/CompletedRead/Light
Before After
before after
agentSessionsViewer/FailedWithoutDuration/Dark
Before After
before after
agentSessionsViewer/FailedWithoutDuration/Light
Before After
before after
agentSessionsViewer/WithFileChangesList/Dark
Before After
before after
agentSessionsViewer/WithFileChangesList/Light
Before After
before after
agentSessionsViewer/WithBadge/Dark
Before After
before after
agentSessionsViewer/WithBadge/Light
Before After
before after
agentSessionsViewer/WithMarkdownBadge/Dark
Before After
before after
agentSessionsViewer/WithMarkdownBadge/Light
Before After
before after
agentSessionsViewer/WithBadgeAndDiff/Dark
Before After
before after
agentSessionsViewer/WithBadgeAndDiff/Light
Before After
before after
agentSessionsViewer/BackgroundProvider/Dark
Before After
before after
agentSessionsViewer/BackgroundProvider/Light
Before After
before after
agentSessionsViewer/ClaudeProvider/Dark
Before After
before after
agentSessionsViewer/ClaudeProvider/Light
Before After
before after

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 turnId through the forking/truncation flow (protocol → agent service → provider) and remove the legacy forkSession provider API.
  • Add turns.event_id tracking (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 turnIdturnIndex 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 onUserMessage handler calls the async setTurnEventId() 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 existing SessionDatabase unit 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

@connor4312 connor4312 marked this pull request as ready for review April 14, 2026 01:56
@connor4312 connor4312 enabled auto-merge April 14, 2026 01:57
@connor4312 connor4312 merged commit d527b0f into main Apr 14, 2026
26 checks passed
@connor4312 connor4312 deleted the connor4312/proper-forking branch April 14, 2026 02:17
@vs-code-engineering vs-code-engineering bot added this to the 1.117.0 milestone Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants