fix: tool interruption 400 error — graceful error handling and conversation state reset#445
Closed
avoidwork wants to merge 3 commits into
Closed
fix: tool interruption 400 error — graceful error handling and conversation state reset#445avoidwork wants to merge 3 commits into
avoidwork wants to merge 3 commits into
Conversation
- Add isInterrupting state flag to track active interruptions - Reset conversation state on interruption to ensure system message is first - Catch and gracefully handle non-AbortError errors during interruption - Add safety net in OpenAI provider to reorder messages if needed - Add spec requirement for graceful interruption error handling Fixes #444
- Add isInterruptingRef to track active interruption state in TUI - Set isInterrupting flag before abort, clear after dispatch resolves - Catch interruption errors gracefully (log + clear, no error display) - Reset conversation state after interruption (ensure system message first) - Add safety net in react.js: reorder system message if not first - Log warning when message reordering occurs - All tests pass (1176), lint clean, coverage maintained
Owner
Author
Audit Results: Fix Tool Interruption 400 Error (Implementation)Goal Fulfillment
Spec Compliance
Task Completion
Quality Check
VerdictNo errors found. Implementation is complete and correct. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When a tool execution is interrupted mid-execution, the system throws an unrecoverable 400 error: "System message must be at the beginning." This occurs because the conversation state becomes corrupted after interruption — the system message is no longer the first message in the conversation array, violating the OpenAI API's strict ordering requirement.
What Changed
isInterruptingstate flag to track when an interruption is in progresshandleInterrupt()to set the flag, signal abort, reset conversation state, and clear the flaghandleChat()error handler to checkisInterruptingand handle errors gracefully during active interruptionhandleInterrupt()to reorder system message to first position after interruptionFiles Changed
src/tui/app.js— AddedisInterruptingRef, modifiedhandleInterrupt()andhandleChat()error handlingsrc/agent/react.js— Supporting changes for interruption handlingopenspec/changes/fix-tool-interruption-400-error/— OpenSpec proposal, design, tasks, and spec deltaTesting