Repository navigation
Run the agents usage model once for every monitor - #20897
omarchybot wants to merge 5 commits into
Conversation
The bar builds the agents widget once per monitor, and each copy built its own usage model: its own refresh timer and updater, its own file watch on every record, its own parse of every record on the shell's main thread after each refresh, and its own sync. The model is now the plugin's service, which the shell builds once, and every monitor's panel reads it. The service reads its settings from the widget's entry in the bar layout, as the panel was handed them, and does nothing while the widget is off the bar, as before. Each panel keeps the last step that needs its local model lines: putting the service's lines in order and adding those. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A clone of the plugin is handed the bar config but not the registry, so the service reads its entry from barConfig and walks the layout itself. An entry in the tray's drawer counts only while a tray is on the bar, since the bar unloads it otherwise. A refresh that would start off the bar starts nothing, which covers a rerun queued or a retry armed before the widget left. A replacement bar hosts widgets without their service in reach, so under one the service stands down instead of refreshing for a panel that cannot read it. Co-Authored-By: Opus 5.5 High <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A clone's service gets a facade with the bar config but neither the shell's view of which bar is up nor the registry. It now reads the selected bar from the config's own id, so a clone under a replacement bar stands down like the built-in one, and counts an entry in the tray's drawer as shown, since without the registry a cloned tray cannot be told apart and a blank panel costs more than an unseen refresh. The bar check moves into entryFor so its test runs the real wiring. Co-Authored-By: Opus 5.5 High <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge, with the previous test concern addressed. SummaryThe PR moves agent usage work into one shared service instead of repeating it on every monitor.
|
The two checks that read the source for the binding and for the panel's missing model restated the implementation. A QML fixture builds the real service and three copies of the real panel, as the bar builds one per monitor, handed a shell that returns the service, with a stub updater on PATH that logs each run: every panel reads the service, two panels cost one refresh, and a third added later costs none. A second real service under a replacement bar refreshes nothing, which goes through the service's own binding. Counts are taken after a quiet window and checked as they arrive. It fails when a panel cannot reach the service, when a panel refreshes on its own, when the binding skips the bar check, and against quattro's per-panel model. Needing Quickshell moves this file to the compositor shard, as dock-test.sh already is. Co-Authored-By: Opus 5.5 High <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The panel drawing from the service, on a worker built from the ISO running this branch, with a usage record written by hand: its line, plan and weekly limit, and the day's prompts in the header. CI is green on |
|
Closing in favour of #20906, at the maintainer's direction. Making the usage model a service saved one thing worth having: the duplicate refresh each extra monitor ran every interval. The rest it shared, the file watch and parse of every record in each panel copy, is about 25 KB of JSON on a heavy user's machine, so not worth what it cost: the panel losing its data under replacement bars, which reach no service, and the bar-entry, clone and tray logic the service needed to find its own settings. #20906 gets the refresh down to one for every monitor with a small shared module in the panel's own process instead, so nothing changes under any bar. |

The bar builds the agents widget once per monitor, and each copy built its own usage model in
Main.qml. So every copy kept its own refresh timer and ranomarchy-agent-usage-updateitself, held its own file watch on every usage record, parsed every record again on the shell's main thread after each refresh, and ran its own cross-device sync. Two monitors meant two refreshes of every collector each time the timers fired, and a monitor plugged in later started a full refresh of its own on top. silversword411 measured about 0.85 s of main-thread stall per refresh on six monitors in #17955, which shared refreshes between the copies with a lock; the lock only joined refreshes that overlapped in time, so once a monitor was hot-plugged the copies drifted apart and never shared again, and it left the watching, parsing and sync to every copy.Main.qmlis now the plugin's service, which the shell builds once, beside the per-monitor widget, asomarchy.mediadoes, and each monitor's panel reads it throughfirstPartyServiceFor. One timer, one updater per refresh, one watch and one parse per record, one sync. A default agent starred or a local model pinned on one monitor now shows on the others at once, rather than after a file watch fires.Settings and the bar. A service is handed no widget settings, so the service reads its widget's entry from
shell.barConfig, as the panel was handed it, and keeps it as a string so a write to another widget's settings rebuilds nothing. First-party plugins are always enabled, so the service exists whether or not the widget is on the bar; it does nothing while it is off, as before, which is why the idle-spawn guard still passes. An entry in the tray's drawer counts only while a tray is on the bar, since the bar unloads it otherwise, and a refresh that would start off the bar starts nothing, which covers a rerun queued or a retry armed before the widget left.What each panel keeps. The panel derives its local model lines from the local models service, so it keeps the last step that needs them: putting the service's lines in order and adding its own,
localModelAdded, and the list of shown lines it handsmoveProvider.For whoever merges this: replacement bars.
docs/omarchy-shell.mdsays widgets hosted by a replacement bar get no service, and that service-backed widgets keep their full integration only under the built-in bar. The agents widget is now service-backed, so under a replacement bar, including a clone ofomarchy.bar, its panel has no usage data and shows the add screen, where before it built its own model and worked; its local model lines already depended on a service it could not reach there. The service stands down under a replacement bar rather than refreshing for nothing. Keeping the old behaviour there would take the panel building its own model when it cannot reach the service, which brings back the per-monitor cost only under replacement bars; that is a few lines if wanted.Clones of the agents plugin get a facade with the bar config but not the shell's view of which bar is up, so a clone reads the selected bar from the config's own
id. That misses one case: a config naming a replacement bar that is not installed, where the shell quietly shows the built-in bar but a cloned agents service stands down.On a worker built from the ISO, running this tree with two outputs, a shell start ran one updater and 23 collectors, where
quattroran two and 46. Plugging in a third output started none; taking the widget off the bar started none, across a shell restart; putting it back started one at once.refreshIntervalSec30 gave two refreshes in 75 s, an unrelated widget setting started nothing, hiding a provider from the panel made the next refresh pass--exceptfor it, and a clone of the plugin refreshed once.runtime-smoke-test.shfails its keepLoaded fixture case the same way onquattro.Reviewed by Opus 5.5 High and muse-wonder (High, via pi) as second opinions, reading the tree, in three rounds. They found that a clone's service would never start, that a refresh queued before the widget left the bar still ran, that an entry in the drawer of a tray off the bar kept refreshing, that the service refreshed under a replacement bar for a panel that could not read it, and that a clone could not tell which bar was up or recognise a cloned tray. Each is fixed or stated here. Greptile then asked for the service to be tested by what it does rather than by its source;
agents-panel-test.shnow builds the real service and three copies of the real panel against a stub updater that logs each run, and a second service under a replacement bar, which moves that file to the compositor shard asdock-test.shalready is.No visible change: the panel draws the same; how often and where the usage model runs changes.
🤖 Generated by Opus 5.5 in Claude Code. Reviewed by Opus 5.5 High and muse-wonder High.