b2fe48ea2e8bf6c5beda207e169f2eecdc308b5c
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2b56b3bc4f |
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). |
||
|
|
57598ad410 |
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.
|
||
|
|
b07478285c |
zcode 0.1.28: a key's route is read again with each card read, after a Start Plan refusal, and a minute after one list without its plan (#369, #379)
Also publishes #371 (a team seat lists the person's gift plans and their
-Trial models,
|
||
|
|
cc0bd902b3 |
zcode 0.1.26: a gift's -Trial models are listed when ZCode's config is out of reach, a failed gift read is asked again in a minute, and a card with no ZCode session says the gift needs one
bigsteven (Discord #feedback, 10-24): GLM Coding Plan spent, requests go to it, and the model list has no GLM-5.3-Trial. Which sign-in the account has is still asked; three ways the plugin drops a signed-in account's -Trial entries, or drops them unsaid, are fixed here: - ZCode's provider config out of reach (cdn-zcode.z.ai, 8s): the list falls back to the table and is marked magpie.fellBack, and magpie then keeps the list it was told last (internal/plugin/providers.go), from before the gift. The -Trial entries just read from the balance went with it. A list that carries trial entries is no longer marked. - A gift balance read that failed was cached as "no gift" for ten minutes beside a good plan list, so one hiccup hid the -Trial entries and the gift's card section for ten minutes. It is now unknown and asked again in a minute (an expired session is known, and kept for ten). - A key, or a sign-in whose ZCode session has expired (that token can't be renewed, and with a key beside it the account is never marked), reads no gift, so it lists no -Trial models, and the card said nothing. Its card now sets aside a line "ZCode gift plans (-Trial models) need ZCode's sign-in", with why in the display (an API key / no ZCode session / sign-in expired). Run: HOME=<scratch> bun test packages/zcode: 102 pass (3 new tests); bun scripts/check.mjs zcode ok. Broken by hand: each of the three fixes reverted alone turns its tests red (fellBack 1, retry 2, card line 1), restored after. Changed on purpose: dual.test's "a gift read that fails at once still trusts the plan list for ten minutes" now says a minute; usage.test's key and key-only oauth cards carry the new line. Not tried: a real account (no ZCode sign-in with a gift in this session), nor a real CDN failure; the config fallback was forced in the test through _internal.config(null). The new line's name is not yet in magpie's i18n. A team-seat sign-in (an account with no plan of its own) still lists no -Trial entries; not changed here. |
||
|
|
1f8d38b8cd |
zcode 0.1.23: with two gift plans each bucket is named by its plan, and the live ones come first
01huadalang (Discord #feedback, 10-24): an account with the 1024 plan and
the new-user plan showed GLM-5.3 at 0 once the new-user plan's GLM-5.3 was
used up, and never showed the 1024 plan's GLM-5.3.
Cause: the plugin already kept every live plan's buckets (giftOf) and
counted a model on the live one (bestBuckets), setting the spent one aside.
But every window was named by its bucket's show_name alone, so both read
"GLM-5.3", and the windows went out in the balance's order: the new-user
plan's spent GLM-5.3 and its Flash first, the 1024 plan's after. magpie's
account row shows a card's first two windows and puts the rest in its
tooltip, so the row showed the spent GLM-5.3 at 0 and the 1024 plan's
allowance was out of sight, and where both showed they couldn't be told
apart.
Fix (startUsage and dualUsage alike): when the gift's buckets come from
more than one plan, each window is named "<plan> · <bucket>" ("ZCode 1024
Dev Day · GLM-5.3"); one plan's buckets keep their own names, as before.
The windows a request spends go before those set aside, each group in the
balance's order. A used-up plan still shows, at 100% used, set aside.
The 1024 plan's plan_id, name, show_names, capabilities and grant_units in
the new fixture are real bytes: the owner's account read
/billing/preview (read-only GET, credentials read in memory, nothing
written) and is offered "ZCode 1024 Dev Day" (zcode-v3-start-plan-1024,
GLM-5.3-Flash 300M, GLM-5.3 200M). That account has no active plan, so
its /billing/balance is empty; the balance rows are written in the shape
the existing fixtures use, and the new-user plan's name is the Start
Plan's from ganlerk's balance. The reporter's real balance wasn't seen.
Run at this head (parent
|
||
|
|
dbd14ccb98 |
zcode 0.1.9: the gift's models are trial entries the user picks, not an automatic gift-first route (#21)
Why: 0.1.8 sent every request for a gift-served model to the gift first, so a user who meant to spend the coding plan had no say, and the card hid the gift's models behind notModels. The gift is an allowance outside the plan; spending it should be a choice. What: every model a live gift bucket serves is listed again as <model>-Trial, in the catalog's spelling (GLM-5.3-Flash-Trial), and a request for that entry goes to the gift dressed as ZCode's own; a plain model always spends the coding plan. A trial entry whose bucket is spent or blocked answers 429 without touching the coding plan, as do the gift's quota errors (1113, 1005 inside a 200); any other gift answer goes on as it came. The usage card names the gift window by its trial model, drops the plan prefix, and puts MCP - Month last. Tests: dual.test.mjs rewritten for the new routing (a plain model to the coding plan whatever the gift holds, a trial entry to the gift), usage.test.mjs and gift.test.mjs follow the naming; bun test (65 pass in the package, 516 in the repo) and bun scripts/check.mjs zcode pass. |
||
|
|
d22ac2039a |
zcode 0.1.8: spend an account's gift plans before its GLM Coding Plan, and show both on the usage card (#19)
Why: a GLM Coding Plan account can also hold gift plans from ZCode activities (a "Trust Build" grant, say). They lapse on a fixed date, and every request went to the coding plan, so their allowance went unspent. What: plansOf now reads the gift's balance (per the ZCode session, kept 10 minutes) and takes the union of the models every live bucket of every active gift plan still serves (not expired, remaining_units > 0). A request for a model the gift serves goes to the Start Plan first, dressed as ZCode's own client; when the gift can't serve it — any answer 400 or over, or its quota error inside an HTTP 200 (code 1113/1005) — the request is replayed once to the coding plan as the agent sent it. Only a quota answer keeps that model off the gift for a minute; a 405 refusal is asked again next request. The usage card shows the coding plan's windows and the gift's buckets together, each bucket prefixed with its plan's name; a gift read that fails leaves just the coding card. A pure gift account (no coding plan) behaves as before. Tests: dual.test.mjs, 14 tests — routing, replay, the 60s quota block, the 200-with-quota-error case, stream passthrough, an expired ZCode session, the cache TTLs, a multi-plan union and a gift-only account; HOME=$(mktemp -d) bun test (37 pass) and bun scripts/check.mjs zcode pass. |