fix(core): bound prompt cache session keys

This commit is contained in:
Kit Langton 2026-06-05 23:11:45 -04:00
commit ff5874f812
2 changed files with 38 additions and 1 deletions

View file

@ -2824,6 +2824,42 @@ describe("SessionRunnerLLM", () => {
}),
)
it.effect("bounds external session prompt cache keys", () =>
Effect.gen(function* () {
yield* setup
const externalSessionID = SessionV2.ID.fromExternal({
namespace: "discord",
key: "thread-one",
})
const otherExternalSessionID = SessionV2.ID.fromExternal({
namespace: "discord",
key: "thread-two",
})
yield* insertSession(externalSessionID)
yield* insertSession(otherExternalSessionID)
const session = yield* SessionV2.Service
yield* session.prompt({
sessionID: externalSessionID,
prompt: new Prompt({ text: "Run external session" }),
resume: false,
})
yield* session.prompt({
sessionID: otherExternalSessionID,
prompt: new Prompt({ text: "Run other external session" }),
resume: false,
})
requests.length = 0
yield* session.resume(externalSessionID)
yield* session.resume(otherExternalSessionID)
const keys = requests.map((request) => request.providerOptions?.openai?.promptCacheKey)
expect(keys).toEqual([externalSessionID.slice(4), otherExternalSessionID.slice(4)])
expect(keys.every((key) => typeof key === "string" && key.length === 64)).toBe(true)
expect(keys[0]).not.toBe(keys[1])
}),
)
it.effect("fans out one failed run and allows a later retry", () =>
Effect.gen(function* () {
yield* setup