Archive verified rollbacks of interrupted activation journals
ABSDEV Framework CI / framework-ci (push) Successful in 20s

This commit is contained in:
Mark Gregory
2026-11-30 12:37:34 +00:00
parent 054c546c8f
commit 611f8d0f3d
5 changed files with 55 additions and 11 deletions
+4 -5
View File
@@ -11,6 +11,9 @@ from core.compatibility import (
from core.locking import DeploymentLock
ROLLBACK_ELIGIBLE_PHASES = frozenset({"ACTIVATING", "ACTIVATED", "FAILED"})
class RecoveryError(RuntimeError):
"""Recovery safety could not be established."""
@@ -140,11 +143,7 @@ class RecoveryPlanner:
)
require(
transaction["phase"] in (
"ACTIVATING",
"ACTIVATED",
"FAILED",
),
transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES,
"Transaction phase does not permit rollback review",
)
+6 -4
View File
@@ -18,6 +18,7 @@ from core.compatibility import (
validate_provenance,
)
from core.locking import DeploymentLock
from core.recovery import ROLLBACK_ELIGIBLE_PHASES
class RollbackArchiveReader:
@@ -65,10 +66,10 @@ class RollbackArchiveReader:
)
require(
transaction["phase"] == "FAILED"
transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES
and intent["status"] == "ROLLBACK_INTENT"
and result["status"] == "ROLLED_BACK",
"Completed failed-transaction rollback required",
"Completed rollback of a failed or interrupted activation required",
)
phases = {
@@ -195,9 +196,9 @@ class RollbackArchive(RollbackArchiveReader):
require(
transaction is not None
and transaction["phase"] == "FAILED"
and transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES
and transaction["site"] == self.planner.site,
"Failed deployment transaction required",
"Failed or interrupted deployment transaction required",
)
identifier = transaction["transaction_id"]
@@ -339,6 +340,7 @@ class RollbackArchive(RollbackArchiveReader):
) from None
def _execute(self, confirmation, fingerprint):
self.journal.require_writes_allowed()
plan = self._plan()
require(
+3 -1
View File
@@ -16,6 +16,8 @@ supply `--site` with the configured site identifier. Each archive must pass
the framework's transaction and backup evidence validation. When the live
journal is absent, exactly one archived verified transaction must match the
active release. Rollback archives also require their original rollback and
backup evidence and the failed release's matching quarantine marker. All
backup evidence and the failed release's matching quarantine marker. A
verified rollback can retire a journal left in an interrupted activation
phase while preserving its original history. All
releases referenced by validated archives are protected. Unknown, ambiguous
or corrupt archive entries deny planning pending review.
+3 -1
View File
@@ -120,7 +120,7 @@ class RecoveryTests(unittest.TestCase):
runtime_check=self.runtime_check,
)
def prepare(self, failed=True):
def prepare(self, failed=True, *, interrupted=False):
transaction = self.journal.create(
"example-absdev-net",
@@ -150,6 +150,8 @@ class RecoveryTests(unittest.TestCase):
)
self.releases.activate("2")
if interrupted:
return transaction
transaction = self.journal.transition(
transaction["transaction_id"],
+39
View File
@@ -4,6 +4,7 @@ import unittest
from unittest.mock import Mock, patch
import test_rollback
import test_recovery
from core.rollback_archive import RollbackArchive, ArchiveError
from core.compatibility import canonical_hash
@@ -250,3 +251,41 @@ class RollbackArchiveTests(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
class InterruptedRollbackArchiveTests(unittest.TestCase):
def test_confirmed_rollback_can_archive_interrupted_activation(self):
prepare = test_recovery.RecoveryTests.prepare
def interrupted(recovery):
return prepare(recovery, interrupted=True)
fixture = RollbackArchiveTests()
self.addCleanup(fixture.doCleanups)
with patch.object(test_recovery.RecoveryTests, "prepare", interrupted):
fixture.setUp()
self.assertEqual(fixture.transaction["phase"], "ACTIVATING")
result = fixture.execute()
self.assertEqual(result["transaction"]["phase"], "ACTIVATING")
self.assertIsNone(fixture.journal.load())
self.assertTrue(fixture.marker.is_file())
self.assertEqual(fixture.archive.load(fixture.identifier), result)
def test_unfinished_migration_blocks_rollback_journal_retirement(self):
from core.approval_store import ApprovalStore
fixture = RollbackArchiveTests()
self.addCleanup(fixture.doCleanups)
fixture.setUp()
approvals = fixture.recovery.root / "approvals"
approvals.mkdir(mode=0o700, exist_ok=True)
fixture.journal.bind_migration_guard(ApprovalStore(approvals))
blocker = approvals / ("b" * 32 + ".migration-intent.json")
blocker.write_text("{}")
before = fixture.journal.path.read_bytes()
with self.assertRaises(ArchiveError):
fixture.execute()
self.assertEqual(fixture.journal.path.read_bytes(), before)
self.assertFalse(fixture.marker.exists())
self.assertFalse(fixture.archive.path(fixture.identifier).exists())