Skip to content

fix: exempt sub-agent sessions from cache warming#340

Merged
BYK merged 2 commits into
mainfrom
fix/subagent-cache-warming-exemption
May 15, 2026
Merged

fix: exempt sub-agent sessions from cache warming#340
BYK merged 2 commits into
mainfrom
fix/subagent-cache-warming-exemption

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 15, 2026

Summary

  • Sub-agent sessions (OpenCode explore/general agents) are ephemeral (1-3 turns) — cache warming is wasted work for them
  • Adds explicit isSubagent flag on SessionState, set from x-parent-session-id header, and checks it in both the idle loop (early skip before expensive work) and shouldWarm() (belt-and-suspenders)
  • Also adds early messageCount check in the idle loop to skip all short sessions before profile/histogram computation — a general optimization that benefits non-sub-agent short sessions too

Approach

Two-layer exemption:

  1. Explicit isSubagent flag — set on SessionState when x-parent-session-id is detected in the request headers during handleConversationTurn(). Checked in shouldWarm() to block warming unconditionally, even with /keep force.

  2. Early idle loop skip — both isSubagent and messageCount < MIN_TURNS_FOR_WARMING * 2 are checked before loadGlobalHistograms(), resolveProfile(), and blendedHistogramForSession(), avoiding wasted computation. Previously, shouldWarm() rejected these sessions but only after all the expensive prep work.

Files changed

File Change
packages/gateway/src/translate/types.ts Add isSubagent?: boolean to SessionState
packages/gateway/src/pipeline.ts Set isSubagent from x-parent-session-id header
packages/gateway/src/idle.ts Early skip for sub-agent + low-turn sessions in warmup loop
packages/gateway/src/cache-warmer.ts isSubagent guard in shouldWarm()
packages/gateway/test/cache-warmer.test.ts 2 new tests for sub-agent exemption (normal + /keep)
packages/gateway/test/helpers/idle-worker.ts Add MIN_TURNS_FOR_WARMING to cache-warmer mock

BYK added 2 commits May 15, 2026 13:37
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)
@BYK BYK merged commit 8e32207 into main May 15, 2026
7 checks passed
@BYK BYK deleted the fix/subagent-cache-warming-exemption branch May 15, 2026 13:47
This was referenced May 15, 2026
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.

1 participant