Skip to content

Pre-flight context-window rejection stalls the session permanently instead of retrying #478

Closed

Description

Summary

When a turn's own unreducible content (the protected active-turn span plus tool schemas) alone exceeds the safe input budget, the session hard-fails with "No provider request was sent" and stops — permanently, with no retry. Recovering requires a human to notice and send anything at all (even just "resume") to unstick it.

Found this from a real overnight run: a benchmark session stalled here for hours with nobody at the machine to notice, well before an unrelated issue happened later in the same night.

Root cause

backend/cli/src/session/prompt.ts:

if (preflight.newest > preflight.hard) {
  await failTooLarge(
    `This message cannot fit in ${window.name}'s context window: ...`,
  )
  break
}

The manual recovery (typing anything, e.g. "resume") works only because of a mechanism already in the codebase: failTooLarge()'s recorded error reply makes that turn terminal — SessionLoopState.terminalError treats any assistant reply carrying error as answered, which means protectedContext (the function that decides what's still "protected" from compaction) no longer protects it on the next preflight check. Any subsequent new message then sees a smaller newest, and the existing total > soft/hard auto-compact-and-retry path (which already exists for the reducible case) can succeed.

So the fix doesn't require anything new architecturally — the session already has every piece needed to recover on its own, it just never tries.

Fix

Opened #477: adds SessionLoopState.preflightRecovery, mirroring the two structurally identical existing patterns in this same file — overflowRecovery (recovers from a compaction-summary-itself-overflowed case) and outputRecovery (recovers from an output-length-truncated case). After recording the same user-visible error as before, the loop now automatically enqueues a synthetic continuation and retries once per turn/epoch — exactly what a human sending "resume" achieves manually today, just without needing a human. A second rejection for the same turn still hard-fails as before, since at that point no amount of compaction could help (the turn's own content doesn't fit even after everything else has been reclaimed).

Verified via new tests plus a full backend/cli suite run against a clean main baseline — zero regressions, two new tests passing. Details in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions