Enhance session customization handling and simplify sync logic#317700
Enhance session customization handling and simplify sync logic#317700DonJayamanne wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves how agent-host session customizations are surfaced and synchronized so that custom agents/customizations are available immediately when a session is created or restored (not only after the first message), and refactors parts of the sync flow to be clearer and more deterministic.
Changes:
- Claim the active client earlier on session restore so the host can sync this client’s customizations into session state immediately.
- Forward
SessionStatesnapshots for “NewSession” into the provider’s cached state so the agent picker can see custom agents before the first message. - Ensure Copilot session customizations are read from a “settled” view (wait for initial discovery/sync), and publish initial customizations right after
createSession.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts | Updates tests to reflect the new “active client claimed on restore” behavior. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts | Claims active client during session restore to unblock customization-derived agents on open. |
| src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts | Adds coverage ensuring NewSession state forwarding populates picker custom agents pre-send and cleans up on dispose. |
| src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts | Implements NewSession state forwarding into _lastSessionStates + cleanup sentinel; avoids duplicate writers on graduation. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Adds “settled” customization snapshotting to avoid empty results during initial discovery/sync. |
| src/vs/platform/agentHost/node/agentService.ts | Publishes initial session customizations after state creation so subscribers see custom agents immediately. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 1
Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
| // is dropped as "Action for unknown session". | ||
| if (provider.getSessionCustomizations) { | ||
| void provider.getSessionCustomizations(session).then(customizations => { | ||
| if (customizations.length === 0) { | ||
| return; | ||
| } | ||
| const sessionKey = session.toString(); | ||
| if (!this._stateManager.getSessionState(sessionKey)) { | ||
| return; | ||
| } | ||
| this._stateManager.dispatchServerAction(sessionKey, { | ||
| type: ActionType.SessionCustomizationsChanged, | ||
| customizations: [...customizations], | ||
| }); | ||
| }).catch(err => { | ||
| this._logService.error('[AgentService] createSession: failed to publish initial customizations', err); | ||
| }); | ||
| } |
There was a problem hiding this comment.
I don't think this is the right approach here. I would expect that after this._stateManager.createSession, we update the resulting session with the instantaneous, current state of any customizations we have. And then after that point any further syncing state updates can happen via the existing ActionType.SessionCustomizationsChanged/ActionType.SessionCustomizationUpdated publishing from the PluginController
Improve session customization management and state synchronization across agents. This update ensures that customizations are immediately available upon session creation, enhancing user experience. Additionally, refactor the synchronization logic for better clarity and efficiency.