Skip to content

feat(compact): cap summary completion and measure post-checkpoint fit - #456

Open
bobzhang wants to merge 2 commits into
agent/compaction-cut-plannerfrom
agent/compaction-summary-cap
Open

feat(compact): cap summary completion and measure post-checkpoint fit#456
bobzhang wants to merge 2 commits into
agent/compaction-cut-plannerfrom
agent/compaction-summary-cap

Conversation

@bobzhang

Copy link
Copy Markdown
Collaborator

Summary

Fourth slice of the compaction production-hardening plan (R2: enforce the reserve's contract). Stacked on #455.

  • Client::chat gains optional max_tokens, encoded per provider: max_tokens for DeepSeek, max_completion_tokens for Kimi — Kimi ignores thinking=No and its legacy field shares the budget with reasoning_content, so a legacy cap could be spent entirely on reasoning and hand back an empty summary, failing every ceiling checkpoint (subal P1).
  • The checkpoint summary request caps itself at CompactionSummaryMaxTokens (8,192); a whitebox test enforces checkpoint_reserve_tokens > cap, the reserve's documented-but-previously-unenforced contract.
  • Generation rejects a summarizer response that answers with native tool calls (fails fail-open exactly like an empty summary — test pins that the compact-on-finish shape keeps the real answer and appends no summary), and warns compaction_summary_truncated when the completion spends the whole cap (summary kept: truncated beats none at the ceiling).
  • auto_compaction_finished gains compacted_projection_chars — the checkpoint's output size at checkpoint time, a lower bound later suffixes only grow — plus an auto_compaction_fit_unproven warning when conservative char accounting can no longer prove the next request fits (explicitly not proven overflow: chars overestimate tokens).

Testing

  • Encode snapshot tests for capped/uncapped DeepSeek and Kimi request bodies.
  • Mock-server tests: the checkpoint request carries the cap while the main streaming request stays uncapped; a tool-call summarizer reply fails fail-open.
  • Reserve-relation whitebox test.
  • moon check --deny-warn clean; deepseek+agent+compact 115/115.
  • Two subal (codex) rounds: P1 Kimi cap starvation + two telemetry-semantics findings fixed; final round clean.

🤖 Generated with Claude Code

bobzhang and others added 2 commits July 11, 2026 12:41
The checkpoint reserve documents that it holds the summary completion,
but nothing enforced it: the summary request passed no max_tokens, so a
rambling summarizer could spend past the reserve and strand the session
via fail-open. Client::chat gains an optional max_tokens (encoded only
when passed); the summary request caps itself at the new
CompactionSummaryMaxTokens (8_192), and a whitebox test pins the
reserve > cap relation. Generation now also rejects a response that
answers with native tool calls (no usable summary; fails fail-open like
an empty one) and warns when the completion spent the whole cap
(length-truncated summary: kept, a truncated checkpoint beats none).

The auto checkpoint additionally logs its fit postcondition: the
compacted projection's model-visible chars on auto_compaction_finished,
plus a warning when even the conservative char accounting says the next
request cannot fit — the summary did not relieve the ceiling it was
generated for.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Three subal findings. Kimi ignores thinking=No and its legacy
max_tokens budget is shared with reasoning_content, so an 8K cap could
be spent entirely on reasoning and hand back empty visible content —
failing every ceiling checkpoint on Kimi; the cap now encodes as
max_completion_tokens for Kimi models (snapshot test added). The
post-checkpoint telemetry field is renamed to
compacted_projection_chars: it measures the checkpoint's output at
checkpoint time, a lower bound the surrounding shapes' suffixes (late
steers, kept answers, goal notices) only grow. The warning becomes
auto_compaction_fit_unproven — chars overestimate tokens, so crossing
the window means conservative accounting can no longer prove the next
request fits, not proven overflow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant