Repository navigation
fix: stop retrying oversized requests and recover with one forced compaction - #460
Merged
Merged
Conversation
…paction A request the provider rejects as too large (HTTP 413, request_too_large, the local request-body check, or a context-window overflow such as MiniMax 'context window exceeds limit (2013)') fails identically on every resend. The API-key and custom-provider paths retried it five times. - Classify these rejections as deterministic (isLLMRequestOversized), so withLLMRetry sends them once on every path. - Add contextOverflowRecoveryHook to PiTurnHooks. When the main-agent request is rejected as too large before any output, the runner runs only these hooks once per turn with trigger 'context_overflow_recovery', persists the replacement and resends once; a second rejection is final. - local-runtime-v2 registers the automatic compaction hook there; the trigger forces compaction and targets at most half of the rejected request, since the local estimate had admitted it.
hetaoBackend
marked this pull request as ready for review
October 9, 2026 06:07
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.
Problem
A request the provider rejects as too large fails the same way on every resend, but:
minimax_api) andcustom_provider:*paths retry every pre-output failure, so the same oversized body went out 6 times (~15 s of backoff). This also applied torequest_too_large, the local pre-send check (Request body too large: … exceeds client limit …), and MiniMaxinvalid params, context window exceeds limit (2013).Fix
shared/llm-error-classifier: newrequest_too_large/context_overflowsignals andisLLMRequestOversized(). HTTP 413, byte-limit rejections and unambiguous context-overflow messages are now deterministic rejections (sent once on every path). Transient shapes (timeouts, network errors, 408/429/5xx) are still excluded. A bare MiniMax2013without overflow wording is not treated as an overflow.agent-core: newPiTurnHooks.contextOverflowRecoveryHook. When a main-agent request is rejected as too large before any output (pi-aiisContextOverfloworisLLMRequestOversized), the runner runs only these hooks, once per turn, withtrigger: 'context_overflow_recovery'. It then persists the replacement through the normal history path and resends once. A second rejection, or a recovery that changes nothing, surfaces the original error. The rejected attempt never reaches history, and ordinary before-LLM hooks (reminders and so on) do not run twice. The wrapper sits inside the logical-call metrics and capture.local-runtime-v2: the executor registers the automatic compaction hook (with its plugin lifecycle) as the recovery hook. The trigger forces compaction regardless of the local estimate and caps the result at 50% of the rejected request's measured tokens/bytes, because the estimate had admitted a request the provider rejected.Tests
llm-retry.test.ts: oversized shapes (413 variants, request_too_large, local body check, 2013 overflow, prompt too long) are sent once onminimax_api,custom_provider, and the managed path. Added classifier positive/negative cases, including the BYOK-attributed form.context-overflow-recovery.test.ts(PiTurnRunner end to end):automatic-context-compactor.test.ts: the forced trigger starts compaction below the thresholds, and the hook maps the runner trigger toforce.pnpm typecheck,node scripts/run-vitest-suite.mjs capability(215 files, 5406 passed), andcheck:sourceall pass.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.