fix(agent): bound agent working context with autoCompactWindow#855
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(agent): bound agent working context with autoCompactWindow#855posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The anthropic harness enables the 1M-context beta so compaction has room to run on large projects, but set no working-context bound. Once the LLM gateway began honoring the beta, the SDK deferred auto-compaction toward the 1M ceiling, so long linear runs' per-generation input climbed past 600K and per-generation cost more than doubled. Pin `settings.autoCompactWindow` to 200K so compaction fires at a bounded working size while the 1M physical window still gives the compaction step headroom, returning per-generation input to the prior band. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Generated-By: PostHog Code Task-Id: 3584c98f-82b2-4d62-867c-ed7d99705d99
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On 2026-07-09 around noon Pacific, the wizard's
claude-sonnet-4-6per-generation input context jumped from the prior ~110K band to ~400K+ and daily spend on the model roughly doubled — a sustained cost regression reaching hundreds of users.Root cause: the anthropic harness enables the 1M-context beta (
context-1m-2025-08-07) so compaction has physical headroom to succeed on large projects, but it set no bound on the working-context size. The beta has been requested since April, but once the LLM gateway began honoring it, the SDK's auto-compaction ceiling effectively moved from ~200K toward ~1M. Long linear runs then stopped compacting at a sane point — per-generation input climbed past 600K on the most expensive traces — and per-generation cost more than doubled.Confirmed against production
$ai_generationdata: the tool-definitions payload was unchanged across the boundary (ruling out the MCP tools-mode pin), while pre-noon traces showed a compaction sawtooth bounded near ~85–180K and post-noon traces grew monotonically with no compaction.Changes
settings.autoCompactWindow(newAGENT_AUTO_COMPACT_WINDOW, 200K) to the SDKquery()in the anthropic harness. This decouples the working window the model pays for from the physical window: the 1M beta still gives the compaction step room to run, while auto-compaction now fires at a bounded size — returning per-generation input to roughly the pre-1M band.CONTEXT_1M_BETAconstant and reuse it at the three sites that set it.piharness drives its own compaction (pi-coding-agent), so this SDK guard does not apply there — flagged as a separate follow-up.Test plan
autoCompactWindowto 100K–1M and silently ignores values outside it, which would quietly reinstate the regression).pnpm build && pnpm test— 1307 tests pass;pnpm lint— 0 errors.claude-sonnet-4-6per-generation input tokens return near the ~110K band.Created with PostHog Code from an inbox report.