Skip to content

fix(turn): surface context-overflow recovery and warn when the window is unknown - #496

Merged
ajianaz merged 1 commit into
developfrom
fix/compaction-window
Nov 3, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/compaction-window

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

Context-window visibility and overflow recovery for the compaction feature (#440):

  • tole doctor --tier catalog prints a non-fatal ! warning ("set TOLE_CONTEXT_WINDOW=") when the configured model is served but neither the setting nor /models provides a window; a pass line when it does. Exit code and coverage ledger unchanged. (run_cli gains a configured_window argument; diagnose unchanged.)
  • compaction::is_context_overflow classifies a provider error as context overflow only when the HTTP status is 400/413/422 AND the error text carries one of five phrasings (context_length_exceeded, "maximum context length", "context length exceeded", "exceeds the context window", "prompt is too long"). After a failover only the last provider's error counts.
  • The turn loop writes a durable fact/context_overflow register in the same commit that settles the failed turn; Compactor::before_turn then forces one compaction pass on the next resume/chat regardless of window or threshold, and clears the flag. No other provider failure writes the flag. --no-compaction disables the recovery pass (flag stays set); a failed summary call keeps the flag; a pass with nothing to summarize clears it with a note.
  • report_outcome/chat failure lines append "(compaction will run on the next resume)" on overflow.
  • Docs: README (TOLE_CONTEXT_WINDOW row, doctor table, the single-turn-too-big limit), docs/epics.md, docs/threat-model.md. CHANGELOG under [Unreleased].

Why (the problem you're solving)

Closes #481 (approved scope: items 1-3). On the fleet gateway /models carries no window field, so compaction was silently off with one stderr hint; and a context overflow ended the turn with no recovery path. Owner decision 3 Nov 2026: a mid-turn overflow ends the turn with the provider's message and a hint, and the next prompt compacts first — compaction stays between-turns; NO compact-and-retry-in-place. Item 4 (built-in window table + 24 h disk cache) is deferred as a possible follow-up.

Testing (how you verified this works)

  • RED: the core and doctor tests first failed to compile (overflow_pending, diagnose_with_window absent). GREEN: core compaction 11/11, cli compaction_host+doctor 25/25.
  • New E2E (real binary, compaction_e2e, 5 passed): provider answers HTTP 400 overflow once -> rc 4 with the provider message + hint, no summary call or retry in the failed turn, flag durable in the session file; the next resume compacts and succeeds; a further resume does not compact again. Doctor E2E: warning with no window, pass line with one.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --no-fail-fast (963 passed / 0 failed, 55 binaries), cargo test -p tole-core --no-default-features (383 passed / 0 failed), cargo build -p tole-cli --no-default-features: all pass. cora pre-commit gave a real verdict: "No issues found".
  • Scope notes: the forced pass keeps the last turn verbatim (existing keep_turns=1) — a single turn bigger than the window cannot be fixed by compaction (README says so). The serve/ACP failure lines show the provider message without the hint (still set the flag and recover on the next prompt); left alone to avoid scope creep. Not run: perf test, live-gateway check.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 3ec70f4 into develop Nov 3, 2026
16 checks passed
@ajianaz
ajianaz deleted the fix/compaction-window branch November 3, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compaction: the fleet gateway reports no context window, so compaction is silently off; no overflow recovery

1 participant