Repository navigation
Conversation
A refresh with nothing new reads no session file, and one after a little activity reads only what was appended. Co-Authored-By: Claude <noreply@anthropic.com>
[Medium impact] The changes affect agent usage refreshes across many collectors, but stay within that workflow. The PR should not merge until successful refreshes reliably return success. Findings
SummaryThe PR keeps a per-file index of pi/omp history and limits refreshes to three collectors at once.
Reviews (4) · Last reviewed commit: "Run at most three usage collectors at on..." · Reviewed by Greptile |
…from ending a scan A fork tree's other files keep only their prompt ids unless they hold a copy of a booked prompt. A cost no float holds skips its row as it did before the index, and no temp file for rg's messages costs a failed run its batch, not the scan. Co-Authored-By: Claude <noreply@anthropic.com>
Every collector started together is a burst across all cores that the desktop feels on each refresh. Three at a time take a little longer and stay out of the way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| while (( running > 0 )); do | ||
| wait -n || status=1 | ||
| running=$((running - 1)) |
There was a problem hiding this comment.
Successful refresh reports failure
If collectors finish before the next wait, Bash can remove them from the jobs that wait -n checks. running still counts those jobs, so wait -n returns 127 and sets status=1 even though every collector succeeded. Both wait loops have this problem.
The same loop with 24 successful no-op jobs reported failure in 71 of 100 local runs on Bash 5.2. Keep the child PIDs and collect each saved exit status instead of assuming every wait -n accounts for one started job.
|
Classification is unsettled at GPT-6 in Codex reviewed the report and existing comments for classification; the session does not expose its effort setting, and the classifier did not report one. Runtime verification and fixes were not attempted because the queue requires classification to agree first. This waits on the maintainer to resolve the classification. |
What changes
Every refresh of the agents panel reads the whole pi/omp session history again, once per collector. The scan cache lasts 20 seconds and the panel refreshes every 15 minutes, so nothing is ever reused. On a machine with 9.6 GB of pi sessions, one refresh ran 17
rgprocesses with 221 threads between them and took the one-minute load from 2.8 to 92.6. No session had changed since the day before. This is #12411 and #17982.scan_pi_sessions()now keeps a per-file index, the way the Claude Code scan already does:This is the pi/omp half of #15906 by @Iann29, redone for the shared helper the scan moved to in #14040. It was written against the in-tree Claude Code index, not from that branch. The opencode scan is not covered here.
Two choices a reviewer may want to question:
acceptnow gets only a reply's provider, model andapi, not the whole message without its content. That is all any of the 18 callers reads (Codex and local readapi).Not fixed here: the first refresh after this lands still reads everything, to build the indexes, and is as heavy as a refresh is today (the "builds the index" column below). So is any refresh after the cache is cleared. The last commit softens that: see below.
At most three collectors at once
omarchy-agent-usage-updatestarted every collector together, which is where the 17rgprocesses at once come from. It now runs at most three at a time (MAX_COLLECTORS=3), starting the next as one finishes withwait -n, and still exits 1 if any collector failed. This mostly matters for the refresh that builds the indexes, and for collectors this index doesn't cover. The tables below were measured before this commit, so they don't show its effect;agent-usage-update-test.shand the other agent tests pass with it.Verification
Measured on an AMD Ryzen 5 5600G (6 cores, 12 threads, 31 GB RAM), NVMe SSD, ripgrep 15.2.0, Python 3.14.10, with 3,216 pi session files (9.6 GB), none changed during the runs. Each column is one full
omarchy-agent-usage-updaterun in an isolated home with the real sessions read in place, atnice -n 19and idle I/O priority so the desktop stayed usable. Nice doesn't change the CPU time or the process and thread counts; it can stretch wall time.quattrorgprocesses at oncergthreads at oncerchar)quattroand this branch, with the index being built and with it built. The only field left out of the comparison isupdatedAt.rgruns list file names.quattrowas measured once. It has no index, so a second run repeats the first, and I didn't want to put a load of 92 on that desktop twice.Tests:
agent-usage-pi-scan-test.shgrows from 10 to 29 checks. It puts anrgon PATH that logs what it is asked to read, and covers: an unchanged history, an append, an unfinished last line, truncation, same-size and larger rewrites, delete and move, a fork tree where the parent, a fork and an orphan change, a corrupt index, a failed read, an unreadable file, and an unfinished listing. Onquattroit fails at "an unchanged history opens no session file".agent-usage-*test files pass: 1,579 checks.quattro'sscan_pi_sessions()on 190 generated session trees (forks, omp model switches, failed replies, summaries, lines without ids or times), with appends, truncations, deletes, moves and touches between scans. All 4,750 comparisons over five patterns matched.What it costs:
quattrowould drop its rows and report incomplete.What I couldn't check:
Screenshots
No visible change: the panel shows the same numbers. Only how the collectors read pi/omp session history changes.
🤖 Generated with Claude Code