aca0f0d8a1630923bf4e8a18b3a5a8ef508fc7bc
202
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
396e0e4638 |
usage: a deleted provider's requests merged into another, or named, from the Requests filter
CyberCaius on Discord: a deleted provider's requests sat under its old id
("<date> 已删除"), and the only way to put them under a provider they
have was renaming that provider onto the old id. Now, with a deleted
provider picked in Usage › Requests' Provider filter, a "…" beside it
offers Merge into… (an app menu of the providers there are now) and
Rename… (the filter's button turns into a name field; Enter or leaving
it saves, Escape keeps it). With the merged-into provider picked, the
same "…" lists Separate <name> for each, the undo.
Nothing in the log is rewritten. Both live on the deletion's own record
in providers.json (Deleted.Into/MergedAt, Deleted.Label), so a provider
added later under the old id inherits neither: it is a different
provider, and its record of its own is what it has. Renaming the target
carries the merge (Rename rewrites Into); deleting the target ends it.
Renames.Both(id, time) gives the id a call is shown under and the one it
was made to (Own). Listing, filtering, the summary and vias go by the
shown id; pricing (Record.priceID, block_price's as), window holds and
the gateway's loggedAnswers go by the own one, so a merge moves no cost
or token, only whose name they sit under. The target's face lists what
was merged into it (Named.Merged). Routes: GET /api/usage/deleted/into,
POST /api/usage/deleted {id, into?, name?}; a field not sent stays.
Run (mote, at this tree on
|
||
|
|
f39fc3ac8b |
usage: a model list that was answered is no row of Requests (ferock on Discord)
ferock (Discord #general): Usage > Requests is full of rows like "magpie · magpie's own · Remote magpie · API · Model list · 0 0 · 757 ms · 200, GET /v1/models", which no tool of theirs sent. Cause: |
||
|
|
3e22123c9c |
usage: a deleted provider's calls stay apart from a new one under its id
cybercaius (Discord): after deleting a provider and adding a new one
that took the same id, the old provider's usage showed under the new one.
Delete now records the provider in providers.json ("deleted": id, name,
icon, when, its Was and Gave). UsageRenames gives a deleted id to
<id>~<when> only once something reuses it (a live provider, a later
deleted record, or a later Was), so a deleted provider nobody replaced
keeps its raw id and the existing probe/usage tests stay as they were.
/api/usage's provider faces name a deleted id from its record and set
Named.deleted; the Usage provider picker notes "Deleted {date}" (zh, zh-TW,
ja, de translated). Old deletes, made before this, have no record and
stay merged: nothing tells their calls apart now.
Run (mote): go test -tags nogui -run 'Deleted|Rename|NotSetUp|Probe'
./internal/usage ./internal/usageapi ./internal/provider ok; gofmt -l
clean; go vet -tags nogui ok.
Broken by hand: dropping the f.Deleted append turns
TestDeletedProviderKeepsItsCallsFromOneAddedUnderItsID and
TestDeletedProviderListedApartAndMarked red; restored, green.
Not tried: a real delete-and-re-add in the GUI app.
|
||
|
|
a42d90d7de |
usage: a test holds every Bedrock maker models.dev lists (#2199)
ggbdpq's change before this one adds xai, writer, moonshot and nvidia to vendorDot, with six pairs read off the catalog. This test reads all 200 amazon-bedrock ids from models.dev's list of today (kept in testdata) and checks that each one answered by its own name, or by maker.name, is no swap. A maker the list gains later and vendorDot lacks fails here once the testdata is refreshed. The four makers are the only ones missing today: the list's makers are amazon, anthropic, deepseek, google, meta, minimax, mistral, moonshot, moonshotai, nvidia, openai, qwen, writer, xai and zai. Reported by gua2100 (ggbdpq) on GitHub. Run (on mote): - go test -tags nogui -count=1 ./internal/usage ok. - go test -tags nogui -count=1 -run 'Bedrock|Swapped|Served|RelayRenamed|Rename' ./internal/gateway ok. - go vet -tags nogui of both packages on darwin, GOOS=linux and GOOS=windows clean; gofmt -l clean. Broken by hand: with origin/main's served.go put back, this test fails on 21 pairs (xai 10, writer 6, nvidia 4, moonshot 1), and TestBedrockProfileAnsweredByItsModelIsNoSwap fails on ggbdpq's rows. Not tried: a real Bedrock account; a full go test ./.... |
||
|
|
c2d6a64c7d |
usage: a Bedrock model of a newer maker answered by its own name is no swap
What changed:
vendorDot names Bedrock's makers so a reply saying the model's own id
reads as the model asked for (
|
||
|
|
85b45b4d71 |
usage: a window's dollar whole prices the model the reply named (#2488)
The ledger prices a call whose own id has no price as the model the
reply named (Served, #1498). A window's whole priced through apiPricer,
which looked only at Record.Model, so one such call in a window had no
API price, the window counted as unpriced and its dollar whole was left
out while its tokens stayed. apiPricer now tries Served through the same
chain (maker, the provider's list, Same as) when the asked id has none.
The asked id keeps its own price when it has one; a price the user set
or a rate still never enters the whole. Past cycles use the same
apiPricer and take it too.
Patch by ggbdpq (Discord gua2100), as posted in #2488. Review: the
pricer is a closure built once per query with its own cache, keyed now
on (provider, model, served); no shared or stateful call added. The
only conflict on current main was the test file, where the Antigravity pools test
(TestWindowHoldsReckonsAntigravityPools) landed in the same spot; both
tests are kept.
Run (sandbox HOME, at this tree on origin/main
|
||
|
|
22bc7a4477 |
usage: a probe at another host of a provider's site is listed under it (CyberCaius)
CyberCaius on Discord, on the latest release: the Usage page's provider
filter listed Leee and leee.baby, and leee.baby's rows were the model
lists ("模型列表", magpie 自身, 200) asked while Leee was being added.
In the first report the same shape was example on api.example.me with
example.me in the filter, which we had put down to another address typed.
The Add sheet's model list runs before the provider has an id, so
probelog records it under the host asked.
|
||
|
|
841bcf8da7 |
usage: a reply under the name its provider's list gives the model is not a swap
jzing.draw (Discord #general, 10-27) had a Usage row for Qoder's free
Qwen model, sent as qfmodel, tagged "actual Qwen3.8-Flash". Since
plugins#412/#413 (qoder 0.2.38) the plugin answers under the model list's
display name, and Qoder's list names qfmodel Qwen3.8-Flash, so it is the
model asked for. Swapped compares names alone and can't know that.
usage.ListedAs(provider, model, served) reads the provider's own list
(Provider.Available, once a minute per provider, only once a reply already
reads as swapped) and holds when served is the name it gives the model,
spelled however (SameSpelled). Every place a swap is set or read again
asks it: the gateway's try, the ledger and request-page rows, block
pricing, a kept row read back (request_page unpack) and a kept route
(history routedAgain), so old rows lose the false tag too.
Run at this tree (base
|
||
|
|
14e4d80402 |
usage: an Antigravity card's pools draw their curve, say when they run out and what the whole holds
max2020 (Discord #help, 10-27): "为什么反重力这里没有额度的预测和对价格的预估". An Antigravity card's rows are its pools' windows (Gemini · 5 hours, Claude & GPT · 7 days …). They are Aside, since routing reads the models' own windows, and the models' windows are a Family's. So: - quota history (pointOf) kept none of them. The card had no curve and no "Runs out … at this pace" line, though noteQuotaHistory and the GUI already name a pool's line "Pool · window" ( |
||
|
|
28f3c4d7fd |
codex: the Codex app's first 100 models hold the ones used, hidden ones last
@ZhenLuoTTAWDTT on X: with Codex on magpie the model list stops short, and the models past it can't be chosen. Cause, from the clients' own code: the Codex app (ChatGPT.app 26.1013.40934, app-initial-90eb42395b7d.js) and the VS Code extension (openai.chatgpt 26.51021.22027, model-queries-667cf4bd657d.js) both ask their app-server for model/list with includeHidden, cursor null and limit 100 (e?.limit??100) and never ask for nextCursor. codex-rs's list_models pages the list sorted by priority, hidden entries counted, so anything past the 100th is in no picker there. The CLI's /model (tui model_popups.rs) lists every preset in a scrolling popup and has no cap. magpie truncated nothing; its models are numbered after the account's own, so a user with many models lost everything past ~100 in the app, while hidden entries (codex-auto-review and the like) took slots at the top. Fix: codexcat.Fit ranks the list last of all, on every route magpie hands Codex a list (/backend-api/codex/models after the user's own order, /v1/codex/models before its 1 MiB cut, and the model_catalog_json file via CatalogUsed): hidden entries go after every listed one, and with more than 100 listed, the models Codex used in the last 30 days (usage.CodexUsed, most recent first, at most 100; on /v1/codex/models only the asking key's, CodexUsedBy) are brought into the first 100 in the order they stood. The rest keep their order. The list's ETag and X-Models-Etag carry a tag of the used set (codexcat.UsedTag), so Codex asks again when it uses a model it hadn't; CodexUsed is read at most once a minute, or at once when Append writes a Codex call to a model it doesn't hold. Documented in docs/subsystems/gateway-routing.md. Tests (each red on the old code, broken by hand: Fit a no-op, the gateway calls and the used tag removed, Append's codexUsedNew removed): TestFitKeepsUsedModelsWhereTheCodexAppReads, TestFitLeavesAShortListsOrder, TestCatalogUsedFits, TestUsedTagIsTheSet (codexcat), TestCodexUsed (usage), TestCodexModelListKeepsUsedModelsInTheAppsHundred and TestCodexCatalogKeepsTheKeysUsedModelsFirst (gateway). Real run: codex-cli 0.162.1's app-server in a sandbox CODEX_HOME (never ~/.codex) with a model_catalog_json of 3 hidden entries at priority 1-3 and 150 listed models, driven over stdio with the app's own request (model/list includeHidden, limit 100). Before: page 1 held 100 of 153, 3 of them hidden, the last many/model-096, nextCursor "100". The same catalog put through Fit with many/model-140 used: page 1 has no hidden entry and ends with many/model-140. The TUI's /model scrolled to all 150 (tmux). Run with this change on |
||
|
|
94c2aaecba |
usage: a deleted provider's tests stay listed under it, not its host (cybercaius)
cybercaius on Discord: one custom provider (example, on api.example.me)
was listed in the Requests page's provider filter under its id and its
host, and the host stayed after the provider was deleted.
The Add sheet's Detect, model-list and Test requests are sent before the
provider has an id, so probelog records them under the host asked
("a provider being added has no id yet").
|
||
|
|
8e2ba36de9 |
usage: a provider's requests made while it was being added are listed under it, not its host (yyddbds)
yyddbds on Discord added one custom provider, 大灰狼 on dahuilang.best, and the Usage page's provider filter listed it twice: 大灰狼 and dahuilang.best. The Add sheet's Detect and model-list requests run before the provider has an id, so probelog records them under the host asked (probelog.Note: "a provider being added has no id yet"). Those rows are listed on the Requests page, and their provider went into the page's provider list as a provider of its own. Renames now also knows each provider by the hosts of its URLs, and probeChunk reads a probe row through Renames.ProbeOf: a host exactly one provider is on is that provider's id. It is done when the log is read, so rows written before this release are merged too. A host no provider is on (an Add given up) or two providers share stays as it was recorded; a provider id is never taken for a host. Run: - go test -tags nogui ./internal/usage ./internal/usageapi ./internal/probelog ./internal/provider (-skip TestUnreadLoginsWriteErrorsKeepCredentials, #3632) ./internal/gui: ok. - New TestProbesOfAProviderBeingAddedListItOnce: Detect rows written through probelog.Note under dahuilang.best and DaHuiLang.best before provider.Add("大灰狼"), plus a gateway call under its id; providers are [dahuilang other.example shared.example:8443], and the filter on dahuilang has its 3 rows. - gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows. Broken by hand: probeChunk back on Renames.Of fails it with providers [DaHuiLang.best dahuilang dahuilang.best other.example shared.example:8443], the reporter's two entries. Not tried: the reporter's own usage.jsonl; the full go test ./... (other sessions' suites were on this machine). |
||
|
|
51af40f9cb |
usage: a poll pairs Codex calls by id without decoding the session files the gateway names none of
codexChunkResponsePairs decoded every local chunk of the period on each Requests poll to look up the few response ids the gateway logged. The ids kept per chunk serial for the fold (foldIDs) now hold every call's id hash, not only Codex log calls', and a chunk none of whose hashes is a pick's is skipped. The pick is still made by the id string, so a hash match only reads a chunk, never pairs one. Measured on real history (rss-home, 8 GUI polls 15s apart, after a 90s warm start), magpie-ids vs v0.1.1677's code, two runs each: - CPU profile: pairRows 0.74s/0.70s vs 0.85s/0.89s; chunk unpacking 0.65s/0.59s vs 0.74s/0.81s; codexChunkResponsePairs 0.13-0.18s gone. - Allocations: the 191MB the pairs decoded is gone from it, but most of it moves to visibleLocal, which now grows the pooled row buffer the pairs grew before. Total 2671MB vs 2528MB, within live-history noise. Run at the pushed head (on |
||
|
|
9fed5dc8c1 |
usage: a Codex effort past its minute is told while the next is built behind it
The Sessions page asks for every Codex thread's consumption on each 15s poll. Once the kept answer was a minute old and any session file had changed (a working Codex or Claude Code changes one all the time), the ask built the ledger of all history inside the request, so /api/sessions held for 0.8 to 1.3 s about once a minute. Now that ask is told the kept answer and the build runs behind it, one at a time as before; the next poll has the change. A period's first answer, and one for another home, are still waited for. effortBehind is off in the usage tests' TestMain, as effortFresh is, so the tests that write a change and ask again still see it at once. TestCodexModelEffortHeldForAMinute now holds the build and checks that the ask after the minute, and one during the build, get the last answer, and that the ask after the build gets the change without a third build. Run at |
||
|
|
f3c4d7b7a7 |
usage: Codex effort reads only the session chunks that have Codex threads
CodexModelEffort (the Usage page's model and effort per Codex thread, read again each minute) unpacked every chunk of the ledger, Claude Code's and every other agent's too, to sum the few rows a Codex actor owns. codexEffortOfIndex now visits only chunks with a Codex actor (pairedRows.visitActors), and effortSums.add clones the model and effort it keeps, since lentRows lends its strings. Run at this head ( |
||
|
|
c272f3799e |
usage: a session file's Codex ids are hashed once while it stands
A Usage page polled while one session was live paired every chunk of the
period again, and foldCodexRows decoded each session file to hash the
same response ids: ~40 MB a poll of today's page, more than any other
part of it. Each chunk's Codex log calls are now kept by its serial as
one uint64 each (the id's hash shifted over its index, 8 bytes a call),
for the four folds after the last that read them, so a poll decodes
only the chunks that changed. Calls whose hash is the same are still
told apart by their ids after, as before.
Run (worktree clip; tests and vet again at this head, rebased on
|
||
|
|
8fba65d0bc |
gateway: what masking took a request is kept, and shown as Masking in its time
fremontdango on Discord asked, after the request that sat as "routing…" while it was masked, how long masking took. Now each request keeps it. noteRedacting adds up the time from the first masking at once to the last's end (redaction.spent); maskingMs gives it in ms, at least 1 when there was any, never more than Own, magpie's own time before the request went out (splitSent), since masking happens inside it. It goes on the route (Route.Masking, /api/gateway/trace) and in the usage record (Record.Masking, masking_ms; packedRow's int32 fits in its padding, so TestRowsOfOneSessionShareAShape's 216 bytes are unchanged, and the process-private snapshot carries it). It is a duration, no text. The Routing page shows it as magpie's "Masking" part, first in where the first try's time went (timeParts, renderSteps); the Usage page's detail splits it out of "In magpie" (page.js). Both use the core "Masking" string every language already has (脱敏, 脫敏, マスク, Maskierung). Why masking can be slow, measured on this machine (go1.27, M-series): the rules are linear, ~0.25 ms/KB. redact.MaskJSON over a Claude Code shaped body: 283 KB 35 ms (secrets) / 63 ms (+ personal data); 511 KB 70 / 122 ms; a dense 402 KB with 7,821 hits 173 ms with personal data, 144 ms with the user's words too. Through the gateway (redactedHits, secrets + personal, 402 KB dense) 145 ms the first time, 123 ms again; noteMasked ~2.6 ms. Doubling the body doubles the time; nothing quadratic or repeated per hit. So a request held "routing…" for 15 s or more (unroutedShow) while masked is the local model (Settings → Privacy → Find with a local model, internal/pii): it reads each text it hasn't seen (a new turn's tool results are the misses), one model turn at a time, so requests queue behind each other (#3682: 480 KB took 90 s on an RX 470/580). No change to masking's speed here; the phase and the time now say which it was. Run at this head, on origin/main |
||
|
|
c2c08850f6 |
usage: a request state hashes Codex's thread identities without encoding them
readRequestState json.Marshal()ed every Codex thread's identity (~20k over a real history) into a new buffer only to write it into the key's hash, on every requests page and effort ask: every 15 s poll. They are now written into the hash directly, each field length-prefixed, in the order of their keys. The key lives in memory only (the disk index is keyed by meta), so the changed form costs nothing on upgrade. Benchmark, 20k identities (a throwaway benchmark, not committed): json.Marshal + hash 7.06 ms, 6.49 MB, 40012 allocs an ask; now 3.36 ms, 0.36 MB, 3 allocs. In a 12-poll real-history run json.Marshal under readRequestState was 116 MB. Test: TestCodexIdentitiesHashed (same identities in another order hash the same; a thread turning subagent changes it; ab|c is not a|bc; none is not one). It fails with the length prefixes taken out by hand. The rest of the package's tests passed with this hash removed altogether: an identity changes only with a rollout, whose size and time are in the key too. Run at this tree: go test ./internal/usage/ ok (8 runs; one earlier run of this change printed a bare FAIL whose test I lost to a tail, not seen again in 8 package runs and 30 of the effort tests); gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/usage ok. |
||
|
|
61d656c696 |
usage: a Codex thread's consumption is built again at most once a minute
The Sessions page asks CodexModelEffort(All) on every 15 s poll. It
built the ledger of all history again whenever any session file or the
gateway log had changed, and with Codex and Claude Code at work they
change between nearly every two polls. In a 3.5-minute real run that was
2.49 GB allocated, the largest single cost of a poll. An answer now
stands for effortFresh (a minute) before a change is built into it, and
an ask inside the minute is answered before the sources' state is read
(that listing and hashing is most of an unchanged ask's cost). Another
home's answer is never held (requestRoot). The page's own rows, totals
and the requests page are read as they change; only this per-thread
model/effort breakdown can be up to a minute behind.
Tests: TestCodexModelEffortHeldForAMinute holds the answer inside the
minute (no build, the old value), builds the change after it, and
builds for a new home at once. It fails with the check turned off by
hand ("inside the minute: builds 2 ... want 1"). The package's TestMain
sets effortFresh to 0, so every other test still sees a change at once.
Measured on a copy of the owner's real history, 12 poll cycles 15 s
apart after a warm start, origin/main
|
||
|
|
d03779cc10 |
usage: the Requests page's seen message ids are hashes, not copies
visibleLocal leaves out a Claude message written again in another file
(a resumed or forked session's copy). It kept every id it had seen as a
strings.Clone of the decoded chunk's string, so a long history's ~400k
ids were copied on each page build: ~7MB held at the start's peak and
27MB more allocated per run. It now keeps two maphash values of each id
(seeds made per process); two ids alike in both are ~1e-28 likely.
Measured with the real ~/.codex and ~/.claude histories (sandbox HOME,
fp3 harness), base
|
||
|
|
39526c0690 |
usage: Append keeps the log open between calls, not an open and a close for each request (#3725)
Every request the gateway serves appends a line to usage.jsonl, and Append opened and closed the file each time. In a CPU profile of the request path (BenchmarkZZIO, a local benchmark not committed) Append was 0.51s of the handler's 1.36s, 0.35s of it in os.OpenFile and 0.07s in Close. Now the handle is held, under the same mu. Before each write the held file's identity is checked against what Path names now (fstat and stat, os.SameFile), so a log another program moves, removes or replaces, or a Path that changes with HOME, is opened again. A failed write drops the handle. Windows still closes after each write, since a file held open there can't be removed or renamed. Measured (local microbenchmark, open+fstat+write+fstat+close against a held file with stat+fstat+write+fstat, 600-byte lines, 20000 runs, load ~80): 55 to 116µs per call before, 11 to 24µs held. On the whole request (BenchmarkZZIO) the difference is inside the noise at this load, so no request-time figure is claimed. TestAppendHeldLogFollowsThePath appends twice and checks the second call used the same handle (and that Windows holds none), then replaces the log by rename, removes it, and moves HOME, checking each time that the next call is counted in the file Path names. Broken by hand (identity check skipped) it is red: after a replacement the call went to the old file and Summarize counted 0 calls. Windows box (test binary run outside the source tree): internal/usage, mine and origin/main |
||
|
|
e1709ab42e |
usage: Append makes the log's folder only when it is missing (#3725)
Every request appends one line to usage.jsonl, and Append ran os.MkdirAll on the folder first each time: a stat, and on its error path a walk up the tree. Now the file is opened first, and the folder is made (then the open tried again) only when that open says it doesn't exist. Measured with a scratch benchmark (not committed) at |
||
|
|
9dc7d6eb84 |
usage: a large build's archives are held in a spill file as they are made (#3493)
A cold build (first start, or after an update that changes internal/usage)
kept every chunk's archive on the heap until save had written
requests-v1.bin and swapped them for the file's pages: 31MB for 15.7k
sessions, the largest thing a cold peak held over a warm start's.
Now a build that wants requestDiskLeast or more files written writes each
archive to requests-*.spill as the chunk is made, lets go of the heap copy,
and maps the file once the build is done (unlinked at once). save then
swaps the spill's pages for requests-v1.bin's as before: pagesRank orders
heap < spill < file, and keep and save take the later. A spill that can't
be written or mapped has each of its chunks made again from its source, so
none is left without an archive. Windows maps no file, so nothing changes
there.
Run, real data (15.7k Claude Code + Codex sessions, sandbox HOME, copies of
the call shards, requests-v1.bin removed before each run), the gui warm-up
harness alternating old (
|
||
|
|
cbbf3163cb |
usage: a cold build's chunks are of the file's pages once it is written (#3493)
A start that reads requests-v1.bin keeps each chunk's archive in the
file's mapped pages, not on the heap. A start that builds the chunks
(a cold one: no file, or one of another build) kept the archives it
encoded on the heap until the next start, after writing the very same
bytes to the file: 32-40MB for 15.7k sessions, and a resting heap
~50MB over a warm start's.
Once save has written the file, onDisk maps it and makes, for each
chunk whose archive is of the heap, a copy whose archive is the same
bytes of the mapping (checked equal). save swaps it in for the chunk
of the same serial: a read since has copied the chunk with a use of
its own, so the pointer it wrote is gone by then. A read that copied
the chunks before the swap and finishes after it keeps the mapped
archive (keep), or it would put the heap one back. Nothing changes
where no file is mapped (Windows).
diskUnmapped, the tests' hook, is an atomic.Pointer: a mapping's
cleanup reads it on its own goroutine while the next test sets it,
which -race -count=4 caught once the new test let go of mappings.
Run at this tree (
|
||
|
|
ba301e98e2 |
usage: a page's passes over the chunks decode into buffers kept between them (#3493)
Each pass of a Requests page over every chunk (foldCodexRows, the
response pairs, visibleLocal, matchedBlocks, visit, partsOf, newest,
rowsOf) started a chunkRows with no buffers and grew its rows, strings,
shapes and decode buffer from nothing. A warm start's All page and
Codex's effort after it read the same rows pass after pass, ~30 MB a
pass. chunkRows now takes a rowBuffer from a pool, unpacks into it
(unpackReusing gets a dst chunk too, so the open chunk isn't allocated
each block), and gives it back on release, its strings cleared so no
row text is held.
Measured on the real data copy (sbpairs: 12k Codex rollouts and the
Claude projects), warm-up harness TestZZWarm, each binary run 3 times
in a row and the first run dropped (the chunk file is named by this
package's source, so alternating binaries rebuilds it):
step 2 (QueryPage All) allocated 835 MB -> 666 MB
allocated through step 3 (effort) 994 MB -> 820 MB
unpackReusing in step 2 163 MB -> 34 MB
peak footprint ~240 MB, unchanged
Run at this head (base
|
||
|
|
42976f9a08 |
usage: a renamed provider is shown once, by the id it has now
cybercaius on Discord (#help, 10-25): "已经更改供应商 id 的也没有变更过来反而
分开显示了". Reproduced in a sandbox HOME (magpie web on 3582, fake upstream
on 3583): after renaming myrelay to newrelay in the editor, the Requests
page's provider list had both myrelay and newrelay, each named "myrelay",
because the model-list probe row was still under myrelay. The summary was
already folded; the probe chunk, the Sessions tab's vias and the gateway's
loggedAnswers (lead-first routing) were not renamed at all.
What changed
- provider.Renames (UsageRenames): Of(id, time) is the id a call recorded
under id at that time belongs to now. Every usage reader goes through it:
summarizeFrom (and its historical-key set), ledgerMatched, NewPricer,
NewCoster, the Requests page's gateway blocks, probe rows and other
computers' days, window holds and their history, buildVias, and
gateway loggedAnswers. Visit stays as recorded so Of is taken once.
The summary, Requests and vias caches key on Renames.Key.
- An id reused by another provider no longer pulls the new one's calls
into the old one. Rename onto, or Save of a new provider under, an id in
another's Was moves it into that one's Gave with the time (giveID):
calls before then stay the old provider's. freeID treats Was ids as
taken, so adding the vendor again gets "-2". Renamed() (refs) skips ids
a provider or subscription holds now.
- A providers.json that can't be read keeps the last renames read instead
of none (a failed read is unknown), so usage doesn't split meanwhile.
- History: nothing in usage.jsonl is rewritten. Calls from before this
release under a renamed id show under the new id at once. An id that was
reused before this release has no hand-over time, so its calls show under
whoever holds the id now, as before.
Siblings checked: budget keys by caller key; per-key limits, RPM and
concurrency count live requests by the current id; tray totals go through
QueryPage; codex_memory reads Requested refs. None needed a change.
Run at the tree before the rebase; rebased onto
|
||
|
|
115ca34343 |
usage: the chunks' file is mapped, not read into the heap (#3493)
A start read requests-v1.bin's 44MB of chunk archives into the heap,
where they stayed: a fifth of the heap at rest, and with GOGC 25 a
larger heap goal through every warm-up step. They are pointer-free and
only ever decoded, so on unix the file is now mapped read-only
(MAP_SHARED, PROT_READ) and each chunk's Archive is a capped slice of
the mapping. A cleanup unmaps it once no chunk refers to it. The file is
only replaced by a rename (toDisk), never written in place; a read past
its end, if another program cut it short, is caught by readMapped
(SetPanicOnFault) as a failed read, not a crash: the chunk unpacks as
nil and reads as no rows, as a corrupt archive did before, until its
session file changes or magpie starts again. Windows can't
rename over a mapped file, so it reads the file as before
(request_disk_map_other.go).
decodeMapped keeps the decode's closure out of unpackReusing: with the
closure there, data escaped to the heap and every row's take() through
it was slower, which made step 2 0.12-0.2s slower than before (found by
profile: unpackReusing.func2 0.28s -> 0.64s over three runs).
Run at this tree, on the owner's real data (sandbox HOME with
.claude/projects and .codex/sessions linked read-only, ~421k rows), warm
runs interleaved with v0.1.1471 (
|
||
|
|
b1f44d099e |
usage: Codex's effort reuses the pairing the page of its period just made (#3493)
The warm-up builds the Requests page of All and then Codex's model and effort over All. The page keeps its pairing of the calls (pairMemo, by chunk serials), but the effort paired every session file's calls again from nothing, the warm-up's step 3. It now reads requestIndex.pairs[p] before taking its private copy and pairs through pairRowsMemo, so unchanged chunks keep their pairing, and it keeps the new pairing for the next page or effort. Storing a period's pairing is one helper, keepPairs, that queryPage uses too. Run at this head (on |
||
|
|
e1f5f9c164 |
usage: the passes that pair a page's calls read a chunk's strings in place (#3493)
A Requests page decodes each packed session chunk in five passes, one chunk at a time (chunkRows). Every decode copied the chunk's whole string section out of the pooled buffer, though four of the passes (folding Codex's repeated calls, pairing Codex response ids, Claude's repeated message ids, request-id matching) only look strings up and clone the few they keep. That copy was the largest allocation of a warm start's page. Those four passes now read through lentRows: the chunk is decoded into a buffer the reader owns, and its strings are of that buffer until the next chunk is decoded over it. The cell pass and every reader that keeps rows still copy. What was run, at this head: - Real data (sbpairs: 421,206 calls, 15.6k session files), warm-up steps three runs each, before / after: step 2 (first Requests page): 0.88-1.03s / 0.76-0.79s, ~560 MB / 446 MB allocated; whole warm-up 1.41-1.45 GB / 1.21 GB allocated; maxrss 320-336 MB / 318-319 MB. - Real pages, base and this change alternately: QueryPage of All, today, 7d and 30d at offsets 0 and 500, and CodexModelEffort(All). Totals, rows and every string are the same; the only differences are float costs' last digits, from summation order, which differ between two base runs as well (and one new live call). - Broken by hand: storing the lent message id and request id without their clones turns TestRequestPageSameFromPackedLocalChunks red. - go test ./internal/usage ./internal/gui ./internal/sessions ok; -race -run 'TestRequest|Codex|Packed|Visible|Match' ./internal/usage ok; GOOS=linux and GOOS=windows go vet -tags nogui of usage and gui clean; gofmt clean. Not tried: the full ./... suite (one suite per machine; only the packages this reaches were run). |
||
|
|
ac149224f9 |
usage: many rows made since the last write have it written once a run (#3493)
The file of the session files' chunks (requests-v1.bin) was written only once 64 files' chunks had been made since the last write. Long sessions that ended since then are few files with many rows: on the real history (sbpairs) two starts in a row each made 9 files' chunks again, 84,625 calls (one Claude Code session alone is 52,191), and neither wrote them, so every start did it again, and the sessions that ended next joined them until they were 64 files. noteBuilt also counts the rows made, and writes the file once a run when they are 20,000 or more. Once, as a session still at work is made again after each of its calls; the 64-file write is as it was. Run on |
||
|
|
42ab935516 |
usage: requests-v1.bin is of the code that makes rows, not of the binary
The file of the session files' chunks was named by the binary's own
stat key, so every upgrade, and magpie ships several a day, read every
session file again on its first Requests page: on a 15.6k-shard history
warm-up step 2 went from ~0.8-0.9s (read from the file) to 1.6-1.9s and
~1.3GB more allocation. It is named now by the call shards' version
(sessions.CallCacheVersion, which already decides whether a shard of the
calls is read) and a SHA-256 of this package's non-test source, which
the binary carries (go:embed *.go, ~750KB with the tests, which the name
leaves out). Of the last 99 releases, 17 changed that source; the other
82 keep the file. Prices, names and settings are in the file's meta as
before. When the embedded source can't be read the name is the binary's,
as it was.
Measured (real history, sbpairs): one test binary wrote the file, a
second binary at another path (the old key differs) read it: step 2
0.79s and 1001MB alloc, against 1.63s and 2285MB cold.
Run at this tree (
|
||
|
|
3767addd4d |
usage: a block's strings and shapes are read into buffers the next block reuses
Each Requests pass (warm-up step 2's whole-history page, step 3's Codex effort pairs) decodes every packed block through chunkRows, which already reused the rows' buffer. Each block still made its strings slice, its shapes slice and a []int of every string's offset and length, ~170MB of the ~450MB a pass allocated on a 15.6k-file history. chunkRows now keeps the strings' and shapes' slices too (unpackReusing), and the offsets are found by walking the copied section's length prefixes a second time instead of being stored. The strings themselves still point into one copy per block, so a row taken from a block keeps its text after the buffer moves on; only the slices are reused, and nothing holds a block's slices past the next of(). Measured (real history, sbpairs: 15,656 call shards, gui warm-up steps, zzbase = |
||
|
|
2a3d9f5aeb |
usage: a session file's rows are made by the reader that read it (#3493)
A cold Requests build (every upgrade) read the call shards eight at a time, but turned every call into a row on the one loop that takes them: logRecord, the account resolver, pricing, interning and packing, ~1 s of serial CPU over a real history, with the readers waiting on the window behind it. prefetchSources becomes prefetchEach: each reader has a make of its own from newMake, and the loop has its own for a source not wanted. Request rows are made there. Each make has its own Pricer and Swapped memo, so neither needs a lock; the session resolver is made once (sync.OnceValue) and only read after. The serial number is still given in the loop, in source order. The window now holds packed chunks, smaller than the calls it held. Measured on a copy of real data (15,656 shards, 3,451 Claude Code subagent meta files), GUI warm-up step 2 (QueryPage(All)), cold (requests-v1.bin written for the other binary), alternating runs: - before ( |
||
|
|
31bff66be3 |
usage: a session file's few calls are kept packed too
pack left a chunk of fewer than 64 rows as rows. Most session files hold a handful of calls, so a cold build (the first start after an update, or with no requests-v1.bin) kept 13,972 of 15,624 local chunks unpacked: 98,320 rows. The same chunks read back from requests-v1.bin are all archives, so the cold build alone held them as rows. Now every chunk with a row is packed when its archive is smaller, as the file's entries already were. Measured on the real history copy (sbpairs: 15.6k session files, 420k calls), one QueryPage(All) from cold under GOGC=25 as the GUI's warm-up runs it, three runs each, old then new: - heap in use after: 267/267/269 MB -> 229/227/232 MB - peak heap in use: 357/367/341 MB -> 308/338/336 MB - max RSS: 454/462/448 MB -> 420/424/449 MB - page: 2.95/2.41/2.52 s -> 3.66/2.19/2.42 s (no change past noise) A page after a new call, packed chunks read from the file: 120-143 ms, as before. TestFewRowsArePacked packs three rows and reads them back. It is red with the old 64-row floor. Run at this head: go test ./internal/usage (ok); go test -run 'Usage|Request|Tray|Session' ./internal/gui ./internal/gateway (ok); go vet ./internal/usage, GOOS=linux and GOOS=windows -tags nogui; gofmt -l. Not run: the full suite (one per machine). |
||
|
|
5d2260d3e6 |
usage: the Requests page's chunks are kept on disk, so a start doesn't open every call shard again
A started magpie opened every session file's call shard (~15.6k on a busy
machine) and turned each call into a row again before its first Requests
page could show (#3493). requests-v1.bin (beside sessions.json) now keeps
each session file's chunk as the page packs it: an entry stands while its
file's size and mtime are the same, as a call shard does, and the whole
file while the binary that wrote it and the index's root and meta (prices,
names, providers) are the same. Each entry has a length and CRC-32; a bad
one ends the read and the entries before it stand.
- The file is read when 64 or more session files want reading (a start, a
change of prices), and written behind the lock once 64 or more chunks
were made since the last write; fewer are a few shard reads next start,
not worth writing the whole file again. The idle trim does not write.
- A chunk of another computer's day is not kept; times keep their zone
(Local, UTC, a tz-database name or a fixed offset).
Real data (sandbox HOME with the live ~/.codex/sessions and
~/.claude/projects symlinked read only, 15,603 sources, 420k rows, load
~90 to 130): a cold All page 3.6s; written in 76 to 168ms behind the lock,
44MB. A start from the file: fromDisk 50ms for 15,602 chunks, then the
blocks 100ms, against the shard reads before; the whole page 1.5s, most of
it now readRequestState (0.65 to 1.1s), which is next. Same total, cost
and input as the cold page.
Run at
|
||
|
|
4982ded8a6 |
usage: a turned page reuses the last pairing while its chunks are the same
A Requests page paired every Codex session file's calls with the
gateway's again on each query: clone, fold forks, match response ids.
That unpacked every session chunk three times and was about half of a
warm page (#3493). pairRowsMemo names the chunks of a pairing by their
serials (the probe chunk, which has none, by its rows' log offsets and
times) and keeps what the pairing found: the rows left out (skip,
matched), the actors it changed and each chunk's compactions. The next
query over the same chunks and window applies that to fresh clones
instead of pairing again. A changed file gets a new serial, a new
window or period misses, and adopt drops the memos with the parts.
Run at
|
||
|
|
a6399dd494 |
usage: a Requests page sums each chunk once and reuses it while the chunk is the same
Turning a page, or the 15s refresh of the open page, built every sum, chart and share from every row of history again. On the owner's real history that was 1.15-1.36s a page (load 170) after the chunks were already cached. Each chunk's rows are now folded into cells: one per provider, agent, model, kind, caller, account, computer, source, filter bits and chart bucket, with its totals. A page merges the cells. The cells of a chunk are kept per (period, filter, since, until, zone), up to 4 such sets, keyed by the chunk's serial (a new one every time a chunk is read or frozen) and a signature of what pairing gave it: rows skipped or matched, Codex actors and their identities (with the parent's role), and compactions. A changed file, a gateway tail block or an identity change from another file sums that chunk again. The newest rows are taken from chunks in Latest order, stopping once the heap holds rows newer than the next chunk. Cell strings are unique handles, so the cache holds no chunk's string block. Totals and Part sums are linear, so merged cells equal the row-by-row sums; date-mode buckets store the day number and are placed against the chart's first day at merge time. What was run (macOS, arm64): - Real history (sbmem sandbox HOME, read-only links to the owner's data), zzbench dump of 9 cases x 2 pages (offset 0/50 after a warm 7/50 call, and 120/30) with the base |
||
|
|
1313b047f5 |
usage: a Codex thread's model and effort are read through the request index
CodexModelEffort, which the Sessions list asks for, read the ledger again on every build: sessions.AgentCalls(since, "codex") opened all of Codex's shards (12k rollouts, 15.6k shards on the reporter-sized sandbox) after any new call, beside the Requests page reading the same files into its own index (#3493). It now reads through the request index as a page does: readRequestBlocks (moved out of queryPage), the page's pairing and visit (pairedRows, moved out of buildRequestBlocksOf), and the sums added row by row as they are visited (effortSums), so a build after a call reads only the files that changed, and the first of the Sessions list and the Requests page reads them for both. The LogCalls path still builds from codexEffortRows. The visit's row is one per visit now: as a returned closure's local it was moved to the heap, one allocation a row, which TestRequestPageAppendDoesNotRepriceHistory caught (10890 allocations over 8000 records against 2000). Measured before the rebase onto |
||
|
|
ffe493773c |
usage: magpie's own Test, Detect APIs and model list requests are rows of the request log, counted nowhere
neiko and gys619 on Discord: a provider's Test or Detect APIs left no
trace in Usage > Requests, so a failing test couldn't be read back.
The provider package marks the context of the editor's Test, Detect APIs
(and per-model detection) and a model list's refresh with a kind
(internal/probelog). Each request sent under the mark is written once:
by the provider's Do, or by probelog.Transport under http.DefaultClient
(netproxy.Install), whichever sends it first; the Claude Code run and
the gateway's translated test write theirs from their result. A row
keeps time, provider, account, model, host, path (no query, no
user:password), method, status, ms and the first 500 bytes of the error.
The row is usage.SourceProbe, agent "magpie", Kind provider_test /
api_detect / model_list ("Test", "Detect APIs", "Model list" in Called
for; purposes.js regenerated). The log index keeps probes apart
(logSnapshot.probes), so Visit, Load, Summarize, budgets, Vias, heatmap,
shared days, LastSeen and observers never meet one. The request page
lists them (probeChunk) and counts none: Row.IsProbe, since a packed row
keeps the row's Source and not its record's. The page shows a muted
badge "magpie's own · not counted in any total" (en, zh, zh-TW, ja, de);
no new control, no layout change.
Tests, each red on the old code:
- usage TestProbeRowsListedNotCounted: listed, clipped, and absent from
Sum, Through, every By group, Summarize, Load, LastSeen, OwnDays and
the observer; a provider filter lists it and sums 0.
- provider TestTestWritesItsRequestsDown / TestDetectWritesItsRequestsDown:
every request the fake server saw is exactly one row, with the right
kind, model and 401 text; an unmarked Do writes nothing.
- probelog TestNoteKeepsNoSecret, TestTransportOnce.
- GUI usage-ledger-probe: badge per language, both engines, 1180/420,
light and dark, no left border, no sideways scroll.
- gui TestProviderDetectDraft now expects the log line (source probe,
kind api_detect, no key) and leaves usage.jsonl out of the unchanged
config comparison.
Broken by hand, each went red: request_page's uncounted check,
log_index's probe skip, Append's observer skip, Do's Taken (6 rows for
4 requests), Test's and Detect's marks, probelog's query strip,
page.js's badge (11 GUI fails).
Run at this head (on origin/main
|
||
|
|
22a7f86c9b |
sessions: the Requests page walks the Codex folders once a rebuild
readRequestState asked CallSources and then CodexIdentities, and each walked ~/.codex/sessions and archived_sessions, lstat()ing every rollout. Over the 12,069 rollouts of a real Codex folder that was two walks of ~75ms on every rebuild, which runs on each 5s refresh while an agent works. CallSourcesAndCodexIdentities walks once and hands the list to both; CallSources and CodexIdentities stay as they were for their other callers. Run at this head: - go test -timeout 45m ./internal/sessions ./internal/usage ./internal/usageapi: ok. TestCodexIdentityParentChainsAndSummaryCache now checks the one-walk pair equals CallSources and CodexIdentities. - GOOS=linux and GOOS=windows go vet -tags nogui on both packages, gofmt. - Real data (sandbox HOME over the owner's ~/.codex, 12,069 rollouts, ~416k rows): CPU profile of two rebuilds, codexFiles 0.31s before, 0.12s after. Wall times on a loaded machine were 1.0-2.1s both ways, too noisy to compare. Not tried: Windows or WSL folders (wslFiles is still walked as before). |
||
|
|
8b460833e0 |
usage: the Requests page keeps its chunks while it is open
Every new call is a new page key, so the open Requests tab works its
page out again on each 5s refresh. The session files' packed chunks
were held to 24 MB. A history of 416,000 calls has 63 MB of them, so
each rebuild read 2,679 shards again (39 MB), gob-decoded them, priced
each call and packed it again, and dropped them again after.
Now the chunks are held to 128 MB while the page is asked for. After 2
minutes with no ask (requestIdle), a timer cuts them back to the 24 MB
they were held to before (requestIdleBytes), so an unopened page holds
what it held before.
Measured on the real sandbox data (sbmem, 416,665 rows):
- zzbench, one QueryPage of period=all and six rebuilds at new offsets,
alternated with v0.1.1439's code at load ~150-200: user CPU
17.26 / 16.09 s before, 10.79 / 10.21 s after; sys 3.41 / 3.01 ->
1.98 / 2.14 s; peak RSS 604 / 664 MB -> 566 / 543 MB. A debug count
showed 2,679 shards read per rebuild before and 1-2 after (the
files that grew).
- A running magpie (`web --gateway` under sbmem), /api/usage/requests
period=all at offsets 1-5, warm file cache, load ~175: rebuilds
1.98 / 1.99 / 1.50 / 1.69 / 1.52 s on v0.1.1439, 1.30 / 1.18 / 1.09 /
1.07 / 1.07 s now. Cold (the first run after building), one rebuild
took 23 s; v0.1.1439's cold rebuilds took 5.5-8.0 s, and the warm
reruns didn't show it again.
- Heap in use on that server, by /v1/magpie/heap: after the builds
175.7 MB (v0.1.1439) and 199.1 MB (now); after 140 s unasked 161.7
and 149.8 MB. Footprint 339 -> 286 MB and 302 -> 254 MB.
Tests: TestRequestChunksTrimmedWhenIdle checks that three chunks over
the idle bound are kept while the page is asked for, and dropped once
it goes unasked. It waits for that state, not for a time. Broken by hand
both ways: without the idle trim it fails ("3 chunks kept after the
page went unasked"), and with the build trimming to the idle bound it
fails ("0 chunks kept while the page is asked for"). It also passes
with -race -count=3.
Run at this head: go test -count=1 ./internal/usage ./internal/gui ok
(16.1s, 201.8s); go vet -tags nogui for GOOS=linux and windows on
internal/usage ok; gofmt -l clean. Not run: the full suite (other
sessions' suites hold the machine).
|
||
|
|
66b6d6ade9 |
usage: the Requests page sums each row once, not once per group
Every Requests page build (each 5s refresh of the newest page, each page
turn, each filter) walks the whole period. Over all of it each row went
into about 17 sums: the page's own, a source cell, five chart series
groups, five dimension groups, the caller key and account groups, the
computers' share, and the chart point with its five parts. Each one
copied the 896-byte Row and worked out Decode and Floor again, and
each dimension rebuilt f.Without(d) and ran keepsRow on another copy.
Now each row's sums are made once (Totals.addRow into d) and added to
each group (Totals.plus, Part.plus). The filters with a dimension, or
the computer and day, cleared are built once. A filter that clearing
leaves unchanged reuses the row's own keep, and with no pick that is
every dimension. keepsRow, keepsRecord, computer, Row.key and keyer.key
take pointers.
Measured on the real sandbox data (sbmem, 416,665 rows), with zzbench:
one QueryPage of period=all, then six rebuilds at new offsets. Process
CPU at load ~110-127, three runs each, alternated with the old binary:
before (
|
||
|
|
7d67910f74 |
usage: the Requests page reads packed chunks in place, and owns its strings
The first Requests page after a start unpacked every local and shared chunk whole and held them all while it built the page, so a cold page on the owner's real usage peaked at ~450-480 MB footprint (#3493 follow-up: "发版后把 RSS 峰值也修了"). queryPage now keeps chunks packed. visibleLocal, matchedBlocks, the Codex identity fold, the chart and rowsOf read a packed chunk through chunkRows, a one-entry cache that decodes into one reused buffer. The Codex response pairs are read per chunk (codexChunkResponsePairs), and pack records Count so a packed chunk's length is known without a decode. An unpacked block's strings are substrings of one text, so a row or name the page kept would hold that whole block (~9 MB, kept by the request cache): buildRequestBlocksWithCodex now copies every string of the finished page (ownStrings). Measured (owner's real usage copied into a sandbox HOME, warm caches, first /v1/magpie/requests page, base = |
||
|
|
3a47e377e0 |
usage: a call whose vendor counts no cache is left out of every hit rate (#3464)
#3464 (zeewell on X): Kiro caches on its side, but its replies give only credits and a context share, never cache tokens. Every hit rate outside the Routing page read those calls' CacheRead of 0 as a miss. A Kiro-heavy day showed "hit rate 6%" when the counted calls hit 90%. The plugin already says so (opencode-kiro-auth 0.1.16 sends usage.magpie_cache_unknown), and the gateway already kept it as RouteUsage.CacheUnknown for Routing. This carries it the rest of the way: - gateway: Usage.cacheNotCounted() (the vendor said so and no try reported a cache token) goes into usage.Record.CacheUnknown on every path that records a call: the gateway's own record, the OTel attempt path in observe.go, and trace's routeUsage. - usage: Record.CacheUnknown is kept as ledger row flag 8192 (rowCacheUnknown; grepped, no other flag uses that bit). Totals sums such calls' prompt into cache_unknown and counts them in cache_unknown_calls. Totals.HitRate leaves that prompt out of its denominator, and gives no rate when nothing is left. - Old records: calls kept before the plugin said so carry no flag. A Kiro call (provider kiro or kiro-plugin) with no cache counted is read as uncounted (usage.CountsNoCache): in the ledger's row read, in Totals, and for Routing's history in internal/gui/trace.go (cacheCounted). The rule is scoped to Kiro's two ids, so another vendor's 0 stays a miss (tested). - GUI: cacheHitOf in app.js drives the tray panel's card, the Usage page's agent rows and cache tile, the requests' Cache hit rate card and each ranking row. When only uncounted calls are left it shows "—" or nothing instead of 0%. Otherwise it says "{n} requests left out: their vendor doesn't count the cache". A request row's cache cells show "—", and its details say the vendor doesn't count the cache. The Context page (context.go, context.js) shows no cache for such a call and doesn't score it as a miss. - No budget raised. This adds 625 bytes to app.js (1,320,224 to 1,320,849, under its 1,321,336); |
||
|
|
1f589e3f4f |
usage: read today's usage ahead at startup
CyberCaius (Discord, Windows): "今天 N 次调用" is slow on the first
panel open after a start. The first usage?period=today parses
usage.jsonl: 0.33s for 2MB, 0.43s for a 40MB sandbox log here, more
on a slower disk. startBackend now runs usage.ReadAhead() in the
background, which works out today's summary into the summary cache,
so the panel's first ask finds it.
Parallel parsing was not done: with the read ahead, a request 1s
after start answers in 1-2ms, so there is nothing left to win there.
Test: TestReadAheadLeavesTodayNothingToRead. After ReadAhead, a
SummarizeTopIn(Today) parses nothing and works nothing out. Red with
ReadAhead's body emptied ("parsed the log 1 more times and was
worked out 1 more").
Run at tree 53ae48f72 (on origin/main
|
||
|
|
3be1f14ebb |
usage: a re-read source asks Swapped once per model pair (#3493)
Swapped's regexps ran for every call of every file read again: a few hundred sent/served pairs over ~289k calls on the owner's real history, about a third of the re-read's pricing cost in a CPU profile. queryPage now keeps each pair's answer for the read. Measured at internal/usage with the owner's real ~/.codex and ~/.claude in a sandbox HOME: a heatmap read whose key changed, 3.0s -> 1.4s together with the heatmap's own page. Run at this tree: go test -count=1 -timeout 45m ./internal/usage ./internal/usageapi ok; GOOS=linux and windows go vet -tags nogui ./internal/usage ok. |
||
|
|
cf8b1e9338 |
usage: the heatmap works out only its days, kept 30s while only session files change (#3493)
The Requests tab asks for the year's heatmap on every ledger refresh. A live agent writes its session file all the time, so the page's key changed for every ask and the whole year was worked out again: groups, shares and series the heatmap never reads, over ~289k calls on the owner's real history. - buildRequestBlocks returns at once for the heatmap's period with only HeatmapOf's days, from the rows the chart filter keeps. - queryPage keeps a heatmap page 30s (heatFresh) while the gateway log's snapshot version is the same; a meta change (prices, names, wires) drops it, and a call through magpie shows at once. Measured at the handler (internal/gui, sandbox HOME with the owner's real ~/.codex and ~/.claude, 15,553 sources, 59.9 GB): heatmap steady refresh 2.99s -> 0.15s, cold 5.5s -> 4.5s. Run at this tree: go test -count=1 -timeout 45m ./internal/usage ./internal/usageapi ok. TestHeatmapKeptWhileOnlySessionsChange is red with the throttle taken out (builds counted twice). |
||
|
|
57a70aaf10 |
usage: a new Codex thread keeps the chunks read before (#3493)
Codex's thread identities were in the request index's meta, so every new
Codex thread, each subagent's included, dropped every chunk, and the next
Usage page read the whole history again: 7s on the reporter-sized
history here (15,553 session files, 418k calls). A chunk's rows don't
hold the identities; the page gives them to its rows as it is built
(cloneCodexChunks, codexIdentities). They now go in the key alone, which
drops only the built pages.
TestCodexNewThreadKeepsReadChunks writes a child thread, reads the page,
then writes its parent: only the parent's file is read again, and the
child's row names the parent's session. Red with the identities put back
in meta (both files read again).
Run at this head (origin/main
|
||
|
|
f6a96b2f0b |
usage: a change time with a fraction settles in 100ms, so a read after an append hashes no log (#3394)
readLogSnapshot checks its snapshot against a SHA-256 of the log's whole prefix whenever the log's change time is under a second old. Under steady traffic every read came within a second of the gateway's last append, so each one hashed the whole usage.jsonl again: 1.8 times the log for each append and read. A stamp with a nonzero fraction of a second comes from a clock that ticks in milliseconds (APFS in ns, Linux's coarse clock 1-10 ms, NTFS ~15.6 ms), so it settles in logFineSettle = 100ms. A stamp in whole seconds (HFS+, FAT, a share) keeps the one-second settle. Run: - go test -count=1 -timeout 45m ./internal/usage/ ./internal/budget/: ok. - TestUsageReadAfterAppendHashesNothingOnAFineClock (20000-row log, 5 appends, each followed by two reads): fine stamp 0 bytes hashed; whole-second stamp 50.7 MB. Broken by hand (logFineSettle = time.Second): 54 MB hashed, red. - Real account, sandbox HOME, a deepseek-only providers.json and a 98 MB usage.jsonl (the owner's own log, repeated 50 times). magpie serve took 30 real /v1/responses calls with a Codex user agent to deepseek/deepseek-flash, all answered, while /v1/magpie/usage?period=today (the Usage page's read) was polled every second. Process CPU time, two runs each: before 3.11 s and 3.05 s, after 1.95 s and 2.25 s. The same calls with /v1/magpie/quotas polled cost 0.2 s on both binaries, since that path never reads the log. - gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/usage/ clean. Not tried: an HFS+ or FAT volume (the test skips when the file system gives whole-second stamps, and covers that case by truncating the stamp); the full suite at this head runs after the push. |
||
|
|
24f24abde3 |
usage: a ClinePass contributor-fallbacks route still shows as a swap (plugins#351)
woyin's Routing rows show cline-pass/deepseek-v4.1-flash-1017 served as vmc/deepseek-v4p1-flash-1017-contributor-fallbacks. Third-party Cline Pass tools record that name as a private contributor deployment (finalProvider "openai-compatible-private"), not DeepSeek's own API. So the row has to keep saying it was served elsewhere. 6db5e9d59's ClineServing already does this, because only the exact model maps. This commit is tests only: they hold the rule, so a looser match (a prefix, say) can't hide the route later. - TestSwappedClineServingName: -contributor-fallbacks (with and without the -1017 date), -contributor and -fallbacks are swaps. - TestRouteKeptClineServingNameNotSwapped: a kept row served as ...-contributor-fallbacks stays swapped when it is read again. Run at 616c87256's tree: - go test ./internal/usage: ok. - go test ./internal/gateway -run 'Clin|Swap|Served|routedAgain|History': ok. - go vet on darwin, linux and windows: ok. gofmt -l: clean. Broken by hand: ClineServing changed to a prefix match. Three usage cases and the history case went red. Restored afterwards. Not run: the full suite (tests only, in two packages). |