Repository navigation
Description
Tracked in #568. This proposal stands on its own and doesn't depend on the others tracked there.
Summary
Every automation run in AHP 1.0 creates a fresh session. Many valuable automations are long-lived instead: an agent that shepherds a pull request through CI failures, review comments, and merge, or a recurring "check on this" inside a conversation the user is already having. Hosts that route work into existing sessions today can't represent it over AHP.
This proposal lets a definition choose where each run's message goes: a new session (today's behavior), a specific existing chat, or the session the automation previously created for the same item, such as a pull request. Delivery reuses AHP's existing queued-message mechanics, and every message an automation delivers says which run delivered it.
Scenarios
- "Check on this every hour." In the middle of a conversation, a user asks for an hourly check on a deployment. Each run should arrive in that conversation, which already has the context.
- Pull request shepherd. One agent owns a pull request for its whole life. CI failures, review comments, and the final merge all go to the same session.
- Issue to pull request. The session that picks up an issue opens a pull request and keeps owning both, so review feedback returns to the session that wrote the code.
- Repository caretaker. One long-lived session receives every scheduled maintenance task for a repository.
AHP today
AutomationSessionTemplateis the "template from which the host creates a fresh session for each automation run," andAutomationDefinition.messageis the "initial message sent to every newly created run session."SessionMetadata.origin(AutomationSessionOrigin) records the single{ automation, run }that created a session.MessageOrigincarries onlykind.MessageKind.Automationis described as "emitted automatically when an automation run starts a session."- Runs already link ordinary sessions (
AutomationRunState.sessions,automationRun/sessionSet), and chats already hold input for later turns (ChatState.queuedMessages,chat/pendingMessageSet).
So a host can't say "this run went to that existing session," and a session that serves many runs can't say which turn belongs to which run.
Proposal
-
Delivery target.
AutomationDefinitiongains an optionaltarget:newSession(the default, and today's behavior): create a session fromdefinition.sessionfor each run.chat: deliver every run into one existing chat.correlated: deliver runs that share a correlation value, such as the same pull request, into the session this automation previously created for that value, and create one fromdefinition.sessionwhen there isn't one.
-
The template applies only to sessions the run creates. When it delivers into an existing chat, the host doesn't apply
definition.session: it doesn't change that session's provider, configuration, working directories, or customizations, and it doesn't install the automation's captured customizations there. A correlated session gets the full template, including captured customizations, when it's created. The message's ownmodelandagentfields still apply where the chat's agent supports them. -
Correlation keys are host-defined and discovered.
AutomationTriggerDefinitiongainscorrelationKeys: the keys its events can carry (for examplepullRequest,issue, orrepository), each with a title. Acorrelatedtarget lists key ids in priority order, and hosts validate them against discovery, just as they validate event ids. -
Resolving a correlated target. The host resolves the target for each run atomically:
- Correlation values are opaque strings that the host derives from the run's input. They're scoped to the automation and the key.
- The host uses the first listed key for which the input has a value. If none has a value, the run gets a new session with no correlation.
- Runs with the same key and value resolve to the same session. When the first runs for a value arrive at the same time, the host creates only one session.
- If the value's session is no longer usable (for example, it was removed or archived), the host creates a new session for the value, and later runs use the new one.
-
Delivery uses existing chat mechanics. When the host delivers a run (it may first hold the run as
pending, for example because of a host limit), it adds the run's message to the target chat as a queued pending message (chat/pendingMessageSetwith kindqueued). A run's message never steers an active turn. A busy chat starts it after the current turn, and an idle chat starts it right away, per the existing rule that hosts SHOULD consume a queued message immediately when the chat is idle. Forcorrelatedtargets, the target chat is the session'sdefaultChat. Clients can reorder or withdraw a run's queued message like any other; hosts MAY reject other edits to it. -
The run records the work it owns. Before it queues the message, the host links the target session to the run with the existing
automationRun/sessionSet, extending the existing rule that the host "records each session URI before sending its first message." The run also records each delivery: the chat, the id of the pending message it added, and, once the message is consumed, the id of the turn it started. Deliveries identify the run's own work in a session that may contain unrelated turns. Hosts can still link more sessions to a run for retries or parallel workers, as they can today. -
Run lifecycle when delivering into an existing chat.
- The run is
pendinguntil its message is delivered and while it waits in the queue. - It becomes
runningwhen a turn starts from its message (chat/turnStartedwith that pending message's id). As today, it staysrunningwhile that turn waits for input or confirmation. - With a single delivery, the run becomes
completed,failed, orcancelledwhen that turn completes, errors, or is cancelled. A host that retries or adds workers ends the run when the last of the run's work ends, as it can today. If the run's turn ends with a resumable error, the host may resume the turn itself (for example, to retry a transient failure), or keep the runrunningwhile a person can still resume it. The run fails once the host decides not to resume, or once the turn can no longer be resumed. - If the run's queued message is removed without a turn starting from it (for example, a user withdraws it), the run is
cancelled. Removal because a turn started from the message is consumption, not withdrawal. - Cancelling the run (
automationRun/cancelRequested) removes its queued message, or cancels its turn if the turn has started. It never affects other work in the session. - If the target chat no longer exists, or the automation may no longer drive it, the run fails with an
ErrorInfo.
For the common single-delivery run, this matches how a run with a single fresh session already behaves: its outcome is the outcome of the turn its message opens.
- The run is
-
Attribution on messages.
MessageOrigingains optional references to the automation and run that delivered the message. Hosts set them on messages that automations deliver, whether into a fresh session or an existing one. They're optional, so older messages and hosts can omit them.SessionMetadata.originkeeps its meaning: what created the session. The description ofMessageKind.Automationchanges to "delivered by an automation run." -
Run correlation. For
correlatedtargets, the run records the key id and value it was routed by, plus a display title, so run history can show "Run for pull request 123" and clients can find the session that handles a value. -
Manual override.
runAutomationaccepts an optionaltargetthat applies to that run only: a specific chat, a new session, or, for correlated automations, a specific correlation key and value ("run for pull request 123 in its session"). Clients learn values from earlier runs' correlation records. Retrying with the samerequestIdbut a differenttargetMUST be rejected. -
Authorization. An automation can deliver into a chat only if its principal may drive that chat. Hosts check this when the target is saved and again each time a run delivers.
-
Capability.
automations.targetslists the target kinds the host supports. Clients MUST NOT author other kinds.
Sketch
Names and shapes are illustrative. The implementation PR settles them.
interface AutomationDefinition {
// ...existing fields
/** Where each run's message is delivered. Omitted means a new session per run. */
target?: AutomationTarget;
}
/** @nonexhaustive */
const enum AutomationTargetKind {
NewSession = 'newSession',
Chat = 'chat',
Correlated = 'correlated',
}
type AutomationTarget =
| { kind: AutomationTargetKind.NewSession }
| { kind: AutomationTargetKind.Chat; chat: URI }
/** Correlation key ids from trigger discovery, in priority order. */
| { kind: AutomationTargetKind.Correlated; keys: string[] };
interface AutomationTriggerDefinition {
// ...existing fields
correlationKeys?: { id: string; title: string; description?: string }[];
}
interface AutomationRunState {
// ...existing fields
/** The correlation value this run was routed by. */
correlation?: { key: string; value: string; title?: string };
/** The run's own messages and turns. Upserted by id with a server-only Set action. */
deliveries?: AutomationRunDelivery[];
}
interface AutomationRunDelivery {
id: string;
chat: URI;
/** The queued PendingMessage the run added, when it went through the queue. */
pendingMessageId?: string;
/** The turn started from the run's message, once consumed. */
turnId?: string;
}
interface MessageOrigin {
kind: MessageKind;
/** Set only when kind is 'automation': the delivering automation and run. */
automation?: URI;
run?: URI;
}
interface RunAutomationParams {
// ...existing fields
/** Overrides definition.target for this run only. */
target?:
| { kind: AutomationTargetKind.NewSession }
| { kind: AutomationTargetKind.Chat; chat: URI }
| { kind: AutomationTargetKind.Correlated; key: string; value: string };
}
interface AutomationCapabilities {
// ...existing fields
targets?: { kinds: AutomationTargetKind[] };
}Why this shape
- Runs already link ordinary sessions. Session and chat channels stay authoritative for transcripts, tools, and confirmations. This proposal only changes which session a run links and how its message gets there.
- Queued messages already mean "wait for the active turn, then start." Reusing them makes delivery visible and controllable with existing UI. Users can see a run waiting in the queue and withdraw it.
- Attribution belongs on the message.
MessageOrigin.kindalready says an automation produced a message. A session's origin can describe only one creator, so it can't describe the many runs that a long-lived session serves. - Deliveries make ownership explicit. A long-lived session mixes a run's turn with other turns. Recording the pending message and turn a run owns lets lifecycle, cancellation, and navigation target exactly that work, without redefining what it means for a run to link a session.
- Correlation keys follow the event-trigger pattern. Their meaning is host-defined, their ids are stable, and they're discovered with
listAutomationTriggerDefinitions, so clients can offer "one session per pull request" without knowing any particular event source.
Compatibility
- Additive: an optional definition field, optional fields on trigger definitions, run state, and
MessageOrigin, and capability-gated authoring. Adding optional fields toMessageOriginis compatible on the Stable chat channel. - Clients that don't understand
targetstill render everything correctly. Runs link sessions as they do today, and messages still carrykind: automation. - Patches replace only the fields they name, so a client that doesn't know
targetwon't clear it when it edits other fields.
Out of scope
- How ownership of a correlation value moves between sessions (for example, when an issue's session opens a pull request and takes ownership of it). This is host-defined, and it's observable through each run's linked sessions and correlation.
- Routing different values to different chats within one shared session.
- Agent-to-agent coordination.
Open questions
- Should a fixed target be a chat (proposed, because chats can move between sessions) or a session that resolves to its
defaultChat? - For
correlated, should each value get its own session (proposed) or its own chat within one session? - What makes a correlated session "no longer usable"? Should users be able to release a value so that the next run starts fresh?
- Does
MessageOriginneed bothautomationandrun, or isrunenough now that runs record their deliveries? - Should deliveries also be recorded for runs that create fresh sessions, so every run links directly to its first turn?
Related proposals (none required)
- Run inputs (Proposal: Give automation runs their trigger context and manual input as data #569): input attachments travel with the queued message.
- Concurrency and coalescing (Proposal: Automation concurrency limits, overlap policy, and coalesced runs #573): overlap policies could apply per correlation value, and occurrences could be coalesced into a message that is still queued.
- Wait reasons and skipped occurrences (Proposal: Explain why an automation run is waiting or didn't happen #570): a run waiting behind a busy chat can report a
targetBusywait reason.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsNo status
Activity
connor4312 commentedon Nov 9, 2026
Why do you propose that the notion of 'correlation' and its keys be delivered to the client? Should those be equally well-served with just a toggle between hinting to the agent host whether an automation should use a new chat vs an existing chat and the notion of per-message origin details as described in #569 (comment)?
benvillalobos commentedon Nov 13, 2026
There's a want for this on the vscode team, but our use case is much simpler at the moment: Allow an automation reuse the same run (minimal metadata).
We have a PR (cc Federico Brancasi (@federicobrancasi)) that attempts to accomplish this, adding a single boolean. I think we can expand this to a simpler shape that can scale into the more complex case mentioned in this proposal. Thoughts?
Eventually we'd get:
connor4312 commentedon Nov 17, 2026
This is now implemented for general reuse signals, let me know if you have future needs around correlation.