diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 7533646745..d50944a530 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -4796,3 +4796,21 @@ view shows its independently checked result in the same conversation. - **Boundary:** this is a source wiring repair. Installed Core and composition qualification, interrupted original-Task recovery, complete context/closure, actual models, costs, full R1/M3 and C1 cutover remain separate acceptance. + +### 2026-11-22 — Checkpoint replay returns the selected runtime's artifacts + +- **Gap:** replaying a committed checkpoint from a copied runtime validated the + relocated artifacts through the existing typed owner, but the public + `refresh-state` response still returned paths from the original runtime. +- **Delta:** the Python transport retains that validated replay result and uses + its JSON and Markdown paths in the idempotent response. Path selection, + artifact validation and refusal remain on the existing TypeScript checkpoint + owner; no new path authority or historical-record migration is introduced. +- **Source evidence:** ten real CLI cases cover File and SQLite, dry-run and + repeated replay, and missing or symlinked JSON/Markdown artifacts. They verify + the relocated bytes, unchanged original/copied history and checkpoint proofs, + preserved settlement identity, no appended replay and zero spend. The fixed + main baseline reproduced the stale public path before this repair. +- **Boundary:** this is a bounded V2/V4/R1 recovery repair. Full original-Goal + regression, installed composition, complete default closure and costs, real + model adoption, R1/M3 acceptance and C1 cutover remain separate gates. diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index 860206b561..71f657f544 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -3703,3 +3703,17 @@ workspace 批准和脚本模型工作。桌面视图在采用检查后显示原 - **边界:**本次是源码接线修复。Installed Core 与组合资格、被中断原 Task 的 恢复、完整 context/closure、真实模型、成本、完整 R1/M3 及 C1 cutover 仍是 独立验收。 + +### 2026-11-22 — Checkpoint 回放返回所选 runtime 的产物路径 + +- **缺口:**从复制的 runtime 回放已提交 checkpoint 时,既有 typed owner + 已验证迁移后的产物,但公开 `refresh-state` 响应仍返回原 runtime 的路径。 +- **改动:**Python 传输保留该已验证的回放结果,并在幂等响应中使用其 JSON + 和 Markdown 路径。路径选择、产物验证和拒绝仍由既有 TypeScript checkpoint + owner 负责;不新增路径权限,不迁移历史记录。 +- **源码证据:**十项真实 CLI 用例覆盖 File、SQLite、dry-run、重复回放, + 以及 JSON/Markdown 产物缺失或被符号链接替换。它们核对迁移后的字节、 + 原始与复制历史及 checkpoint 证明不变、结算 identity 保留、回放不追加记录 + 和零消费。修复前,固定 main 基线已复现公开响应路径陈旧。 +- **边界:**这是有界的 V2/V4/R1 恢复修复。原 Goal 完整回归、安装组合、 + 完整默认闭包与成本、真实模型采纳、R1/M3 验收和 C1 切换仍是独立门槛。 diff --git a/loopx/control_plane/goals/checkpoint_context_io.py b/loopx/control_plane/goals/checkpoint_context_io.py index 0ffc13bbaa..d63b51467e 100644 --- a/loopx/control_plane/goals/checkpoint_context_io.py +++ b/loopx/control_plane/goals/checkpoint_context_io.py @@ -236,11 +236,20 @@ def commit_checkpoint_run( return result -def inspect_checkpoint_replay(runtime_root: Path, goal_id: str, prior: dict[str, Any]) -> None: - if isinstance(prior.get("vision_checkpoint"), dict) and prior["vision_checkpoint"].get("read_context"): - _checkpoint_effect("goal.checkpoint_read_context.inspect_replay", { - "runtime_root": str(runtime_root.resolve()), "goal_id": goal_id, "prior": prior, - }) +def inspect_checkpoint_replay( + runtime_root: Path, goal_id: str, prior: dict[str, Any], +) -> dict[str, Any] | None: + checkpoint = prior.get("vision_checkpoint") + if not isinstance(checkpoint, dict) or not checkpoint.get("read_context"): + return None + result = _checkpoint_effect("goal.checkpoint_read_context.inspect_replay", { + "runtime_root": str(runtime_root.resolve()), "goal_id": goal_id, "prior": prior, + }) + if not isinstance(result, dict) or not isinstance(result.get("ok"), bool): + raise RuntimeError("invalid typed checkpoint replay result") + if not result["ok"]: + raise CheckpointReadContextRejected(result) + return result def render_checkpoint_context(payload: dict[str, Any]) -> str: diff --git a/loopx/state_refresh.py b/loopx/state_refresh.py index d63eac6af6..890e255286 100644 --- a/loopx/state_refresh.py +++ b/loopx/state_refresh.py @@ -941,13 +941,16 @@ def refresh_state_run( checkpoint_supplement = bool( refresh_recovery["decision"] == "supplement_checkpoint" ) + checkpoint_replay = None if refresh_recovery.get("decision") in {"replay", "repair_receipt"} and prior_writeback_run: - inspect_checkpoint_replay(runtime_root, safe_goal_id, prior_writeback_run) + checkpoint_replay = inspect_checkpoint_replay(runtime_root, safe_goal_id, prior_writeback_run) recovery_payload = refresh_recovery_payload( settlement_readback, registry_path=registry_path, runtime_root=runtime_root, goal_id=safe_goal_id, dry_run=dry_run, goal_ref=goal_ref, ) if recovery_payload is not None: + if checkpoint_replay is not None: + recovery_payload.update({key: checkpoint_replay[key] for key in ("json_path", "markdown_path")}) return recover_refresh_todo_projection( recovery_payload, registry_path=registry_path, runtime_root=runtime_root, goal_id=safe_goal_id, project=project, state_file=state_file, diff --git a/tests/control_plane/test_checkpoint_relocated_replay.py b/tests/control_plane/test_checkpoint_relocated_replay.py new file mode 100644 index 0000000000..907c3a5ba9 --- /dev/null +++ b/tests/control_plane/test_checkpoint_relocated_replay.py @@ -0,0 +1,118 @@ +"""Public CLI replay returns the verified artifacts from the selected runtime.""" +from __future__ import annotations + +import json +from pathlib import Path +import shutil + +import pytest + +from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime +from tests.managed_effect_runtime_fixture import stop_disposable_effect_runtimes +from tests.control_plane.test_checkpoint_read_context import _missing +from tests.control_plane.test_quota_settlement_cli import GOAL_ID, _run_cli, _spend_run_count + + +@pytest.fixture(autouse=True) +def _retire_owned_runtime(tmp_path: Path): + yield + stop_disposable_effect_runtimes(tmp_path) + + +def _historical_records(runtime: Path) -> dict[str, bytes]: + goal = runtime / "goals" / GOAL_ID + paths = [ + *sorted((goal / "runs").glob("*.json")), + *sorted((goal / "runs").glob("*.md")), + *sorted((goal / "runs").glob("*.jsonl")), + *sorted((goal / "checkpoint-contexts").glob("*.json")), + ] + events = goal / "rollout-event-log.jsonl" + if events.exists(): + paths.append(events) + return {str(path.relative_to(goal)): path.read_bytes() for path in paths} + + +def _relocated_checkpoint(tmp_path: Path, monkeypatch, provider: str): + isolate_sqlite_runtime(tmp_path, monkeypatch) + project, runtime, registry, binding, delivery, original = _missing(tmp_path, provider=provider) + rc, context = _run_cli(registry, runtime, "checkpoint-context", *binding, cwd=project) + assert rc == 0, context + replay_args = ( + *delivery, + "--vision-unchanged-reason", "The accepted scope and evidence remain applicable.", + "--checkpoint-read-context", context["read_context_id"], + ) + rc, committed = _run_cli(registry, runtime, *replay_args, cwd=project) + assert rc == 0 and committed["appended"] is True, committed + assert committed["vision_checkpoint"]["satisfied"] is True + assert committed["vision_checkpoint"]["read_context"]["ok"] is True + assert committed["settlement_identity"] == original["settlement_identity"] + relocated = tmp_path / "copied-runtime" + # Copy a completed disposable runtime without rewriting historical paths, + # provider lineage, receipts, checkpoint proofs or index rows. + shutil.copytree(runtime, relocated, symlinks=True) + return project, runtime, relocated, registry, replay_args, committed + + +@pytest.mark.parametrize("provider", ["file", "sqlite"]) +def test_public_checkpoint_replay_returns_relocated_artifacts_without_rewriting_history( + tmp_path: Path, monkeypatch, provider: str, +): + project, runtime, relocated, registry, replay_args, committed = _relocated_checkpoint( + tmp_path, monkeypatch, provider, + ) + original_records = _historical_records(runtime) + copied_records = _historical_records(relocated) + assert copied_records == original_records + for dry_run in (True, False, False): + rc, replay = _run_cli( + registry, relocated, *replay_args, *(("--dry-run",) if dry_run else ()), cwd=project, + ) + assert rc == 0 and replay["ok"] is True, replay + assert replay["dry_run"] is dry_run + assert replay["appended"] is False and replay["idempotent_replay"] is True + assert replay["settlement_identity"] == committed["settlement_identity"] + assert replay["vision_checkpoint"] == committed["vision_checkpoint"] + assert replay["generated_at"] == committed["generated_at"] + for field in ("json_path", "markdown_path"): + original_path = Path(committed[field]) + expected = (relocated / "goals" / GOAL_ID / "runs" / original_path.name).resolve() + assert Path(replay[field]) == expected + assert expected != original_path.resolve() + assert expected.read_bytes() == original_path.read_bytes() + # The selected index and artifact still record their historical basis. + assert _historical_records(relocated) == copied_records + assert _historical_records(runtime) == original_records + assert _spend_run_count(relocated) == _spend_run_count(runtime) == 0 + assert json.loads(Path(replay["json_path"]).read_text())["vision_checkpoint"] == committed["vision_checkpoint"] + + +@pytest.mark.parametrize("provider", ["file", "sqlite"]) +@pytest.mark.parametrize("field", ["json_path", "markdown_path"]) +@pytest.mark.parametrize("failure", ["missing", "symlink"]) +def test_public_checkpoint_replay_rejects_missing_or_linked_relocated_artifacts( + tmp_path: Path, monkeypatch, provider: str, field: str, failure: str, +): + project, runtime, relocated, registry, replay_args, committed = _relocated_checkpoint( + tmp_path, monkeypatch, provider, + ) + original_records = _historical_records(runtime) + original_path = Path(committed[field]) + candidate = relocated / "goals" / GOAL_ID / "runs" / original_path.name + candidate.unlink() + if failure == "symlink": + candidate.symlink_to(original_path) + copied_records = _historical_records(relocated) + rc, rejected = _run_cli(registry, relocated, *replay_args, cwd=project) + assert rc == 1 and rejected["ok"] is False, rejected + assert rejected["error_code"] == "checkpoint_commit_unknown", rejected + assert "checkpoint artifact path is invalid" in rejected["error"] + assert rejected["checkpoint_read_context"]["reread_required"] is False + assert _historical_records(relocated) == copied_records + assert _historical_records(runtime) == original_records + assert _spend_run_count(relocated) == _spend_run_count(runtime) == 0 + if failure == "symlink": + assert candidate.is_symlink() and candidate.resolve() == original_path.resolve() + else: + assert not candidate.exists()