fix(claude): keep subagent and cumulative usage off the context meter - #185
Merged
Conversation
Claude subagent usage could replace the parent session's active context count and select a child's larger model window. Cumulative result usage could also force the meter to 100% when a turn ended. Scope active usage to the parent session, preserve monotonic processed totals, and prefer the last per-request snapshot at completion. Mark Claude usage as automatically compacting. Ports upstream pingdotgg#8453 and pingdotgg#8617.
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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
The Claude context meter lied in three ways. A subagent's cumulative
total_tokensfromtask_progresswas written into the parent'susedTokensthroughMath.max, so the ring spiked to 100% on every subagent tick and only settled once the parent's next request arrived. The context window was picked as the largest across every model inmodelUsage, subagents included. And when a turn ended without a captured parent assistant usage,completeTurnfell back to session-cumulativeresult.usage, which clamps to the max.Fix
Subagent totals now only advance
totalProcessedTokens. The window is looked up by the model actually serving the session (tracked frominit, refusal retries, andsetModel), and a mid-thread model switch refreshes the known window immediately so live deltas are not clamped against the old model until the turn ends. At turn end the last per-request reading wins over the cumulative result. Claude snapshots now assume auto-compact is on, as the Codex adapter already does, which restores the tooltip line that went silent whengetContextUsagewas removed in pingdotgg#8610.Ports upstream pingdotgg#8453 and pingdotgg#8617 as a fork carry. Upstream's comments and code shape are kept verbatim so both land as auto-merges. The only fork-only lines are the
compactsAutomaticallyflag and the window refresh on switch. Drop this delta when upstream merges.Verification
vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts: 123 passedvp run typecheck: passedvp check: passedImplemented by gpt-5.6-sol in Claude Code. Reviewed by gpt-5.6-sol (correctness) and Fable 5.1 (merge cost), findings applied in the second commit.