fix(core): restore session request headers (#43188)

This commit is contained in:
Filip
2026-08-18 21:27:28 +02:00
committed by GitHub
parent ad905f8e6c
commit 0033bb3559
3 changed files with 55 additions and 0 deletions
+1
View File
@@ -202,6 +202,7 @@ export const make = (dependencies: Dependencies) => {
.stream(
LLM.request({
model: input.model,
http: input.request.http,
messages: [Message.user(summaryPrompt)],
tools: [],
generation: { maxTokens: summaryOutput },
+7
View File
@@ -204,6 +204,13 @@ const layer = Layer.effect(
const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id
const request = LLM.request({
model,
http: {
headers: {
"x-session-affinity": session.id,
"X-Session-Id": session.id,
...(session.parentID ? { "x-parent-session-id": session.parentID } : {}),
},
},
providerOptions: { openai: { promptCacheKey } },
system: [agent.info?.system, system.baseline]
.filter((part): part is string => part !== undefined && part.length > 0)
+47
View File
@@ -1101,6 +1101,16 @@ describe("SessionRunnerLLM", () => {
yield* session.resume(sessionID)
expect(requests).toHaveLength(2)
expect(requests.map((request) => request.http?.headers)).toEqual([
{
"x-session-affinity": sessionID,
"X-Session-Id": sessionID,
},
{
"x-session-affinity": sessionID,
"X-Session-Id": sessionID,
},
])
expect(userTexts(requests[0])[0]).toContain("## Objective")
expect(userTexts(requests[1])).toHaveLength(1)
expect(userTexts(requests[1])[0]).toContain("<summary>\n## Objective\n- Preserve the task\n</summary>")
@@ -2508,6 +2518,43 @@ describe("SessionRunnerLLM", () => {
}),
)
it.effect("adds session correlation headers to model requests", () =>
Effect.gen(function* () {
yield* setup
const session = yield* SessionV2.Service
yield* session.prompt({ sessionID, prompt: Prompt.make({ text: "Run correlated request" }), resume: false })
requests.length = 0
yield* session.resume(sessionID)
expect(requests[0]?.http?.headers).toEqual({
"x-session-affinity": sessionID,
"X-Session-Id": sessionID,
})
}),
)
it.effect("adds the parent session header to child model requests", () =>
Effect.gen(function* () {
yield* setup
const session = yield* SessionV2.Service
const parentID = SessionV2.ID.make("ses_runner_parent")
const { db } = yield* Database.Service
yield* db
.update(SessionTable)
.set({ parent_id: parentID })
.where(eq(SessionTable.id, sessionID))
.run()
.pipe(Effect.orDie)
yield* session.prompt({ sessionID, prompt: Prompt.make({ text: "Run child request" }), resume: false })
requests.length = 0
yield* session.resume(sessionID)
expect(requests[0]?.http?.headers?.["x-parent-session-id"]).toBe(parentID)
}),
)
it.effect("bounds 64-character session prompt cache keys", () =>
Effect.gen(function* () {
yield* setup