zcode 0.1.30: a coding plan's requests name the device in metadata.user_id, as ZCode's do (#387)
wendyeq measured BigModel's GLM Coding Plan through magpie hitting the
prompt cache 1 time in 19 without metadata.user_id and 13 in 16 with it;
the official ZCode on the same account reads 95-98% of input from cache.
The plugin only put user_id on the Start Plan's dressed body; a coding
plan or team request went as the agent sent it, and Pi sends none.
ZCode 3.14.3 (glm/zcode.cjs) sets it on every Anthropic-format request,
not only the Start Plan's: Pst() returns MLs({deviceMid, sessionId}) for
any providerKind "anthropic", and vWr() puts it in
providerOptions.anthropic.metadata.userId for both generateText and
streamText. The value is {"device_id":<machine id>,"account_uuid":"",
"session_id":...}.
Now a coding plan or team request to .../v1/messages gets
metadata.user_id = {"device_id":<sign-in's saved device>,
"account_uuid":"","session_id":""}, the same value dress() puts on the
Start Plan's, when the agent sent no user_id of its own; other metadata
is kept and content-length dropped when the body changed. count_tokens
and non-Messages bodies go as they were. An account known only by a key
(a pasted API key, or a saved state with no device) gets a device id
hashed from the key, so it is the same on every start rather than
anyDevice, which was new per process.
Differences from ZCode, kept on purpose: ZCode overwrites any user_id
and fills session_id with its session (sess_ prefix stripped); this
keeps an agent's own user_id and sends session_id "" as dress() does,
one stable value per account.
Tests: userid.test.mjs (new, 6 tests; 5 red on origin/main's index.mjs,
the count_tokens one passes there as it should). start, toolsearch and
dual tests that pinned coding plan bodies byte for byte now expect the
agent's body plus the device's user_id.
Run at this tree: HOME=$(mktemp -d) bun test -> 2672 pass, 1 skip,
0 fail across 229 files; bun scripts/check.mjs ok.
Not tried: a real BigModel or Z.ai coding plan request, so the cache
hit rate after the change is the reporter's measurement, not mine.
This commit is contained in:
@@ -25,7 +25,12 @@ over Anthropic's Messages API. Provider id: `zcode`.
|
||||
agent's system prompt at the end of the third (a fourth block is
|
||||
refused, #343), the day in a `<system-reminder>` turn before the agent's
|
||||
turns, and the sign-in's device id in `metadata.user_id`. GLM Coding
|
||||
Plan and team requests go as the agent sent them. zcode.z.ai also
|
||||
Plan and team requests go as the agent sent them, but for that same
|
||||
`metadata.user_id` when the agent sent none: ZCode puts it on every
|
||||
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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user