Skip to content

Fix agent host worktree metadata timing#324280

Merged
roblourens merged 1 commit into
mainfrom
agents/worktree-info-delay-fix
Jul 4, 2026
Merged

Fix agent host worktree metadata timing#324280
roblourens merged 1 commit into
mainfrom
agents/worktree-info-delay-fix

Conversation

@roblourens

@roblourens roblourens commented Jul 4, 2026

Copy link
Copy Markdown
Member

Fix #322529

Summary

  • update cached Agent Host session adapters when materialization publishes the final worktree
  • defer Git-state refreshes until a session leaves the creating lifecycle
  • overlay live workspace metadata on session-list snapshots and persist remote adapter updates
  • notify session-list consumers when Git metadata changes

Validation

  • npm run typecheck-client
  • focused and complete AgentService/Git-state/local-provider/remote-provider unit suites (303 passing, 28 pending)
  • npm run valid-layers-check
  • hygiene checks
  • isolated Agents window validation: final worktree path in SessionAdded, corrected branch metadata 185ms later and before turn completion

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 4, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a timing problem where Agent Host sessions surfaced stale worktree/branch metadata during session creation and materialization. When a session is created, its provisional working directory is the selected checkout, not the final isolated worktree; the metadata (project, working directory, Git branch) only becomes authoritative once materialization completes. The changes ensure the cached session adapters and the session-list snapshot reflect the final materialized state, and that Git-state refreshes don't run against the transient checkout.

Changes:

  • Treat notify/sessionAdded as an authoritative upsert: update an already-cached adapter in place (via a new updateAdapter hook) and report it as changed, instead of ignoring duplicates.
  • Defer refreshSessionGitState while a session's lifecycle is Creating, and overlay live workspace metadata (modifiedTime, project, workingDirectory) onto listSessions snapshots.
  • Persist remote adapter updates and fire onDidChangeSessions when session _meta (Git state) changes.
Show a summary per file
File Description
src/vs/platform/agentHost/node/agentHostGitStateService.ts Skips Git-state refresh while the session is in the Creating lifecycle.
src/vs/platform/agentHost/node/agentService.ts Overlays live modifiedTime/project/workingDirectory from the state manager summary onto list snapshots.
src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts Makes sessionAdded an upsert, adds the updateAdapter hook, and fires change events on meta changes.
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts Overrides updateAdapter to refresh the persisted metadata cache and mark it dirty.
src/vs/platform/agentHost/test/node/agentHostGitStateService.test.ts Adds coverage for deferring Git state while creating.
src/vs/platform/agentHost/test/node/agentService.test.ts Adds coverage for overlaying live metadata over a stale snapshot.
src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts Adds in-place upsert and Git-meta notification tests; renames the dedup test.
src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts Adds a persistence test for materialized workspace metadata.
src/vs/sessions/SESSIONS.md / AGENT_HOST_SESSIONS_PROVIDER.md Document the authoritative-upsert and deferred Git-state behavior.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 0
  • Review effort level: Medium

@roblourens
roblourens marked this pull request as ready for review July 4, 2026 03:12
@roblourens
roblourens enabled auto-merge (squash) July 4, 2026 03:12
@roblourens
roblourens merged commit 6759ccd into main Jul 4, 2026
30 checks passed
@roblourens
roblourens deleted the agents/worktree-info-delay-fix branch July 4, 2026 06:19
@vs-code-engineering vs-code-engineering Bot added this to the 1.128.0 milestone Jul 4, 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.

Worktree information is getting updated only after first turn

3 participants