Commit Graph
3 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 2163a66b78 fix(context): over-estimate tokens when no tokenizer is available
The chars/4 fallback under-counts dense text (code, base64, CJK), which
could let a summary request be packed past the real context window and get
rejected. Use a conservative ~3-chars/token estimate instead so budget
checks never under-count.
2026-07-26 00:04:13 +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