Skip to content

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

Closed

Description

@ajianaz

Summary

Compaction (#440) and the tole status context meter need the model's context window. Tole gets it only from an explicit setting (TOLE_CONTEXT_WINDOW / config) or the provider's GET /models. The fleet gateway's /models entries carry only id, created, owned_by, so on the fleet compaction is silently off unless the setting is made. The only signal is one stderr line, printed once per process by run / chat / resume and only after the prompt passes the 8,000-token detection floor (compaction_host.rs, DETECT_FLOOR). And when a provider does report a context overflow, nothing recovers from it.

Measured

  • Gateway /models: 11 entries; fields = {created, id, owned_by}; 0/11 carry any recognized window field (context_length, context_window, max_context_length, max_model_len, max_input_tokens, top_provider.context_length).
  • On the maintainer's host: TOLE_CONTEXT_WINDOW is not set in the fleet env files and there is no user config file.
  • Mock /models without a window, resume after a ~15k-token prompt: stderr tole: compaction off: the provider's /models reports no context window for this model; set TOLE_CONTEXT_WINDOW (tokens) to enable it; with a window present compaction proceeds silently.
  • tole doctor --tier catalog prints catalog: mock-model is served (<N> models) and exits 0 in both cases; it does not mention the missing window.
  • The window is re-fetched in every process (no disk cache); the gateway's /models takes 0.15-0.36 s (3 probes) and is only called once the prompt passes DETECT_FLOOR.
  • Overflow: the mock answers HTTP 400 context_length_exceeded; tole ends the turn with rc 4 http status: 400 (the body is hidden, see the provider-error-body issue). The session is resumable, but nothing shrinks the history.
  • Worst case is derived from source, not measured: MAX_STEPS = 32 per turn x read_file up to 20,000 chars per call is about 640k chars (about 160k tokens) of tool output inside ONE turn, against a window of about 200k for the fleet model. Compaction only runs between turns, so a single large turn can fill most of the window (and, on top of earlier history, exceed it) before compaction gets a chance.
  • Public window figures for the fleet model: 202,752-204,800 tokens depending on the source.

Why it matters now

#458 (session status snapshot) and the TUI footer (#460: "context used / window") need the same window; on the fleet gateway they would show no window at all.

Compare

  • nca 0.5.5: static table of known windows, then the provider catalog, cached on disk 24 h per provider+endpoint+model. Its own benchmark: removing the catalog round trip cut first-event latency from 2.5-4.3 s to 14-20 ms. The table is stale (Claude 3.x era): copy the idea, not the data.
  • fx: compacts at 80% of the usable window; if the provider reports a context overflow before any text or tool call, it compacts and retries once.

Proposal (smallest first)

  1. tole doctor (catalog tier): warn when the catalog has no window for the configured model and print the exact setting to add. The coverage ledger stays honest. Note: doctor fetches ids only (fetch_model_ids_with_timeout, doctor.rs:447), so this needs fetch_context_window (openai.rs:819, returns Result<Option<u64>, String>) or an extended fetch; it is not a one-line tweak.
  2. Document TOLE_CONTEXT_WINDOW / config context_window in the fleet setup and set it for the fleet model.
  3. Overflow safety net: classify a context-overflow error (needs the provider-error-body issue: provider: HTTP error body is discarded (ureq default) — 4xx/5xx detail never reaches the operator #474) and force a compaction at the next resume <id> "<prompt>", independent of window detection. Design question for the owner: compaction is deliberately between-turns only, so a mid-turn overflow can end the turn with a clear message and let the next turn compact, versus compacting and retrying in place as fx does.
  4. Optional: small built-in table for the fleet's own models as a last-resort hint (explicit setting and catalog both win); optional 24 h disk cache of a successful lookup (atomic temp+rename; never cache failures).

Acceptance

  • doctor --tier catalog surfaces the missing window as a non-fatal warning.
  • Overflow: mock E2E where the provider answers context_length_exceeded; the operator sees the provider message and the next prompt compacts and succeeds.
  • If a table/cache is added: precedence tests (flag/env/config > catalog > table) and cache expiry; no write on failure.
  • Docs.

Found by

Competitor research 2026-11-02 (nca model_limits_api.rs disk cache; fx compaction docs), measured against the fleet gateway and develop @ 438ad0d.

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

    enhancementreliability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions