Skip to content

fix(rusqlite-runtime): retire ledger rows of exited daemon incarnations - #4129

Merged
ScriptedAlchemy merged 1 commit into
masterfrom
refactor/storage-idempotency-retirement
Oct 16, 2026
Merged

ScriptedAlchemy merged 1 commit into
masterfrom
refactor/storage-idempotency-retirement

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Step 3 of the storage redesign (docs/plans/storage/README.md in #4118), growth source 9 from #4099.

Every store's writer keeps an idempotency ledger (td_runtime_writer_idempotency_v2). A lookup matches on (shard, incarnation, authority_epoch, key), and the incarnation is the daemon's generation. So each daemon restart left the previous incarnation's rows unreachable, and nothing removed them. The only prune deleted rows of the committing incarnation at a superseded authority epoch.

A commit now also retires the rows of any incarnation whose checkpoint on that shard has been unchanged for more than 7 days. Each checkpoint row already holds its incarnation's last commit time, so the candidates come from the small checkpoint table plus the idempotency key prefix. No age column is scanned, and no schema object changes, so the exact-final-shape admission of existing stores is unaffected. Both rules share the existing bound of 256 deleted rows per commit.

The committing incarnation is never a candidate. Its checkpoint has just been persisted at this commit's own time, and a test pins that ordering. So a daemon that runs past 7 days keeps replaying its own receipts. That keeps the module's existing rule that content-derived keys of a live writer are never retired by age.

This differs from the design's literal "idempotency pruned at 7 d of age". Pruning the live incarnation by age needs an index on committed_at_micros. That index changes the store's exact schema shape, and memory-holding stores have no migration path yet (step 2). Retiring exited incarnations ends the stranding the design names, without that schema change.

Test plan

  • bazel test //crates/tracedecay-rusqlite-runtime:unit_test //crates/tracedecay-rusqlite-runtime:rusqlite_suite
  • a_restarted_daemon_retires_the_previous_incarnations_records_after_a_quiet_week: rows of incarnation 1 survive a commit by incarnation 2 at exactly 7 days and are retired 1 µs later. Skipping the retirement fails it, and so does changing < to <=.
  • the_live_incarnation_keeps_replaying_its_own_receipts_past_the_window: a two-week-old receipt of the committing incarnation still replays. Moving the prune before checkpoint::persist fails it.
  • The existing prune tests pass unchanged, including the bounded-batch and corrupt-neighbour cases.
  • bazel build --config=clippy //crates/tracedecay-rusqlite-runtime/... and //crates/tracedecay-rusqlite-runtime:rustfmt_check_2024
  • //crates/tracedecay:daemon_suite, :mcp_suite, :session_suite, :unit_test in CI

Refs #4099


Devin Review

@changeset-bot

changeset-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7e4a5b0

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: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@ScriptedAlchemy
ScriptedAlchemy merged commit 840d722 into master Oct 16, 2026
18 of 21 checks passed
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