zcode: name the conversation in x-session-id as a bare UUID, so BigModel's prompt cache hits (#388)
ZCode's client names every request's conversation in x-session-id: a bare UUID, the same on each turn (3.14.3 xst/Tst). BigModel keeps a prompt's cache for the requests that name the same session. The plugin sent none, so a long conversation seldom hit the cache (#387). Every zcode request, on the Start Plan and on Coding Plan or team seats alike, now carries it: - the agent's session (chat.headers' sessionID, which magpie fills) goes as it is when it is a UUID, lower-cased; - any other id (magpie-<hex>, ses_..., sess_...) goes as a stable UUID made from its sha256; - with no session, a UUID made from the device. metadata.user_id's session_id is the same UUID, in dress() and marked(). Reviewed at 48013c0, which addresses all four points of the earlier review (UUID shape, session_id in user_id, rebase onto 0.1.30, no "Closes #387"): - TMPDIR=<scratch> HOME=$(mktemp -d) bun test in packages/zcode: 125 pass, 0 fail. bun scripts/check.mjs zcode passes. Merges cleanly onto main. - With main's index.mjs and the PR's tests: 17 fail (all 7 new session tests, plus the start, userid and dual assertions on the header). - Probe through the plugin's chat.headers and loader fetch, as magpie's host calls them (host.js passes sessionID and sets out.headers before the fetch): magpie-<hex> twice gives the same UUID in the header and in user_id.session_id, and ses_other gives a different UUID. None contains magpie, ses_ or sess_. Not tried: a real BigModel request (the author's hit-rate numbers are the evidence: 3/12 before, 24/24 after through magpie).
This commit is contained in:
@@ -69,7 +69,9 @@ const userIdOf = (b) => JSON.parse(JSON.parse(b).metadata.user_id)
|
||||
test("a coding plan's Messages request names the sign-in's device, as ZCode's does", async () => {
|
||||
const { body, path } = await send(signedIn, pi())
|
||||
expect(path).toBe("/open.bigmodel.cn/api/anthropic/v1/messages")
|
||||
expect(userIdOf(body)).toEqual({ device_id: DEVICE, account_uuid: "", session_id: "" })
|
||||
const { sessionOf } = require("./index.mjs")._internal
|
||||
// and the conversation, as x-session-id names it; Pi named none (#387)
|
||||
expect(userIdOf(body)).toEqual({ device_id: DEVICE, account_uuid: "", session_id: sessionOf("", DEVICE) })
|
||||
// the rest of the request is the agent's, as it sent it
|
||||
const b = JSON.parse(body)
|
||||
delete b.metadata
|
||||
|
||||
Reference in New Issue
Block a user