fix: add stream retry cap and context recovery hint for provider errors#12091
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: add stream retry cap and context recovery hint for provider errors#12091roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…rs (#12087) - Add MAX_STREAM_RETRIES (5) to cap first-chunk and mid-stream error retries, preventing indefinite retry loops when auto-approval is enabled - Add context recovery hint prepended to user content on retry attempts, helping weaker models re-orient to the current task instead of hallucinating about previously completed tasks - When max retries are exceeded, present the error to the user for manual retry instead of continuing to auto-retry indefinitely - Update last user message in API history on retry with recovery hint and refreshed environment details
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.
Related GitHub Issue
Closes: #12087
Description
This PR attempts to address Issue #12087 where provider errors during API requests cause the agent to lose context and hallucinate about previously completed tasks.
Two key improvements:
Stream retry cap (
MAX_STREAM_RETRIES = 5): Both the first-chunk error retry path (inattemptApiRequest) and the mid-stream error retry path (inrecursivelyMakeClineRequests) now have a maximum retry limit. Previously, only context window errors had a cap (MAX_CONTEXT_WINDOW_RETRIES), while stream/provider errors could retry indefinitely with exponential backoff. After exceeding the limit, the error is presented to the user for manual retry, which resets the counter.Context recovery hint on retry: When a retry occurs (
retryAttempt > 0), a[CONTEXT RECOVERY NOTE]is prepended to the user content. This helps weaker models re-orient to the current task instead of latching onto earlier completed task context. The hint explicitly instructs the model to focus on the most recent request and not repeat previously completed tasks. Additionally, the last user message inapiConversationHistoryis updated with the hint and refreshed environment details.Feedback and guidance are welcome.
Test Procedure
src/core/task/__tests__/stream-retry-limit.spec.ts(17 tests, all passing)grace-retry-errors.spec.tstests still pass (11 tests)To run the new tests:
Pre-Submission Checklist
Documentation Updates
Additional Notes
The context recovery hint is designed to be model-agnostic and uses clear, directive language to help even weaker models (like glm-5 via OpenAI Compatible endpoints) maintain focus on the current task after error recovery. The retry cap of 5 was chosen to match a reasonable threshold -- with exponential backoff starting at the configured base delay, 5 retries provides sufficient recovery window while preventing runaway loops.
Interactively review PR in Roo Code Cloud