Skip to content

feat(agent): structured, economical compaction (soft/force ratios + fold economics)#3073

Merged
esengine merged 1 commit into
main-v2from
feat/compact-economical-2406
Jun 4, 2026
Merged

feat(agent): structured, economical compaction (soft/force ratios + fold economics)#3073
esengine merged 1 commit into
main-v2from
feat/compact-economical-2406

Conversation

@esengine
Copy link
Copy Markdown
Owner

@esengine esengine commented Jun 4, 2026

Rebase of #2406 (by @SivanCola) onto current main-v2 (after #3050/#3057 landed). The branch had drifted; I applied the net diff and re-merged the compaction core by hand, since compact() had diverged on both sides.

What it does

  • Soft ratio (0.5) — between the soft mark and the trigger, emit a one-shot notice instead of compacting, so the cache-stable prefix is kept intact while the user is warned.
  • Force ratio (0.9) — a high-water mark that compacts even a low-value region.
  • Fold economics — skip the summarizer round-trip when the foldable region is too small to pay for the extra latency/cost (bypassed by force and by manual /compact).

Rebase notes (signature reconciliation)

  • main-v2 had compact(ctx, trigger, instructions); this PR had compact(ctx, force bool). Unified to compact(ctx, trigger, instructions, force) so the force flag coexists with the existing /compact <focus> text + PreCompact-hook path and the cache-diagnostics rewrite tracking from feat(agent): cache prefix diagnostics for prompt-cache churn #3057.
  • Kept main-v2's token-budgeted tail (planCompaction, parameterized with a min-message count for the single-large-message fallback) rather than reverting to the PR's message-count tail, and kept main-v2's more detailed summary prompt.
  • maybeCompact now layers the soft-notice and force logic on top of main-v2's anti-re-compaction compactStuck latch.
  • Adapted the threshold tests to the token-budgeted tail (a single large old message folds 1→1: the summary is installed but the message count is unchanged).

Local: go build ./..., go vet, and go test ./internal/agent ./internal/config ./internal/boot ./internal/cli ./internal/control all green.

Closes #2406

…old economics)

Adds a soft-notice ratio (report growing context without cratering the cache prefix), a force ratio (compact even low-value folds at the high-water mark), and a fold-economics gate that skips a summarizer round-trip when the region is too small to pay for itself. Rebased onto main-v2: unified compact() to (ctx, trigger, instructions, force) so the new force flag coexists with the existing /compact focus + PreCompact-hook path; kept main-v2's token-budgeted tail (planCompaction) and detailed summary prompt rather than reverting to the PR's message-count tail; adapted the threshold tests to the token-budgeted tail.

Closes #2406
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 4, 2026
@esengine
Copy link
Copy Markdown
Owner Author

esengine commented Jun 4, 2026

C:/Program Files/Git/e2e

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

🤖 Reasonix e2e benchmark

Accuracy: 3/4 (75%) · Cache hit: 75% · Tokens: 160,894 (prompt 158,586 / completion 2,308) · Compactions: 3 · Cost: ¥ 0.0463

Task Result Steps Prompt Completion Cache hit Compact Cost
compaction ❌ fail 8 102,828 1,073 63% 3 ¥ 0.0419
fix-add-bug ✅ pass 3 18,342 227 98% 0 ¥ 0.0011
fizzbuzz ✅ pass 3 18,821 535 99% 0 ¥ 0.0017
palindrome ✅ pass 3 18,595 473 98% 0 ¥ 0.0016

Real provider run. Cache-hit % is cached prompt tokens / total prompt tokens.

agent: PR head (dadbd87) · triggered by @esengine

@esengine
Copy link
Copy Markdown
Owner Author

esengine commented Jun 4, 2026

C:/Program Files/Git/e2e

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

🤖 Reasonix e2e benchmark

Accuracy: 4/4 (100%) · Cache hit: 74% · Tokens: 153,899 (prompt 151,915 / completion 1,984) · Compactions: 3 · Cost: ¥ 0.0452

Task Result Steps Prompt Completion Cache hit Compact Cost
compaction ✅ pass 8 102,684 988 63% 3 ¥ 0.0416
fix-add-bug ✅ pass 3 18,368 247 98% 0 ¥ 0.0012
fizzbuzz ✅ pass 3 18,681 480 99% 0 ¥ 0.0016
palindrome ✅ pass 2 12,182 269 99% 0 ¥ 0.0009

Real provider run. Cache-hit % is cached prompt tokens / total prompt tokens.

agent: PR head (dadbd87) · triggered by @esengine

@esengine esengine merged commit 0081d81 into main-v2 Jun 4, 2026
9 checks passed
@esengine esengine deleted the feat/compact-economical-2406 branch June 4, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants