Commit Graph
6 Commits
Author SHA1 Message Date
Ahmed Allam 4eedfc64b4 fix(context): cap summary output at model limit; safe token upper bound
- Clamp the summary request's max_tokens to the model's output limit so a
  large STRIX_CONTEXT_SUMMARY_TOKENS can't get the request rejected (which
  left the overflowing session uncompacted). Applied consistently to the
  input-budget reservation and the request itself.
- Replace the tokenizer-unavailable fallback with the UTF-8 byte length, a
  guaranteed upper bound on tokens for byte-level BPE, so budget checks can
  never under-count dense history.
2026-07-26 00:15:49 +00:00
Ahmed Allam 16cbd516c8 refactor(context): detect overflow via LiteLLM's typed error only
Drop the brittle substring matching for context-overflow detection. LiteLLM
already normalises every provider's overflow error to
ContextWindowExceededError and maintains the provider-specific matching
upstream, so is_context_overflow just checks that type.
2026-07-25 23:48:47 +00:00
Ahmed Allam dd35af6181 fix(context): skip compaction when the window can't fit a summary request
When instructions, the reserved summary output, and any prior checkpoint
already consume the model's context window, the summary-input budget is
zero. Previously a doomed summary request was still submitted (and
rejected). Skip summarization in that case and log, rather than issue a
request guaranteed to overflow.
2026-07-25 23:46:27 +00:00
Ahmed Allam 739e969914 fix(context): never floor summary input above the model's remaining room
The 1,000-token floor on summary-input room could exceed the space
actually left after instructions, the reserved summary output, and any
existing checkpoint. On a small window the summary request then overflowed
and returned nothing, leaving the oversized session uncompacted. Clamp to
the real room instead so the request always fits.
2026-07-25 23:46:27 +00:00
Ahmed Allam 8fd871249c fix(context): bound the compaction summary input to the model window
Head+tail-truncate the serialized history before the summary request so a
very large head cannot itself overflow the model context and abort the
recovery it is meant to perform.
2026-07-25 23:46:27 +00:00
Ahmed Allam a73300f840 feat(context): model-aware conversation compaction for long scans
Restore cumulative history compaction (removed in the SDK migration) so a
long scan no longer replays an ever-growing transcript until it overflows
the model's context window and the run fails.

- strix/llm/context_budget.py: resolve the model's real input/output token
  limits from LiteLLM metadata (128k gpt-4o, 272k gpt-5, 1M claude-sonnet-4,
  131k deepseek), with a large configurable fallback for unmapped models and
  a chars/4 token-count fallback.
- strix/llm/compaction.py: provider-agnostic compaction via litellm. Keeps a
  security-focused structured summary (objective, findings, credentials,
  payloads, URLs/paths, work state, dead ends, next move), keeps the most
  recent turns by token budget, and snaps the summary boundary so no tool
  call is separated from its result. Both triggers: proactive before each
  run and reactive compact-and-retry on a real context-overflow error.
- Wire both triggers into the agent run loop next to the existing image
  recovery; add replace_session_items() with restore-on-failure.

Env-tunable via STRIX_CONTEXT_* (auto-compact on by default).
2026-07-25 23:46:27 +00:00