Skip to content

Cost-aware compaction: scheduled runs compact once the resent prompt exceeds a token budget - #1561

Merged
obsessixnv merged 1 commit into
mainfrom
feat/1534-resend-budget-compaction
Sep 17, 2026
Merged

obsessixnv merged 1 commit into
mainfrom
feat/1534-resend-budget-compaction

Conversation

@obsessixnv

Copy link
Copy Markdown
Collaborator

Closes #1534.

Problem

Compaction fired only on context-window pressure (90%), and scheduled runs only warned unless FLEET_SCHEDULED_AUTO_COMPACT=1. A 1M-window model never reaches 90% in a 100-turn run, yet every turn resends the whole transcript and pays for it: Reklaim 6bd0c212 resent ~115K tokens per call for 99 calls at an 11% cache-hit rate — 11.35M prompt tokens, $8.29 — and no compaction ever ran.

Change

  • Resend-budget trigger (checkContextPressure, scheduled engines only — requireCompactionOptIn is the driver's scheduled marker): once LastStepPromptTokens (the anti-spiral signal the window path already uses) exceeds FLEET_CONTEXT_RESEND_BUDGET_TOKENS (default 80 000; 0 disables), the same oldest-half proactiveCompact runs through the same governed summarizer. It is a cost control, not a safety valve, so it is deliberately not behind FLEET_SCHEDULED_AUTO_COMPACT, which keeps guarding the window-pressure path. Interactive chats are untouched.
  • Observability: fleet.context_compacted now carries trigger (resend_budget | window) and, for the budget path, used_tokens + resend_budget_tokens; the session log gets a [context_compacted] trigger=resend_budget used=… budget=… breadcrumb.
  • Knob: registered in knobs.go (scopeExternal) and the env-file allowlist; AGENT-RUNTIME.md compaction table + a paragraph. The per-result lever the issue also asked for already exists (max_tool_output_bytes, default 64 KiB); the docs point at it.

Contract change, on purpose

TestRun_ContextPressure_ScheduledWarnsOnlyWithoutFlag ("a scheduled run must not silently rewrite its transcript without the opt-in") now disables the budget trigger explicitly: that test pins the window-pressure contract, while the cost trigger is default-on for scheduled runs — with #1518's completed-step checkpoints making re-drives safe, and the breadcrumb + event making it not silent. Expected effect on the Reklaim job: ~50K resent tokens per turn instead of ~115K.

Tests: TestRun_ResendBudget_ScheduledCompactsWithoutOptIn (run-loop, event payload + breadcrumb), TestCheckContextPressure_ResendBudgetIsScheduledOnly (interactive ignores; scheduled compacts; 0 disables), TestCheckContextPressure_WindowCompactionNamesTrigger, TestContextResendBudgetTokensKnob; existing context/compaction suites green; vet + golangci-lint clean.

🤖 Generated with Claude Code

…exceeds a token budget

Compaction fired only on context-WINDOW pressure (90% of the model's window),
and scheduled runs only warned unless FLEET_SCHEDULED_AUTO_COMPACT=1. A
1M-window model never reaches 90% in a 100-turn run, yet every one of those
turns resends and pays for the whole transcript: the Reklaim health scan
(6bd0c212) resent ~115K tokens per call for 99 calls at an 11% cache-hit
rate — 11.35M prompt tokens, $8.29, mostly re-reading its own history. No
compaction ever ran (#1534).

Scheduled runs (the driver-supplied requireCompactionOptIn marks them) now
also compact — the same oldest-half summary through the same governed
summarizer — once the resent prompt (LastStepPromptTokens, the anti-spiral
signal the window path already uses) exceeds FLEET_CONTEXT_RESEND_BUDGET_TOKENS
(default 80K; 0 disables). This is a cost control, not a safety valve, so it
is deliberately NOT behind the SCHEDULED_AUTO_COMPACT opt-in, which keeps
guarding the window-pressure path; interactive chats are untouched. The
fleet.context_compacted event and the [context_compacted] session breadcrumb
carry trigger=resend_budget with the measured size and the budget, and the
window path now labels its own compactions trigger=window.

The per-result lever the issue also asked for already exists as the
max_tool_output_bytes admin setting (default 64 KiB); the docs now point at
it for jobs that keep rendering 40 KB documents into return_vars.

TestRun_ContextPressure_ScheduledWarnsOnlyWithoutFlag pins the window
contract and now disables the budget trigger explicitly; the budget trigger
has its own tests.

Closes #1534

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@obsessixnv
obsessixnv enabled auto-merge (squash) September 17, 2026 18:45
@obsessixnv
obsessixnv merged commit 7a8ad81 into main Sep 17, 2026
21 checks passed
@obsessixnv
obsessixnv deleted the feat/1534-resend-budget-compaction branch September 17, 2026 18:54
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.

Cost-aware compaction and tool-output bounds for large-window models; scheduled compaction is opt-in and window-pressure-only

1 participant