Skip to content

sessions: let automation runs continue the same chat - #347867

Merged
Federico Brancasi (federicobrancasi) merged 4 commits into
mainfrom
fbrancasi/automation-continue-session
Nov 18, 2026
Merged

Federico Brancasi (federicobrancasi) merged 4 commits into
mainfrom
fbrancasi/automation-continue-session

Conversation

@federicobrancasi

@federicobrancasi Federico Brancasi (federicobrancasi) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

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 configureAutomation tool takes the same option as continueSession.

How it works (the code calls a chat a session)

  • Uses the Agent Host Protocol's new automation 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 at 1928cd4e): Same Chat is target: { kind: 'previousSession' }, and the host advertises it as capabilities.targets.previousSession. The dialog and the tool offer the option only when the host does. Turning it off sends newSession, since an omitted target keeps the host's. Nothing goes in _meta.
  • 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

  1. 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."
  2. Edit it, turn on Same Chat, and save.
  3. Run it twice. Both runs use one chat, and the replies are 1, then 2. History lists that chat once.
  4. 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.
  5. 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.
  • pnpm run typecheck-client: passed.
  • pnpm run oxlint on the changed files: passed.
  • pnpm run valid-layers-check: passed.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 11:44
@vs-code-engineering

vs-code-engineering Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ulugbek Abdullaev (@ulugbekna)

Matched files:

  • src/vs/platform/agentHost/common/meta/agentHostAutomationsMeta.ts
  • src/vs/platform/agentHost/common/meta/vscode/agentHostAutomationsMeta.ts
  • src/vs/platform/agentHost/node/agentHostAutomationService.ts
  • src/vs/platform/agentHost/test/node/agentHostAutomationService.test.ts
  • src/vs/workbench/contrib/chat/common/automations/automation.ts
  • src/vs/workbench/contrib/chat/common/automations/automationService.ts

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Base: 5044e600 Current: a1b4f5e0

No screenshot changes.

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.

🟡 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.

2 open issues
What changed in this PR

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.
File Description
src/​vs/​workbench/​contrib/​sessions/​providers/​agentHost/​browser/​reconnectableAgentHostAutomationStore.ts Forwards continuation capability checks.
src/​vs/​workbench/​contrib/​sessions/​providers/​agentHost/​browser/​agentHostAutomationStore.ts Persists and projects the continuation option.
src/​vs/​workbench/​contrib/​chat/​common/​automations/​automationService.ts Extends automation options and store contracts.
src/​vs/​workbench/​contrib/​chat/​common/​automations/​automation.ts Adds the descriptor’s continuation flag.
src/​vs/​sessions/​contrib/​sessions/​test/​browser/​automationsView.test.ts Tests history deduplication and focus preservation.
src/​vs/​sessions/​contrib/​sessions/​browser/​views/​automationsView.ts Shows shared sessions once and restores focus.
src/​vs/​sessions/​contrib/​providers/​agentHost/​test/​browser/​agentHostAutomationStore.test.ts Tests capability detection and metadata round trips.
src/​vs/​sessions/​contrib/​automations/​test/​browser/​automationDialog.test.ts Tests Same Chat controls and cloud restrictions.
src/​vs/​sessions/​contrib/​automations/​browser/​providerAutomationService.ts Routes capability checks to provider stores.
src/​vs/​sessions/​contrib/​automations/​browser/​media/​automationDialog.css Styles the shared run-options row.
src/​vs/​sessions/​contrib/​automations/​browser/​automationTools.ts Adds and validates continueSession tool input.
src/​vs/​sessions/​contrib/​automations/​browser/​automationDialogService.ts Loads and saves the dialog’s continuation choice.
src/​vs/​sessions/​contrib/​automations/​browser/​automationDialog.ts Adds the Same Chat switch and disabled-cloud state.
src/​vs/​sessions/​AUTOMATIONS.md Documents the continued-session lifecycle.
src/​vs/​platform/​agentHost/​test/​node/​protocolServerHandler.test.ts Verifies capability advertisement.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests customization refresh and archived-session rejection.
src/​vs/​platform/​agentHost/​test/​node/​agentHostAutomationService.test.ts Covers continuation, waiting, cancellation, and persistence races.
src/​vs/​platform/​agentHost/​node/​agentService.ts Implements session eligibility and continued-turn execution.
src/​vs/​platform/​agentHost/​node/​agentHostAutomationService.ts Coordinates session reuse and run-specific lifecycle tracking.
src/​vs/​platform/​agentHost/​common/​meta/​vscode/​agentHostAutomationsMeta.ts Defines continuation flags and run-message metadata helpers.
src/​vs/​platform/​agentHost/​common/​meta/​agentHostAutomationsMeta.ts Exports the new metadata helpers.
src/​vs/​platform/​agentHost/​common/​agentHostExtensionProtocol.ts Advertises continuation support in initialization metadata.

Review effort: Balanced

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.

🟡 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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent duplicate sessions while the first run is still starting

src/​vs/​platform/​agentHost/​node/​agentHostAutomationService.ts:949

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.

2 resolved since last review

Review effort: Balanced

@federicobrancasi

Copy link
Copy Markdown
Member Author

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.

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.

🟢 Approval recommended

No active review issues are recorded for the opt-in Same Chat changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@benvillalobos

Copy link
Copy Markdown
Member

Ref for AHP proposal for this: #347867

@benvillalobos

Copy link
Copy Markdown
Member

Context from chatting with Connor Peet (@connor4312): We should add this to AHP first to avoid using _meta for the extra automationContinueSession field. Some discussion happening here: microsoft/agent-host-protocol#572

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]>
@federicobrancasi

Federico Brancasi (federicobrancasi) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

Ben Villalobos (@benvillalobos) Connor Peet (@connor4312) Martin Aeschlimann (@aeschli) reworked this on top of the new AHP automation target, as discussed:

Could you take another look? Thanks!

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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]>
@federicobrancasi

Copy link
Copy Markdown
Member Author

Connor Peet (@connor4312) Good catch, thanks! Changed it in cd2fb70

Merged via the queue into main with commit bfbaab8 Nov 18, 2026
37 checks passed
@federicobrancasi
Federico Brancasi (federicobrancasi) deleted the fbrancasi/automation-continue-session branch November 18, 2026 18:56
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.

Agents window: let an automation's runs continue the same chat

5 participants