Skip to content

Refresh agent usage once for every monitor - #20906

Closed
omarchybot wants to merge 3 commits into
quattrofrom
omabot/agents-shared-refresh
Closed

omarchybot wants to merge 3 commits into
quattrofrom
omabot/agents-shared-refresh

Conversation

@omarchybot

@omarchybot omarchybot commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

The bar builds the agents panel once per monitor, and each copy's usage model ran omarchy-agent-usage-update on its own timer. Two monitors meant two full refreshes of every collector each interval, and a monitor plugged in later started one of its own. The collectors already run two at a time at idle priority, so what this costs is CPU time and energy rather than stutter, but it is all wasted: every copy reads the same records.

The copies now share one .pragma library module, RefreshOwner.js, which the shell loads once for all of them and which keeps the list of copies. The oldest copy still on it owns the timed refresh and the limits retry; the others start none. When the owner goes with its monitor, the next copy is the oldest. Since the other copies no longer run updates of their own, a finished update has every copy run the same afterUpdate: look for new records, reload them, and re-arm its sync and limits retry. That also keeps the owner's records current, so it arms the same retry any other copy would. Refreshes a person asks for, opening the panel or the refresh button, are not gated.

Each copy still watches and parses the records itself. They are small, about 25 KB in all on a heavy user's machine, so sharing those too, by making the model a plugin service, would buy little and cost the panel under replacement bars, which reach no service; that version is closed as #20897. This supersedes #17955, where silversword411 found and measured the duplication; its lock only joined refreshes that overlapped in time, so copies drifted apart after a hot-plug.

On a worker built from the ISO with two outputs, a shell start ran one updater and 23 collectors in each of three restarts, where quattro ran two and 46; plugging in a third output started none; unplugging one again left the next refresh running cleanly; a refresh from the command line still ran.

Reviewed by Opus 5.5 High and muse-wonder (High, via pi) as second opinions, reading the tree, in three rounds. They found that the other copies were rescanned after an update but never re-armed their sync or limits retry, which would have frozen a second monitor's synced totals; each copy now finishes the update the same way. The later rounds found nothing further.

No visible change: the panel draws the same; only how many refreshes run changes.

🤖 Generated by Opus 5.5 in Claude Code. Reviewed by Opus 5.5 High and muse-wonder High.

omarchybot and others added 2 commits November 30, 2026 12:55
The bar builds the agents panel once per monitor, and each copy's timer ran the usage updater itself, so a second monitor meant a second refresh of every collector each interval, and a monitor plugged in later started one of its own. The copies share one module, which names the first copy to tick as the owner of the timed refresh and the limits retry; the rest start none, and the next copy takes over when the owner goes. A finished update has every copy look again, since only the copy that ran it would otherwise see a new agent's record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The copies that ran no update of their own were rescanned and reloaded but never rescheduled their sync or limits retry, so with synced aggregation on a second monitor's totals could freeze after an update that changed no record's content, and a retry the owner had not armed could wait out the interval. Each copy now runs the same afterUpdate, which also keeps the owner's own records current, so it arms the same retry any other copy would.

Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found in the reviewed changes.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found in the reviewed changes.

Summary

The agents panel shares timed usage refreshes across monitors through RefreshOwner.js.

  • Only one monitor copy runs timed agent refreshes.

No new actionable issues were found. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Monitor copies join shared list] --> B[Oldest remaining copy]
  B --> C[Timed refresh or limits retry]
  D[Manual refresh from any copy] --> E[Run updater]
  C --> E
  E --> F[Update finishes]
  F --> G[Every copy reloads records]
  G --> H[Each copy schedules sync and retry]
  I[Owner leaves] --> B
Loading

Reviews (2) · Last reviewed commit: "Make the oldest agents copy the refresh ..." · Reviewed by Greptile

The owner is the oldest copy still on the list, so there is no claim to make or hand back: when its monitor goes, the next copy is first. finishUpdate runs afterUpdate over every copy, itself included. The logic is tested by driving the module and finishUpdate directly, which replaces the QML fixture that tested a few lines of change with a stub updater and kept the whole file off the non-compositor shards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Closing at the maintainer's direction: the saving is real but too small to carry the code. Each extra monitor's duplicate refresh costs about 8 to 30 CPU-seconds every 15 minutes, and since #19026 and #19831 it runs two collectors at a time at idle priority, so nobody sees it. The stutter that made the duplication matter in #18973 is fixed by those two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant