fix(core): drop session ID and order instructions for prompt-cache reuse - #51960
Merged
Merged
Conversation
rekram1-node
enabled auto-merge (squash)
September 29, 2026 00:29
rekram1-node
disabled auto-merge
September 29, 2026 00:29
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.
The instructions baseline started with the
<env>block, and its first line was the session ID. So every session's prompt differed from the start of the instructions block, and nothing after it could be reused from cache across sessions. In particular, sibling subagents with identical instructions never shared a cached prefix.This PR removes the session ID from
<env>and orders the instruction sources from most to least shared across sessions. The date and environment go last, just before per-session API entries, because the date changes daily and the environment by directory. Built-in session tools default to the current session, and cross-session prompts record their origin, so the model doesn't need its own ID. Removing it also fixes forks, which started out showing their source session's ID.What the model sees
Existing sessions re-render their baseline once in the new order. The removed line shows up as one appended environment update.
How we measured it
We replayed recorded V2 usage offline: 2,372 sessions over 63 days, 124k model steps across 86 projects. The data comes from one heavy user, and one project is 91% of the sessions, but every project with 15 or more cold starts ranks the layouts the same way.
Instructionsrenderers. The result matched recorded update text byte for byte (Code Mode 59/59, env 13/13, date 8/8, AGENTS.md 10/10), with 0 hash mismatches across 2,672 stored values.prompt_cache_key. We also modeled an optimistic variant that ignores routing.Results
Share of the static prefix served from cache on cold starts, with 95% intervals and a 1-hour cache lifetime unless noted:
For sibling subagents, the pairs with realistic reuse under key routing, OpenAI prefix reuse goes from 38% to 93–95%.