Skip to content

Persist interrupted assistant output as authoritative session state - #5206

Merged
Hmbown merged 2 commits into
agent/v094-release-train-20260802from
copilot/engine-make-interrupted-assistant-output-durable
Aug 3, 2026
Merged

Persist interrupted assistant output as authoritative session state#5206
Hmbown merged 2 commits into
agent/v094-release-train-20260802from
copilot/engine-make-interrupted-assistant-output-durable

Conversation

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Interrupted assistant text was previously visible only to the client and absent from durable session history and subsequent model context. This change records that text as an explicit incomplete assistant item before TurnComplete(Interrupted).

  • Engine persistence

    • Adds assistant_interrupted session items containing only publicly streamed text.
    • Emits SessionUpdated before the interrupted terminal event.
    • Prevents duplicate commits and preserves completed messages and tool records.
  • Model context

    • Reopens and persists interrupted items with session data.
    • Serializes them as assistant messages with explicit incomplete-context guidance:
[The following assistant output was interrupted before completion and may be incomplete or wrong]
  • Client behavior
    • Updates chat, Responses, and Anthropic serializers to preserve assistant semantics while marking interrupted context.
    • Includes interrupted items in TUI history, notifications, and session repair paths.

Copilot AI changed the title [WIP] Add durable session item for interrupted assistant output Persist interrupted assistant output as authoritative session state Aug 3, 2026
Copilot AI requested a review from Hmbown August 3, 2026 08:20
@Hmbown
Hmbown changed the base branch from main to agent/v094-release-train-20260802 August 3, 2026 11:58
@Hmbown
Hmbown marked this pull request as ready for review August 3, 2026 12:48
Copilot AI review requested due to automatic review settings August 3, 2026 12:48
@Hmbown
Hmbown merged commit 59a8b87 into agent/v094-release-train-20260802 Aug 3, 2026
7 checks passed
@Hmbown
Hmbown deleted the copilot/engine-make-interrupted-assistant-output-durable branch August 3, 2026 12:48

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.

Pull request overview

This PR makes interrupted assistant output a durable, first-class session item so that text already streamed to the user is preserved in Engine session state, survives reopen/resume, and is included in subsequent model context with explicit “interrupted/incomplete” semantics.

Changes:

  • Persist publicly streamed assistant text on interruption as an assistant_interrupted session message, emitting SessionUpdated before returning TurnComplete(Interrupted).
  • Treat interrupted assistant items as assistant-like across the TUI (history, notifications, translation replacement) and tool-history repair logic.
  • Serialize interrupted items into downstream model inputs (Chat/Responses/Anthropic) as assistant messages prefixed with explicit incomplete-context guidance.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/tui/src/core/engine/turn_loop.rs Commits visible assistant text as an interrupted item on cancel/pause before returning Interrupted.
crates/tui/src/core/engine.rs Adds add_interrupted_assistant_text with basic idempotency to persist interrupted text and emit session updates.
crates/tui/src/models.rs Introduces INTERRUPTED_ASSISTANT_ROLE and an interrupted-context prefix constant; adds a serde round-trip test.
crates/tui/src/client/chat.rs Includes interrupted assistant items in Chat serialization with explicit interrupted-context prefixing.
crates/tui/src/client/responses.rs Includes interrupted assistant items in Responses input conversion and prefixes them for model context.
crates/tui/src/client/anthropic.rs Maps interrupted assistant items to role: assistant and prefixes the first text block for model context.
crates/tui/src/tui/ui.rs Allows assistant-text replacement logic to operate on interrupted assistant messages too.
crates/tui/src/tui/notifications.rs Includes interrupted assistant items when generating “latest assistant text” notification previews.
crates/tui/src/tui/history.rs Extends archived-context parsing to treat interrupted assistant messages as assistant-like.
crates/tui/src/tool_history_repair.rs Treats interrupted assistant messages as assistant boundaries for tool call/result integrity repair.
crates/tui/src/session_manager.rs Updates tests to accept interrupted assistant items as assistant-like where appropriate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +590 to 594
if (msg.role == "assistant"
|| msg.role == crate::models::INTERRUPTED_ASSISTANT_ROLE)
&& let Some(archived) = parse_archived_context(text)
{
cells.push(archived);
Comment on lines +668 to +672
"assistant" | crate::models::INTERRUPTED_ASSISTANT_ROLE => {
for block in &msg.content {
match block {
ContentBlock::Text { text, .. } => {
let text = if msg.role == crate::models::INTERRUPTED_ASSISTANT_ROLE {
Hmbown pushed a commit that referenced this pull request Aug 4, 2026
…5206)

* Initial plan

* WIP: persist interrupted assistant output

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Hmbown pushed a commit that referenced this pull request Aug 4, 2026
…5206)

* Initial plan

* WIP: persist interrupted assistant output

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.

Engine: make interrupted assistant output a durable first-class session item

3 participants