fix(k1): restore low-latency live recovery path

This commit is contained in:
DCCONSTRUCTIONS
2026-08-22 16:17:27 +03:00
parent 85035fa07b
commit 1001a31638
12 changed files with 1252 additions and 124 deletions
@@ -1047,6 +1047,33 @@ def service_with_fake_runtime(
return service, runtime
def test_passive_state_reuses_one_final_physical_snapshot(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
service, _runtime = service_with_fake_runtime(tmp_path)
coordinator = service._physical_command_coordinator # noqa: SLF001
original_snapshot = coordinator.snapshot
snapshot_calls = 0
def counted_snapshot() -> dict[str, object]:
nonlocal snapshot_calls
snapshot_calls += 1
return original_snapshot()
monkeypatch.setattr(coordinator, "snapshot", counted_snapshot)
state = service.state()
# Two earlier reads are deliberate pre/post settlement proofs. Presentation
# policy and the nested control-session projection must share the one final
# verified durable snapshot instead of recursively reloading the ledger.
assert snapshot_calls == 3
assert state["application_control_session"]["physical_command"] == state[
"physical_command"
]
def test_service_owns_one_wifi_association_probe_across_monitor_recreation(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
@@ -10283,9 +10310,11 @@ def test_classified_scanning_cancels_stop_eof_and_preserves_or_rearms_camera_epo
target: str,
session_dir: Path,
*,
pre_prepare_fence: Callable[[Callable[[], bool]], bool],
commit_fence: Callable[[Callable[[], bool]], bool],
committed_before_start: Callable[[dict[str, object]], None] | None = None,
) -> dict[str, object]:
assert pre_prepare_fence(lambda: True) is True
select_camera(source_id, target)
start_recording(session_dir)
assert committed_before_start is not None
@@ -13763,9 +13792,11 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
target: str,
session_dir: Path,
*,
pre_prepare_fence: Callable[[Callable[[], bool]], bool],
commit_fence: Callable[[Callable[[], bool]], bool],
committed_before_start: Callable[[dict[str, object]], None] | None = None,
) -> dict[str, object]:
assert pre_prepare_fence(lambda: True) is True
events.append(("select", (source_id, target)))
camera_state["active_source_id"] = source_id
events.append(("record", session_dir))
@@ -13849,6 +13880,27 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
"snapshot",
snapshot_physical,
)
full_control_snapshot_calls = 0
control_only_snapshot_calls = 0
real_control_snapshot = control.snapshot
def snapshot_control() -> dict[str, object]:
nonlocal full_control_snapshot_calls
full_control_snapshot_calls += 1
return real_control_snapshot()
def snapshot_control_only() -> dict[str, object]:
nonlocal control_only_snapshot_calls
control_only_snapshot_calls += 1
return real_control_snapshot()
monkeypatch.setattr(control, "snapshot", snapshot_control)
monkeypatch.setattr(
control,
"snapshot_control_only",
snapshot_control_only,
raising=False,
)
runtime.pcl_frames = 1
frame = DecodedPointCloudView(
context=ConsumerFrameContext(
@@ -13863,6 +13915,8 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
positions_xyz=((0.0, 0.0, 0.0),),
)
full_snapshots_before_pcl = full_control_snapshot_calls
control_only_snapshots_before_pcl = control_only_snapshot_calls
service._observe_published_runtime_envelope( # noqa: SLF001
frame,
runtime.producer_generation,
@@ -13871,6 +13925,8 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
# Public manual controls stay closed until that worker proves an exact
# recording epoch, preventing a left/right selection race.
assert activation_entered.wait(timeout=2.0)
assert full_control_snapshot_calls == full_snapshots_before_pcl
assert control_only_snapshot_calls == control_only_snapshots_before_pcl + 1
activating_state = service.state()
activating_camera_streams = [
stream
@@ -13890,6 +13946,8 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
)
)
assert events == []
full_snapshots_before_camera_worker = full_control_snapshot_calls
control_only_snapshots_before_camera_worker = control_only_snapshot_calls
release_activation.set()
deadline = time.monotonic() + 2.0
while len(events) < 2 and time.monotonic() < deadline:
@@ -13899,6 +13957,8 @@ def test_confirmed_scanning_waits_for_first_authoritative_pcl_before_camera(
("select", ("sensor.camera.right", "192.168.1.20")),
("record", out_dir),
]
assert full_control_snapshot_calls == full_snapshots_before_camera_worker
assert control_only_snapshot_calls == control_only_snapshots_before_camera_worker + 2
assert camera_state["active_source_id"] == "sensor.camera.right"
assert camera_state["recording"] == {
"active": True,
@@ -14068,9 +14128,11 @@ def test_failed_post_pcl_camera_activation_retries_on_later_authoritative_frame(
target: str,
session_dir: Path,
*,
pre_prepare_fence: Callable[[Callable[[], bool]], bool],
commit_fence: Callable[[Callable[[], bool]], bool],
committed_before_start: Callable[[dict[str, object]], None] | None = None,
) -> dict[str, object]:
assert pre_prepare_fence(lambda: True) is True
del commit_fence, committed_before_start
select_calls.append((source_id, target))
recording_calls.append(session_dir)
@@ -14827,10 +14889,12 @@ def test_stop_priority_overtakes_blocked_initial_camera_popen(
_target: str,
_session_dir: Path,
*,
pre_prepare_fence: Callable[[Callable[[], bool]], bool],
commit_fence: Callable[[Callable[[], bool]], bool],
committed_before_start: Callable[[dict[str, object]], None] | None = None,
) -> dict[str, object]:
del committed_before_start
assert pre_prepare_fence(lambda: True) is True
candidate_blocked.set()
assert release_candidate.wait(3.0)
if not commit_fence(lambda: candidate_committed.append(True) or True):