diff --git a/src/k1link/device_plugins/xgrids_k1/physical_command_ledger.py b/src/k1link/device_plugins/xgrids_k1/physical_command_ledger.py index b3187ae..e8554ac 100644 --- a/src/k1link/device_plugins/xgrids_k1/physical_command_ledger.py +++ b/src/k1link/device_plugins/xgrids_k1/physical_command_ledger.py @@ -3820,13 +3820,21 @@ def _is_reopened_classified_stop_standby_settlement( ) -> bool: """Accept one fresh READY that settles a reopened READY-classified STOP.""" - classification = _prepared_stop_classification(record) + operation_id = reconciliation.original_attempt.operation_id + classification = next( + ( + item + for item in record.reconciliations + if item.kind == "prepared-stop-classification" + and item.original_attempt.operation_id == operation_id + ), + None, + ) if not ( classification is not None and classification.resolution == "physical-standby-observed" and reconciliation.kind == "resolved-active-cessation" and reconciliation.resolution == "physical-standby-observed" - and reconciliation.original_attempt.operation_id == record.operation_id and reconciliation.observation.session_state == "ready" and not reconciliation.observation.project_bound and not reconciliation.observation.init_ready @@ -3837,7 +3845,7 @@ def _is_reopened_classified_stop_standby_settlement( for reopening in record.operator_reconciliation_reopens for retirement in record.operator_retirements if reopening.retirement_id == retirement.retirement_id - and retirement.original_attempt.operation_id == record.operation_id + and retirement.original_attempt.operation_id == operation_id and retirement.original_attempt.resolution == "not-dispatched" ] if settlement_index >= len(matching_reopens): diff --git a/tests/test_xgrids_physical_command_ledger.py b/tests/test_xgrids_physical_command_ledger.py index 0509fb3..4aec5b6 100644 --- a/tests/test_xgrids_physical_command_ledger.py +++ b/tests/test_xgrids_physical_command_ledger.py @@ -2142,6 +2142,30 @@ def test_ready_prepared_stop_reset_reopen_accepts_fresh_ready( settled ) + successor = ledger.prepare( + operation_id=NEXT_START_OPERATION, + parent_operation_id=STOP_OPERATION, + acquisition_id="acquisition-after-reset-fresh-ready", + action="start", + identity=IDENTITY, + connection=fresh_connection, + compatibility_profile_id="xgrids-k1-v0.6.0", + payload_sha256="8" * 64, + baseline_status=_status( + "ready", + connection=fresh_connection, + observed_at="2026-08-14T11:11:01.000Z", + ), + ) + + assert successor.revision == settled.revision + 1 + assert successor.action == "start" + assert successor.stage == "prepared" + assert successor.parent_operation_id == STOP_OPERATION + assert successor.reconciliations[-1].reconciliation_id == ( + "prepared-stop-ready-reset-fresh-ready" + ) + def test_scenario_reset_retires_effective_active_prepared_stop_classification( tmp_path: Path,