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:
wendyeq
2026-10-26 16:02:38 +08:00
committed by GitHub
parent 6bd998a3f8
commit 2b56b3bc4f
6 changed files with 185 additions and 27 deletions
+10 -1
View File
@@ -30,7 +30,8 @@ over Anthropic's Messages API. Provider id: `zcode`.
request, and the plan's endpoint keeps a prompt cache on the machine it
picks by it, so without it the cache is mostly missed (#387). An
account known only by its key gets a device id made from the key, the
same on every start. zcode.z.ai also
same on every start. Every request also carries the `x-session-id`
header below. zcode.z.ai also
answers 405 code 3012 to every request of an account its risk control
blocked, ZCode's own app's included (plugins#348). That answer comes
back as ZCode's words, then "ZCode's risk control blocked this account
@@ -40,6 +41,14 @@ over Anthropic's Messages API. Provider id: `zcode`.
firewall says this network's address was blocked instead.
- The Start Plan's token can't be refreshed. When it runs out, sign in
again.
- Every request, on any plan, names its conversation in `x-session-id`,
as ZCode does: a bare UUID, the same on each turn. BigModel's prompt
cache follows it: without it a long conversation's turns hit the cache
about one time in twenty, with it nearly every turn (#387). The
agent's own session id (magpie tells it to the plugin) goes as it is
when it is a UUID, else as a UUID made from it, so the vendor sees
only ZCode's format; with none, a UUID made from the device. The same
id is `metadata.user_id`'s `session_id`, as in ZCode's requests.
- **ZCode: a team's GLM Coding Plan**
- For an account with a plan of its own and a seat on a team's plan
(#285). The sign-ins above take the account's own plan, as ZCode does