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

This commit is contained in:
Aiden Cline
2026-09-21 22:44:43 -05:00
committed by GitHub
Unverified
parent 6f8c5ae0aa
commit 94b9133910
3 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -229,7 +229,7 @@ export const layer = Layer.effect(
const entries = Object.entries(shaped.options)
const generation = Object.fromEntries(entries.filter(([k]) => GENERATION_KEYS.has(k))) as GenerationOptionsFields
const providerOptions = Object.fromEntries(entries.filter(([k]) => !GENERATION_KEYS.has(k)))
const root = session.fork?.sessionID ?? session.id
const affinity = session.parentID ?? session.fork?.sessionID ?? session.id
const base = LLM.request({
model: model.model,
http: {
@@ -244,7 +244,7 @@ export const layer = Layer.effect(
},
},
// TODO: Persist cache lineage so nested forks reuse the root session's cache key.
promptCacheKey: /^ses_[0-9a-f]{64}$/.test(root) ? root.slice(4) : root,
promptCacheKey: /^ses_[0-9a-f]{64}$/.test(affinity) ? affinity.slice(4) : affinity,
system: shaped.system,
messages: boundImages(unsupportedParts(shaped.messages, model.capabilities)),
tools: Array.from(hooked, ([name, t]) => ({ ...t, name })),
@@ -397,7 +397,7 @@ it.effect("manual compaction summarizes short context instead of no-op", () =>
])
expect(requests).toHaveLength(1)
expect(requests[0]?.promptCacheKey).toBe(sessionID)
expect(requests[0]?.promptCacheKey).toBe(parentID)
expect(requests[0]?.http?.headers).toEqual({
"x-session-affinity": sessionID,
"X-Session-Id": sessionID,
+2 -1
View File
@@ -4411,7 +4411,7 @@ describe("SessionRunnerLLM", () => {
})
})
scenario("adds the parent session header to child model requests", function* (s) {
scenario("uses parent cache affinity for child model requests", function* (s) {
const parentID = Session.ID.make("ses_runner_parent")
yield* s.db
@@ -4423,6 +4423,7 @@ describe("SessionRunnerLLM", () => {
yield* s.runPrompt("Run child request")
expect(s.requests[0]?.http?.headers?.["x-parent-session-id"]).toBe(parentID)
expect(s.requests[0]?.promptCacheKey).toBe(parentID)
})
scenario("runs different sessions concurrently", function* (s) {