Skip to content

Cap parallel collectors in omarchy-agent-usage-update - #19026

Merged
dhh merged 3 commits into
omacom:quattrofrom
eisen0419:fix/agent-usage-update-concurrency
Nov 29, 2026
Merged

dhh merged 3 commits into
omacom:quattrofrom
eisen0419:fix/agent-usage-update-concurrency

Conversation

@eisen0419

@eisen0419 eisen0419 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #18973.

omarchy-agent-usage-update started every omarchy-agent-usage-* collector at once. Each one re-scans local session stores, so on a machine with real agent history a refresh held every core for the length of the scan, and since the agents widget runs it on a timer, games and the desktop hitched every 15 minutes.

The collectors now take turns, two at a time: before starting one, the updater waits for a free slot with wait -n, and each collector's status is still read from its own pid afterwards, so a failing collector is reported as before and the rest are still written. The other threads stay free for whatever is in the foreground.

The cost is wall time. A refresh takes roughly half the sum of the collectors rather than the slowest one: over the 24 collectors on a machine with no history, 0.9s instead of 0.6s, and on a large history it can be a minute or more. That includes the --limits-only refresh the panel runs when it opens, which is network probes rather than scans, so its records arrive two at a time as well. Each record still appears as soon as its collector writes it, and Main.qml already collapses refreshes requested while one is running into a single rerun.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge, with no new actionable findings.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with no new actionable findings.

Summary

Caps omarchy-agent-usage-update at two collectors at a time.

  • Usage refreshes run at most two collectors at once.

Reviews (6) · Last reviewed commit: "Cap the collectors with a plain slot loo..." · Reviewed by Greptile

Comment thread bin/omarchy-agent-usage-update Resolved
Comment thread test/shell.d/agent-usage-update-test.sh Resolved
@Gui-dev

Gui-dev commented Nov 17, 2026

Copy link
Copy Markdown

Data point from #18973, in case it helps pick the default.

On an i7-1255U (4P+8E, 15 W, 12 threads), the 23 collectors cost 499 CPU-s sequentially (41 s wall, cold; 475 CPU-s warm, since SCAN_REUSE_SECONDS is 20 against a 900 s refresh). With all of them forked at once that is ~40 s of all 12 threads at 99–100 %, package pinned at 1.5 GHz instead of 4.1, and any full-screen game drops to single digits.

So a cap of 2 converts that into ~250 s on 2 cores. I think that is the right trade — 10 of 12 threads stay free, which is the whole point — but it is worth saying in the body that a refresh can now take minutes on a laptop, so nobody is surprised when the panel's numbers look stale for a while.

Two notes from checking the consumer side:

Happy to re-run my telemetry with the patch applied and report the before/after wall time if that's useful for the PR.

@eisen0419

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed telemetry on the i7-1255U and for verifying Main.qml's pendingUpdateKind timer coalescing on multi-minute runs, @Gui-dev!

Updated the PR description to call out the longer refresh wall time on large local session histories (and aligned the PID-reaping note with the current reap_finished implementation). Keeping this PR scoped strictly to the concurrency cap so commits stay atomic and don't overlap with #17983 covering idle scheduling priority — if you get a chance to run your before/after telemetry with this branch, sharing those numbers here would definitely be helpful.

Comment thread bin/omarchy-agent-usage-update Resolved
The usage refresh started every collector at once, so each periodic run
pinned every core for the length of the scan. Keep two running. Take each
exit status from wait on that collector's pid: wait -n returns 127 when
several have already finished, and that 127 is not a failed collector.

A capped refresh can run longer than the Codex forced-read window. The
updater's pid keeps that one scan valid until the refresh exits. A stamp
inherited without that parent still expires.

Fixes omacom#18973
@eisen0419
eisen0419 force-pushed the fix/agent-usage-update-concurrency branch from ee7bdd0 to 92e5b50 Compare November 17, 2026 19:39
@omarchybot

Copy link
Copy Markdown
Collaborator

Classification is unsettled. GPT-6 in Codex (High) classified this as a bug fix for the unbounded collector concurrency reported in #18973; the separate classifier, deepseek-v4p1-flash (effort unspecified), returned enhancement.

I read the PR description, discussion and linked issue, and inspected the change for classification. Runtime verification has not run, and no class or verification labels were applied. This is waiting on the maintainer to resolve the classification before verification continues.

@angellindo

Copy link
Copy Markdown

Adding a controlled thermal data point for #18973 on Omarchy 4.5.0-3, MacBookPro14,3, kernel 7.2.15-1.3-omarchy-mbp143ab-sbs. Both captures used the same boot and matched sampled controls, with the Mac awake on battery and T3 Code closed.

In the installed build, the Agents timer defaults to 900 s and calls omarchy-agent-usage-update, which launches the selected collectors in parallel. Ten observed thermal peaks lined up with that 15-minute phase.

  • Agents enabled. At the 21:00:14 refresh, the CPU temperature reached 87 °C, tripping the diagnostic's 85 °C stop. Aggregate CPU was 25.7% over 4.6 s. The snapshot caught 29 processes with the truncated comm value omarchy-agent-u that had started about 1.1 s before the peak and accumulated 4.04 CPU-seconds across cores. The fans ramped after the peak.
  • Agents disabled. A 630 s capture covered the nominal 22:45:14 refresh. Temperature stayed at 49–51 °C within ±15 s of the slot and nearby aggregate CPU peaked at 7.45%. The full capture peaked at 58 °C. The widget was restored afterward.

The comparison covers one disabled slot, and battery charge differed between the two runs. It supports the scheduled refresh as the trigger on this setup. The thermal effect of the proposed two-collector cap, which release introduced the behavior, power draw, and S3 behavior remain unverified.

@itstxl

itstxl commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

The cap leaves the other threads free, but when the foreground is already using all of them, the two collectors still compete with it at normal priority. Dropping the updater to idle CPU and I/O priority fixes that, and the collectors inherit it:

 [[ $collector_jobs =~ ^[1-9][0-9]*$ ]] || collector_jobs=2

+chrt --idle -p 0 $$
+ionice -c 3 -p $$
+
 collector_pids=()

I tried it on this branch (92e5b50) on a 5600X (6c/12t). I ran a CPU-bound load on all 12 threads doing fixed 8ms units of work, timed each unit during a forced refresh, and repeated each case 5 times:

slowest unit (median) units over 16ms (median)
no refresh 32ms 38
this PR 108ms 435
this PR + idle priority 47ms 181

With 4 threads left free I couldn't measure any difference, so it only matters when nothing is spare. That's the case for a game, say, or a laptop with fewer threads.

Under full load the refresh takes longer (about 7.5s vs 4s), since it only gets leftover time. The refresh PID handling you already added covers a refresh that runs long. On an idle machine the time is the same.

I had this in #19831 (jampick's #17983 does the same), but it fits better here. Happy to close mine if you pick it up.

@omarchybot

Copy link
Copy Markdown
Collaborator

The queued fold from #19831 remains unapplied because classification is still unsettled: GPT-6 in Codex (effort not exposed) calls this a bug fix, while the classification-only reviewer deepseek-v4p1-flash (effort unspecified) again returned enhancement. GitHub also reports a conflict with current quattro.

I read the updated discussion and linked issue, checked the base-branch rules and updater, and inspected the change for classification. No worker verification ran, no code was pushed, and no verification labels were applied. This is waiting on the maintainer to resolve classification before the fold and runtime verification can continue.

@Gui-dev

Gui-dev commented Nov 25, 2026

Copy link
Copy Markdown

Sizing data for the cap, measured on the machine where I hit this (i7-1255U, 4P+8E, 12
threads, 15 W), so you have a real number behind the "two at a time" default:

refresh wall CPU threads busy
23 collectors, first run 3.7 s 32.0 CPU-s 8.7 of 12
23 collectors, warm rerun 0.8 s 7.7 CPU-s 10.2 of 12

Measured with getrusage over the whole tree, idle baseline 0.22 threads. So the burst is
short but it takes every thread while it lasts, which matches the multi-second desktop
hitches reported in #18973.

Two things that bear on the cap:

  1. It runs twice on a two-monitor setup. Both updaters are direct children of the same
    quickshell pid, spawned in the same 100 ms window, 23 collectors each, i.e. 46
    collectors at once. Since OMARCHY_AGENT_USAGE_JOBS is per updater, two screens still
    run 2 x 2 = 4 collectors concurrently. Still a big improvement over 46, but if the
    width were shared or the duplicate timer fixed separately, that would be better.
  2. The doubled refresh here costs 52.9 CPU-s and pushes psi_cpu avg10 to 16 on an idle
    desktop.

On @itstxl's idle-priority diff: agreed, and the numbers they measured (108 ms -> 47 ms
median under full synthetic load) are the right comparison. A cap alone does not help when
the foreground already owns every thread.

Correction to my earlier comment in #18973: the "499 CPU-s" figure was a measurement bug on
my side (I counted idle time as busy) and is retracted there with the corrected numbers
above.

omarchybot and others added 2 commits November 29, 2026 21:24
quattro deleted test/shell.d/agent-usage-codex-rollouts-test.sh when it slimmed the shell suite (omacom#19904), and this branch had extended it with the cases for a refresh stamp older than its window. The deletion stands: the file's other cases went with it on quattro, and bringing it back for these would undo that. The stamp's ancestor check is left covered only by the updater test that the pid is exported.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Running two collectors at a time needs only a wait for a free slot before each start: wait -n frees one, and each collector's status is still read from its own pid afterwards, which bash keeps after wait -n has reaped it. That replaces the polling reaper, and the 50ms sleeps that made a refresh over the 24 collectors take 1.2s where this takes 0.9s.

The refresh pid and the ancestor walk in collectors.py are gone: they only spared a repeated Codex scan in a refresh that runs past five minutes, and the stamp window can be raised if one ever does. OMARCHY_AGENT_USAGE_JOBS is gone too, since nothing set it but the tests. The test covers what the change is: no more than two at once, every record written, a failure still reported, and a run where every collector passed still succeeding, which is the case that breaks if a status is ever lost to wait -n.

Co-Authored-By: itstxl <154011486+itstxl@users.noreply.github.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@omarchybot omarchybot added the enhancement New feature or request label Nov 29, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed, and reduced at the maintainer's request to the smallest change that caps the collectors. The cap itself works: on a stock Omarchy worker (bash 5.3.20, 4 cores) quattro's updater ran 8 stub collectors at once and this branch ran 2, with every record written.

What I pushed, and why

  • 6ffd1871 merges quattro, which the branch conflicted with. quattro deleted test/shell.d/agent-usage-codex-rollouts-test.sh when it slimmed the shell suite in Speed up test suite and run compositor tests headlessly #19904; the merge keeps that deletion.
  • c3f705bf replaces the pool with a plain slot loop: wait -n until fewer than two collectors are running, then start the next, with each status still read from its own pid at the end. The pull request is now +40 across two files, from +546 across five. Thank you, eisen0419, for the careful original; what came out was correct, just more than this fix needs:
    • The polling reaper. It guarded against wait <pid> returning 127 after wait -n, which happens in posix mode and not under the #!/bin/bash launch every caller uses. Its 50ms sleeps also made a refresh over the 24 real collectors take 1.23s where the loop takes 0.90s (0.62s uncapped).
    • OMARCHY_AGENT_USAGE_REFRESH_PID and the ancestor walk in collectors.py. They spare a repeated Codex scan only in a forced refresh that runs past CODEX_REFRESH_SECONDS (300s). If a refresh that long turns up, raising that constant is the smaller remedy.
    • OMARCHY_AGENT_USAGE_JOBS, which nothing set but the tests.
    • Most of the tests: the bash --posix runs, the BASH_ENV trap injection, and the bash "$ROOT/bin/…" rewrites of existing cases. One block remains, covering no more than two at once, every record written, a failing collector still reported, and an all-passing run still exiting 0.
  • The loop is the one Keep the agent usage refresh from stuttering games #19831 uses, so itstxl is credited on the commit. I also rewrote the description to match what the branch now does.

What was checked

All of it ran on the worker, nothing on a maintainer's machine. The cap test fails against quattro's updater 20 of 20 times with two busy loops per core, and passes 20 of 20 on this head, idle and loaded. The all-passing case fails when the updater is forced into posix mode, so it would catch a lost status. agent-usage-update (10), agent-usage-shared (164), agent-usage-partition (32), agent-usage-accounts (17), agent-usage-agy (6), agent-usage-grok (40), agents-panel (160), agent-account (48) and ./test/cli all pass on c3f705bf. Not measured here: the effect on frame times on a machine with a large session history; that rests on the reporters' numbers in #18973.

Second opinion

Opus 5.5 (high) and muse-wonder (high, via pi) each read this head, in two rounds; I am Fable 5.2 in Claude Code. Their independence from my reasoning is not guaranteed. What they added beyond agreement:

  • muse-wonder first reported the loop as broken, on the claim that wait <pid> returns 127 after wait -n has reaped the collector. Running it showed otherwise under a normal bash launch, and it withdrew the finding in the second round.
  • Opus asked for the all-passing case, which is now in the test and earns it co-authorship of the commit, and pointed out that I had not run the uncapped updater under load; the 20 of 20 above is that run.

Both ended with nothing open on c3f705bf.

Still open, for the maintainer

@dhh
dhh merged commit 50859d5 into omacom:quattro Nov 29, 2026
1 check passed
omarchybot added a commit to itstxl/omarchy that referenced this pull request Nov 29, 2026
quattro now caps the collectors at two at a time (omacom#19026) with the same slot loop this branch had, so the merge takes quattro's loop, its cap of two over this branch's four, and its test of the cap. What is left of this branch is the idle CPU and I/O priority.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
cursor Bot pushed a commit to mark-groves/omarchy that referenced this pull request Nov 29, 2026
* Cap parallel collectors in omarchy-agent-usage-update

The usage refresh started every collector at once, so each periodic run
pinned every core for the length of the scan. Keep two running. Take each
exit status from wait on that collector's pid: wait -n returns 127 when
several have already finished, and that 127 is not a failed collector.

A capped refresh can run longer than the Codex forced-read window. The
updater's pid keeps that one scan valid until the refresh exits. A stamp
inherited without that parent still expires.

Fixes omacom#18973

* Cap the collectors with a plain slot loop

Running two collectors at a time needs only a wait for a free slot before each start: wait -n frees one, and each collector's status is still read from its own pid afterwards, which bash keeps after wait -n has reaped it. That replaces the polling reaper, and the 50ms sleeps that made a refresh over the 24 collectors take 1.2s where this takes 0.9s.

The refresh pid and the ancestor walk in collectors.py are gone: they only spared a repeated Codex scan in a refresh that runs past five minutes, and the stamp window can be raised if one ever does. OMARCHY_AGENT_USAGE_JOBS is gone too, since nothing set it but the tests. The test covers what the change is: no more than two at once, every record written, a failure still reported, and a run where every collector passed still succeeding, which is the case that breaks if a status is ever lost to wait -n.

Co-Authored-By: itstxl <154011486+itstxl@users.noreply.github.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: itstxl <154011486+itstxl@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agents widget: 23 usage collectors run in parallel and saturate all cores for ~40s every 15 minutes

6 participants