perf(daemon): preserve telemetry source collection state - #269
Conversation
Update: incremental telemetry read modelI pushed a structural follow-up in Root causeThe existing aggregate cache avoids work while the database is idle, but every new event invalidates it. Under an active Codex session, OpenUsage repeatedly:
Rolling windows also used the exact nanosecond ImplementationThe new implementation adds:
This is intentionally a hybrid read model: the change log is durable, while candidates, winners, and aggregate state are process-local. A daemon restart performs one cold build; subsequent refreshes are incremental. MeasurementsTest database:
Results:
A later 60-sample check after more than one hour of daemon uptime, while 18 additional events were ingested, measured:
Correctness coverageTests cover:
Validation completed with:
|
Closes #268.
What changed
Root cause
collectAndFlushrebuilt collectors throughproviders.AllProviders()every cycle. SinceAllProviders()constructs new provider instances, the per-provider telemetry caches were discarded every 20–30 seconds. Codex therefore reparsed historical session JSONL files repeatedly.Even when a provider cache survived within one instance, cache hits returned all cached events again. That kept the cycle non-empty, repeated mapping/SQLite dedup work, retained large event slices, and prevented adaptive backoff.
User impact
Large local Codex or Claude Code histories no longer cause unchanged session files to be reparsed and re-ingested every collection cycle. After the initial import, idle cycles return no local-file events and can back off normally.
Codex still reparses a file when that file changes; implementing stateful suffix parsing for Codex can be a separate follow-up because token deltas and tool-result correlation cross line boundaries.
Tests
New regression coverage verifies:
Validation run:
make fmtmake vetmake buildmake testgo test -race -count=1 ./internal/providers/codex ./internal/providers/claude_codego test -race -count=1 ./internal/daemon -skip TestChangeDetectorReturnsFalse_WhenNoFilesOne existing environment-dependent daemon test,
TestChangeDetectorReturnsFalse_WhenNoFiles, fails on this machine because a real Kiro CLI database is present. The same failure reproduces unchanged on upstreammain.