Skip to content

automations: let runs continue the previous run's session - #604

Merged
Connor Peet (connor4312) merged 5 commits into
mainfrom
fbrancasi/automation-run-target
Nov 16, 2026
Merged

Connor Peet (connor4312) merged 5 commits into
mainfrom
fbrancasi/automation-run-target

Conversation

@federicobrancasi

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

Copy link
Copy Markdown
Member

Adds an optional AutomationDefinition.target, so an automation's runs can continue the previous run's session instead of each creating a new one. This is the small first step proposed in #572: two target kinds now, leaving room for the chat and correlated targets from the full proposal later.

type AutomationTarget =
  | { kind: 'newSession' }       // default: each run creates a session
  | { kind: 'previousSession' }; // each run continues the previous run's session
  • AutomationDefinition.target and AutomationDefinitionPatch.target. A patch that omits it leaves it unchanged; newSession resets it.

  • AutomationCapabilities.targets: { kinds }, which must include newSession. Clients set only listed kinds, and hosts reject requests that set any other kind.

  • previousSession semantics, on AutomationPreviousSessionTarget and in the guide:

    • Runs resolve their session and start their turns in creation order, so concurrent runs can't split the conversation.
    • The previous session is the primarySession of the latest earlier run that has one, even if that run was pruned from history.
    • The run sends message in that session's default chat. If the session was removed or archived, or has no default chat, the run creates a session that later runs continue. The host may also start over when the session can't honor the current template.
    • Model and agent selections apply to the run's turn as in a created session; the template's other settings aren't reapplied.
    • While the chat runs another turn (a user's or another run's), the run stays pending. It's running from the start of its own turn and ends with that turn. Cancelling a run only affects its own turn.
  • AutomationTargetKind is @nonexhaustive and the variants are @preserveUnknownMembers, so clients relay kinds added later.

  • Text that assumed every run creates a session now also covers continued sessions:

    • AutomationDefinition.message and session, AutomationSessionTemplate, MessageKind.Automation;
    • AutomationSessionOrigin and the customization guarantees;
    • the guide and specification intros.

    Run lifecycle and usage now refer to the run's own work, since a continued session also holds other turns.

  • Added a "Run targets" section to the automations guide.

  • Regenerated the schema and all six clients, registering the new union in each generator. The Rust commands module also gets the AutomationTargetKind import it was missing.

  • The Go MultiHostClient deep-copies targets like the other capability fields, with a test.

  • Round-trip fixtures:

    • a catalogue snapshot with a previousSession target (094);
    • a reset patch keeping unknown variant members (095);
    • an unknown target kind preserved verbatim (096);
    • targets with an unknown kind added to the capability fixture (043), and target to the patch unknown-members fixture (093).

Part of #572; the full proposal stays open. microsoft/vscode#347867 stores this option in _meta today and will switch to target once this lands.

Compatibility

  • Additive and capability-gated. Older hosts don't advertise targets, so clients don't send target, and an omitted target keeps today's behavior. No protocol-version change.
  • target is declared after _meta, so Kotlin's existing constructor, copy and destructuring order is unchanged. Rust struct literals of AutomationDefinition, AutomationDefinitionPatch and AutomationCapabilities need target: None or targets: None (one test literal is updated here), and existing Kotlin data-class binaries must be rebuilt.

Validation

  • npm run generate: regenerated, no further changes.
  • npm test: passed (667 tests, 100% reducer branch coverage, plus the release, changelog, change-fragment and generated-output checks).
  • cd clients/typescript && npm ci && npm test: passed (79 tests).
  • cd clients/rust && cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace: passed (104 tests).
  • swift build && swift test: passed (104 tests).
  • cd clients/go && gofmt -l . && go vet ./... && go test ./...: passed. The new MultiHostClient test fails without the copy fix.
  • npx tsc -p clients/dotnet/tests/AgentHostProtocol.Tests/interop/tsconfig.json, then cd clients/dotnet && dotnet format whitespace --verify-no-changes --no-restore && dotnet build --no-restore --configuration Release && dotnet test (.NET 10 SDK): passed (696 tests).
  • cd clients/kotlin && ./gradlew build in eclipse-temurin:17-jdk: passed (531 tests).

Add an optional AutomationDefinition.target, its patch field, and the automations.targets capability. `newSession` (the default) keeps today's behavior; `previousSession` sends each run's message in the previous run's session, creating one when it isn't usable. Runs resolve their session and start their turns in creation order, and a run waiting for the chat stays pending until its own turn starts.

Update text that assumed every run creates a session, scope run lifecycle and usage to the run's own work, document run targets in the automations guide, regenerate the schema and clients, deep-copy the new capability in the Go MultiHostClient, and add round-trip fixtures.

Part of #572.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Adding target before _meta breaks Kotlin’s existing positional constructor/copy calls and changes destructuring semantics in both interfaces; append it after _meta and regenerate the clients.

1 open issue
What changed in this PR

Adds capability-gated automation targets so recurring runs can continue the previous run’s session instead of always creating a new one. This implements the initial scope of #572 while retaining new-session behavior by default.

Changes:

  • Adds target types, definition patches, and capability discovery, with documented ordering, fallback, and lifecycle semantics.
  • Updates generators, native client models, and JSON schemas.
  • Adds round-trip fixtures and Go capability-copy coverage.
File Description
types/​test-cases/​round-trips/​096-automation-target-unknown-kind-preserved.json Tests preservation of unknown target kinds.
types/​test-cases/​round-trips/​095-automation-reset-target-patch.json Tests target reset and unknown-member preservation.
types/​test-cases/​round-trips/​094-automation-previous-session-target-snapshot.json Tests previous-session targets in catalogue snapshots.
types/​test-cases/​round-trips/​093-automation-patch-unknown-members.json Extends unknown-member coverage to targets.
types/​test-cases/​round-trips/​043-automation-capabilities.json Covers advertised target kinds, including unknown values.
types/​common/​commands.ts Adds target capability discovery.
types/​channels-session/​state.ts Clarifies that continued sessions retain their original provenance.
types/​channels-chat/​state.ts Broadens the automation-message documentation.
types/​channels-automation/​state.ts Defines targets and session-continuation semantics.
types/​channels-automation/​actions.ts Adds target replacement to definition patches.
types/​channels-automation-run/​state.ts Clarifies run-specific lifecycle, usage, and session links.
scripts/​generate-swift.ts Registers Swift target models and capability types.
scripts/​generate-rust.ts Registers Rust target models and required imports.
scripts/​generate-kotlin.ts Registers Kotlin target models and capability types.
scripts/​generate-go.ts Registers Go target models and capability types.
scripts/​generate-csharp.ts Registers .NET target models and capability types.
schema/​state.schema.json Regenerates state schemas with targets.
schema/​notifications.schema.json Updates embedded automation state schemas.
schema/​errors.schema.json Updates embedded target and capability schemas.
schema/​commands.schema.json Adds target capabilities and related schemas.
schema/​actions.schema.json Adds target patches and related state schemas.
docs/​specification/​automation-run-channel.md Clarifies run-specific work and message reconciliation.
docs/​specification/​automation-channel.md Documents that automations can continue sessions.
docs/​guide/​automations.md Explains target selection and continuation behavior.
docs/​.changes/​20261113-automation-run-target.json Records the new protocol feature.
clients/​swift/​AgentHostProtocol/​Sources/​AgentHostProtocol/​Generated/​State.generated.swift Generates Swift target models and serialization.
clients/​swift/​AgentHostProtocol/​Sources/​AgentHostProtocol/​Generated/​Commands.generated.swift Generates Swift target capabilities.
clients/​rust/​crates/​ahp/​tests/​hosts.rs Updates the capability test literal.
clients/​rust/​crates/​ahp-types/​src/​state.rs Generates Rust target models and serialization.
clients/​rust/​crates/​ahp-types/​src/​commands.rs Generates Rust target capabilities and imports.
clients/​kotlin/​src/​main/​kotlin/​com/​microsoft/​agenthostprotocol/​generated/​State.generated.kt Generates Kotlin target models and serializers.
clients/​kotlin/​src/​main/​kotlin/​com/​microsoft/​agenthostprotocol/​generated/​Commands.generated.kt Generates Kotlin target capabilities.
clients/​go/​ahptypes/​state.generated.go Generates Go target models and serialization.
clients/​go/​ahptypes/​commands.generated.go Generates Go target capabilities.
clients/​go/​ahp/​hosts/​hosts.go Deep-copies target capabilities between host handles.
clients/​go/​ahp/​hosts/​hosts_test.go Tests target capability isolation between handles.
clients/​dotnet/​src/​AgentHostProtocol.Abstractions/​Generated/​State.generated.cs Generates .NET target models and converters.
clients/​dotnet/​src/​AgentHostProtocol.Abstractions/​Generated/​JsonSerializerContext.generated.cs Registers new types for generated serialization.
clients/​dotnet/​src/​AgentHostProtocol.Abstractions/​Generated/​Commands.generated.cs Generates .NET target capabilities.

Review effort: Balanced

Comment thread types/channels-automation/state.ts Resolved
Appending the new field keeps Kotlin's positional constructor, copy and destructuring order for AutomationDefinition and AutomationDefinitionPatch, as other fields added after _meta do.

Co-authored-by: Copilot <[email protected]>
Megan Rogge (meganrogge) added a commit that referenced this pull request Nov 13, 2026
Per review, keep only the oneTime trigger kind and its host capability. Drop purpose/provenance fields, existing-conversation targets (covered by #604), dispatch receipts, conditional updates, manual-run restrictions, and client/reconnect capabilities with their projection helpers. One-time triggers reuse misfirePolicy for missed times.

Co-authored-by: Copilot <[email protected]>
@meganrogge

Copy link
Copy Markdown
Contributor

Following up from #603: one gap I see for VS Code's "Send Later" is scheduling a message into a chat the user already has open. previousSession continues the previous run's session, but a one-time automation only has one run, so it would start a new session. I think we'd need the chat target from #572 for this. Is that planned as a follow-up? Until then, VS Code will keep the target chat in _meta.

@jackfreemanceo-dotcom

This comment was marked as spam.

- Replace `AutomationCapabilities.targets.kinds` with
  `targets.previousSession?: {}` (`AutomationTargetsCapabilities` and
  `AutomationPreviousSessionTargetCapability`). `newSession` is always
  supported; clients SHOULD NOT author `previousSession` without the marker.
- Spell out `previousSession` delivery: the run links the session, then adds
  its message to the default chat as a queued pending message. Withdrawing
  that message cancels the run, and a session that becomes unusable first
  has its queued message removed before the run fails. A session the
  automation may no longer drive is never usable.
- The template's model and agent still apply to a continued run's message.
- Align revalidation and security wording in the guide and specification.
- Update the Go capability clone and its test, the Rust test literal, the
  capability round-trip fixture, and regenerate all clients.

Co-authored-by: Copilot <[email protected]>
Add `{ kind: 'chat', session, chat }` (`AutomationChatTarget`), gated by
`AutomationCapabilities.targets.chat` (`AutomationChatTargetCapability`).
Each run sends its message to one existing chat as a queued pending message
and never creates a session.

- The host rejects a chat that doesn't exist or that the automation may not
  drive, sets `session` to the chat's current owner on every accepted create
  or update, and republishes the definition when the chat moves.
- Delivery and run lifecycle match a reused `previousSession` run. Only the
  template's model and agent apply; the session's provider, configuration,
  working directories, and customizations are untouched.
- If the chat is gone or may no longer be driven, the run fails, after
  removing its queued message.
- Register the new types in every generator, copy `targets.chat` in the Go
  capability clone, extend fixture 043, and add fixture 097.

Co-authored-by: Copilot <[email protected]>
Resolve generator capability-list conflicts with the one-time trigger work (#603), renumber the chat target fixture to 099, and regenerate.

Co-authored-by: Copilot <[email protected]>
@connor4312
Connor Peet (connor4312) merged commit 54b1f53 into main Nov 16, 2026
9 checks passed
@connor4312
Connor Peet (connor4312) deleted the fbrancasi/automation-run-target branch November 16, 2026 16:32
Federico Brancasi (federicobrancasi) added a commit to microsoft/vscode that referenced this pull request Nov 18, 2026
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]>
Wing K.Y (wingwkyuen) pushed a commit to tcgoidc/vscode that referenced this pull request Nov 18, 2026
* agent host: sync AHP automation run targets

Syncs microsoft/agent-host-protocol to 1928cd4e, which adds AutomationDefinition.target (newSession, previousSession, chat) and the targets capability (microsoft/agent-host-protocol#604, microsoft#611).

Co-authored-by: Copilot <[email protected]>

* Automations: option to continue the same chat

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 microsoft#347866

Co-authored-by: Copilot <[email protected]>

* Automations: expect the previousSession target in the E2E capabilities

Co-authored-by: Copilot <[email protected]>

* Automations: fail a run whose previous session can't be restored

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

---------

Co-authored-by: Copilot <[email protected]>
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.

6 participants