Dedupe redundant per-tick ContentIdle reads + gate the outer task-list fetch on DB change - #949
Merged
Merged
Conversation
anutron
force-pushed
the
argus/tick-cost-followup
branch
from
August 23, 2026 03:58
e999c69 to
737a80c
Compare
…t fetch on DB change Two follow-up CPU optimizations to the 1s TUI tick (companion to #944): 1. agent.ContentIdle gained a cachedSignal parameter so it can reuse the ContentIdleFingerprint/ParkedSelectionSignal reading detectNeedsInputSticky already computed for the same session tail moments earlier in the same tick, instead of paying for a second tail read + VT re-emulation pass. Nil-safe (push.go's daemon-side watcher is unaffected). 2. refreshTasksWithIDs's outer a.db.Tasks() fetch is now gated by a PRAGMA data_version dirty-check (mirroring hera.HeraPage's existing pattern), but ONLY on the periodic onTick path — every other caller still fetches unconditionally, since a write it just made through the same connection is invisible to that connection's own next DataVersion() read. Closes every write site that needed an explicit invalidateTasksChangeGate() call (reconciliation's own SetStatus, several hera mutations via heraRefresh, startSession, switchSession's live-session branch, and the async session-ID recapture path) — found via a code review that caught the initial narrower implementation missing four of these five sites. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
anutron
force-pushed
the
argus/tick-cost-followup
branch
from
August 23, 2026 04:05
737a80c to
acc19a0
Compare
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two follow-up CPU optimizations to the TUI's 1s
onTick, companion to #944 (ce74221f).1.
agent.ContentIdlereusesdetectNeedsInputSticky's already-computed signalContentIdle(BUG-036) ran right afterdetectNeedsInputStickyevery tick but independently re-read each session's tail and re-ranContentIdleFingerprint/ParkedSelectionSignalVT emulation — even thoughdetectNeedsInputSticky's resumed-activity and content-stability passes had just computed the identical values for the identical tail moments earlier in the same tick.ContentIdlegained a trailingcachedSignal func(id string) (ContentIdleSignal, bool)parameter: a cache hit skips the tail read + VT emulation entirely;ok=false(including a nilcachedSignal) falls back to the exact pre-existing independent computation, byte-for-byte.internal/api/push.go's daemon-side idle watcher (which has no equivalent shared per-tick pass) passesniland is untouched. The TUI wiresApp.contentIdleSignalOf, sourced froma.needsInputRawSignals(the dirty-check cache from #944), which now also threads through thefpthat pass was already computing and discarding.Safe because it's the literal same function call, not an approximation —
ScreenRenderer.render's RIS-reset-per-call idempotency (already relied on by #944) guarantees identical output for identical(tail, cols, rows).2.
refreshTasksWithIDs's outera.db.Tasks()fetch is gated on DB changeMirrors
hera.HeraPage's existingshouldRebuild/markRebuilt/InvalidateChangeGatePRAGMA data_versionpattern, applied to the plain task-list fetch — but only on the periodiconTickpath (newallowCachedTasksparam). Every other caller (refreshTasksLocal,refreshTasksAsync, a direct bulk-prune call) keeps unconditional-fetch, sincedb.DB.DataVersion's documented same-connection blind spot means the gate can never be trusted to see a write made by the very call that would also be consulting it.A code review of the first pass at this caught that it only handled the one write site named in scope (reconciliation's own
SetStatus) and missed four more: several hera mutations funneled throughheraRefresh()(nuke/cascade-nuke/step-status),startSession(called from 5 sites, only 2 of which separately refresh),switchSession's live-session branch, and the async session-ID recapture path inhandleSessionExitUI. All five now callinvalidateTasksChangeGate()at their write site; each has a dedicated regression test that fails when its invalidate call is removed (verified by hand before writing this up).One accepted, named, bounded gap remains:
internal/agent/autorename.go's background rename goroutine has noAppreference to invalidate through — cosmetic-only (a suggested rename lags until an unrelated write), documented incontext/knowledge/gotchas/events.md.Testing
TestContentIdle_CachedSignal,TestRefreshTasksWithIDs_GatedFetch, plus 4 regression tests pinning each newly-found write site) — each regression test verified to fail when its fix is reverted.make pre-prgreen exceptmake vuln(pre-existing stdlib CVEs,continue-on-errorin CI — not introduced by this PR).-racesuite green; coverage 88.7% (floor 88).Specs: No behavioral changes (internal perf/caching only, no observable behavior change) — no
openspec/change folder, matching precedent set by #944.🤖 Generated with Claude Code