Skip to content

fix(usage): avoid SQLite history scans for latest additional quotas - #14

Merged
aneym merged 1 commit into
aneym:mainfrom
shiniken:fix/sqlite-additional-quota-latest
Oct 14, 2026
Merged

aneym merged 1 commit into
aneym:mainfrom
shiniken:fix/sqlite-additional-quota-latest

Conversation

@shiniken

Copy link
Copy Markdown

SQLite additional-quota routing and cache warming ranked the full matching usage history on each latest lookup. With roughly 1.1 million historical rows, representative reads took 0.7–4.2 seconds and repeatedly consumed several CPU cores.

Replace that SQLite path with covering-index seeks per account and alias, then choose the latest candidate using the existing timestamp, usage and ID precedence. Keep canonical and historical aliases, account/window/since filters, orphan history and large account pools intact. The additive SQLite-only migration supplies matching indexes; PostgreSQL routing is unchanged.

Validation: 75 relevant repository, integration and migration tests; imports; Ruff; strict OpenSpec. A database-snapshot comparison returned identical result IDs for four quota keys, with representative reads reduced to 3–19 ms; EXPLAIN QUERY PLAN confirms covering-index seeks. Migration downgrade/upgrade was exercised on the snapshot. The deployed fix reduced observed backend CPU from approximately 465% to 0.6–12.5% under active traffic after a graceful restart.

Replace history-wide ranking with indexed per-account alias seeks while preserving latest-row semantics. Add SQLite covering indexes and large-pool regression coverage.

Seat: Codex

Check: 75 relevant repository/integration/migration tests; Ruff; import; strict OpenSpec; historical result equality and query-plan benchmark.
@aneym
aneym merged commit 700a3df into aneym:main Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants