Repository navigation
fix: auto-recover from a pre-flight context-window rejection instead of stalling - #477
Closed
Satya Arjunan (satya-arjunan) wants to merge 1 commit into
Conversation
…of stalling When the current turn's own unreducible content (protected span + tool schemas) alone exceeds the safe input budget, the session hard-failed with "No provider request was sent" and just stopped - no retry, nothing automatic. Recovering required a human to notice and send literally anything (even "resume") to unstick it, which worked only because the recorded error reply makes that turn terminal/answered and therefore no longer protected from compaction on the next attempt. Confirmed via a real overnight incident: a benchmark session stalled here for hours before an unrelated desktop crash even happened, with nobody around to send the nudge. Adds SessionLoopState.preflightRecovery, mirroring the existing overflowRecovery/outputRecovery pattern: after recording the same error as before (unchanged, for transcript/observability), automatically enqueue a synthetic "context" continuation once per epoch, which correctly sidesteps terminalError's gate the same way an operator-sent message would. A second rejection in the same epoch means the turn's own content doesn't fit even after everything else has been compacted away, and still requires a real user decision rather than looping forever.
|
Satya Arjunan (@satya-arjunan) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #478
Problem
When the current turn's own unreducible content —
contextPreflight()'snewest, the protected active-turn span plus tool schemas — alone exceeds the safe input budget (hard), the session hard-fails with:backend/cli/src/session/prompt.ts:That's it — the loop just stops. No retry, nothing automatic. In a real overnight run, a session stalled here for hours before an unrelated issue happened later — recovery required a human to notice and send literally anything (even just "resume") to unstick it.
That manual recovery works only because
failTooLarge()'s error reply makes the failed turn terminal (SessionLoopState.terminalErrortreats any assistant reply witherroras answered) — so it's no longer "protected" from compaction the next time around, and any new message triggers a fresh preflight where the previously-stuck bulk is now compactable. There's no reason that recovery needs a human in the loop; the session already has everything it needs to do this itself once the error is recorded.Fix
Mirrors the existing
overflowRecovery/outputRecoverypattern (backend/cli/src/session/loop-state.ts) already used for two structurally similar recoverable-failure cases in this same loop:After recording the same error as before (unchanged, for transcript/observability — nothing about what the user sees on the first failure changes), the loop now automatically enqueues a synthetic
"context"continuation (a newContinuationkind, same mechanismoutput/contractcontinuations already use) and retries once per epoch:A second rejection in the same epoch means the turn's own content doesn't fit even after everything else has been compacted away — that still hard-fails exactly as before, since no amount of compaction could ever help there.
Verification
test/session/loop-state.test.ts:preflightRecovery's cap-at-one-retry behavior, andrestore()'s replay correctly recoveringpreflightCompactionsfrom a syntheticcontextcontinuation after a session reload (mirrors the existingoutput-continuation restart test directly above it).bun run typecheck— clean.backend/clisuite: 2906 pass / 115 fail / 16 errors (3058 total) on this branch vs. 2900 pass / 116 fail / 16 errors (3053 total) on a cleanmainbaseline — net +6 passing (this PR's 2 new tests plus normal variance), one fewer failure, identical error count. Same pre-existing, unrelated failures both times (confirmed the increase from an earlier ~90-fail baseline was entirely from two newly-merged, environment-dependent test suites unrelated to this change).SessionPrompt'swhile(true)loop anywhere in this codebase — every other recovery path in it (overflowRecovery,outputRecovery,terminalError) is tested purely at the extracted-decision-function level, which this follows exactly.