-
Notifications
You must be signed in to change notification settings - Fork 663
fix(agent): preserve failed context #1608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Failed Message Context Preservation Plan | ||
|
|
||
| ## Approach | ||
|
|
||
| - Add a shared runtime predicate for context-eligible records: include `sent` records and `assistant:error` records, exclude `pending` and `user:error`. | ||
| - Update `recordToChatMessages` to append a readable assistant summary for error blocks while preserving existing content, reasoning, and settled tool call replay behavior. | ||
| - Use the same eligibility predicate in new-turn history collection, resume context, and compaction inputs. | ||
|
|
||
| ## Data Flow | ||
|
|
||
| - Failed generation already persists an assistant `error` record with terminal error blocks. | ||
| - On the next turn, `buildContext` selects eligible records and converts the failed assistant record into provider-facing assistant text. | ||
| - Compaction receives the same eligible assistant error records so summarized history matches provider context. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - Stored records are unchanged. | ||
| - Existing sent history behavior and provider tool-message ordering remain unchanged. | ||
| - Pending interactions keep their existing resume path and are not included in normal next-turn context. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Failed Message Context Preservation | ||
|
|
||
| ## User Story | ||
|
|
||
| When an agent loop fails or is canceled, the next user turn should still know what happened. The failed assistant message, including any partial progress and the failure reason, must be included in the next request context so the model can recover instead of repeating work. | ||
|
|
||
| ## Acceptance Criteria | ||
|
|
||
| - Assistant messages with status `error` are eligible for future agent context. | ||
| - User messages with status `error` and all `pending` messages remain excluded from normal next-turn context. | ||
| - Error blocks are converted into readable context text: | ||
| - `common.error.userCanceledGeneration` becomes `User canceled generation`. | ||
| - Unknown error text is preserved as-is. | ||
| - If the failed assistant message has partial content, that content is preserved and followed by a failure or cancellation summary. | ||
| - Settled tool calls with non-empty responses are still replayed; unfinished tool calls are not fabricated into tool results. | ||
| - Auto-compaction and resume context budgeting consider assistant error records consistently with next-turn context. | ||
|
|
||
| ## Non-Goals | ||
|
|
||
| - No database schema changes. | ||
| - No IPC, renderer UI, or message storage format changes. | ||
| - No attempt to resume unfinished tool calls without stored tool responses. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Failed Message Context Preservation Tasks | ||
|
|
||
| - [x] Add SDD spec, plan, and task documents. | ||
| - [x] Add focused context-builder tests for assistant error and cancel records. | ||
| - [x] Update context-builder record eligibility and assistant error conversion. | ||
| - [x] Reuse eligibility in agent runtime and compaction history selection. | ||
| - [x] Run focused tests and required repository quality commands. |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.