A fast publish still spends ~1s a tick globbing 1000 cycle directories to build a 40-row window
Id: TD-PPagop-26082601 · Status: resolved · Filed: 2026-08-26 · Resolved: 2026-09-22 · Ref: https://github.com/Pullwright/agent-ops/pull/1751
Severity: Low
Noticed while implementing #798 (the tiered publish), which took a full build
from 15.8s to 11.1s and a fast build to 4.4s on ockham-container.
Of the 4.4s a fast tick now costs, the largest single item left is the
“Recent cycle ids, newest first, fleet-wide” section at about 2.2s, and roughly
half of that is building $cycle_rows: dir_rows globs every entry in the
local cycles/ directory (bounded at state_local_cycles_retained, which is
1000 on every node) plus each peer’s, interleaves them with the ids known only
from the event stream, sorts the lot in fleet time order and then keeps the
newest MAX_CYCLES (40).
So the window costs a scan proportional to the retained history to produce a list bounded by a constant, and it does it on every tick. Nothing about the result changes between ticks except when a cycle is created — roughly hourly.
The rest of the 4.4s, for the record: read_events and the events array 1.3s,
status 0.55s, the log tail 0.56s, the per-node scan 0.43s, the fingerprint
0.36s, the fleet 0.17s, the payload merge 0.17s.
Why it was not fixed with #798
Section titled “Why it was not fixed with #798”#798’s acceptance is that a cycle’s progress reaches the page within a minute,
and at the launcher’s 1:9 duty cycle 4.4s already gives about 45 seconds. This
would buy roughly another 10 seconds off that figure — real, but not what the
issue was for, and it needs a cache key of its own with its own invalidation
(the local cycles/ mtime, each peer’s, and the union’s event positions),
which is the part that has repeatedly gone wrong here: #793, #801 and #803 were
all a cache key that failed silently.
What a fix would look like
Section titled “What a fix would look like”Cache $cycle_rows keyed on the mtimes of the local and peer cycles/
directories plus the union log’s own size and mtime, alongside
.dashboard-cycle-cache/ and excluded from the fingerprint the same way. The
directory mtime is sound as an input here — it moves whenever an entry is
added or removed, which is exactly when the row set changes — as distinct from
its use as a liveness signal, which is what made it a hazard in #803.
Test it the way #798’s cache is tested: plant a sentinel row, assert it survives an unchanged tick, and assert it is gone once a new cycle directory appears.
Migrated to https://github.com/Poetic-Poems/agent-ops/issues/993.