Repository navigation
feat(store): keep the spectrum history across restarts - #17
Merged
Merged
Conversation
The spectrum history is wiped at every start, so an accidental close loses up to a day of trend. The plan keeps one history file across restarts with the existing 24 h retention, loads it into the trend at start, and sets a damaged or outdated file aside. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each start wiped its own spectra-<pid>.db and swept the files of other instances, so the 24 h history died with every restart. The store now writes spectra.db in the store folder and keeps it. Prepare deletes the spectra-<pid>.db files and sidecars of older builds instead of sweeping each hour. The writer runs one retention pass right after the open, so a file closed for days loses its expired rows before it is read. The schema statements skip existing tables until the version gate of a later change replaces them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The history file now survives restarts, so a file closed for a day or more holds only expired rows at the next start. The row-wise retention delete visits every row and index entry: 908.5 ms on a 762 MB day, and it runs before the trend can read. DeleteBefore reads max(received_at) of both tables inside its transaction. When both are below the cutoff or empty, it runs DELETE without WHERE, which takes SQLite's truncate optimisation: 77.9 ms on the same file. Otherwise it keeps the row-wise statements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The history file now outlives the process, so a build with another schema can meet a file it cannot use. Task 1 papered over the reopen with CREATE TABLE IF NOT EXISTS, which accepts any file that happens to hold tables of those names. SpectrumDatabase.Open now reads PRAGMA user_version and the table count in one IMMEDIATE transaction: a table-less file gets the schema and version 1, version 1 is used, anything else fails with StoreSchemaMismatchError. StoreOpening, the writer's new open sequence, deletes a mismatched file with its sidecars, logs one Warning naming both versions and opens a fresh file; no panel entry, since an app update causes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The history file now lives across restarts, so a file SQLite reports as not a database (26) or corrupt (11) would end history for every later run with a StoreOpenError. SpectrumDatabase.Open turns those two codes into StoreFileUnreadableError. StoreOpening then renames the file to spectra.broken-<local stamp>.db with its WAL, keeps the two newest set-aside files, opens a fresh file and reports StoreFileReplacedError as a Warning. A failed rename or reopen still ends in StoreOpenError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The open reads only the header and the schema page, so damage deeper in the history file shows later, as a failed write or read, and the next run would keep using the damaged file. StoreDamage.IsDamage tells SQLite codes 11 and 26 from other failures. After such a failed batch, retention pass, checkpoint or history read, the failing party creates the empty marker spectra.db.damaged; a held lock marks nothing. The next open finds the marker before it opens the file and sets the file aside with the same report as an unreadable one. SetAside and DeleteWithSidecars delete the marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A spectra.db.damaged marker whose spectra.db was deleted by hand made the open try to set aside a missing file, so the store failed with StoreOpenError at every start until someone deleted the marker. Prepare now deletes a marker whose history file is gone. The marker beside an existing file stays, so the next open still sets that file aside. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The trend's start read must not open spectra.db while the writer may still delete, rename or create it during the open, the set-aside or the schema replace. SpectrumStore.Opened completes true once the writer opened the file and ran the retention at open, and false when the open fails, a dispose cancels the writer first, or a stop comes before the start. A reader that waits on it never meets a file the writer is about to replace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FrameContinuity raised a NoSpectra break only between frames of the current run, so the time the app was closed and the closed periods inside a loaded stored day drew as a continuous line. The fold now adds a NoSpectra break at each point more than the silence limit after the point before it, also the one just before the range. Every spectrum, live or stored, is one point (NaN when uncovered), so one rule covers a live silence and the gaps in stored history. FrameContinuity keeps the seq reset, Loss breaks and failure marks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a restart the trend stayed empty until a key change, although the history file now keeps the last 24 h across runs. The cache records its run start and asks for the stored day before it, at the live key or else at the key of the last stored spectrum. The feed waits for the store's ready signal with the token its subscription cancels, reads that spectrum, and the existing throttled history read lands the day. FoldCurrent drops expired points without new frames, and every finished history read logs its landing times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan's edge case, a key change while the start read lands the stored day, had no test of its own; only the generic second-key-change test covered the Switch it relies on. The new test holds the start read's first chunk, feeds a live spectrum at another wavelength, and checks that the held read is cancelled and the new key is read. The plan records the acceptance run: 1045 of 1045 tests, the gates, and the warm benchmark trend rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The architecture docs still described one store file per process, wiped at start and swept hourly, and NoSpectra breaks from FrameContinuity. They now describe spectra.db kept across restarts, the legacy cleanup, the schema version gate, the damage marker and set-aside, retention at open with its fast path, the Opened signal, the trend's start read and NoSpectra breaks from point gaps, with the matching test coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan said no reader opens the history file while the writer may delete or rename it, but only the start read waits for the open. It now says so and names the outcome of the rare race: the file is kept and the session reports a store open error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The spectrum history was wiped at every start, so an accidental close lost up to a day of trend.
%LOCALAPPDATA%\SemiSpec\Spectra\spectra.dbis kept across restarts; the 24 h retention runs at open and every minute, with a one-step path when every row has expired (78 ms instead of 909 ms on a full day). Store files of older builds are deleted at start.spectra.broken-<time>.db(at most 2 kept) and reported in the message panel; damage found later by a write, read or retention pass leaves a marker so the next start sets the file aside the same way.Verified: 1045 tests (992 before), Release build 0 warnings, format and terse clean; warm benchmark within targets (whole-day re-read 752 ms against 2000 ms). Reviewed by a second model with no blocking findings. Left for the operator PC: the cold read of a full day after a reboot (budget 10 s) and the smoke checklist in the plan.
🤖 Generated with Claude Code