Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions phoenix/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions tests/test_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading