The health rollup now reuses an unchanged root's memory walk for up to 30 s, and storage retention batches its admission rechecks across due caches, so a large backlog drain drops from about 10 s to about 1 s per pass. Held foreground bash calls stop building a task snapshot on every 100 ms tick.
Retention rechecks due caches in batches of 16 under one barrier hold instead of rereading all binding records and owner manifests per cache; a cancelled or out-of-budget batch drops its queued caches before taking the barrier and rechecks cancellation and expiry under the barrier, reporting stopped_early and leaving dropped caches for the next pass.
Held bash waits poll the child and check the terminal flag instead of opening task files for a full snapshot each poll; the returned snapshot is still built once by the executor poll.
The health rollup reuses each root's index memory walk while shape counters are unchanged, walking again on any move or lock; the rollup and its memory census report the reuse age as memory_measured_age_ms, while the status command's memory snapshot still walks every time.
Refactors
Adds read-only memory_shape() counters to the semantic index, trigram index, and symbol cache; indexing, ranking, and routing are unchanged.
Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues remain.
Summary
Speeds up three recurring daemon tasks:
Storage retention rechecks due caches in batches of up to 16.
Held bash waits check for a finished child without building a task snapshot.
Health rollups reuse unchanged index memory walks for up to 30 seconds.
Both earlier, unnumbered retention findings are addressed in the current code. No new actionable issues were found.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Validate due caches and keep leases] --> B[Queue up to 16 caches]
B --> C{Cancelled or expired?}
C -->|Yes| D[Release leases and leave caches]
C -->|No| E[Try sweep.lock]
E --> F[Recheck cancellation and deadline]
F --> G[Read current bindings and owners]
G --> H[Recheck each cache and retire eligible caches]
H --> I[Release sweep.lock]