Skip to main content

Module interrupt

Module interrupt 

Source
Expand description

How an interrupted turn is recorded in conversation history.

When a turn is cancelled, the engine publishes the REAL partial history — the assistant’s partial message (text / signed thinking / completed tool calls), every completed tool round, and a canceled tool_result for any call that did not finish. The frontend adopts that history verbatim and then appends ONE short, factual user message: the interruption marker.

This replaces the old “ABORT CONTEXT” recap, which re-described the model’s own reasoning and tool calls as text inside the NEXT user message. A user turn that impersonates the model’s output reads as a prompt injection, and current models refuse it. The marker carries no instructions and claims nothing about what the model did — the history already says that, in the provider’s own message format.

Prompt caching: the marker is only ever APPENDED after the adopted history, never folded into or edited onto an existing message, so every byte the provider already cached stays identical.

Enums§

InterruptReason
Why a turn was interrupted. Selects the marker text only.

Functions§

append_marker
Append the marker for reason unless the history already ends with a marker (a second interruption with no turn in between records nothing new). Returns whether a message was appended.
interruption_label
"[Request interrupted by user]" → "Request interrupted by user", for display. None for anything that is not a marker.
is_interruption_marker
True iff text is EXACTLY one of the interruption markers. Clients use this to render the marker as an “interrupted” line instead of a user bubble (the daemon’s DisplayItem has no dedicated variant: adding one would break older clients, whose DisplayItem has no #[serde(other)]). Exact, not a prefix: a user message that merely starts like a marker is the user’s, and is shown (and deduplicated) as such.
migrate_legacy_abort_context
Load-time migration for sessions saved before this change. A non-None abort_context means the saved history ends at the interrupted turn and the recap was waiting to be prepended to the next user message. The recap is DISCARDED (it is exactly the injection-shaped text this module replaces) and the marker is appended in its place.
recover_crashed_turn
Fold an in-flight turn draft left by a process that died mid-turn (agent_core::core::session_draft) into the loaded history.