fix: exempt sub-agent sessions from cache warming#340
Merged
Conversation
Sub-agent sessions (OpenCode explore/general agents) are ephemeral (1-3 turns), making cache warming wasted work. Two-layer exemption: 1. Explicit isSubagent flag on SessionState, set when x-parent-session-id header is present. Checked in shouldWarm() as a belt-and-suspenders guard that blocks warming even with /keep force. 2. Early skip in the idle tick warmup loop — both isSubagent and messageCount < MIN_TURNS_FOR_WARMING*2 are checked before the expensive resolveProfile/loadGlobalHistograms/blendedHistogram work, avoiding wasted computation for all short sessions.
- Add 'Sub-agent session (ephemeral)' to computeWarmingSnapshot's notWarmingReason chain for dashboard debuggability - Fix JSDoc on isSubagent: 'created with' -> 'carried' (detection happens on any turn, not just session creation)
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.
Summary
isSubagentflag onSessionState, set fromx-parent-session-idheader, and checks it in both the idle loop (early skip before expensive work) andshouldWarm()(belt-and-suspenders)messageCountcheck in the idle loop to skip all short sessions before profile/histogram computation — a general optimization that benefits non-sub-agent short sessions tooApproach
Two-layer exemption:
Explicit
isSubagentflag — set onSessionStatewhenx-parent-session-idis detected in the request headers duringhandleConversationTurn(). Checked inshouldWarm()to block warming unconditionally, even with/keepforce.Early idle loop skip — both
isSubagentandmessageCount < MIN_TURNS_FOR_WARMING * 2are checked beforeloadGlobalHistograms(),resolveProfile(), andblendedHistogramForSession(), avoiding wasted computation. Previously,shouldWarm()rejected these sessions but only after all the expensive prep work.Files changed
packages/gateway/src/translate/types.tsisSubagent?: booleantoSessionStatepackages/gateway/src/pipeline.tsisSubagentfromx-parent-session-idheaderpackages/gateway/src/idle.tspackages/gateway/src/cache-warmer.tsisSubagentguard inshouldWarm()packages/gateway/test/cache-warmer.test.tspackages/gateway/test/helpers/idle-worker.tsMIN_TURNS_FOR_WARMINGto cache-warmer mock