Repository navigation
fix(gjc): turn on adaptive compaction so long sessions stop resending their prefix - #163
Merged
Merged
Conversation
… their prefix The runtime ships adaptive compaction off for backward compatibility, so the only trigger is the legacy reserve threshold - roughly `contextWindow - reserve` and commonly near 85% of the window. On a 1M-token model that is ~850K, which a long app session never reaches: it grows its prefix for hundreds of turns and resends all of it every turn. A measured 681-turn run on claude-opus-5 peaked at 644K context (64% of the window), never compacted once, and spent $125.18 of its $140.95 on cache reads - 88.8% of the bill to re-read its own history, against $6.76 of output. Per-turn cacheRead grew monotonically from 96K to 644K with no plateau. The runtime's own guidance names this exact case: adaptive compaction "targets long sessions where a 150K-230K context can otherwise be resent many times before hitting the static threshold". The values here are the starting point it recommends for long, tool-heavy sessions. App sessions cannot opt in for themselves - the app tells them to use Settings instead of editing ~/.gjc, and Settings has no compaction control - so the app picks the default. `has()` is true only for loaded settings and overrides, never schema defaults, so a user who did configure compaction keeps every value they set. This is a default the app chooses, not a boundary it enforces. Both contract fixtures needed `has` on their settings clones; without it every session creation threw, which is the same trap the existing comment records for `override`. Refs #159
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.
Closes #159.
The bug
The runtime ships
compaction.adaptive.enabledoff for backward compatibility. With it off the only trigger is the legacy reserve threshold, roughlycontextWindow - reserveand commonly near 85% of the window.anthropic/claude-opus-5has a 1,000,000 token window, so the trigger sits around 850K — and a long app session never gets there. It grows its prefix for hundreds of turns and resends all of it every turn.Measured on app session
01a0aaca-e1c4-74fb-8a41-a85d5fd35954, 681 billed turns from one user message:Per-turn cacheRead never plateaus:
681 turns, zero compaction records in the transcript. 80% of turns read more than 200K from cache. $125.18 was spent re-reading the session's own history against $6.76 of actual output.
Why the app has to decide this
The runtime's own doc names this case exactly:
...and recommends, for long tool-heavy sessions, precisely the values used here (base 75, aggression 0.2, window 15, floor 50). It leaves the shipped default off "for exact legacy behavior".
App sessions are the long tool-heavy case and cannot opt in for themselves: the app's own system prompt tells users to use Settings rather than edit
~/.gjc, and Settings exposes no compaction control. So the app picks the default.What this is not
This is a default the app chooses, not a boundary it enforces. Unlike the five overrides in
applyGjcToolSettingsPolicy, each value is guarded bysettings.has()— true only for loaded settings and runtime overrides, never for schema defaults. A user who did configure compaction keeps every value they set, includingenabled: false.Delegated child sessions are untouched:
gjc-delegation-executor.tsdisables compaction for them deliberately, and they are bounded by their receipt.Verification
New tests:
adaptive compaction is on for a session that configured none— also asserts the runtime default is stillfalse, so this policy gets revisited if upstream flips it.a user who configured compaction keeps every value they seta partially configured session keeps its own value and gets the restthe compaction policy leaves the tool boundary alonestarting a session turns adaptive compaction on— the livesession.startpath, not just the function.Both contract fixtures needed
hason their settings clones. Without it every session creation threw and 70 tests failed — the same trap the existing fixture comment already records foroverride.