menubar: skip unchanged background refreshes, 120s AC idle cadence, utility QoS for tick spawns#704
Conversation
…tility QoS for tick spawns (getagentseal#703)
iamtoruk
left a comment
There was a problem hiding this comment.
Verified locally: swift build green, 81 tests across 17 suites green, and both load-bearing behaviors are mutation-pinned; inverting the change comparison and removing the 30-minute backstop each fail the guard tests, including the dedicated backstop-expiry case. The design reads right: the shallow snapshot is a perf optimization with the backstop as the correctness contract, interactive refreshes always bypass, and anchoring only on fetch success means failures cannot mask changes. The Swift-side provider root list duplicating TS path logic is unavoidable cross-language and is exactly what the backstop bounds. The CPU reduction figures rest on the #703 measurements; the mechanism they depend on is what is verified here.
Problem
Items 2-4 of #703: even with #648's work, an idle menubar on AC still spawns a full Node re-parse every ~60s (measured ~10 CPU-s each, ~16% of a core sustained on a real user machine; details and raw numbers in #703). Items 1 (release) and 5 (CLI incremental parse) are intentionally not addressed here.
Fix
Data/UsageDataChangeGuard.swift): before a background tick spawns the CLI, a shallow snapshot (root + first-level directory mtimes — deliberately not a recursive walk) of the provider data roots is compared against the snapshot taken at the last successful fetch; unchanged → skip the spawn. Interactive paths (popover open, Refresh Now) always bypass. The snapshot anchors only on fetch success, so failures can't mask changes. Backstop: unchanged-skips are honored for at most 30 minutes — the hand-maintained root list is a perf optimization, not a correctness contract; a provider missing from it degrades to a 30-minute refresh, never stale-forever.RefreshCadence.swift): closed-popover Auto on AC moves from 30s to 120s (battery 150s / low-power 300s from menubar: cut idle energy (video-call-class drain, fixes #647) #648 unchanged; popover-open stays 30s). Settings label updated.Security/CodeburnCLI.swift, threaded throughDataClient/AppStore): background tick spawns run.utility(E-cores); interactive fetches keep.userInitiated.Combined with the guard, an idle machine goes from ~120 spawns/hour (post-#648 AC behavior) to at most 2/hour, and genuine refreshes land on efficiency cores.
Tests
UsageDataChangeGuardTests(swift-testing): fresh-skip, stale-no-skip, first-run, force-bypass, and the 30-minute backstop boundary.RefreshCadenceTestsupdated to pin the 120s closed-popover AC value.Verification
swift buildclean (Swift 6.3.3 toolchain). Test targets need XCTest (Xcode/CI) to execute — same constraint as #702.Part of #703 (items 2-4).