Repository navigation
automations: let runs continue the previous run's session - #604
Conversation
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]>
There was a problem hiding this comment.
🟡 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
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]>
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]>
|
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. |
This comment was marked as spam.
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]>
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]>
* 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]>

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 thechatandcorrelatedtargets from the full proposal later.AutomationDefinition.targetandAutomationDefinitionPatch.target. A patch that omits it leaves it unchanged;newSessionresets it.AutomationCapabilities.targets: { kinds }, which must includenewSession. Clients set only listed kinds, and hosts reject requests that set any other kind.previousSessionsemantics, onAutomationPreviousSessionTargetand in the guide:primarySessionof the latest earlier run that has one, even if that run was pruned from history.messagein 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.pending. It'srunningfrom the start of its own turn and ends with that turn. Cancelling a run only affects its own turn.AutomationTargetKindis@nonexhaustiveand the variants are@preserveUnknownMembers, so clients relay kinds added later.Text that assumed every run creates a session now also covers continued sessions:
AutomationDefinition.messageandsession,AutomationSessionTemplate,MessageKind.Automation;AutomationSessionOriginand the customization guarantees;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
AutomationTargetKindimport it was missing.The Go
MultiHostClientdeep-copiestargetslike the other capability fields, with a test.Round-trip fixtures:
previousSessiontarget (094);targetswith an unknown kind added to the capability fixture (043), andtargetto the patch unknown-members fixture (093).Part of #572; the full proposal stays open. microsoft/vscode#347867 stores this option in
_metatoday and will switch totargetonce this lands.Compatibility
targets, so clients don't sendtarget, and an omittedtargetkeeps today's behavior. No protocol-version change.targetis declared after_meta, so Kotlin's existing constructor,copyand destructuring order is unchanged. Rust struct literals ofAutomationDefinition,AutomationDefinitionPatchandAutomationCapabilitiesneedtarget: Noneortargets: 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 newMultiHostClienttest fails without the copy fix.npx tsc -p clients/dotnet/tests/AgentHostProtocol.Tests/interop/tsconfig.json, thencd 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 buildineclipse-temurin:17-jdk: passed (531 tests).