Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/session/model-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 })),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/session-compaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/session-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Loading