e4e9eb0928becfa4e48484dde85ef5032671d582
368
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2926b7beff |
usage, routing: the model id a request went out under is kept and shown
daoche_wuzui on X asked how magpie serves Antigravity and whether a
request goes out under a suffixed model: nothing showed the id actually
sent. Antigravity's plugin turns gemini-3.7-flash at high effort into
gemini-3.7-flash-high, and a relay's upstream name (ModelWires) renames
a model too; the ledger and Routing showed only the routed model.
- A plugin's reply may carry X-Magpie-Sent-Model
(provider.SentModelHeader). forward() reads it from plugin providers
only (a non-plugin's header is ignored) and deletes it, so it never
reaches the agent. Without it, provider.SentNameOnIn (the upstream
name, or Antigravity's variant) is used.
- wireName keeps the id only when it differs from the model. It goes in
usage.Record.Wire (`wire`, omitempty), the trace's Try.Wire, the
ledger cache and a last CSV column, sent_model (docs/reference.md).
- Usage › Requests: the Sent cell and the detail show the sent id when
there is one, with "model → sent id" on hover. Routing: a try sent
under another id gets one aside line, "Sent to the vendor as {model}"
(zh, zh-TW, ja, de).
- Antigravity's mover min is 0.2.4: plugins 67fb1258 sets the header on
every reply (stream, whole and errors); its tgz is on the plugins
repo's dist branch.
Run at this head (
|
||
|
|
f1e2ada0f7 |
usage: GPT-6.2's Ultrafast is priced at OpenAI's 3x, then 6x from March 1st (mu33410 on X)
mu33410 on X asked whether the cost magpie shows is adjusted for GPT's fast modes. Mostly it was: a call is priced at the tier its reply named (else the one sent, which is what a Codex/ChatGPT row has) from models.dev's experimental.modes, on every route (Responses, Chat Completions, the Responses WebSocket, which goes through the same handler, and Codex's backend), in the Usage page, a key's spend limit and a subscription window's API value. Checked against OpenAI's pricing page: Fast (priority) is 2x on every model that lists it, Flex 0.5x, Ultrafast 6x on GPT-6 Astra and GPT-6.1 Sol, all matching. The gap: OpenAI prices GPT-6.2 Astra's and Sol's Ultrafast at "3 times the Standard rate through February 28, 2027" and "6 times the Standard rate starting March 1, 2027 (Pacific time)", and models.dev lists their ultrafast mode with no cost. TierPrice skipped it, so every GPT-6.2 Ultrafast call, on an OpenAI key or a Codex subscription, was priced at the standard rate, below Fast. catalog.TierTimes holds that dated multiple; TierPrice takes the call's time and gives the standard price times the multiple of its day, every part and the long-context rate with it (Price.Times). The price caches in Pricer and apiPricer key on the day's rate (Record.tierKey), and the request-index ask names it, so calls either side of March 1st price apart. Scoped to the openai maker entry and those two models; Claude's fast mode reads its own mode as before. Run (WSL magpie-desktop, Linux, Go 1.26.8; mote overloaded by another session's full suite, mica's disk full): - TestDatedUltrafastPricedAtItsDay (new; Claude fast and standard unchanged among its cases): red on origin/main |
||
|
|
4d79bebfa7 |
usage: speed counts all output, reasoning and tool calls too, from the first output (Archivemylife on X)
Archivemylife on X: speed should be the upstream's usage over the local time, with no split into reasoning, tools and answer, since reasoning and tool calls are tokens too. Speed is now every output token the vendor's usage counts (reasoning and tool-call arguments included) over the time from the first output of any kind to the end of the reply. The first output is the earlier of the first content (TTFT) and the first sign of reasoning, firstToken.reasoningMs in ttft.go, which works the same in every protocol: - a Responses reasoning item's start; - an Anthropic thinking or redacted_thinking block's start; - sealed (hidden) thinking; - reasoning deltas spread over 100 ms or more. Deltas that came at once are a buffered burst and tell none. A summary is no sign (summaryPart: a Responses reasoning summary, a Gemini thought, or a summary translated from another protocol via firstToken.summarized), because it is written after some of the reasoning it sums up (#1463). A reply that reasoned with no sign of when it began counts only its answer, its output less the reasoning, from its first text, and none with no text. Before this, a reply that reasoned always counted only its answer, and a reply that wrote tool calls after reasoning told no speed. Burst and held-content checks judge the answer's part. The same definition holds everywhere: - gateway: speed.go, trace.go, codex_backend.go; - usage.DecodeOf, for the Usage cards, rows and `magpie usage`; - the Usage page's ledDecode; - the Routing page's decodeOf and its ranking (fast routing reads noteTrySpeed, which uses DecodeOf). settledCountVersion goes to 8, so settled heat totals are counted again. The rule text is in en, zh, zh-TW, ja and de. Docs: reference.md, and gui-shell.md under "Streamed output speed". Red on the old code (scratch worktree at |
||
|
|
81c666e1c2 |
gateway: an advisor call Anthropic's server ran is a usage row of its own (#6977)
A Claude Code turn relayed on Messages with its advisor on has the advisor run at the vendor. The reply's top-level usage is the executor's alone; each advisor call is an advisor_message entry of usage.iterations, billed at the advisor model's rates (Anthropic's advisor tool page, "Usage and billing"). magpie read only the top level, so an Opus advisor beside a Sonnet executor was in no row and priced nowhere. aUsage reads iterations, whole and from a stream's message_delta (whose list is cumulative, so the latest stands for the reply). Each advisor call becomes its own row (advisorRows, written by appendAdvised at every row of a try that reached a provider, and on the native route): under the advisor's model by magpie's id (advisorKeyModel of the request's advisor tool), Served as the vendor names it, Kind "advisor" (named Advisor in Usage's filters, already translated), the request's route, agent, account and session, status 200, counted as its own request as magpie's own advisor calls already are. The executor's row is unchanged. Routing prices the calls too, before the request's own usage so the prompt is still read from the last entry. Iterations with no advisor entry (Copilot) leave Usage as it was. The fixture is Anthropic's documented example word for word; no real reply with an advisor call was captured. The core script budget is raised by 52, the Advisor entry in the generated purposes.js (the base had no room; 1 byte less is red). The kinds are read wherever Usage and Routing draw a row, so there is no page to move it to. Run at this commit's tree on |
||
|
|
2ace161020 |
usage: the model speed ranking by provider, with each provider's failed and swapped tries
skingstyle48487 on X runs more than ten relays and asked for a live view of each one's speed and model performance. The ranking's key is now model plus provider: each key counts its tries, the failed ones (failed or handed on) and the swapped ones (the reply named another model, Row.Swapped). The ledger sends them as provider_speeds; the model view merges them back as before. settledCountVersion goes to 7 so settled pages are counted again with the new fields. Run (mote): go test ./internal/usage ./internal/usageapi, and the full suite (see the last commit of this push). Broken by hand: dropping m.Swapped++ or m.Failed++ turns TestModelSpeedRankByProvider red. |
||
|
|
50c5a52dbd |
backup: a backup file carries the usage history, and a restore merges it (JasonLeeForOnly on Discord)
JasonLeeForOnly moved magpie to a new server with magpie backup / magpie
restore and lost every call's usage history: a backup file held the setup
only.
- backup.WithUsage puts usage.jsonl's whole lines (gzipped, usage.LogBackup)
and the quota history (gzipped) in Bundle.Usage. magpie backup and
Settings -> Sync -> Export add it unless --no-usage / the tick says no.
Collect never does, so sync, join and automatic backups are unchanged.
- Restore (Parts.Usage, on in All; magpie restore --no-usage and the Import
tick turn it off) merges: usage.MergeLog appends the lines the log here
doesn't have, compared byte for byte as a multiset, so restoring the same
file twice adds nothing and two equal calls both arrive. It reads most
of the log before the gateway's log lock, the rest under it, and appends
with O_APPEND in 4MB chunks, after a newline when the log ends in an
unfinished line. Quota points merge with provider.MergeQuotaHistory.
A file without usage (older magpie, or --no-usage) restores as before.
- Result.Usage is the calls added; the CLI and the Import form say it.
- Docs: sync-backup.md, reference.md, site sync pages (en, zh, ja) and the
search index/llms-full.txt rebuilt with node docs-index.mjs.
Not changed: where usage is also shared by sync, the old computer's calls
are in usage-others and, after a restore, in this log too: filed #6987.
Run on mote at this head (26f69e85e rebased on origin/main
|
||
|
|
6c31af7ad9 |
usage: a Fast call is priced at Fast's price, not the standard one (Archivemylife on X)
Every service tier was priced at standard, so a Fast (priority) call was billed at half its price, and a subscription's API-equivalent value was half too. Sources: - OpenAI, developers.openai.com/api/docs/pricing: gpt-6.1-sol Fast is $4 / $20 / $0.20 cached (2x standard $2 / $10 / $0.10); Ultrafast 6x, Flex 0.5x. "Priority processing was renamed Fast mode on July 30, 2026." - Anthropic, platform.claude.com/docs/en/about-claude/pricing: Claude Opus 5.5 fast mode $8 / $40 (2x), "across the full context window". - models.dev's experimental.modes in magpie's catalog carry the same prices: OpenAI's keyed by provider.body.service_tier, Anthropic's by speed "fast". catalog.TierPrice reads those modes, only where the model's base price is the vendor's own (a relay's or a custom price is left alone). The Ledger's Pricer and the window's apiPricer both price by the billed tier: TierServed when the vendor says (Codex's backend always says auto/default, so servedTierAt keeps it "" and TierSent is used), otherwise TierSent. The tier ask is noted so a catalog change re-keys the request index, and settledCountVersion goes to 6 so stored settled costs are counted again. Run on mica. The full run was at this change on f9492fd8e; it was then rebased onto |
||
|
|
a75a1fffcb |
provider: agy's Orchestrator (Argon), gemini-pro-orchestrator-g1-pro, is priced as Gemini 4 Argon (mu33410 on X)
mu33410 on X: agy's Orchestrator model showed no cost. |
||
|
|
90d54a2675 |
usage: Factory Droid's own sessions count under Not through magpie (_meouwu on X)
Droid's sessions were on the Sessions page, but Usage's "Not through
magpie" read no Droid calls, so what Droid spent straight at Factory or
a BYOK provider never added up.
Droid writes no tokens into a transcript: a message line has its time,
the message and a reply's modelId. Read from droid 0.231.0's binary
(its session schema) and the real runs in testdata/droid-skills, what a
session spent is only in <id>.settings.json: tokenUsage, its own running
total (input less the cache, output with thinking, cache read and
written), and lastCallTokenUsage, the latest call alone. So each session
is one call of its total, at its last message (the day Sessions already
counts the same total on), under its settings' model; a subagent's is
under the session that called it, a fork's starts at none.
- sessions: calls_droid.go reads a session with its settings whole
(wholeCallReaders "droid"); droidFiles joins callSources, behind
Reads("droid") and allowed() like the rest. WSL is not read: the
Sessions page doesn't list Droid in a distro either.
- No double count: a session whose settings or any reply names magpie's
own entry (custom:magpie/...) or a custom model whose baseUrl is the
gateway's port on loopback is left out whole; the gateway counted those
calls, and a total can't be split by model. A session is judged when
read, again once it or its settings change.
Tests: TestDroidCalls (the 4 real droid 0.231.0 sessions: tokens, time,
model; custom:mh on localhost:11434 counted, on the gateway's port left
out; Reads off counts none), TestDroidCallsOfSessions (subagent, fork,
no settings, magpie's entry, Factory's own model), and
TestDirectDroidSessionTotals in usage. Both sessions tests are red on
origin/main (0 calls); with the gateway check broken by hand both go red
on the gateway cases.
Run (mote): go test ./internal/sessions
./internal/usage ok; go vet + GOOS=linux/windows go vet of both ok;
gofmt clean; go test ./internal/gui ./internal/agent ok.
Not tried: a real Droid session against Factory's own models (no Factory
account here); no GUI change.
|
||
|
|
91b3af8470 |
usage: Qoder's own calls are under Not through magpie, by the credits they cost (eating_dream on X)
Qoder's and Qoder CN's sessions were on the Sessions page and nowhere in
Usage: callSources never listed their files. They are Claude Code's
lines, and are now read for calls as Claude Code's are (ccCallAgent:
claudeCallLine, the call cache, continuations and revisions).
Qoder writes a reply on its own models ("auto" among them) with every
token count 0 unless QODER_EXPOSE_TOKEN_USAGE is set: the transcript
writer (vUl in qodercli, the same in Qoder.app's worker, qoder-agent-sdk)
zeroes them unless the model is a custom one, from qodercli 1.1.0 on. It
keeps the reply's credits. So such a call carries Credits (new on
sessions.Call, passed to the ledger's Record), counted with no tokens
and no price; "auto" names no model, so nothing is priced for it. A
model of the user's own, whose counts are written, is read and priced
as before. The GUI's direct section already shows credits (ledCredits).
Fixture: testdata/qoder-1.1.89 is lines as qodercli 1.1.89's writer
lays them out (key order, zeroed usage, credits/original_credits/
billable, a reply with no usage), read from its npm bundle; the ids are
made up. The older invented qoder fixtures got message ids of their own
(Calls counts a message id once across agents, and they shared
WorkBuddy's m1/m2).
Run (on mica, at f07e3e067's tree, rebased on
|
||
|
|
9bcdcfb7d1 |
provider: Antigravity's Orchestrator ids are priced as the Gemini model each is
guyng35955 on X: an Antigravity local session's calls under gemini-pro-orchestrator-argon, gemini-pro-orchestrator-carbon and the worker gemini-flash-worker-agy showed tokens and cache but cost "—". They are Orchestrator mode's role ids, which no catalog prices. pricedNamesTo now reads them as the model Antigravity's docs name (https://antigravity.google/docs/models/): Orchestrator (Argon) plans with Gemini 4 Argon, Orchestrator (Carbon) with Gemini 4 Carbon, and Gemini 4 Hydrogen does the implementation, so the worker is priced as gemini-4-hydrogen. gemini-pro-orchestrator (Carbon's id before Argon came, per the Antigravity Context Window Monitor extension 1.17.1's table) is Carbon too. Only these four ids, under a route prefix or an effort suffix; a name only like one stays unpriced. Every cost reads through this one place: the Sessions list and overview (sessions.priceOf -> PricedName), the usage ledger, its totals and per-agent view (Pricer -> ListPrice / MakerPrice). Prices are taken as rows are read, so sessions recorded before the update are priced once it is installed; nothing is re-parsed. Google publishes no rate for the role ids themselves; they are priced at the named model's models.dev list price. Run (mote, at this tree): - the three new tests red on origin/main's models.go (every role id unpriced), green with the fix; red again with argon mapped to carbon by hand - go test -tags nogui ./internal/provider ./internal/sessions ./internal/usage: sessions and usage ok; provider ok but for TestRemoveListedAccountLeavesHiddenNamesake (ZCode account removal, not reached by this change), which passes alone -count=3 with and without this change; filed as #6764 with its output - go vet, GOOS=linux and GOOS=windows go vet of those packages; gofmt -l clean Not tried: the reporter's own Antigravity database, or a real Orchestrator mode account (this Mac has no Antigravity app and the account isn't offered Argon). No GUI change. Reported-by: guyng35955 on X |
||
|
|
e99307fb86 |
usage: a file read anew forgets when the last one was written or pruned (#6760)
TestWholeKeptAcrossReset was red on main at -count=5 (4 of 5, "after a
restart: <nil>"), and TestFeedExpiresACursorOlderThanItsTombstones at
-count=3 (2 of 3, "must be refused, not skipped over: <nil>"). Both had
the same cause. A package-level "last done at" outlived the file it was
about:
- carryLoad reset the window-holds map and dirty bit for a new path,
but not wroteAt. carrySave then waited 30s from the last file's write,
or from a held clock later than this one, and wrote nothing.
- feedLoad reset everything but pruned, so a journal read anew wasn't
pruned for an hour after another one was.
In the app it matters when the config dir changes (MAGPIE_CONFIG_DIR, a
sandbox HOME) without a restart, or when the clock moves back.
Each reset is now done where its sibling fields already were.
Run on mote at origin/main
|
||
|
|
d50ae6fcb1 |
usage: an agent group says when its last call was
The Usage page will fold a small client idle for days into one Other row (WJaunita45604 on X: dozens of randomly named test clients). It needs each agent's newest call in the period, so Group gets Last (json "last", omitted when zero), set for agents only by summaryCounts.add and by direct(). Run: go test ./internal/usage -run 'AgentsSayTheirLastCall|LastCallMovesOn' on mica, ok. Broken by hand: without the Last assignments both tests go red. |
||
|
|
80a315a70a |
gui: a closed or hidden page lets its Sessions and Usage caches go in 30 s
What a visit to the app's page read stayed until each cache's own idle
timer fired: the Sessions stats after 2 minutes, the Requests chunks
trimmed at 2 and forgotten 5 after that, each chunk's derived keys at 3.
On a real history (acctp, requests-v1.bin 71.5 MB) a web page open 70 s
and closed held 123 MB at the close, 108 MB a minute on, 74-76 MB three
to five minutes on, and was back to the tray's 52 MB only at ten.
The page now says it has gone from view (POST /api/page-away, sent from
the visibilitychange listener every window already has, when hidden: a
browser fires it as a tab closes, and the Mac window's orderOut
dispatches it too). 30 s later (pageAwayFor), unless a Sessions or Usage read
was in flight or ended since, the stats, overviews and tags go
(letGoStats, split out of forgetIdleStats), the Requests chunks and each
chunk's derived caches go (usage.ForgetPages: trim(0) + dropDerived,
idle timers stopped) and the pages go back to the system. A second tab
still polling, or a tab looked away from for under 30 s, keeps them. The
beacon writes nothing, so held's provider.Changed passes it by. The panel
sends it as well when it hides; it reads no Sessions or Usage page, so
there is nothing of its own to keep.
Tests: TestPageAwayLetsStatsGo (red with the forget skipped, and red
when a read after the beacon is ignored, both broken by hand) and
TestForgetPagesLetsChunksGoAtOnce.
The core script budget goes up 83 bytes, with the reason in its
comment: the beacon is folded into the existing listener and packed to
its shortest form (335 over as first written, with a pagehide listener
and a panel check).
Measured on mote (pageclose2.sh, the acctp history, a web page open
70 s and closed, footprint-overlay build like the release):
before (w88): close 123 MB, +60 s 108, +180 s 76, +300 s 74, +600 s 52;
peak 154
after (w89): close 123 MB, +45 s 92, +90 s 90, +180 s 54, +600 s 53;
peak 149, 3.08 s CPU over 11 min
final (w90, visibilitychange only): close 122 MB, +45 s 93, +90 s 90,
+180 s 55, +600 s 52; peak 152
Run: go test ./internal/gui ./internal/usage on mote (ok);
GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... (ok);
16 visibility GUI files + i18n-keys in chromium and webkit: red only in
routing-pin-away (the same subtest red alone at origin/main
|
||
|
|
925bc7188b |
usage: the Requests card's up arrow opens what the bytes sent upstream were made of
theforeveriris (X, 2121408745616162998) saw 8169 requests send 8.6 GB up and 1.0 GB down and wanted to know why. About 1 MB a request is normal: every request sends the whole conversation again, with the system prompt and the tools' definitions. This shows it. Gateway: promptOf, which already parses the body off the request path, now also counts the bytes of the system prompt, the tool definitions and images in the body it read. upParts scales those to the wire bytes and puts them on Record.UpParts. Nothing new runs on the request path, and a body that isn't parsed stays "Not measured". Usage: a packed row keeps the mix in 255ths under flag rowUpParts (32768); the row stays 152 bytes. Totals gain up_calls, up_measured, up_system, up_tools and up_images, and Shares carry up_bytes and up_calls by agent and by model. settledCountVersion goes 4 -> 5, so settled days are counted again once on the next start. GUI (Usage -> Requests): the "↑ 8.6 GB" on the Requests card is a button that opens a "Sent upstream" card: the average per request, one sentence on why, a bar and legend for Conversation / Tool definitions / System prompt / Images / Not measured, and the top 8 agents and models with bytes sent and per request. The open state is kept; × closes it. A request's details get a "Made of" line. zh, zh-TW, ja, de strings. Entrance is 200ms ease-out, no movement under reduced motion. Run (mote, at this head on |
||
|
|
f53c4a1a14 |
usage: three tests hold the clock, so midnight never falls between a call and Today (#6486)
TestAliasCallsAreTheGatewaysNotDirect stamped its direct call 6 minutes
before time.Now() and asked Direct(Today), so in the six minutes after
local midnight the call was yesterday's: red on mote at 00:00 PST and on
macOS CI at 00:07 UTC (run 43523008440). TestLoopsCountedPerModel and
TestRequestsCountedOnceWithTheirRetries do the same with stamps up to 9 s
back (same class). All three now take their time from holdClock at a
fixed noon, as TestPeriodsReadTheClock does.
Run (mica, at
|
||
|
|
08f77528f4 |
usage: the serials sourceDigest met go when idle
sourceDigests.by and .last, the serials met this turn and the one
before, stayed for the life of the process: 577 KB of a real history's
idle heap. They only order which digests heat-digests.bin keeps first
when there are more than it holds (2*65536, against ~17k session
files). dropDerived, the 3-minute idle drop, now writes what was made
and lets them go; sourceDigest notes a read (derivedUsed) as the other
per-chunk caches do.
TestDigestTurnsGoWhenIdle: the turn's serials are nil after the idle
drop and the next key hashes nothing again. Red with the nil-ing taken
out by hand ("kept 1 and 0 serials when idle").
Run at this commit on mote (load 23.7, over its 18 cores; mica's disk
was full): go vet for darwin, linux and windows ok; go test
./internal/usage ok (52s), ./internal/gui ok (132s). Real Codex history
in a sandbox HOME (~/r2278), page open 30s then 8.5 min idle: liveHeap
13.13 MB against 13.68 MB before; the heap diff shows sourceDigest's
577 KB gone. Not run: the full suite.
|
||
|
|
a532b646eb |
usage: the set of listed session paths is not kept on the index
readRequestBlocks makes a set of every session file's path (on), and noteBuilt kept it on the index for save, the only reader, which it calls right after. The set outlived the chunks' forget: 853 KB of a real Codex history (pprof inuse_space at request_page.go:1214, the make of on) at 8 minutes idle. save takes it as an argument now; the field is gone. Run at this commit on mote (load 24): go vet for darwin, linux and windows ok; go test ./internal/usage ok (57s), ./internal/gui ok (158s). Real Codex history in a sandbox HOME (~/r2278), page open 30s then 8.5 min idle: liveHeap 13.68 MB, against 17.07 MB for v0.1.4089; the heap diff shows readRequestBlocks' 853 KB gone. One earlier capture read 22.3 MB with 5.2 MB under prefetchEach/sharedBuild; a goroutine dump of the next run had no prefetchEach goroutine left, so that was a build in flight when the heap was taken, not a stuck reader. Not run: the full suite. |
||
|
|
58629a0f8e |
usage: a trim that lets most chunks go gives back the map's table
The usage page's index of session-file chunks is let go when no page has asked for it in requestIdle + requestForget (trim(0)). A Go map never shrinks, so the emptied map kept its table: 853 KB of a real Codex history's index (pprof inuse_space at request_page.go:1461, the map assignment in keep) stayed for the life of the process, 8 minutes after the page was last open. trim now copies what is left into a map of its size when it dropped more than it kept. TestRequestTrimGivesBackTheMap fills an index with 100k chunks, holds the keys, and checks trim(0) gives back the table. Broken by hand (the copy skipped): red, heap 9,054,088 -> 9,051,552. Fixed: 3 of 3 green. Real Codex account sandbox (mote, acctp HOME, page open 30s then 8 min idle, memprofilerate=1): liveHeap 18.00 MB -> 17.07 MB; nothing held under requestIndex.keep (was 853 KB). One earlier run read 23.1 MB with a usage build in flight at the capture (sharedBuild 5.2 MB); the rerun had none. mica: gofmt clean; go vet ./internal/usage for darwin, linux, windows; go test ./internal/usage ./internal/gui ok. Not run: the full suite. |
||
|
|
82512bb640 |
usage: the probe chunk is let go when the pages rest and after warm-up
probeChunk memoised its last chunk for the polling page (#2278), and nothing ever cleared it: ~5 MB of unpacked probe rows held for the process's life on a real gateway's history, the largest single live holder left in an idle heap profile (makeProbeChunk -> rowChunk.add). ReleaseScratch (page rest) and ReleaseMatchScratch (after warm-up) now drop it with the rest of the reads' scratch; the next page read makes it again, and while a page polls the memo still answers. Run (mica): go test -run 'TestProbe|TestAnswered' ./internal/usage/ ok. Broken by hand: without the two releaseProbes() calls, TestProbeChunkLetGoAtRest fails ("ReleaseScratch kept the probe chunk"). Measured on mote, real accounts in the sandbox HOME, idle after the page was open 30 s and closed 60 s (memv.sh), base vs this, two runs each: heap profile in use: 52.5 MB (4.91 MB under makeProbeChunk, held from gui.warmStart) vs 46.9 MB (none under it) liveHeap: 40.0 / 45.7 MB vs 40.4 / 40.4 MB footprint: 94 / 117 MB vs 102 / 107 MB (noisy run to run) go test ./internal/usage/ ./internal/gui/ on mica: ok. |
||
|
|
d5585933f1 |
usage: heat-digests.bin is read mapped, not copied into the heap
The heatmap's key names each session file's chunk by a digest kept on disk by serial (#2278). The file holds up to 2*sourceDigestsKept digests at 40 bytes each, 5MB on a long history, and every start read it whole into the heap and kept it there for the process's life. After a save the encoded bytes stayed instead, the same 5MB. Where the system maps files (unix), the file is now mapped read-only, as requests-v1.bin already is (mapDiskFile), and kept is read from the mapping: its pages are clean file pages, not footprint, and a lookup is a binary search that touches a few of them. After a save the file just written is mapped in place of the encoded bytes, when it is still those bytes. The file is only ever replaced by a rename, so a mapping stays as it was read. Windows reads it into memory as before (mapsFiles). Run (mica, go1.26.8): - go test ./internal/usage/: ok (54s) - go vet ./internal/usage/, GOOS=windows go vet ./internal/usage/: clean - Broken by hand (no mapping on load, no keepMapped after save): TestSourceDigestsKeptAcrossStarts red, "after a save the digests are kept as encoded"; green again with the change. Real account (mote, the owner's history in a sandbox HOME, magpie web with the page open, 90s idle, footprint + Go MemStats): - before (w63 = v0.1.4074's code): footprint 109MB, live heap 44.9MB - after: footprint 101MB, live heap 39.6MB - wsl-run and win-run: go test -run 'SourceDigest|Heat' ./internal/usage/ ok on Linux (the mapped path) and Windows (read into memory). Not run: the full ./... suite (only internal/usage is changed). |
||
|
|
b3395ffdaf |
usage: a models.dev change no call of the user's names keeps the request index
The request index's meta named the catalog by models.json's bytes (catalog.CacheKey, v0.1.4037), so every real change models.dev made, most of them to aggregators' lists (OpenRouter, NanoGPT, Kilo, Vercel) no call names, dropped every chunk and read every session file again: ~15 s of CPU on a long history, several times a day. The meta now names catalogBase: the catalog the rows were made under, kept while each question the rows asked of the catalog is answered the same. The questions are Pricer's base price (basePriceIn, taken out of Pricer whole) and ListedAs's listed name; each is noted with its answer the first time it is asked (noteAsk). A new catalog file, or a catalog read again (catalog.Resets: Sync writes the file before it resets), asks them all again; one answered otherwise names the index anew, as any change did before. A question answered otherwise than first, or more than 50k of them, does the same. The asks are kept in catalog-asks-v1.json, written before any file of rows under the meta (toDisk, heat, page, effort, digests), so a restart holds the rows on disk to them too. The price cache key (usagePriceCacheKey) is unchanged. Run on mica at this tree: go test ./internal/usage ./internal/catalog ./internal/gateway ok (gateway 1038s); go vet, GOOS=linux and GOOS=windows go vet of usage and catalog clean; gofmt clean. Broken by hand, each red in TestRequestStateKeptAcrossACatalogChangeNoRowAsks: answersSame always true, the meta back on catalog.CacheKey, and the catalog.Resets check dropped (a check between Sync's write and its reset). catalog_asks.go joins the row code's go:embed, so the index is built once after this update. Not tried yet: a real models.dev change on a real account (next, on mote). |
||
|
|
2f1759c96c |
usage, catalog: the same catalog fetched again keeps the usage index
A Claude account's model list fetches models.dev again every 45 minutes (catalog.Asked), most often to the same bytes. Each fetch rewrote models.json, so its mtime changed, and usage keyed its request index, the index's file on disk (requests-v1.bin, heat, page, effort) and its priced summaries on that mtime: the next usage query dropped every chunk and read every session file again. On the acctp history (15.7k session files) a start that rebuilds takes ~15 s of CPU in its first 30 s, against ~2 s for one that keeps the index. Each fetch also forgot the parsed catalog and told every agent to rewrite its list (catalog.Changed), for nothing changed. - catalog.CacheKey names models.json and labs.json by a hash of their bytes, kept by their stat so a key costs a stat until a file changes. Usage's request meta and price key use it in place of the mtime, as liveListKey already did for the providers' lists. - Sync writes models.json and labs.json only when their bytes changed; the same bytes are dated now (Stale, Missing and Asked read the time), and Reset and Touched run only when either file changed. Tests: TestSameCatalogFetchedAgainChangesNothing (catalog) and TestRequestStateKeptAcrossACatalogFetchedAgain (usage). Broken by hand: with keepFetched always writing, the catalog test is red (told the agents on the same bytes); with usage keyed on statKey again, the usage test is red (meta and price key changed). |
||
|
|
a95a7a1cd8 |
providers: each API key can bill at a price rate of its own (tnt12231 on X)
A relay sells keys in groups that bill at different rates against the
official price (0.5x on one, 1.2x on another) under one endpoint, and
magpie had only the provider's price rate. Now a key can have its own:
- provider.KeyPriceRates, keyed by key id like KeySpendCaps: cloned,
normalized on save, carried when a key is replaced. A key without one
bills at the provider's PriceRate. A price the user set for a model
stands as set, as it does under the provider's rate.
- Usage prices each call at its key's rate (usage.Pricer memoizes per
key id, BaseKeyPriceIn), so the Usage page, a key's spend cap and its
typed balance follow it. PriceAt, used to route by price, takes the
rate of the key the provider holds.
- GUI: the provider editor's Advanced has "Price rate per key" under
Price rate, shown only with two or more keys, folded past 8 keys like
the per-key proxies. An empty line shows the provider's rate as its
placeholder. Save sends keyPriceRates ({} clears, left out keeps).
The lines, the check and the placeholder live in keyrates.js,
imported when a provider with two or more keys opens. The core's
budget goes up 397 for what is left in app.js (the import, the
draft's copy, Advanced opening for it, the save's line, proxyLines
drawing another kind of line); app.js stays under its own.
- CLI: magpie provider key-rate <id> [key [rate|default]].
- docs/subsystems/providers-accounts.md: a Key price rates row.
Run, at this head (rebased on
|
||
|
|
d370bef982 |
usage: Failed lists the requests a fallback answered, as Routing shows their tries failed (maohy915 on X)
maohy915 runs magpie on a NAS and uses it from another computer's magpie
through Remote magpie. The NAS's Routing page showed failed calls, but
Usage → Requests → Failed found none. Reproduced with two sandbox
instances on mote (B → remote-magpie → A, where A's provider `bad`
answers 429 and falls back to `good`). A's trace had 2 requests and 1
rerouted. Usage had 2 rows, Failed had 0 and Retried had 1. A try that
fails and is handed on writes no row when nothing is billed, and its
request's row is an answer on the second try. Failed kept only
LostRequest, the requests whose agent got the error, so the failed try
was nowhere under Failed. Plain failures, remote or not, were already
listed; only rerouted ones were missing.
Failed now keeps every request a try failed on (Record.FailedTry): the
requests the agent got an error for, the tries handed on, and the
requests a later try answered. Retried still keeps only the answered
ones. The counts are unchanged: each request is counted once, by how it
ended (小一's rule), so a Failed list reads "1 failed · 2 answered on a
retry". The Failed option and the card's "N failed" button now say so in
their tooltip, in every language. Filtered page cells are cached on disk
under the filter, so settledCountVersion goes to 4; the first start after
the upgrade pairs the history again once.
Run (mote):
- go test ./internal/usage ./internal/usageapi ./internal/gui: ok.
- New test TestFailedKeepsRequestsAFallbackAnswered; updated
TestRequestsCountedOnceWithTheirRetries.
- GUI, both engines: ledger-retried (5 languages, 420/1100), i18n-keys,
i18n-en-no-cjk, usage-ledger, api-key-usage, purpose-filter,
usage-ledger-content, usage-phone-head, usage-loops, usage-request-page.
All pass except known reds: i18n-keys "a plugin's words are its own"
(#6422/#6423) and usage-ledger "newest live route needs no
return-to-live button" (#4078/#3104/#4626).
- gofmt; go vet for darwin, linux -tags nogui, and windows.
- Real repro with a binary built from this tree: A's Failed went from 0
rows to the rerouted request, both in the API and in the real page
(Chromium).
Broken by hand:
- Filter back to LostRequest: both Go tests red.
- The Failed option's title dropped: ledger-retried red.
Not tried:
- Restoring settledCountVersion to 3 doesn't turn
TestSettledCountedAsVersioned red: it counts only Filter{}. The bump is
by reading.
- Not tried on a real NAS or in the desktop app's remote window; the
page is the NAS's own web page.
|
||
|
|
acced81418 |
usage: Codex effort read back shares its model and effort names (#2278)
effortDiskRead decoded every saved (model, effort) pair with its own copy
of both strings, so a few names were held thousands of times in the kept
Codex effort sums. The read now hands each entry the first copy of its
name.
Measured on mote, acctp real-account sandbox (17k chunks), pageheap.sh,
w53v (
|
||
|
|
743001128d |
usage: chunk digests in use are named by serial, read from the kept list (#2278)
sourceDigests held every chunk's 32-byte digest in a map (by, and last
for the turn before), beside heat-digests.bin's sorted list that already
holds them: ~2-3 MB of maps on a 17k-file history. by and last now hold
only the serials used, which decide what the kept file keeps first; a
digest is read from the kept list, or from made, the few hashed since
the last save. A save encodes the list and keeps what it wrote as the
list, so made is empty again after each heat key.
Measured on mote, real-account sandbox (17k chunks), pageheap.sh, page
open, w52v (v0.1.3983) against w53v (this), 3 runs each:
liveHeap 79.34 / 79.57 / 79.63 MB -> 78.77 / 78.64 / 77.99 MB
Footprint 133 / 134 / 133 MB -> 130 / 132 / 126 MB
heap profile, sourceDigest cum: 2.99 MB -> 0.90 MB (the list read)
Run: go vet ./internal/usage; go test -count=1 ./internal/usage ok (mote).
Broken by hand: not putting a hashed digest in made and not keeping the
written list made TestSourceDigestsKeptAcrossStarts red ("same run,
hashed 2 chunks"). New in the test: a second key in the same run hashes
nothing and leaves made empty; a used serial with no digest is left out.
Not tried: a history past 2*65536 chunks (the cap is unchanged).
|
||
|
|
c2fd48782b |
Put back what 1f05c311d took out of main by mistake
|
||
|
|
1f05c311d9 |
library: an open memory holds still while the Memory tab polls (Nietzsche_Li on X)
"资源库-记忆中,被展开的记忆的表单会定时抖动". While search by meaning
still has memories to read (read < of, which can last up to a minute
between memembed.Keep's reads) or a learn-from-conversations run goes,
the Memory tab reads its row again every 2s, and each read drew the
whole page anew. The open editor was a new .lib-detail each time and
played its content-in entrance (opacity .5, 2px slide) every 2s.
- semWatch/distWatch draw nothing when the read changed nothing, and
redraw only their own row (redrawRow) when it did; the whole tab only
when the memories changed.
- render() marks a .lib-detail open before it (same data-detail) as kept,
so it doesn't replay its entrance. This covers every render of an
open editor in the Library: memories, instruction sets and agents'
files (the siblings; no other Library tab polls into render()).
- A new memory's text no longer takes the focus back on every render.
Run (mote): library-memory-steady.test.cjs, all 5 languages, 980/420,
chromium + webkit: green 4 of 4 whole-file runs after the last change
(webkit alone 2 of 2 before it). Broken by hand: the same test against
origin/main's client.js and library.css: 22 of 22 red ("the editor
played its entrance again"). One webkit de 420 red was the test's own
first row click intercepted by the header at 420px while the page
settled; the test now opens rows with a DOM click.
Also run, both engines, every language, 980/420: library-memory, library-memory-select, library-memory-suggest, memory-icon, library-instr-busy, library-instr-sets, library-linked-set, library-follow-server: all green. No Go code changed, so no go test or vet.
Not tried: the real app on a real memory store mid-read.
|
||
|
|
a095e40279 |
usage: a start doesn't hash every session file's rows again for the heatmap's key (#2278)
The heatmap's settled days are named by a digest of each session file's chunk of rows (sourceDigest). The digests were kept in memory only, so every start unpacked and hashed every chunk again: 0.14-0.16 s of CPU in the first 40 s of a start on a real history (startpg profile, w50v). A chunk's serial names its file as read under one root and meta (sourceSerial: root, meta, path, size, mtime), the same in every run, so the digests are now kept in heat-digests.bin next to heat-v1.json, by serial, under requestDiskBinary()'s key of the code that makes the rows: another build's rows are hashed again. A file that can't be read, was cut short or names other code is nothing kept. It is written as heat-v1.json is (temp file renamed over it), only when a digest was made, with this run's digests first and then those kept it hasn't met, at most two turns' worth (2 x 65536 x 40 bytes), sorted by serial. The file is kept as read and searched in place: a map of its 17k entries beside sourceDigests' own cost 1.4 MB of live heap in a first try (w51v). Measured on mote with the real-account sandbox (acctp, 17k chunks), a start with the page opened, second start of each build: - CPU profile, first 40 s: 2.00 s (w50v, v0.1.3978) -> 1.54 s (w52v); sourceDigest/heatSettledKey 0.12-0.13 s -> gone - pageheap at the mark: CPU 2.48 s -> 2.12 s, Footprint 134 -> 131 MB, liveHeap 79.1 -> 79.4 MB Run (mote, Go 1.26.8): - go test -count=1 -timeout 45m ./internal/usage: ok - GOOS=windows and GOOS=linux go vet ./internal/usage: ok; gofmt clean - TestSourceDigestsKeptAcrossStarts (new): a second start hashes 0 of 2 chunks with the same key; a start of one file keeps the other's; a new file hashes 1; other row code hashes again; a cut file hashes again. - Broken by hand (the disk lookup ignored): the new test goes red, "started again, hashed 2 chunks". |
||
|
|
2ae8e61a4f |
usage: an upgrade reads session files again only when the code of their rows changed (#2278)
requests-v1.bin and log-v1.bin were keyed on a hash of every .go file in internal/usage, so nearly every release that touched the package threw both away. The first start after such an upgrade read all ~24k call shards again: on the owner's real accounts (mote, acctp sandbox) that is 13.8s of CPU and ~3.4GB allocated before the page settles, against 2.4s warm. Each file now keys on the source its rows are made, written and read through: rowSource (15 files) and logSource (23 files), embedded by name. The row pricer and a file's chunk builder are lifted out of readRequestBlocks (sessionRowPricer, sessionChunk) so they can be roots. TestRequestDiskNamesTheCodeOfItsRows type-checks the package and walks every declaration reached from those roots (uses, package vars assigned elsewhere, interface calls, encoding/String/sort methods); it fails when a reached file is not embedded or an embedded one is not reached. Of the last six usage-changing releases, four (3962, 3958, 3941, 3908) would have kept the cache. Run: - go test -count=1 ./internal/usage on mote: ok 51.9s. - go vet ./internal/usage for darwin, windows, linux on mica: ok. - Broken by hand: session_provider.go left out of rowSource's embed -> "rowSource: session_provider.go is reached but isn't in its go:embed", FAIL; restored. - Real accounts on mote (pageheap.sh, page open, CPU at mark): w47v first start after an older binary 13.80s, numGC 217 (rebuild, expected); w47v again 2.45s; w48v (w47v plus a live init() in effort_split.go, a different binary) 2.59s, numGC 56; back to w47v 2.43s. Before, the same swap cost ~14s. Not tried: Windows or Linux real start. |
||
|
|
6af6ae9885 |
usage: a log of MCP calls and probes keeps its blocks on disk too (#2278)
log-v1.bin was written only once a gateway block had filled. A log of
MCP tool calls and probes has none (the real-account sandbox's 8.3 MB
log is 25,223 MCP lines and 2,539 probes, 54 probe blocks, 0 gateway
blocks), so full.n stayed 0, the file was never written, and every
start parsed all 27k lines again: readLogSnapshot took 60 MB of the
start's allocations. The probes that were kept went as JSON and were
parsed back a record at a time.
A full point is now marked too when a probe block fills while no
gateway row stands after the full blocks, and it records how many probe
blocks were full there (logFull.probes). Those go to the file as binary
entries, as the gateway blocks do, read from its mapped pages; only the
probes after them, up to the full point, still go as records. The file
is written again when its full point reaches further (by offset, not
the gateway block count). The magic is magpie-log-v2, so a v1 file is
parsed over once.
Run:
- go vet ./internal/usage; go test ./internal/usage ./internal/gateway
(mica, -timeout 45m): ok usage 31s, ok gateway 859s.
- TestStartReadsKeptProbeBlocks (new): an MCP-only log of 3 blocks + 100
is kept, a start reads 3 blocks from the file, and reads as a whole
parse. Broken by hand (no probe full point): red, "a log of probes
wasn't kept".
- Real-account sandbox on mote (acctp, page open 2.5 min, version
0.1.3961 builds): log-v1.bin written on the first start (645 KB);
warm starts, w45v (v0.1.3961) against this:
CPU at mark 3.21s, 3.00s -> 2.50s, 2.39s
allocated 701 MB -> 646 MB, 629 MB
readLogSnapshot cum 60 MB -> 2.6 MB
numGC 66 -> 56
Footprint 128-133 MB -> 132-135 MB, liveHeap ~80 MB both: the same
within noise.
Not tried: a log with both gateway and probe blocks across a v1 -> v2
start on a real account (the unit test's mixed log covers the format).
|
||
|
|
a8b0e80f65 |
usage: the request page's probes are made into a chunk once per change
readRequestBlocks made probeChunk again on every poll of the Requests and Usage pages: a rowChunk holding every probe since the period's start minus a day, interned again each time. On the real-account sandbox it was ~45 MB of 952 MB allocated in two and a half minutes (rowChunk.add under probeChunk, #2278). probeChunk now keeps the last chunk it made, with the probe blocks, since, renames and hosts it was made from. A frozen block is never written again (a new probe reopens the tail as a copy), UsageRenames hands back the same maps while providers.json is unchanged (Renames.Same compares them by identity), and hosts are compared by content, so the same inputs make the same chunk, which no reader writes. Any of them changing makes it again. TestProbeChunkMadeOncePerChange: the same inputs give the same chunk; a later since, a changed host and a new probe each make a new one. Measured on mote with the real-account sandbox (pageheap.sh, the request page polled to the mark): probeChunk allocated 43.81 MB at the base (w42) and 24.54 / 24.10 MB with this (w43, two runs). It is not zero there because the sandbox's network is blocked, so every probe fails and logs a new row, which makes the chunk again. Run on mote: go test ./internal/usage ok (33.9s); the test is red with the memo turned off by hand. |
||
|
|
d85ee9e53f |
usage: the probes are kept in packed blocks, as the gateway rows are
The request log's probes (magpie's own tests, model lists, MCP tool calls
and searches) were a slice of whole Records, 952 B each, and every read
that continued the log appended to a copy of it. The owner's real log has
25,379 of them (25,223 MCP tool calls): ~24 MB of live heap in every
running app, the tray's included, for rows only the Requests page lists.
Now they are rowChunk blocks of logBlockRows, frozen (packed) when full,
the last one reopened as a copy for the next append (probeRows), the way
readLogSnapshot keeps gateway rows. probeChunk and log-v1.bin read them
back through chunkRows; a block whose Latest is before since is skipped
whole. log-v1.bin's format is unchanged.
Tests: TestProbeBlocksContinued (3 blocks + an appended block: the earlier
snapshot reads as before, the continued read equals a fresh parse, since
cuts at the right row). Broken by hand: dropping the continued snapshot's
probe blocks turns it red. TestStartReadsKeptLogBlocks covers the disk
round trip with probes.
Run at this head on mica: go vet ./internal/usage; go test ./internal/usage
./internal/gateway/... ./internal/gui, all ok (gateway 869s).
Real app on mote (sandbox HOME from the real-account sandbox, plus the
25,379 probe lines of the owner's real log), tray idle at 150s, cold:
before (w36, v0.1.3938's code): footprint 105 MB, live heap 48.4 MB,
readLogSnapshot 26.5 MB of it
after (w37): footprint 70 MB, live heap 16.0 MB, readLogSnapshot out
of the top; warm start (log-v1.bin read back): live heap 15.6 MB
Requests page, web mode, same HOME: requests.csv byte for byte the same
on both builds; /api/usage/requests' 100 rows the same apart from the 4
probe rows the first run itself wrote (token refreshes through the dead
proxy).
Not tried: Windows and Linux (no OS-specific code here).
|
||
|
|
477bbb7a15 |
usage: GET /v1/magpie/usage/requests?cursor= reads requests as changes, with stable ids (rdsaltbo on X, #6060)
A program keeping a ledger of its own (a WakaToken plugin) can now read the requests incrementally: cursor=start or cursor=now, then each next_cursor. Rows carry a stable content-derived id (same after a restart), origin, and original_ids (request_id, response_id, client_response_id, message_id, session_id, native_session_id), each only when the source gave it. A call read late, a corrected row (same id, higher seq) and a native row replaced by the gateway's (deleted, with seq) all come through a persisted journal (usage-feed.jsonl, appended and synced before answering). Cursors magpie cannot resume from are refused: 400 cursor_invalid / cursor_filter_changed, 410 cursor_expired / cursor_reset. A held key sees only its own rows and tombstones. Without cursor, offset/limit mode is unchanged. Also: Record.MessageID (not persisted) from the agent file's message id, and usageapi's row decoration moved into a namer shared by both modes. Docs: reference.md, integrating.md, gateway-routing.md, gateway-sessions.md, site remote.html (en/zh/ja), llms-full.txt. Run (mote, this tree): go vet darwin, GOOS=windows, GOOS=linux -tags nogui on usage, usageapi, gateway (gui on darwin); go test -count=1 for internal/usage, usageapi, gui, gateway: all ok. New tests: resume gets exactly the new rows, ids and cursors survive a restart, correction keeps the id, gateway takeover retires the native row, refused cursors, expiry, now cursor, identical records, and the feed over the gateway (held key, 401 without key, offset mode). Broken by hand: an unconditional memo made the new-rows test red (fixed to memo only the next page). Not tried: real Claude Code/Codex session files, a huge (700k+) history, Windows run of the tests, GUI browser suites (no GUI file touched). |
||
|
|
10a27651f0 |
usage: a window's whole is kept across its reset until the new one tells its own (Musikrv77852 on X)
After Kimi Code's 7-day window reset with nothing used, the card lost its "Whole ≈ N tokens" until the new week passed 5% used. The reckoning is every provider's (usage.WithWindowHolds), so the fix is too: carryHolds keeps the last whole told for each account's window (window-holds.json, temp-and-rename) and, where the new window is under the floor or has none routed yet, shows it with holds.prevAt set. The tooltip reuses the past cycle's "Estimated from the window that began X, read Y" line; no new label. The new window's own figure replaces it as soon as it can be told. Run (mote): TestWholeKeptAcrossReset (reset with 0% and 2% used, restart from disk, same-window under floor, other account, new window with data), go test ./internal/usage ./internal/provider ./internal/gui (only TestCoreScriptBudget red until its +10 here), quota-holds and quota-curve GUI files in chromium and webkit (all 5 languages x 360/1000px for the new case), gofmt, go vet darwin/linux/windows for usage and provider. Broken by hand: carryHolds returning early reds the Go test and the GUI case; dropping the prevAt branch in app.js reds the GUI case. Not tried: a real Kimi account across a real weekly reset; a full ./... suite before the tag. |
||
|
|
5241308212 |
settings: a day can start at 0 to 6 o'clock (ssharpcc on X)
Settings > Usage > "Day starts at" (dayStart, 0 to 6, default 0; also magpie settings set dayStart 4). With 4, a call at 01:30 counts toward the day before: the Usage page (summary, charts, heatmap, ledger day filter, hour labels of Today) and the daily and monthly key caps (access.Window, provider.SpendCap.Window). internal/dayzone makes a time.Location whose midnight is the real day's hour:00 (TZif built from the zone's own offsets, same DST instants), so every place that cuts days by a Zone's midnight follows without edits; usage.Zone returns it and the "now" reads use it too. Run (mote): go test usage, settings, settingsapi, access, provider, gui, dayzone, also with TZ=UTC and TZ=Pacific/Kiritimati; gofmt; go vet darwin, linux nogui and windows; day-start, currency, number-units and i18n-keys GUI files in chromium and webkit, en zh zh-TW ja de; TestCoreScriptBudget. Broken by hand: TestDayStartsAfterMidnight red with 9 failures when the hour is ignored. New tests: dayzone over 5 zones x hours 1/4/6 x two years of days, usage, limit window, spend-cap window, day-start GUI. Not tried: a real log history in a real window. Not shifted, filed as #6314: the Sessions page, TUI sessions filter, davsync shared per-day files, gateway_sessions day keys, credits_daily. Rows are never stored in the shifted zone. |
||
|
|
ffc1d64e5e |
usage: a call recorded under magpie's alias id is the gateway's, not a direct one (CrazyJal on X)
Claude Desktop's Code tab, and Claude Code under it, write the id the gateway listed the model by (magpie-<number>.anthropic.<Claude model>, mythos-magpie-<n>, anthropic/magpie-<n>, claude-magpie-<n>) as each turn's model. The gateway's log counts the turn under the model that served it, and the agent's file counted it again under the alias: a row for a model that is none, its cost on top of the real one. Only the gateway knows those ids, so a call that names one went through it. Such calls are now left out of what Direct, the ledger and the Requests page's chunks take from session files, for every agent that records one. Calls under a model of the agent's own are unchanged. usage.MagpieAlias mirrors the gateway's alias forms; a gateway test fails when the two differ. Run (mote, at the pushed head): TestAliasCallsAreTheGatewaysNotDirect, TestMagpieAliasForms and the gateway's TestUsageKnowsEveryAliasForm pass; with ownCalls returning its input the first fails (7 rows, four under aliases). go test internal/usage, internal/gui, internal/sessions ok; vet darwin, linux nogui and windows of usage and gateway clean; gofmt clean. Go-only change, so no GUI file was run. Not tried: a real Claude Desktop 3p session (none on this machine; the model forms come from the gateway's own alias code and its tests, not JSONL bytes). Existing persisted request chunks rebuild with the new binary. |
||
|
|
e6bf4adf1f |
usage: Claude Code's helper requests are labelled, the largest cache write is one click away (recih on X, #6199)
Claude Code's AgentSummary and its auto mode classifier name themselves nowhere in the request, so there is no client marker to read. The gateway tells them by their content (inferredKind: a claude-cli/ request on the Messages API; the classifier by autoModeClassifierAsk, the summary by its last user text "Describe your ... in 3-5 words") and records them as agent_summary_inferred and auto_mode_check_inferred. The purpose catalog names them "Progress summary (inferred)" and "Auto mode check (inferred)" and puts each with its plain kind's purpose, so the existing Purpose filter lists both; nothing known and nothing inferred share a name. A tool that printed the same words, a chat, and another agent's request stay unmarked. A requests page now also holds BigWrite, the gateway-served row that wrote the most to the cache (cells, page-v1.json and pageFromLedger all carry it; rows from session files have no request to open). The Requests line shows it as "109K largest write", a button that opens that request through openUsageRoute. settledCountVersion is raised to 3, which keys the cached pages. Not done: the per-request branch recovery result asked for in #6199. No structured field holds it. Run on mote (load 21-24 of 18 cores, mica was higher): go test ./internal/usage ./internal/usageapi, the gateway and gui purpose tests, go vet for darwin, linux (nogui) and windows, gofmt; the GUI files usage-big-write (new), purpose-filter, routing-kind, i18n-keys and usage-ledger in chromium and webkit. Broken by hand: inferredKind returning "" turns TestClaudeHelperRequestsAreLabelled red; the larger-than test of BigWrite.add turned round turns TestRequestPageBigWrite red on both paths; the jump off turns usage-big-write red. Not tried: a real Claude Code session against a live subscription, Linux WebKitGTK. |
||
|
|
4b1f3eca4a |
usage: a ZCode call magpie routed is not counted again as a local session's (nori_tsukiji on X)
With ZCode on the same computer as magpie, the Usage page's local session calls came out equal to the calls magpie had routed: each was counted twice. Cause: a ZCode request names its session without the sess_ prefix ZCode's database gives it (zcodeBareID; GatewayKeys, Titles and the Sessions list already knew). The Usage page pairs a gateway record with a session file's call by session, tokens and end time (matchedBlocks), and the calls read from ZCode's database kept sess_<id> / sess_subagent_agent_<id>, so they never shared a session with the gateway's records and were never paired. Leaving out calls whose providerID is "magpie" (ocGatewayProvider) only helps when ZCode writes that id beside a reply; with any other id the call was listed twice. Fix: readZCodeCalls gives each call the bare session id; zcode's call parse version is 3, so cached shards are read again. Claude Code, Codex, Pi, OpenCode, Kimi, dsh, grok, minimax, agy and WorkBuddy name their sessions as their requests do (raft.go's requestIDs has ZCode alone); not changed. Run on mote: go test ./internal/usage ./internal/sessions (ok; the zcode fork test's expected session ids are now the bare ones), gui and cli with -run 'ZCode|Zcode|Usage|Session' (ok), go vet darwin/linux/windows (clean), gofmt -l clean. TestZCodeCallsPairWithTheGatewaysRecords (a session, a provider id of ZCode's own, a subagent) was red on the old code: 4 rows for 2 routed calls, the local ones Session sess_7c1f against the gateway's 7c1f. Not tried: a real ZCode database (this computer has none, only the app's tasks index) and the full suite. |
||
|
|
ce0960b4ab |
usage: a first Requests build reads with four workers, not eight
A first build of the request rows runs on any upgrade that changes internal/usage (the cache key hashes its source) and on a first install. Each prefetchEach worker holds a whole file's calls while it reads, so eight of them stacked up in the cold peak. Measured on mote with a copy of the owner's real accounts and history (HOME ~/r2278/acct, requests-v1.bin removed before each start), five cold starts of each build alternated, physical footprint peak at 12s (vmmap): eight workers: 248.3 259.1 252.1 257.5 276.1 MB (mean 258.6) four workers: 243.3 230.2 232.6 245.2 246.7 MB (mean 239.6) Every four-worker run is below every eight-worker run. The build takes the same time: the gctrace burst ends at 5.0/5.0/5.6/5.0/6.2s against 5.0/4.8/4.9/5.0/6.4s, and CPU in the first 12s is 6.7-7.6s for both. The cache written is the same size (71,523,711 bytes) for both. TestPrefetchEachMakeIsAReadersOwn counts four readers' makes now. Run at this head (rebased on |
||
|
|
82f09e3248 |
sessions: Codex's leftover review threads are no rows, and its one-session folders are one group
Deleting a thread in Codex leaves its subagent rollouts behind: the
guardian's review threads, titled by the prompt it asks ("The following
is the Codex agent history whose request action you are assessing…"),
and the title threads it opens. magpie reads every rollout, so each was
a session of its own, and one whose thread was gone had nothing to hang
under. On this computer 642 Codex sessions held 422 subagent threads,
86 of them with their parent thread's file gone (and 2 more under one of
those): they filled folders of their own (Documents\Codex\2026-08-17\
shan, wang, wei…), and the bar counted 531 sessions made with another
provider, 371 of them review threads no one ever opened. Codex Desktop
also makes a folder for every chat started without a project
(~/Documents/Codex/<date>/<name>, its outputs/ and work/ in it, named
from the prompt): 36 of them here were 36 folders of one session each.
listAgentWith now drops a Codex subagent thread whose parent is not
listed, to a fixed point, so a chain of them goes too; the agent's tab
counts the rows it lists. The "Scratch sessions" group that commit
e373adddf gave ZCode's draft folders now holds Codex's own per-session
folders as well (that one, Documents\Codex\<date>, a probe in a temp
folder, worktrees, another app's hidden folder). The provider bar counts
Codex's own threads only (role main or unknown): 531 became 160 here.
And a gateway session no call of which was answered and which spent
nothing is no row either (usage.GatewaySession.SpentNothing): the three
empty rows under "Seen through the gateway" were Codex's failed
title calls (kind thread_title, 400/499, 0 tokens), their ids ones no
file of Codex's has.
Rows: 642 Codex sessions to 554 (88 review threads gone), 422 subagent
threads to 334; 36 folders (51 sessions) folded into Scratch sessions;
3 gateway rows to 0, so "Seen through the gateway" is empty here. Usage
still counts every one of those calls, and nothing was deleted.
Run:
- go test ./internal/sessions -run 'TestCodexSubagentWhoseParentIsGone|TestZCode' -count=1: ok.
- go test ./internal/gui -run 'Session|Gateway|Manage' -count=1: ok.
- go build ./...; go vet ./internal/gui ./internal/usage ./internal/sessions; gofmt -l; git diff --check; node --check client.js: clean.
- go test ./internal/sessions -count=1: the same failures as without this
change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder,
TestCCListingKeepsItsNames: path separators and allocation counts on
this Windows box).
- go test ./internal/usage -count=1: TestDesktopSessionAccountMetadata
fails without this change too.
Broken by hand:
- without keptSubagents the 86 rows come back
(TestCodexSubagentWhoseParentIsGoneIsNoRow fails);
- hiding a gateway session on "spent nothing" alone breaks
TestSessionsSameWithoutRows and TestGatewayConversationAPI: a call
answered with no tokens is still a session, so SpentNothing also asks
that none of its calls was answered;
- counting subagent threads in the provider bar says 531 here, 371 of
them review threads.
Not changed: the review threads' calls are still counted by Usage and by
the Sessions page's stats; their rollouts stay on disk (Deleting the
parent does not delete them); the scratch grouping is worked out on the
page (client.js), so Usage's folder filter still lists those folders by
their paths.
|
||
|
|
059d995d56 |
gateway keys: the list reads the ledger once for all keys, and a proxy's web page is said by its title (aiandcloud on X)
aiandcloud (2.98B tokens, 12,654 requests a day, server mode behind a
proxy) saw Gateway keys draw a Cloudflare 524 page as raw HTML.
Slow list: every poll of /api/caller-keys read up to a month of ledger
rows once per window per key. budget.AllOf now reads each distinct window
once for all keys, and keeps the settled blocks' sums with a cursor
(usage.VisitFrom), so a poll only reads what was appended since; the
unfinished tail block is always read again. A rewritten or shorter log
resets the cursor. All(k) is AllOf of one key.
Numbers (BenchmarkAll vs BenchmarkReadEach, 8 keys x day/week/month,
31 days x 12000 rows/day = 372k rows, warm): 211-228 ms before, 23.5 ms
after.
Raw HTML: fail() now turns an error string holding a web page (a remote
magpie's or a vendor's 524/502 page inside the JSON error) into a short
said/what pair, "A proxy in front of magpie answered, not magpie ({what})"
with the page's title, translated in all 5 languages (key already in
i18n.js). The browser already handled non-JSON bodies (notJSON, #2032).
Run (Windows box, mote ssh was down earlier): go test budget, usage, gui
(AllOf, Budget, FailSays, I18n, Keys); gateway-keys-proxy-page and
gateway-key-limit GUI files in chromium and webkit, 5 languages: 24/24;
gofmt; vet windows, linux nogui, darwin (mote, only a clang deprecation
warning). Broken by hand: with the old fail() TestFailSaysAProxyPageByItsTitle
is red; with VisitFrom's reset() removed TestAllOfIsWhatEachWindowRead is red.
Not tried: a user-scale cold ledger, a server behind a real Cloudflare,
the full suite before the tag (started after).
|
||
|
|
88c417392e |
usage: a sortable model speed ranking on the Requests tab (@flying_crp on X)
Usage's Requests tab gets a "Model speed" card: per model, the median output tokens/s, the median wait for the first token and the request count, over the selected range, sortable by every column (aria-sort header buttons, quiet table, no gradients). A request counts when it was answered (not rejected, handed on, failed or canceled), its first token was timed and it wrote 100 tokens or more (usage.MinRankTokens; the tooltip says so). Computed locally: each chunk keeps a 2% log-bin histogram per model beside its cells (speed_rank.go, chunkPart.speeds), a page merges the chunks' histograms, so there is no per-request sort and medians are within ~1%. The settled chunks' histograms are in the page file; its key salt is now page-v2, so the first load after upgrade recounts settled history once. /api/ledger sends speeds and speed_min. Run (mote): gofmt clean; go vet darwin, linux nogui, windows for the touched packages and ./... earlier; go test internal/usage, internal/usageapi, internal/gui ok at this head; usage-model-speed.test.cjs 12 of 12 (chromium and webkit, en/zh/zh-TW/ja/de, 400px: order, sort by every column, aria-sort, focus kept, no horizontal overflow, ellipsis, hidden when empty); with i18n-keys and i18n-en-no-cjk 20 of 20; the whole GUI suite once on the branch before the rebase: every red is in a file unrelated to this change (account-arrange #6010, account-refresh-holds #5814, account-eye #5052, agent-switch-accounts #5925, bulk visibility and disconnect previews #5982 fixed in |
||
|
|
d5f6159109 |
usage: a test that a failed stat keeps the log's last read (f2039c13f)
|
||
|
|
f2039c13fc | usage: a log that can't be read but for being absent keeps its last read (@simonzyzy on X) | ||
|
|
28a79bc33a |
gui: the gateway-mode stats test holds its clock at a local 00:30 (#5690)
TestGatewayModeStatsNameTheGatewaySessions wrote its record at
time.Now()-1h, which in the first hour of a local day is yesterday, so
days=1 left it out: red on macOS and ubuntu CI at
|
||
|
|
d02bb81788 |
usage: Codex's effort before the last few days goes when idle too
dropEffortPeriods let go of every period's kept CodexModelEffort answer,
but effortOlds (each period's effort before the cut, ~2.1 MB in the t60
idle heap with real accounts, under effortSplit) stayed for the life of
the process. It is in effort-v1.json and effortSplit reads it back from
there when the entry is missing, so it now goes with the rest, under
codexEffortBuilding (TryLock: a build under way keeps it).
Run on mote at this head: go test ./internal/usage ./internal/usageapi
./internal/gui ok; gofmt clean; GOOS=windows go vet and GOOS=linux go
vet -tags nogui ./internal/usage ok.
Broken by hand: without clear(effortOlds),
TestIdleCodexEffortLetGoAndBuiltAgain fails ("0 periods' answers and 1
periods' effort before the cut kept while idle").
Not tried: a fresh real-account heap at this head (next acrss run).
|
||
|
|
8d68b5f219 |
usage: Codex's model and effort answers go with the chunks' caches when idle
CodexModelEffort kept each period's answer (every Codex thread's
consumption by model and effort) for the life of the process. On a real
history it was ~6.9 MB of the idle heap after one visit to the Sessions
page (t59 measured on mote, heap at 10 idle minutes:
usage.keptCodexModelEffort).
Each ask now notes itself with derivedUsed, as the pairing and heatmap
reads do, and dropDerived lets go of every period's answer but one being
built. The page polls every 15 s while open, so it keeps them; the first
ask after derivedIdle (3 minutes) builds the answer again, waiting for it
as a first ask does.
Run on mote (go1.26.8):
- go test -count=1 ./internal/usage ./internal/usageapi ./internal/gui: ok
- gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui
for internal/usage: clean.
- Broken by hand: with dropEffortPeriods left out of dropDerived,
TestIdleCodexEffortLetGoAndBuiltAgain fails ("1 periods' answers kept
while idle").
|
||
|
|
d401c25951 |
usage: the found-group names hold the catalog, so a usage ask no longer builds it again (#5978)
|