Skip to content

Keep offline tokens out of backups - #82

Open
dcmcand wants to merge 1 commit into
slice/agent-tokens-17-uifrom
slice/agent-tokens-18-backups
Open

dcmcand wants to merge 1 commit into
slice/agent-tokens-17-uifrom
slice/agent-tokens-18-backups

Conversation

@dcmcand

@dcmcand dcmcand commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Slice 18: Backups and restores hold no offline token

No database backup Tapas writes, copies to the bucket, or keeps aside at restore holds an offline token, and a restore is never blocked by the clean-up.

Spec: nebari-dev/tapas/docs/superpowers/specs/2026-11-30-agent-token-broker-design.md
Plan: nebari-dev/tapas/docs/superpowers/plans/2026-12-01-agent-tokens-and-frames.md (Slice 18)
Contracts touched: The SQLite backup file that store.Store.Backup writes, The database copy in the backup bucket (what backup.DatabaseCopier uploads), store.RestoreSQLite and the <database>.before-restore file it keeps, The chart's Postgres backup (pg_dump in the javo-db-backup CronJob)
Depends on: #69

  • SQLite backups: both token tables emptied and vacuumed in the .partial before the rename; stale partials a crash left are removed; a second backup to a name being written is refused.
  • Restore: the staged copy is stripped before it goes live (refused if that fails); the replaced database is renamed aside first, then stripped; a failed strip there never blocks the restore.
  • Bucket copier: refuses a SQLite file holding token rows, reading the main file alone (immutable=1).
  • Chart pg_dump: --exclude-table-data for both tables (checked with pg_restore --list on the pinned image).
  • SQLite file URIs escaped (#, ?, % in a name opened the wrong file).

Reviewer notes:

  • TestScheduledBackupsRunAndPrune is timing-based and fails locally under full-package -race load (also before this PR); CI runs without -race.
  • The CLI reference page had about 50 lines of older drift; only the javo db restore line is regenerated here.

Validation

Step Command / action Expected Result
store go test -count=1 ./internal/store/... ./internal/backup/... ok, existing backup and copier tests unmodified ok; new tests only
helm go test -count=1 ./test/helm/... ok ok
cli ref site/scripts/cli-reference.sh && git diff --exit-code site/src/content/docs/reference/cli.md no drift after commit not met: older drift kept out of this PR (approved deviation)
local make test-local ok exit 0 (also make test-postgres)

No database copy Tapas writes, uploads or keeps aside at restore holds
a stored agent token:

- A SQLite backup empties both token tables in its .partial file and
  vacuums before the rename. Each backup first removes .partial files a
  crash left (they hold every token), and refuses a second backup to a
  name that is already being written.
- A restore strips the staged copy before it goes live, so a hand-made
  copy brings back no token, and refuses the restore if that fails. It
  renames the replaced database aside first and then strips it; a failed
  strip there never blocks the restore, and the error says to delete the
  file only when the restore finished.
- The bucket copier refuses a SQLite file holding token rows before any
  upload, reading the main file alone, the bytes it uploads.
- The chart's pg_dump excludes both tables' data.

SQLite file URIs are now escaped, so a backup to a name with #, ? or %
no longer opens a different file. contracts.md, patterns.md, the spec,
the restore help, the CLI reference line for it, and the plan's evidence,
checkpoint review and deviations are updated.

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