Skip to content

fix(core): share child prompt cache affinity - #50495

Merged
rekram1-node merged 1 commit into
v2from
inspect-cache
Sep 22, 2026
Merged

rekram1-node merged 1 commit into
v2from
inspect-cache

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

  • use the parent session ID as the prompt cache affinity key for child sessions
  • preserve existing top-level and fork cache affinity behavior
  • cover child runner and compaction requests

Testing

  • bun typecheck (packages/core)
  • focused session runner cache-affinity tests
  • bun test test/session-compaction.test.ts
  • bun run check

@rekram1-node

Copy link
Copy Markdown
Collaborator Author

Validated with real OpenAI gpt-4.1-mini sessions in an isolated A/B against the pre-PR commit.

Fixture:

  • empty temporary project and dedicated SQLite database
  • project config discovery, MCPs, and unrelated tools disabled
  • three fresh foreground general children under one parent
  • identical model, system prompt, and user prompt
  • children created sequentially with sessionID omitted
  • static prompt deliberately above OpenAI's 1,024-token cache threshold

OpenAI-reported child usage:

Build Child 1 cache read Child 2 cache read Child 3 cache read
pre-PR 0 0 0
PR 0 4,992 4,992

Each child request contained about 6,319 prompt tokens. On the PR, warmed siblings reported about 1,324 uncached input tokens plus 4,992 cached tokens; before the PR every sibling reported the full ~6,319 as uncached. This confirms that parent-derived affinity produces real cross-child cache reuse.

The remaining uncached ~1.3k tokens are consistent with the separate early session-ID/system-context prefix divergence and are intentionally outside this PR.

@rekram1-node
rekram1-node merged commit 94b9133 into v2 Sep 22, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the inspect-cache branch September 22, 2026 03:44
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