You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sessions: let automation runs continue the same chat - #347867
Adds an opt-in option to Agent Host automations, Same Chat. When it's on, each run sends the automation's prompt in the chat of the automation's latest run instead of creating a new chat, so a recurring automation keeps its conversation. It's off by default.
In the automation dialog it's a switch next to Run in the Cloud, and hovering it explains what it does. Cloud runs can't continue a chat, so while Run in the Cloud is on, the switch is off and disabled with the reason "Not available in the cloud"; turning the cloud off brings back your choice. The configureAutomation tool takes the same option as continueSession.
Each run still gets its own run. The host links the previous run's session to the new run without a creation journal, so restart recovery never deletes it, gives the session the automation's current customizations as its vscode.automation active client (a restored session has none), and adds the run's message, with the template's model and agent, to the session's default chat as a queued pending message whose id is the run. The chat's normal queue starts a turn from it once the chat is idle, so it never interrupts the user's turn.
The run stays pending while its message waits, becomes running when a turn starts from it (queuedMessageId), and ends only with that turn; other turns in the session never end it. Withdrawing the message cancels the run; cancelling the run removes the message or cancels only its own turn; archiving or deleting the session before the turn starts fails the run. While a run waits, further due occurrences are skipped, as they would only queue the same prompt again.
Runs of one automation resolve their session one at a time, so overlapping runs share one session. After a restart, a waiting run queues its message again (queued messages live in memory).
A run creates a new session, which later runs continue, when the previous session is gone, archived, from another provider, or was created from other folders, persistent configuration (such as mode, approvals, sandbox, isolation and branch) or model presence than the current template. The host records that shape for each session it creates, in its own storage. Archiving or deleting the session starts over.
History shows a session shared by several runs once, for its newest run.
src/vs/sessions/AUTOMATIONS.md describes the new run lifecycle.
How to test
In the Agents window, create an automation with the Manual trigger and the prompt "Reply with just one number: the next number after the last number you said in this conversation. If you have not said a number yet, reply 1. Do not use any tools."
Edit it, turn on Same Chat, and save.
Run it twice. Both runs use one chat, and the replies are 1, then 2. History lists that chat once.
In that chat, send a message, and run the automation while the reply is still running. The run waits for your turn, then replies 3.
Click New Automation and turn on Run in the Cloud: Same Chat turns off and says "Not available in the cloud". Turn the cloud off again: Same Chat is back as you left it.
Validation
./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostAutomationService.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.ts --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts --run src/vs/sessions/contrib/providers/agentHost/test/browser/agentHostAutomationStore.test.ts --run src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts --run src/vs/sessions/contrib/automations/test/browser/automationDialog.test.ts --run src/vs/sessions/contrib/automations/test/browser/automationTools.test.ts --run src/vs/sessions/contrib/sessions/test/browser/automationsView.test.ts: 4269 passing. The new tests fail without the change.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Same Chat can retain the old model after its selection is cleared and unnecessarily restart conversations when template edits are compared against queue time rather than the session’s template revision.
Adds opt-in Same Chat support to Agent Host automations, allowing recurring runs to build on one conversation. The option defaults to off and is unavailable for cloud runs.
Changes:
Exposes the capability-gated option through the automation dialog, tool, and persisted metadata.
Adds session reuse with turn-aware waiting, cancellation, customization refresh, and fallback to a new session.
Deduplicates shared-chat history, preserves focus, and adds lifecycle tests and documentation.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Saved permission restrictions can leave shared Codex sessions running with full access, while slow Same Chat session creation can allow overlapping runs to create duplicate conversations.
If the first Same Chat session takes longer than one schedule interval to create, its run is already Running but has no primarySession and is absent from _continuedRuns. This predicate admits the next occurrence, which cannot find that session and creates a second conversation. Treat a running run with no linked primary session as covering the occurrence too.
The previously missed issue from the last Copilot review (agentHostAutomationService.ts, a run that is still creating its session) is fixed in 6ad96d9: a due occurrence of a Same Chat automation is now also skipped while one of its runs has no linked session yet, so slow session creation can't start a second conversation. Covered by a new test.
Syncs microsoft/agent-host-protocol to 1928cd4e, which adds AutomationDefinition.target (newSession, previousSession, chat) and the targets capability (microsoft/agent-host-protocol#604, #611).
Co-authored-by: Copilot <[email protected]>
Adds Same Chat, an opt-in for Agent Host automations that uses the AHP previousSession target. Each run queues its message in the previous run's session instead of creating a new one, and ends with the turn that starts from it.
Fixes#347866
Co-authored-by: Copilot <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and it follows the AHP automation target semantics: it only advertises and authors previousSession when supported, queues the run's message, ties the run lifecycle to the turn started from it, and resets with newSession.
One thing I'd consider changing. In _queueInPreviousSession, any error from prepareSessionMessage is logged at info and the run then creates a new session, which silently forks the conversation. That is right for deterministic cases (archived, no default chat, provider changed). It is less right for a transient failure such as a restore I/O error, where the run would start over even though the previous session is still usable. For those cases I'd fail the run (or retry) rather than fall back, or at least log a warning instead of info. Not blocking.
Only a session that can never take the run's message, such as an archived one, makes the run start over in a new session. A failure to check or restore the session now fails the run, so a transient error doesn't fork the conversation, and the next run tries the same session again.
Co-authored-by: Copilot <[email protected]>
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
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.
Fixes #347866
Demo
demo-automation-continue-session.mp4
Before
before-automation-continue-session.mp4
After
after-split-chat-mode.mp4
Adds an opt-in option to Agent Host automations, Same Chat. When it's on, each run sends the automation's prompt in the chat of the automation's latest run instead of creating a new chat, so a recurring automation keeps its conversation. It's off by default.
In the automation dialog it's a switch next to Run in the Cloud, and hovering it explains what it does. Cloud runs can't continue a chat, so while Run in the Cloud is on, the switch is off and disabled with the reason "Not available in the cloud"; turning the cloud off brings back your choice. The
configureAutomationtool takes the same option ascontinueSession.How it works (the code calls a chat a session)
target(automations: let runs continue the previous run's session agent-host-protocol#604 and types: remove an unused import and check unused locals like VS Code agent-host-protocol#611, synced here at1928cd4e): Same Chat istarget: { kind: 'previousSession' }, and the host advertises it ascapabilities.targets.previousSession. The dialog and the tool offer the option only when the host does. Turning it off sendsnewSession, since an omitted target keeps the host's. Nothing goes in_meta.vscode.automationactive client (a restored session has none), and adds the run's message, with the template's model and agent, to the session's default chat as a queued pending message whose id is the run. The chat's normal queue starts a turn from it once the chat is idle, so it never interrupts the user's turn.pendingwhile its message waits, becomesrunningwhen a turn starts from it (queuedMessageId), and ends only with that turn; other turns in the session never end it. Withdrawing the message cancels the run; cancelling the run removes the message or cancels only its own turn; archiving or deleting the session before the turn starts fails the run. While a run waits, further due occurrences are skipped, as they would only queue the same prompt again.src/vs/sessions/AUTOMATIONS.mddescribes the new run lifecycle.How to test
Validation
./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostAutomationService.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.ts --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts --run src/vs/sessions/contrib/providers/agentHost/test/browser/agentHostAutomationStore.test.ts --run src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts --run src/vs/sessions/contrib/automations/test/browser/automationDialog.test.ts --run src/vs/sessions/contrib/automations/test/browser/automationTools.test.ts --run src/vs/sessions/contrib/sessions/test/browser/automationsView.test.ts: 4269 passing. The new tests fail without the change.pnpm run typecheck-client: passed.pnpm run oxlinton the changed files: passed.pnpm run valid-layers-check: passed.