Skip to content

fix(rusqlite-runtime): admit stores left by an interrupted checkpoint - #4913

Open
ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/session-store-open-unckpt-wal
Open

ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/session-store-open-unckpt-wal

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Problem

After tracedecay update (beta.105 → beta.106) the daemon crash-looped (86 restarts) with:

open registered session runtime: identify repository attachment: existing SQLite file has no valid database header; refusing sidecar access

The old daemon was killed during store_close while checkpointing ~/.tracedecay/user-sessions.db (7 GB, 55 MB WAL). That left the standard SQLite crash state: a main file mixing committed generations plus a WAL holding every committed frame. PRAGMA quick_check with the WAL was ok; the data was intact.

OpenedDatabaseFile::pin_initialized refused it:

  1. The immutable main-only view fails every statement (SQLite parses the schema first, even for header pragmas).
  2. The WAL fallback (live_wal_has_store_schema) read the full schema through the WAL, but its shared-index check returned SQLITE_READONLY_CANTINIT (rc 1288): no live process maps the WAL index, so SQLite recovered it into a heap index, which the guard deliberately rejects. An empty -journal left by initialization also disqualified the fallback.

Fix

FinishInitialSchema stamps application_id = TDST and must then wal_checkpoint(TRUNCATE) it into the main file, so a TDST main header proves the store was published and owns its sidecars. pin_initialized now reads that header through the inspection connection's own VFS file (no new descriptor, so no POSIX-lock hazard). It admits the store when that header is present and a nonempty WAL completes the schema view. SQLite's ordinary recovery then restores the frames on the next writable open.

Unchanged refusals:

  • Unstamped (legacy or interrupted-initialization) files with a disconnected WAL still return InvalidHeader / IncompleteInitialization.
  • A stamped store whose inconsistent main has no recoverable WAL is still refused (live_wal_recovers_an_inconsistent_immutable_checkpoint_view).

Verification

  • New crash_interrupted_checkpoint_of_a_published_store_remains_attachable: failed with InvalidHeader before the fix. It now admits the stamped store, refuses the identical unstamped files, and SQLite recovery returns the committed row with quick_check = ok.
  • cargo test -p tracedecay-rusqlite-runtime --lib: 483 passed.
  • cargo clippy -p tracedecay-rusqlite-runtime --all-targets -D warnings and //crates/tracedecay-rusqlite-runtime:rustfmt_check_2024 pass.
  • Against an APFS clone of the real failing store (pre-checkpoint main + WAL + SHM + empty journal): pin_initialized went from Err(InvalidHeader) to Ok, leaving the sidecars untouched.

🤖 Generated with Claude Code


Devin Review

@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 49ce939

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

A daemon killed while closing its stores can leave a main file mixing
committed generations beside a WAL that no live connection maps. SQLite
recovers that state from the WAL, but pin_initialized refused it: the
immutable main-only view fails every statement, and a disconnected WAL
recovers into a heap index that cannot prove SHM ownership. The daemon
then crash-looped on "existing SQLite file has no valid database header".

FinishInitialSchema stamps the registered application ID and must then
checkpoint it into the main file, so that header proves the store was
published and owns its sidecars. Read it through the inspection
connection's VFS file and admit the store when its nonempty WAL completes
the schema view. Unstamped files and stores with no recoverable WAL are
still refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy force-pushed the fix/session-store-open-unckpt-wal branch from 231e86a to 49ce939 Compare November 17, 2026 02:33
@ScriptedAlchemy ScriptedAlchemy changed the title fix(rusqlite-runtime): admit published stores after a crash-interrupted checkpoint fix(rusqlite-runtime): admit stores left by an interrupted checkpoint Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant