Skip to content

feat(daemon): apply declared durable migrations at archive open - #5689

Merged
Sinity merged 2 commits into
masterfrom
claude/prep-migrations
Sep 27, 2026
Merged

Sinity merged 2 commits into
masterfrom
claude/prep-migrations

Conversation

@Sinity

@Sinity Sinity commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

polylogued run now applies pending declared durable migrations when it opens the archive, before it serves anything. A step that changes existing data runs only behind a backup the daemon takes itself and scratch-verifies.

Problem

  • Durable tiers (source, user, audit) evolve by numbered migrations with change-train sidecars. refactor(maintenance): delete archive repair and bootstrap commands #5646 deleted ops maintenance migrate-tier, their only application route, so execute_durable_change_train had no production caller.
  • No durable migration is declared today. The first one would therefore have shipped with no way to apply it except a maintenance command, which the operator has ruled out.

Solution

  • operations/durable_change_train.py gains pending_durable_migrations. It lists each durable tier standing below the runtime's declared version that has a complete declared route (every step from the current version to the target) and says whether any step requires a backup. A tier with no declared route is left alone, and schema preflight still reports its skew.
  • daemon/durable_migrations.py adds apply_declared_durable_migrations. For each pending tier it runs execute_durable_change_train under the daemon's write lease, with the daemon's exclusive archive ownership. The daemon keeps that ownership afterwards, so the train's release is a no-op.
  • For a step that requires a backup, pre_migration_backup first runs backup_archive(verify=True) into .maintenance-state/pre-migration-backups/:
    • It uses the user_overlays profile for user and audit, and rebuildable_cache_exclude for source, which carries its blobs.
    • The train binds the backup's authenticated receipt to the exact pre-apply bytes.
    • A failed backup refuses startup.
  • backup_archive accepts archive_owner: the caller's existing exclusive ownership. The backup copies under that ownership instead of acquiring its own, which the daemon's own lock would refuse at open.
  • daemon/cli.py calls the route right after durable-change-train reconciliation, inside the same ownership scope, and emits daemon.durable_migration.applied for each applied tier.
  • The durable-schema section of docs/maintenance.md describes the route.

Verification

  • tests/unit/daemon/test_durable_migrations.py ships synthetic numbered migration packages:
    • An archive already at the runtime version is left alone and gets no backup directory.
    • An additive source step applies without a backup, and a second open is a no-op.
    • A data-changing user step applies only after a verified backup; the manifest and verification receipt are present.
  • devtools test over test_durable_migrations.py, test_daemon_cli.py and test_backup.py: 185 passed, 3 failed.
    • test_run_daemon_services_parks_operation_recovery_on_audit_schema_mismatch failed because the first version tried to migrate a tier with no declared route. That is fixed, and it passes on rerun with the migration tests.
    • test_run_daemon_services_waits_for_fts_startup_before_watcher (2 parametrizations) fails the same way on current master: its fake converger lacks the derivation_barrier argument fix(daemon): repair backup scope, restart resume and derivation barrier #5664 added.
  • devtools gate mypy: Success.
  • devtools gate schema-closure: ok, no change (567).

Residuals

  • The source-tier backup copies referenced blobs, so a data-changing source migration pays that copy at open.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

Applying a declared durable migration had no production route once
the maintenance command was deleted. polylogued run now applies every
pending durable change train when it opens the archive, under the
exclusive ownership it already holds and before it serves. A step that
changes existing data runs only behind a backup the daemon takes and
scratch-verifies under that ownership.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-27T22:58:19.811177Z 98d229f New commits
ℹ️ 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.

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

Copy link
Copy Markdown

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: 9618bcc7da

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

Comment thread polylogue/daemon/durable_migrations.py Resolved
Comment thread polylogue/daemon/durable_migrations.py Resolved
…orage

One open now advances each durable tier step by step to the declared
version, taking a backup before each data-changing step, and refuses to
loop if a train does not advance. The daemon reaches archive ownership
through operations rather than importing storage directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
@Sinity
Sinity enabled auto-merge (squash) September 27, 2026 23:22
@Sinity
Sinity merged commit dc6d8f1 into master Sep 27, 2026
3 checks passed
@Sinity
Sinity deleted the claude/prep-migrations branch September 27, 2026 23:22
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