Skip to content

perf(db): spool only changed usage facts - #2590

Merged
mariusvniekerk merged 3 commits into
kenn-io:mainfrom
tpn:perf/usage-spool-delta-20261031
Nov 2, 2026
Merged

mariusvniekerk merged 3 commits into
kenn-io:mainfrom
tpn:perf/usage-spool-delta-20261031

Conversation

@tpn

@tpn tpn commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Usage-cache refills now compare complete extracted facts with the expected cache installation and spool only changed or new rows. Complete per-session counts remove obsolete tails, and identity invalidation uses the complete installed cache. Existing source snapshots and installation revision checks remain in place. Repeated full-size SQL batches reuse their prepared statement within the extraction transaction.

This reduces temporary database writes for active sessions whose history is mostly unchanged. In a synthetic 2,048-fact single-edit case, spooled rows fell from 2,048 to one and the temporary file shrank from 220 KiB to 12 KiB. The added comparisons have a cost: complete-fill medians were approximately 41 ms before and 46 ms after, with wide overlapping ranges. This change exposes that write-volume/runtime tradeoff for review.

Full source extraction still scales with session history, and appends can shift later activity or event indexes. No persistent schema or fact semantics change. Refs #2542; incremental source extraction remains open there.

Also includes the upload-artifact reference correction carried in #2589 so the CI workflow can start. The existing lockfile resolves the corrected reference to the same action commit.

Compare extracted facts with the expected cache installation before
writing the temporary spool. Keep complete fact counts for tail removal
and invalidate identities from the complete installed cache.
@roborev-ci

roborev-ci Bot commented Oct 31, 2026

Copy link
Copy Markdown

roborev: Combined Review (06dade4)

Verdict: Changes require fixes for 1 finding.

Medium

  • internal/db/usage_cache_fill_test.go:780: TestUsageSpoolRejectsInvalidCountsWithoutChangingCache tests missing session rows and negative counts created through test-only SQL mutations. Neither state can reach installation through the production extraction lifecycle, so both cases test unreachable scenarios.

    Fix: Delete TestUsageSpoolRejectsInvalidCountsWithoutChangingCache and both mutation cases. Keep the reachable truncation and empty-session checks in TestUsageSpoolRetainsOnlyChangedFacts.


Reviewers: 2x codex, codex (security), codex (test-value) | Synthesis: codex, 9s | Total: 3m55s

@roborev-ci

roborev-ci Bot commented Oct 31, 2026

Copy link
Copy Markdown

roborev: Combined Review (208bb7a)

Verdict: No findings at or above medium severity.


Reviewers: 2x codex, codex (security), codex (test-value) | Synthesis: codex | Total: 4m16s

@tpn
tpn marked this pull request as ready for review November 1, 2026 01:02
@mariusvniekerk mariusvniekerk added the benchmark-triggered Used to indicate when you've triggered a benchmark on a PR label Nov 1, 2026
@mariusvniekerk mariusvniekerk self-assigned this Nov 2, 2026
@mariusvniekerk
mariusvniekerk added this pull request to the merge queue Nov 2, 2026
Merged via the queue into kenn-io:main with commit 7b389aa Nov 2, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark-triggered Used to indicate when you've triggered a benchmark on a PR

Development

Successfully merging this pull request may close these issues.

2 participants