diff --git a/phoenix/backend.py b/phoenix/backend.py index 6e4bffb..30bc80e 100644 --- a/phoenix/backend.py +++ b/phoenix/backend.py @@ -39,9 +39,9 @@ def publish_author_trajectory(stage, attempt, observed, rc): source = completed if source is None: return - temporary = stage / ".author.traj.tmp" + temporary = stage / f".{stage.name}.traj.tmp" shutil.copyfile(source, temporary) - temporary.replace(stage / "author.traj") + temporary.replace(stage / f"{stage.name}.traj") class DockerBackend: @@ -250,6 +250,11 @@ def generate(self, task, stage, *, allowance, final_stage, candidate=None, summa num_candidates=num_candidates, base_agent=self.base) with lock(stage / "stage.lock", blocking=False): bind(stage / "identity.json", identity) + if self.settings["method"] in REPAIR_METHODS: + previous_trace = stage / "author.traj" + stage_trace = stage / f"{stage.name}.traj" + if previous_trace.is_file() and not stage_trace.exists(): + previous_trace.rename(stage_trace) cached = verified_result(stage) if cached: return cached diff --git a/tests/test_repair.py b/tests/test_repair.py index 3698529..5170313 100644 --- a/tests/test_repair.py +++ b/tests/test_repair.py @@ -207,19 +207,21 @@ def test_single_trajectory_runs_without_location_or_summary(monkeypatch, task, s assert not (Path(settings["output"]) / "localization").exists() -def test_publish_author_trajectory_preserves_last_author_on_submission_replay(tmp_path): +@pytest.mark.parametrize("stage_name", ["location-1", "location-2", "final"]) +def test_publish_author_trajectory_preserves_last_author_on_submission_replay(tmp_path, stage_name): from phoenix.backend import publish_author_trajectory - stage = tmp_path / "location-1" + stage = tmp_path / stage_name attempt = stage / "attempts/001" official = attempt / "generate/author/author.traj" checkpoint = attempt / "checkpoint.json" write_json(checkpoint, {"history": [{"content": "checkpoint"}]}) publish_author_trajectory(stage, attempt, {"trajectory": checkpoint}, 1) - assert (stage / "author.traj").read_bytes() == checkpoint.read_bytes() + assert (stage / f"{stage_name}.traj").read_bytes() == checkpoint.read_bytes() write_json(official, {"history": [{"content": "completed"}]}) publish_author_trajectory(stage, attempt, {"trajectory": checkpoint}, 0) publish_author_trajectory(stage, stage / "attempts/002", {"trajectory": None}, 0) - assert (stage / "author.traj").read_bytes() == official.read_bytes() + assert (stage / f"{stage_name}.traj").read_bytes() == official.read_bytes() + assert not (stage / "author.traj").exists() def test_resume_uses_bound_stage_paths(task, candidate, settings):