GeezerVison is showing github.com — impl(backups): mesh class D — fleet-queue-backup D1 export to Turso home (#13458) by dezren39 · Pull Request #13539 · developing-today/code
Conversation
dezren39
commented
Nov 23, 2026
•
edited by blacksmith-sh
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Refs #13458 — backup-mesh class D leg (design: #9093, record PR #13467). This PR lands the code half of the leg; the issue stays open for the live leg and the step-2 inventory (named on the issue).
What lands
The reverse of the #8584 pipeline, reusing its machinery (fq_common clients, restore_drill's D1 schema/read path with keyset paging and CAST-AS-TEXT integer fidelity):
bin/export_to_turso.py — weekly D1 → Turso-home export for the fleet-queue-backup D1 database into the new home d1-backup-fleet-queue-backup. Staged wholesale import: load into _d1stage_ tables, verify emitted counts cross-checked against D1 count(*) (a disagreement means the source moved mid-run → fail, previous import intact — the Fleet unification slice 6: backups — Turso into D1, repos to Cloudflare plus mirror plus R2 #8584 smear lesson), then swap behind a commit marker in _d1_backup_home_meta (marker/record import_id equality is the witness), recreate indexes/views/triggers, verify live counts, write the import record with per-table counts, drop the retiring set. An interrupted swap is recovered at the next run's start: uncommitted → roll back to the recorded import; committed → clean the retiring leftovers.
bin/restore_drill_d1_home.py — the restore verification: rebuilds the D1 database from the home alone into a local SQLite file (the issue's local-SQLite scratch target) and verifies counts against the import record.
systemd/ — run-d1-home-export.sh wrapper (secrets by name from Bitwarden; fails with a clear message while the home token is unprovisioned), fleet-queue-backup-d1-home.service (TimeoutStartSec=2h) + .timer (Sun 03:40 + RandomizedDelaySec 30m, Persistent), install-units.sh extended, argument tests extended.
- Tests:
tests/test_export_to_turso.py (6) + tests/test_restore_drill_d1_home.py (3) — hermetic, sqlite-backed fakes in the established standalone pattern. They caught two real defects during development (the swap renaming its own staging tables aside; a fixture drop-order error), both fixed in-branch.
doc/fleet-schedule-registry.md — new Surface 2b row for the timer (declared in repo; laptop install is part of the issue's live leg).
- README + RUNBOOK: class-D pieces, credentials, provisioning steps for the live leg, failure/recovery notes.
No new dependencies (Python standard library only). No changes to fq_common.py or restore_drill.py.
Evidence
Full infra/fleet-queue-backup suite run remotely against this branch (fleet queue dispatch): fleet-command run 45230221803 — conclusion success: all 9 test files pass (38 tests: pre-existing 29 incl. the #8584 suites, plus 7 export + 3 D1-home drill tests added here) and systemd/test-export-arguments.sh reports all checks passed. Two earlier runs against this branch (45221374628, 45228755235) caught real defects in the new code — the swap renaming its own staging tables aside, and the rollback dropping the retiring set it was about to restore — both fixed in-branch with regression tests before this green run.
What remains on #13458 after this PR
- Live leg: provision the Turso home
d1-backup-fleet-queue-backup, mint the vault token turso.d1-backup-fleet-queue-backup-rw-token, install the units on the laptop, first live import record posted on the issue, live restore verification.
- Step 2 (follow-on): account-wide D1 inventory.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The reverse direction of the #8584 leg: bin/export_to_turso.py exports
the fleet-queue-backup D1 database into its dedicated Turso home
(d1-backup-fleet-queue-backup) on a weekly schedule, reusing
restore_drill's proven D1 read path (keyset paging, CAST AS TEXT
integer fidelity, _cf_KV excluded) and fq_common's libsql client.
Wholesale replace, staged: the new copy is loaded into staging
tables and verified (emitted counts, cross-checked against the
source so a mid-run source move fails the run) before anything live
moves; a failed import leaves the previous import intact. The swap
writes the incoming record as a marker before its first rename and
as the import record after live counts verify -- marker/record
agreement by import_id is the commit point -- and a later run
reconciles retiring tables against it (roll back an uncommitted
swap, drop a committed swap's leftovers).
bin/restore_drill_d1_home.py is the acceptance drill: rebuild the
D1 database from the home into a local SQLite file and verify
counts against the import record. Weekly systemd units
(Sun 03:40) + wrapper fetching credentials by name, install-units
and argument-test coverage, schedule-registry row in the same pass,
README + runbook (incl. the provisioning steps for the live leg).
Hermetic tests: sqlite3 is the oracle -- row-for-row copy incl.
int64::MAX, wholesale replacement, failed-import and smear refusal
leaving the previous import intact, and both swap-crash readings.
…3458)
home_schema lists every table in the home, staging included, so
_swap renamed the staging tables aside as if they were the live
copy and then could not find them to rename in. Caught by the
hermetic suite on its first remote run (6 errors, no such table:
_d1stage_tasks).
)
DROP TABLE notes removes idx_notes_task with it, so the explicit
DROP INDEX afterwards failed with 'no such index'. The first
export tests passed in the same run; only the variant-2 fixtures
errored.
#13458)
recover_interrupted_swap built its 'live' set from every table in
the home -- retiring tables included -- dropped them all, and then
failed renaming the retiring tables back ('no such table:
_d1retire_tasks'). The rollback now decides per live table from
the marker: the marker carries the pre-swap live set (replaces),
and a live table is dropped only when a retiring copy shadows it
or it is an incoming table that did not exist before the swap;
untouched old copies stay. New test covers the early-crash shape
(one table renamed aside, the rest live, one incoming-only table
already in). Caught by the hermetic suite on its second remote
run: 5 of 6 export tests passed, this one errored.
Warning
Review limit reached
You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.
Next included review available in 34 minutes.
Check out review usage here.
View limit details
-
Limit details: You’ve used the included review currently available.
Learn how review limits work.
Review configuration:
Run configuration
-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ee356eed-22f6-4c2f-a5a7-36d45aa4bde4
Commits
-
Reviewing files that changed from the base of the PR and between cb4f687 and fc40874.
Files selected for processing: 12
-
doc/fleet-schedule-registry.md
infra/fleet-queue-backup/README.md
infra/fleet-queue-backup/bin/export_to_turso.py
infra/fleet-queue-backup/bin/restore_drill_d1_home.py
infra/fleet-queue-backup/docs/RUNBOOK.md
infra/fleet-queue-backup/systemd/fleet-queue-backup-d1-home.service
infra/fleet-queue-backup/systemd/fleet-queue-backup-d1-home.timer
infra/fleet-queue-backup/systemd/install-units.sh
infra/fleet-queue-backup/systemd/run-d1-home-export.sh
infra/fleet-queue-backup/systemd/test-export-arguments.sh
infra/fleet-queue-backup/tests/test_export_to_turso.py
infra/fleet-queue-backup/tests/test_restore_drill_d1_home.py
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-11-23T18:00:34.209705Z |
fc40874 |
PR opened |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc40874e12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+57
to
+59
|
|
record = export_to_turso.read_import_record(home)
|
|
|
if record is None:
|
|
|
raise RuntimeError("Turso home has no import record; nothing to verify")
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify the import generation stays stable throughout the restore
If the weekly export swaps the home while this drill is reading it, separate table/page requests can copy different import generations. The drill reads the import record only once and never checks the swap marker or rechecks import_id, so an export that changes values without changing per-table counts lets a mixed-generation database pass verification. An interrupted export after the incoming renames can likewise expose uncommitted data under the previous import record. Reject an uncommitted swap and verify that the committed generation remains unchanged through the final read before reporting success.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 24, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|