1ccacad63281094de8a3372d5a507d38f9969e5c
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c93d9e0c0b |
usage: an unchanged Codex effort ask is told the kept answer, not a copy (#2278)
CodexModelEffort copied every thread's consumption for each ask (cloneEffort), though the kept answer is only replaced by a later build, never written, and its callers (the Sessions list, overview and a session's details) only index it and copy their thread's slice (addCodexModelEffort, addCodexSummaryModelEffort). On the #2278 bench (15G .codex) the copies were ~230 MB allocated every 80 s of an open Sessions page. Asks are now told the kept map itself; the doc comment says it is read-only. TestCodexModelEffortReadsLedgerOnlyWhenCallsChange wrote into the answer to check a caller's copy was its own. That guarantee is now the GUI's: TestCodexModelEffortCopiedPerSession checks a session and a summary get their own slice. TestCodexModelEffortAsksShareTheKeptAnswer checks two unchanged asks get the same map. Run at this tree on mote (macOS 27, Go 1.26.8): - go test -count=1 ./internal/usage ./internal/sessions ./internal/gui: usage ok, sessions ok; gui red only in TestMainWindowCorners/ macOS_26_SDK, which is #3949 (filed, red on macOS 27 on main). - GOOS=linux,windows,darwin go vet -tags nogui ./internal/usage ./internal/gui: ok. Broken by hand: maps.Clone back in the kept-answer return makes TestCodexModelEffortAsksShareTheKeptAnswer red ("told a copy"); dropping the GUI's slices.Clone makes TestCodexModelEffortCopiedPerSession red ("written through a session's copy: 999"). Not run: the full ./... suite, and the bench A/B (the 230 MB is from the v0.1.1967 heap profile, not yet re-measured). |
||
|
|
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 ( |
||
|
|
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
|
||
|
|
8a1b5916f3 |
sessions, usage, gui: one read of every call at a time, the Codex effort built once and kept, and the Sessions page asks for an overview once, so the app no longer grows to 85 GB (#2278)
On a long history (the reporter's: 68k call files in calls-v15, 415 MB;
42 MB usage.jsonl; 75k calls in 7 days), the app's main process grew to
85 GB in about 90 minutes and the gateway froze. `magpie serve` alone held
83-153 MB for 20 minutes (the reporter's follow-up), so the growth is in
the app's Sessions path:
/api/sessions/overview -> usage.CodexModelEffort -> LedgerOfAt ->
sessions.Calls(all history).
Why it grew:
- CodexModelEffort's cache key changes on every gateway write, and it
never kept an answer when usage.jsonl was missing or grew during the
build. So every /api/sessions, overview, /one and /manage ask with a Codex
session rebuilt the all-history ledger, gob-decoding every shard (only
64 stay in memory).
- Nothing joined concurrent asks.
- The page's 15s reload asked for an overview again while the last one
was still under way, so slow asks piled up.
What changes:
- sessions.Calls and the new AgentCalls go through sharedCalls. An ask
while the same read is under way waits for it and gets a copy, and
reads run one at a time.
- AgentCalls(since, "codex") reads Codex's files only. pruneCalls still
sees every file.
- CodexModelEffort is built from Codex's calls plus the gateway's records.
Only those name a Codex actor, and TestCodexModelEffortIsTheWholeLedgers
checks the answer equals the whole ledger's on a mixed Claude + Codex +
gateway fixture.
- One build per period at a time. An ask during a build gets the last
answer for the same home (root), or waits if there is none.
- The answer is kept when usage.jsonl is missing or grows during the
build.
- At most 8 periods are kept.
- page.js: sessOverview shares one promise per query, so the filter's ask
and the 15s reload's ask for the same overview send one request.
- docs/subsystems/gateway-sessions.md says this.
Reproduced (temporary test, not committed): a sandbox HOME with 62k
Claude Code session files, 5.9k Codex rollouts and 100k gateway records.
Sessions routes in-process, 4 rounds x 6 concurrent asks
(overview?days=0 and /api/sessions), a usage record appended every 300ms:
before (
|