Auto-compact fails with compact_error:too_few_groups well below context limit, killing session with Prompt is too long
Summary
A non-interactive scheduled Claude Code CLI session (Agent SDK, sonnet, tool-result-heavy/low-turn-count transcript) dies mid-run even though cumulative input tokens are far below the models real context window.
Observed failure
- Run reached 225,541 cumulative input tokens on an ordinary tick, well under context ceiling.
- Auto-compact triggered mid-run and failed with compact_error:too_few_groups.
- Session died with result:Prompt is too long, terminal_reason:blocking_limit - a hard kill, not graceful.
- Recurred 74 times for the same scheduled job over roughly a week, at token counts 70K-225K - not correlated with approaching the real ceiling.
Reproduction pattern (from production evidence, not yet isolated to a minimal repro)
- Spawn claude non-interactively (--strict-mcp-config + minimal MCP config) for a scripted repeated task.
- Transcript is tool-result-heavy but low turn-count.
- Somewhere in the 70K-225K cumulative input token range, auto-compact fires and fails with too_few_groups.
- Session terminates with Prompt is too long instead of retrying or falling back.
Expected behavior
Either auto-compact should succeed well below the real ceiling, or a failed auto-compact should not hard-kill the session. It should retry, fall back to partial summarization, or surface a recoverable error.
Environment
Claude Code CLI, non-interactive scheduled spawn via Agent SDK (stream-json I/O), Windows, model sonnet.
Not using the advisor() tool, ruling out the doubled-token-accounting bug in issue 53065.
Distinct from issue 83682 (near-ceiling interactive failure): this fires at a small fraction of context in short non-interactive sessions.
Can provide exact JSONL run logs on request. Error signature and thresholds are drawn from real production logs across 74 recurrences.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗