From 9eb2bacaedc03b377a4d855ea39d86b9a7a60922 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:45:53 +0800 Subject: [PATCH] Verify Turn recovery against live work and its original receipt Exercise matching and changed live Todo recovery through the real CLI. Read the Steward terminal delivery at the accepted recovery presentation key. Preserve the core recovery expectations also covered by the broader C1 integration. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- .../test_turn_host_decision_capture.py | 42 +++++++++++++------ tests/test_steward_interrupted_answer.py | 2 +- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/tests/control_plane/test_turn_host_decision_capture.py b/tests/control_plane/test_turn_host_decision_capture.py index 648f63cdcd..2cacde11cd 100644 --- a/tests/control_plane/test_turn_host_decision_capture.py +++ b/tests/control_plane/test_turn_host_decision_capture.py @@ -594,10 +594,14 @@ def no_new_host(_request): @pytest.mark.parametrize("provider", ["file", "sqlite"]) -@pytest.mark.parametrize("first_attempt_fails", [False, True]) +@pytest.mark.parametrize(("first_attempt_fails", "restore_live_work"), [ + pytest.param(False, False, id="committed"), + pytest.param(True, True, id="restore-live-work"), + pytest.param(True, False, id="changed-live-work"), +]) @pytest.mark.parametrize("legacy_pretty", [False, True]) def test_real_host_reads_original_capture_after_source_change( - tmp_path, monkeypatch, provider, first_attempt_fails, legacy_pretty, + tmp_path, monkeypatch, provider, first_attempt_fails, restore_live_work, legacy_pretty, ): from loopx.cli_commands import turn_decision @@ -701,8 +705,9 @@ def legacy_launch_selection(*_args, **_kwargs): prefix = ["--registry", str(registry), "--runtime-root", str(runtime), "--format", "json"] code, current = f._run_cli([*prefix, "todo", "list", "--goal-id", f.GOAL_ID, "--todo-id", f.TODO_ID]) assert code == 0 + original_text = current["todo"]["text"] code, update = f._run_cli([*prefix, "todo", "update", "--goal-id", f.GOAL_ID, - "--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", current["todo"]["text"] + " SOURCE_B", + "--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", original_text + " SOURCE_B", "--update-operation-id", "source-b", "--update-expected-provider-revision", current["authority_read"]["provider_revision"], "--execute"]) assert code == 0, update @@ -773,17 +778,30 @@ def unexpected_effect(*_args, **_kwargs): assert (workspace / "received.txt").read_bytes() == received_before assert f._quota_spend_count(runtime) == 0 path.write_bytes(original) - code, recovered = f._run_cli([*replay, "--resume-turn-key", request["turn_key"], - "--retry-failed-turn", "--execute"]) - assert code == 0 and recovered["status"] == "committed", json.dumps(recovered) - retried = json.loads((workspace / "received.txt").read_text().split("Turn request:\n", 1)[1]) - assert retried["task_context"] == request["task_context"] - assert retried["detail_ref"] == detail + # The snapshot remains readable when live work changes. Launching it + # again also requires the current Todo to match the original work. + if restore_live_work: + code, restored = f._run_cli([*prefix, "todo", "update", "--goal-id", f.GOAL_ID, + "--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", original_text, + "--update-operation-id", "restore-source-a", "--update-expected-provider-revision", + current["authority_read"]["provider_revision"], "--execute"]) + assert code == 0 and restored["changed"], restored + code, recovered = f._run_cli(retry) + if restore_live_work: + assert code == 0 and recovered["status"] == "committed", json.dumps(recovered) + retried = json.loads((workspace / "received.txt").read_text().split("Turn request:\n", 1)[1]) + assert retried["task_context"] == request["task_context"] + assert retried["detail_ref"] == detail + else: + assert code == 1 and recovered["error_code"] == "current_turn_work_changed", recovered + assert not any(recovered["effects"].values()) + assert (workspace / "received.txt").read_bytes() == received_before assert path.read_bytes() == original code, repeated = f._run_cli([*replay, "--resume-turn-key", request["turn_key"], "--execute"]) - assert code == 0, repeated - assert not any(repeated["effects"].values()) - assert f._quota_spend_count(runtime) == 1 + blocked_retry = first_attempt_fails and not restore_live_work + assert code == (1 if blocked_retry else 0), repeated + assert repeated["replayed"] and not any(repeated["effects"].values()) + assert f._quota_spend_count(runtime) == (0 if blocked_retry else 1) assert path.read_bytes() == original # Admission can run between source validation and publication. It cannot # replace or silently recreate an original capture changed in that window. diff --git a/tests/test_steward_interrupted_answer.py b/tests/test_steward_interrupted_answer.py index d11f737ab0..cbf1764df0 100644 --- a/tests/test_steward_interrupted_answer.py +++ b/tests/test_steward_interrupted_answer.py @@ -856,7 +856,7 @@ def crash(**kwargs): assert done["status"] == ("failed" if fault in {"native-changed", "review-action", "checkpoint-empty"} else "completed"), done restarted.reconcile_request(path) delivered = json.loads(path.read_text()) - terminal = delivered["deliveries"]["terminal.recovery.22.review.1"] + terminal = delivered["deliveries"][f"terminal.recovery.{recovery['presentation_key']}"] assert terminal["verified"] actual = provider.messages[terminal["attempt"]["message_ref"]] assert actual["chat_id"] == event["chat_id"] and actual["sender"]["id"] == provider.profile_apps["steward-app"]