Skip to content

feat(history): move query history into SQLite - #597

Merged
EVWorth merged 1 commit into
mainfrom
feat/history-sqlite-store
Sep 10, 2026
Merged

EVWorth merged 1 commit into
mainfrom
feat/history-sqlite-store

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Closes #585, closes #331.

Stacked on #593 (which is itself stacked on #584). This branch rewrites the same store those change, so it carries their commits. The commit to read here is the last one.

Why the medium was the bug

History lived in localStorage under one key, rewritten in full on every query:

  • Shared quota. 5–10 MB per origin, shared with settings and favorites.
  • Silent loss. persist swallows a quota failure — recording just stopped and nothing said so.
  • Unbounded entries. One pasted migration script could consume the quota by itself.
  • Wiped with site data. Not a durable record.
  • Full-array sync rewrite on every add. That's [P1/arch] Every addEntry writes the entire entries array to localStorage synchronously — no debounce #331, which only existed because of the medium — hence closing it here rather than debouncing around it.

Where it lives now

history.db, beside connections.db, with the same PRAGMA user_version migration machinery (mas_core::history). Its own file, not a table in connections.db — history is append-only and much larger, and a corrupt or oversized history should not be able to take the connection profiles with it.

The frontend store is now a view over the database rather than the thing holding it.

Details worth a look in review

  • LIKE needs an explicit ESCAPE. Without one, searching 100% matches every row containing 100, and searching _ matches everything. Both are tested.
  • Truncation walks back to a character boundary. A 256 KB cut landing mid-codepoint panics on the slice; a query full of non-ASCII text would have taken the app down. Tested with "é".repeat(MAX_SQL_BYTES).
  • The handover removes the legacy key only after the import succeeds. Ids carry across, so an app killed midway resumes rather than duplicating. A parse failure leaves the data alone — deleting someone's only copy of their history because we couldn't read it is the one outcome worth designing against.
  • A failed history write no longer fails the query. Recording is a side effect; it surfaces in the panel instead.
  • i64 doesn't cross specta, so counts use the existing #[specta(type = Number)] idiom from QueryResult rather than inventing a new convention.

Verification

21 Rust store tests + 2 migration tests, 26 frontend store tests, 20 panel tests. Full suites green (1842 frontend, all Rust crates), clippy clean, 0 lint errors. ARCHITECTURE §9.4, the data-dir tree and the localStorage key table all updated.

The old store tests asserted localStorage behaviour that no longer exists, so they were rewritten against the new contract rather than patched.

History lived in localStorage under one key, rewritten in full on every
query. That medium shares a five-to-ten megabyte origin quota with settings
and favorites; swallows a quota failure silently, so recording simply
stopped and nothing said so; and is wiped when the user clears site data.
A single entry was unbounded, so one pasted migration script could consume
the quota by itself (#585).

It now lives in history.db beside connections.db, with the same
PRAGMA user_version migration machinery. Its own file rather than a table
in connections.db: history is append-only and much larger, and a corrupt or
oversized history should not be able to take the connection profiles with
it.

The frontend store is a view over the database rather than the thing that
holds it. Search is a LIKE with an explicit ESCAPE — without one, searching
for "100%" matches every row containing 100, and searching for "_" matches
everything. A statement over 256 KB is stored cut and marked, with the walk
back to a character boundary that stops a non-ASCII query panicking on the
slice.

On first run the old localStorage key is imported and then removed. Ids
carry across, so an app killed midway resumes rather than duplicating, and
the key is removed only after the import succeeds — deleting someone's only
copy of their history because we could not read it is the one outcome worth
designing against. A parse failure leaves it alone.

A failed history write no longer fails the query that produced it; it
surfaces in the panel instead. Deletes and clears are optimistic and roll
back if the write fails.

This supersedes #331: the full-array synchronous rewrite was a property of
the medium, not something to debounce around.

Closes #585
Closes #331

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth force-pushed the feat/history-sqlite-store branch from 45b27cd to 5d22f5d Compare September 10, 2026 00:01
@EVWorth
EVWorth merged commit 7d50df2 into main Sep 10, 2026
12 checks passed
@EVWorth
EVWorth deleted the feat/history-sqlite-store branch September 10, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant