fix: preserve context after successful assistant retry#498
Open
thekfjie wants to merge 2 commits into
Open
Conversation
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.
Summary
Fix default-branch context truncation after a failed generation is recovered by retrying the assistant response.
branch_reason=retry, have asource_message_id, and besuccessorinterrupted.Reproduction
error.The active path is now:
Actual behavior
selectLatestDefaultParentCandidatecorrectly selects the successful retry assistant, butnormalizeDefaultBranchContextwalks backward, sees the reused user still markederror, and treats it as a hard boundary. Earlier transcript and attachment context are discarded.In a sanitized affected trace, the next request contained only 776 input tokens plus 4,070 cache-read tokens (4,846 total), while retrying the same message with its full branch produced 64,704 total input tokens.
Expected behavior
A successful or retained interrupted assistant retry makes its reused user turn valid context. The next default message should keep the complete active ancestor chain and its attachments.
Root cause and approach
Assistant retry intentionally creates only a new assistant branch message and does not change the reused user row. The default context normalizer previously evaluated every message independently, so the stale user
errorstate split an otherwise recovered branch.The fix recognizes this specific two-message relationship during normalization and changes only a copied message slice. Doing this at read time also repairs already affected conversations; changing only the retry persistence path would protect new retries but leave existing conversations truncated.
Change type
Affected areas
Verification
go test ./internal/application/conversation -count=1go test -race ./internal/application/conversation -count=1go test ./internal/application/... -count=1go test ./... -count=1go vet ./...Screenshots, API examples, or logs
No UI change. The reproduction and token counts above are sanitized; no conversation content, identifiers, credentials, or user data are included.
Configuration, migration, and compatibility notes
Documentation
Security and privacy
Checklist
.pycfiles,.envfiles, and local storage data are not committed.