GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(fleet-queue-backup): Turso to D1 export with restore drill (#8584) by dezren39 · Pull Request #12686 · developing-today/code

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •
edited by blacksmith-sh Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

Slice 6 of the fleet unification design (#8575), the Turso -> D1 leg of #8584: a scheduled, verified export of the fleet-queue Turso database into a D1 database in the fleet's existing Cloudflare account (Drew's 2026-11-16 account-scope answer on #8584), plus the restore drill that proves the copy can be brought back into a live Turso store. New directory infra/fleet-queue-backup/, modeled on infra/github-backup.

What landed

  • bin/export_to_d1.py — full logical export (schema + every row) over the libsql HTTP API into D1 via the D1 import API. Literals are rendered by SQLite's quote() at the source, never by Python string formatting. Success is reported only after the per-table row counts are read back out of D1 and match the source counts taken in the same run. --create provisions the D1 database as an explicit act; the scheduled wrapper never passes it.
  • bin/restore_drill.py — the acceptance drill: reads the D1 copy out through the D1 query API, rebuilds a scratch Turso store with parameterized statements (values never pass through SQL text on this path), and verifies restored counts against the counts the export recorded in the copy's _fleet_queue_backup_meta table.
  • bin/fq_common.py — libsql pipeline client, D1 client, dump builder (idempotent: drops dependents first, so re-import is the refresh path). Paged reads carry the Design: complete, bounded, or say so — one pagination contract for the repo's paged reads #6622 bound.
  • systemd/ — daily user timer (02:15 + 30m randomized delay); the wrapper fetches credentials from Bitwarden by name at runtime and exposes them only to its process tree. Strict no-argument contract per Design: unknown means stop — one strict argument contract for the repo's operator scripts #3352, with the argument test.
  • docs/RUNBOOK.md — freshness target (meta row never >24h old), the by-hand export, and the disaster restore path ending in a live claim through a scratch broker against the restored store (counts alone do not close the acceptance).
  • doc/fleet-schedule-registry.md — the new timer's registry row, per the AGENTS.md schedule rule.

Verification

  • Hermetic, sqlite3 as oracle: tests/test_fq_common.py (5 tests — dump rebuilds the source row-for-row including quote/newline/unicode/blob/NULL cases, re-import idempotence, pagination bound, Hrana round-trip) and tests/test_restore_drill.py (4 tests — full restore from a fake-D1 copy rebuilds the target row-for-row; D1 value decoding). All pass.
  • bash systemd/test-export-arguments.sh passes; bash -n clean; git diff --check clean.
  • The dump builder was also run against the live fleet-queue store from this seat (read-only): result recorded in a comment below when the run completes.

Live run status (honest)

The D1 provisioning + first verified export + restore drill into a scratch Turso DB + live claim are not yet run. Both venues are blocked this evening: the laptop agent leg is down (fleet shell lands on the sandbox runtime instead of the laptop, where turso/wrangler and the production broker live), and api.cloudflare.com is unreachable from the sandbox (110 s timeout, HTTP 000). One Cloudflare probe attempt in this session was not performed because its approval timed out; it was not retried. The resume condition — run from the laptop checkout per the runbook, starting with bin/export_to_d1.py --create — is recorded on #8584. Nothing in this PR depends on that run; the code is reviewable as-is.

Remaining for #8584 after this PR

  • The live provisioning + drill above (venue-blocked, not code-blocked).
  • The Cloudflare rehost leg (the design's open question on Design: one door, one home per fact — the fleet tool owns every route and every fallback #8575) and the unified five-copy freshness/lag readout with automatic issue filing.

Refs #8584 #8575 #12538. No new dependencies (Python stdlib only).


Get evidence
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.

All reactions
felix added 2 commits November 22, 2026 21:06
felix
feat(fleet-queue-backup): Turso to D1 export with restore drill (#8584)
f513536
Slice 6 of the fleet unification design (#8575), Turso-to-D1 leg:
a full logical export of the fleet-queue store into a D1 copy
(literals rendered by SQLite quote() at the source, read-back count
verification before success is reported), a restore drill that
rebuilds a scratch Turso store from the D1 copy with parameterized
statements and verifies counts against the export's recorded meta,
a daily systemd timer whose wrapper fetches credentials by name at
runtime, the runbook for the disaster restore path, and the schedule
registry row. Hermetic tests use sqlite3 as the oracle.
felix
docs(fleet-queue-backup): correct the broker env in the runbook claim…
993bfc2
… step (#8584)

QUEUE_BROKER_BIND is the bind setting (there is no QUEUE_BROKER_PORT);
the scratch broker also needs its own socket path and token file so
it never touches the production broker's.
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 21:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
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-22T21:37:50.321170Z 993bfc2 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39 dezren39 mentioned this pull request Nov 22, 2026
Fleet unification slice 6: backups — Turso into D1, repos to Cloudflare plus mirror plus R2 #8584
Closed
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

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 31 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: ba35716c-0166-490a-9b82-fd0274d667b4
Commits

Reviewing files that changed from the base of the PR and between 50fba55 and 993bfc2.

Files selected for processing: 13

  • doc/fleet-schedule-registry.md
  • infra/fleet-queue-backup/README.md
  • infra/fleet-queue-backup/bin/export_to_d1.py
  • infra/fleet-queue-backup/bin/fq_common.py
  • infra/fleet-queue-backup/bin/restore_drill.py
  • infra/fleet-queue-backup/docs/RUNBOOK.md
  • infra/fleet-queue-backup/systemd/fleet-queue-backup-export.service
  • infra/fleet-queue-backup/systemd/fleet-queue-backup-export.timer
  • infra/fleet-queue-backup/systemd/install-units.sh
  • infra/fleet-queue-backup/systemd/run-export.sh
  • infra/fleet-queue-backup/systemd/test-export-arguments.sh
  • infra/fleet-queue-backup/tests/test_fq_common.py
  • infra/fleet-queue-backup/tests/test_restore_drill.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

  • X
  • Mastodon
  • Reddit
  • LinkedIn
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39

dezren39 commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Live-run correction and status (task 21043, worker felix, 2026-11-22 evening):

The PR body says the read-only dump run against the live store would be recorded here when it completes. It did not complete: the seat's egress to the Turso endpoint is degraded enough that a full 500-row-page pass over the production store did not finish in ~15 minutes, and I stopped it rather than leave it running. What is verified against the live store: a libsql pipeline query from this seat returned the store's schema count (25 tables/views), and both vault credentials the export needs are present by name (turso.fleet-queue-rw-token, cloudflare.api-token-account-wide, checked via bws directly). The dump builder itself is proven by the hermetic suite (sqlite3 oracle, row-for-row rebuild).

Nothing else in the PR changes: the D1 provisioning, first verified export, restore drill, and timer install remain venue-blocked (laptop agent leg down; api.cloudflare.com unreachable from the sandbox at 110 s), with the resume condition recorded on #8584. When the laptop leg is back, the whole live sequence is the runbook's: export_to_d1.py --create, scratch-DB drill with the live broker claim, systemd/install-units.sh.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
dezren39 merged commit 11d8888 into main Nov 22, 2026
2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
dezren39 deleted the felix/8584-turso-d1 branch November 22, 2026 21:36
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Nov 22, 2026
View reviewed changes

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 993bfc2c5e

ℹ️ 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.

All reactions
Comment thread infra/fleet-queue-backup/bin/fq_common.py
Comment on lines +331 to +335
for _attempt in range(60):
poll = self._call(
"POST",
f"/accounts/{self.account}/d1/database/{db_id}/import",
{"action": "poll", "filename": filename},

@chatgpt-codex-connector chatgpt-codex-connector Bot Nov 22, 2026

Copy link
Copy Markdown

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.

P1 Badge Start D1 ingestion before polling its bookmark

Every real export reaches this loop immediately after uploading the SQL file, without ever starting an import. The D1 import API requires an ingest request containing etag and filename, followed by polling with current_bookmark; this request instead sends poll with filename. Consequently, the uploaded dump is never ingested and the scheduled backup cannot refresh D1. Send the ingest request first, then use its returned bookmark for subsequent polls.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread infra/fleet-queue-backup/bin/fq_common.py
Comment on lines +226 to +227
schema = read_schema(client)
counts = table_counts(client, schema)

@chatgpt-codex-connector chatgpt-codex-connector Bot Nov 22, 2026

Copy link
Copy Markdown

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.

P1 Badge Read the source dump from one consistent snapshot

When the production queue changes during an export, these counts and the later table pages describe different database states: LibsqlClient.execute() opens and closes a separate pipeline for every statement, so no read transaction spans the dump. For example, a claim appends an event between counting events and reading its rows, causing the eventual D1 count verification to fail even though the import succeeded. Updates that preserve counts can also produce a mixed-time copy that passes verification. Keep schema, counts, and all row pages in one source snapshot rather than requiring the live broker to remain idle for the entire export.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread infra/fleet-queue-backup/docs/RUNBOOK.md
Comment on lines +89 to +91
REPO_QUEUE_BROKER_URL=http://127.0.0.1:4899 \
QUEUE_BROKER_TOKEN_FILE=~/restore-drill/broker-token \
~/tools/fleet queue claim --worker restore-drill

@chatgpt-codex-connector chatgpt-codex-connector Bot Nov 22, 2026

Copy link
Copy Markdown

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.

P2 Badge Pass the client token variable in the restore drill

Following this drill with the distinct scratch token created above makes the claim authenticate with the wrong token. The queue client's direct_token() in pkgs/fleet/crates/fleet-queue/src/client/transport.rs reads REPO_QUEUE_TOKEN_FILE, not QUEUE_BROKER_TOKEN_FILE; the latter only configures the server. Thus the client uses its existing production token file, or fails if that file is absent, instead of authenticating to the scratch broker. Set REPO_QUEUE_TOKEN_FILE for both the claim and listing commands so the documented live-restore acceptance step can succeed.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread infra/fleet-queue-backup/bin/fq_common.py
Comment on lines +91 to +92
if isinstance(value, (bytes, bytearray)):
return {"type": "blob", "value": base64.b64encode(bytes(value)).decode()}

@chatgpt-codex-connector chatgpt-codex-connector Bot Nov 22, 2026

Copy link
Copy Markdown

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.

P2 Badge Use the Hrana base64 field for blob values

When a backed-up row contains a BLOB, the restore converts it to bytes and passes it through this encoder, which emits the wrong wire shape. The Hrana protocol specification defines blob values with a base64 field, not value, so the live Turso endpoint cannot decode these arguments. The corresponding python_value() branch also reads value and would raise KeyError on a valid blob response. Use base64 in both directions; the current round-trip test misses this because the encoder and decoder share the same incorrect format.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread infra/fleet-queue-backup/bin/fq_common.py
raise RuntimeError(
f"{table}: expected {ncols} columns, found {len(colnames)}"
)
quoted = ", ".join(f'quote("{c}")' for c in colnames)

@chatgpt-codex-connector chatgpt-codex-connector Bot Nov 22, 2026

Copy link
Copy Markdown

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.

P2 Badge Preserve embedded NUL characters when rendering text

If a source TEXT value contains an embedded NUL, applying quote() here silently drops that character and everything after it. For example, a text value containing before, U+0000, and after is exported as only 'before'; this is documented behavior of SQLite's quote function. Both export and restore verification compare only row counts, so the truncated backup is reported as successful. Render text through a lossless representation, such as a hex blob cast back to TEXT, or reject such values explicitly rather than silently corrupting the copy.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dezren39 dezren39 mentioned this pull request Nov 22, 2026
Fleet unification slices (#8581 #8583 #8584) #12538
Open
@dezren39 dezren39 added the audit:partial PR partially implemented; gap filed label Nov 24, 2026
@dezren39 dezren39 mentioned this pull request Nov 24, 2026
AUDIT-7 Lane 4 — MERGED-PR-AUDIT: merged PRs since 2026-10-23 vs their spawning issues #13879
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

audit:partial PR partially implemented; gap filed

Projects

None yet

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.

1 participant

@dezren39
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.