fix(k1): settle same-process standby checkpoint

This commit is contained in:
DCCONSTRUCTIONS
2026-08-14 21:32:26 +03:00
parent 986ea69610
commit 321cde70e8
4 changed files with 134 additions and 15 deletions
@@ -455,11 +455,17 @@ def test_repeated_reset_reopen_fresh_ready_ceases_old_active_checkpoint(
assert service._active_acquisition_checkpoint_trust == "trusted" # noqa: SLF001
def test_restart_ready_after_dispatched_stop_ceases_active_checkpoint(
@pytest.mark.parametrize(
"same_process",
(False, True),
ids=("process-restart", "same-process-new-control-epoch"),
)
def test_ready_after_dispatched_stop_ceases_active_checkpoint(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
same_process: bool,
) -> None:
"""Fresh READY settles a dispatched STOP whose outcome crossed restart."""
"""Fresh READY settles a dispatched STOP across either recovery boundary."""
service = _service(tmp_path, monkeypatch)
original = _connection(
@@ -509,9 +515,10 @@ def test_restart_ready_after_dispatched_stop_ceases_active_checkpoint(
observed_at_utc="2026-08-13T12:01:01.000Z",
),
)
service._snapshot_runtime_id = ( # noqa: SLF001
"snapshot-runtime-checkpoint-dispatched-stop-successor"
)
if not same_process:
service._snapshot_runtime_id = ( # noqa: SLF001
"snapshot-runtime-checkpoint-dispatched-stop-successor"
)
restarted = _connection(
control_session_id="checkpoint-dispatched-stop-restarted-control",
host_path_epoch=2,
@@ -561,6 +568,7 @@ def test_restart_ready_after_dispatched_stop_ceases_active_checkpoint(
lambda: None,
)
settle_checkpoint = service._settle_restart_checkpoint_after_verified_standby # noqa: SLF001
monkeypatch.setattr(
service,
"_settle_restart_checkpoint_after_verified_standby",
@@ -583,10 +591,23 @@ def test_restart_ready_after_dispatched_stop_ceases_active_checkpoint(
assert checkpoint is not None
assert checkpoint.state == "active"
# Simulate the exact live process boundary: the physical ledger fsync is
# durable, while checkpoint cessation did not commit in the prior process.
restarted_service = _service(tmp_path, monkeypatch)
assert restarted_service._active_acquisition_checkpoint_reason is None # noqa: SLF001
# The physical ledger fsync is durable while checkpoint cessation did not
# commit. Recovery may happen after a process restart or, as observed in
# production, later in the same process under a fresh control/path epoch.
if same_process:
monkeypatch.setattr(
service,
"_settle_restart_checkpoint_after_verified_standby",
settle_checkpoint,
)
token = service._validate_active_acquisition_checkpoint_lineage() # noqa: SLF001
assert token is not None
assert service._settle_durable_prepared_stop_standby_checkpoint( # noqa: SLF001
token
), service._active_acquisition_checkpoint_reason # noqa: SLF001
else:
restarted_service = _service(tmp_path, monkeypatch)
assert restarted_service._active_acquisition_checkpoint_reason is None # noqa: SLF001
checkpoint = ActiveAcquisitionRecoveryCheckpointStore(tmp_path).snapshot().checkpoint
assert checkpoint is not None
assert checkpoint.state == "ceased"
@@ -1312,6 +1312,7 @@ def test_cease_active_reconciled_standby_rejects_inexact_restart_proofs(
replace(
status.binding,
runtime_instance_id=binding.runtime_instance_id,
host_path_epoch=binding.host_path_epoch,
),
replace(
status.binding,