Skip to content

fix(session): preserve context after user interrupts - #2563

Closed
ribelo wants to merge 30 commits into
anomalyco:devfrom
ribelo:dev
Closed

ribelo wants to merge 30 commits into
anomalyco:devfrom
ribelo:dev

Conversation

@ribelo

@ribelo ribelo commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

#2554

Prior behavior dropped all assistant messages with any error flag, so Ctrl+C (AbortError) removed crucial context like read files and patches. This caused the model to ‘forget’ work after an interruption.

Change: when building provider messages, filter out assistant messages only if error exists and it is not MessageAbortedError. Aborted messages now remain in context; genuine failures (auth/output length/unknown) are still excluded. Also ensure summaries with errors are not treated as lastSummary anchors.

Includes: adjust lastSummary lookups to ignore errored summaries.

Edge cases considered: multiple interrupts, partial tool calls are marked error on parts but message retained; stopWhen short-circuits on permission rejects; compatibility with MessageV2.AbortedError schema.

It seems to help, but I don’t know if it breaks something else.

@NaikSoftware

NaikSoftware commented Sep 12, 2025 •

Copy link
Copy Markdown

This solution is a partial. We have a case with subagents. After interruption inside child conversation, it just finished and the main agent always thinking a delegated task was done. But for fixing this problem will need major refactoring I think

@ribelo

ribelo commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

@NaikSoftware done

@rekram1-node
rekram1-node requested a review from thdxr September 12, 2025 15:38
…ption state

This commit addresses two critical interruption handling issues:

1. Context preservation after interruption (fixes anomalyco#2554):
   - Messages with AbortedError are preserved in context (already in prompt.ts)
   - filterSummarized() ignores errored summaries (message-v2.ts)
   - prune() ignores errored summaries when checking compaction (index.ts)

2. Subagent interruption propagation:
   - Task tool now checks result.info.error after subagent execution
   - Throws error when subagent was interrupted or errored
   - Includes partial output from interrupted subagents in error message
   - Parent agents correctly detect when delegated tasks are interrupted

This ensures the model remembers work done before interruption and parent agents properly handle interrupted subagent tasks.
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.

3 participants