Skip to content

Official Codebase of 3DCodeVerse

Python

cleanup: drop the duplicated git lock, the AgentJob.extra mirror and dead re-exports

gaoypeng20ad36784655
diff --git a/harness/codeverse/cli/main.py b/harness/codeverse/cli/main.py
index eba901c9..f494b80f 100644
--- a/harness/codeverse/cli/main.py
+++ b/harness/codeverse/cli/main.py
@@ -498,17 +498,7 @@ def _resume_in_lock(ws, runs_dir, *, force: bool, max_usd, max_minutes, rounds,
# --------------------------------------------------------------------------- status / render / judge
# moved to codeverse/cli/inspect_cmd.py; imported here so existing importers keep working
-from codeverse.cli.inspect_cmd import ( # noqa: E402, F401
- _best_round_of_record,
- _event_time,
- _latest_round,
- _print_candidates,
- _render_graphics,
- _render_round_or_refuse,
- judge,
- render,
- status,
-)
+from codeverse.cli.inspect_cmd import judge, render, status # noqa: E402
app.command()(status)
app.command()(render)
diff --git a/harness/codeverse/tracks/generation.py b/harness/codeverse/tracks/generation.py
index e5c3ce49..08b5294c 100644
--- a/harness/codeverse/tracks/generation.py
+++ b/harness/codeverse/tracks/generation.py
@@ -36,9 +36,6 @@ from __future__ import annotations
import json
import logging
import os
-import subprocess
-import threading
-import time
from collections.abc import Callable
from pathlib import Path
from typing import Any
@@ -176,37 +173,6 @@ class GenerationResult(BaseModel):
)
-# ----------------------------------------------------------------------------- git helpers
-_GIT_LOCKS: dict[str, threading.Lock] = {}
-_GIT_LOCKS_GUARD = threading.Lock()
-
-
-def workspace_lock(ws: Workspace) -> threading.Lock:
- """One lock per workspace root: git index operations from parallel tasks must serialise."""
- key = str(ws.root)
- with _GIT_LOCKS_GUARD:
- lock = _GIT_LOCKS.get(key)
- if lock is None:
- lock = _GIT_LOCKS[key] = threading.Lock()
- return lock
-
-
-def changed_files_safe(
- ws: Workspace, since: str | None = None, *, retries: int = 6
-) -> list[FileChange]:
- """``ws.changed_files`` serialised per workspace and retried on transient git index locks."""
- with workspace_lock(ws):
- for attempt in range(retries):
- try:
- return ws.changed_files(since)
- except subprocess.CalledProcessError as e:
- if attempt == retries - 1:
- raise
- log.warning("git diff failed (attempt %d): %s", attempt + 1, (e.stderr or "")[:200])
- time.sleep(0.2 * (attempt + 1))
- return []
-
-
# ----------------------------------------------------------------------------- strategies
def is_single_shot(agent_id: str) -> bool:
return agent_id.startswith(SINGLE_SHOT_PREFIX)
@@ -416,14 +382,6 @@ def run_agent_task(
# language/track → spatial tool filtering, files_hint → per-session attribution of
# files_changed when tasks run concurrently in ONE workspace (see agents/cli_common).
language, track = _spec_lang_track(ws)
- # extra mirrors the typed fields until every agent backend reads job.round/… directly
- extra: dict[str, Any] = {
- "round": task.round,
- "kind": task.kind,
- "files_hint": list(task.files_hint),
- "language": language,
- "track": track,
- }
job = AgentJob(
workspace=str(ws.root),
prompt=task.prompt,
@@ -438,7 +396,6 @@ def run_agent_task(
language=language,
track=track,
files_hint=list(task.files_hint),
- extra=extra,
edit_only=task.edit_only,
always_writable=_always_writable(language, task),
read_only=_read_only(language),
@@ -656,7 +613,7 @@ def _attributed_fallback(ws: Workspace, task: GenerationTask, before: str) -> li
A whole-worktree diff claims sibling tasks' files under fan_out (a task that
wrote nothing looked ok because its neighbours wrote files); attribute the diff
to this task instead: inside its write roots, never harness-owned paths."""
- raw = changed_files_safe(ws, before)
+ raw = ws.changed_files(before) # Workspace serialises + retries the git index itself
try:
from codeverse.agents.cli_common import attribute_changes
except ImportError: # pragma: no cover — agents package always ships with tracks
diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.py
index 3cebad94..09cd2713 100644
--- a/harness/tests/flywheel_cli/test_cli.py
+++ b/harness/tests/flywheel_cli/test_cli.py
@@ -542,7 +542,7 @@ def test_render_refuses_when_the_tree_is_not_the_best_round(tmp_path: Path):
The harness correctly kept r3, but a plain `3dcv render` re-rendered the blank r4 and
was very nearly published."""
from codeverse.cli._common import CliError
- from codeverse.cli.main import _render_round_or_refuse
+ from codeverse.cli.inspect_cmd import _render_round_or_refuse
ws = _round_guard_ws(tmp_path, best=3, tree=4)
with pytest.raises(CliError) as ei:
@@ -558,7 +558,7 @@ def test_render_round_flag_cannot_mislabel_another_rounds_code(tmp_path: Path):
"""--round only chose the OUTPUT FOLDER, so `render X --round 3` wrote r03-labelled
images of round 4's code. Refuse rather than write a picture whose label is a lie."""
from codeverse.cli._common import CliError
- from codeverse.cli.main import _render_round_or_refuse
+ from codeverse.cli.inspect_cmd import _render_round_or_refuse
ws = _round_guard_ws(tmp_path, best=3, tree=4)
with pytest.raises(CliError):
@@ -568,7 +568,7 @@ def test_render_round_flag_cannot_mislabel_another_rounds_code(tmp_path: Path):
def test_render_is_unaffected_when_the_best_round_is_the_last(tmp_path: Path):
"""The common case must not become noisier: no record, or best == tree, just renders."""
- from codeverse.cli.main import _render_round_or_refuse
+ from codeverse.cli.inspect_cmd import _render_round_or_refuse
assert _render_round_or_refuse(_round_guard_ws(tmp_path / "a", best=2, tree=2), None) == 2
ws = _round_guard_ws(tmp_path / "b", best=1, tree=1)
diff --git a/harness/tests/graphics/test_track.py b/harness/tests/graphics/test_track.py
index c1bc4816..ffdaee6c 100644
--- a/harness/tests/graphics/test_track.py
+++ b/harness/tests/graphics/test_track.py
@@ -94,7 +94,7 @@ class FakeGlRuntime:
def _writer(job, ws):
body = "void mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec2 uv = fragCoord / u_resolution.xy;\n"
- body += f" // {job.label} r{job.extra.get('round', 0)}\n fragColor = vec4(uv, 0.5 + 0.5 * sin(u_time), 1.0);\n}}\n"
+ body += f" // {job.label} r{job.round}\n fragColor = vec4(uv, 0.5 + 0.5 * sin(u_time), 1.0);\n}}\n"
return {"src/shader.frag": body}
diff --git a/harness/tests/orchestrator_tracks/fakes.py b/harness/tests/orchestrator_tracks/fakes.py
index a4faf216..ad1470bd 100644
--- a/harness/tests/orchestrator_tracks/fakes.py
+++ b/harness/tests/orchestrator_tracks/fakes.py
@@ -31,7 +31,6 @@ from codeverse.contracts.plan import Plan
from codeverse.contracts.run import RunRecord
from codeverse.conventions import to_snake
from codeverse.tracks.common import Services, ServiceUnavailable
-from codeverse.tracks.generation import changed_files_safe, workspace_lock
from codeverse.workspace import Workspace
FAIL_MARK = "RAISE_BUILD_ERROR"
@@ -154,7 +153,7 @@ class FakeAgent:
def run(self, job: AgentJob) -> AgentResult:
self.jobs.append(job)
ws = Workspace(job.workspace)
- with workspace_lock(ws):
+ with ws._lock: # noqa: SLF001 — the fake mimics a real agent's serialised writes
before = ws.head()
files = self.writer(job, ws)
for rel, content in (files or {}).items():
@@ -163,7 +162,7 @@ class FakeAgent:
p.write_text(content)
traj = ws.trajectory_dir(job.label or "job", 0)
(traj / "transcript.jsonl").write_text(json.dumps({"prompt": job.prompt[:200]}) + "\n")
- return AgentResult(ok=bool(files), exit_reason="completed" if files else "no_changes", files_changed=changed_files_safe(ws, before),
+ return AgentResult(ok=bool(files), exit_reason="completed" if files else "no_changes", files_changed=ws.changed_files(before),
transcript_path=str(traj / "transcript.jsonl"), usage=Usage(backend="fake", cost_usd=self.cost, input_tokens=100))
diff --git a/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py b/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py
index 3e3ecbbd..feb3da23 100644
--- a/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py
+++ b/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py
@@ -206,7 +206,7 @@ def test_candidate_count_persists_for_resume_and_settings_default(tmp_path, chai
def test_refine_round_within_margin_needs_pairwise_win(tmp_path, chair_plan, settings):
spec = make_spec(language=Language.BLENDER, max_rounds=2)
ws = Workspace(tmp_path / "runs" / "tie")
- agent = FakeAgent(lambda job, ws: {"src/model.py": f"import bpy # {job.label} {job.extra.get('round')}\n"})
+ agent = FakeAgent(lambda job, ws: {"src/model.py": f"import bpy # {job.label} {job.round}\n"})
pw = FakePairwise(verdicts=[("a", 0.8), ("b", 0.9)])
# r01 scores +0.01 (noise) → pairwise says incumbent wins → best stays r00; r02 +0.02 → pairwise b wins → best r02
judge = FakeJudge(scores=(0.60, 0.61, 0.62))
diff --git a/harness/tests/orchestrator_tracks/test_fix_batch2.py b/harness/tests/orchestrator_tracks/test_fix_batch2.py
index 9a03e0ce..766cef9a 100644
--- a/harness/tests/orchestrator_tracks/test_fix_batch2.py
+++ b/harness/tests/orchestrator_tracks/test_fix_batch2.py
@@ -35,7 +35,7 @@ def _planner(plan_dict):
def _writer(job, ws):
- return {"src/object.js": f"// {job.label} r{job.extra.get('round', 0)}\nexport function build(THREE) {{ return new THREE.Group(); }}\n"}
+ return {"src/object.js": f"// {job.label} r{job.round}\nexport function build(THREE) {{ return new THREE.Group(); }}\n"}
def degraded_verdict(cost: float = 0.003) -> Judgment:
@@ -177,7 +177,7 @@ def test_degraded_verdict_recovers_via_rejudge_of_same_commit(tmp_path, chair_pl
assert rec.status is RunStatus.PASSED and rec.best_round == 1
assert rec.rounds[1].score == pytest.approx(0.85)
# the recovery re-judged the SAME commit: exactly 2 generation rounds ran
- assert [j.extra.get("round") for j in agent.jobs] == [0, 1]
+ assert [j.round for j in agent.jobs] == [0, 1]
saved = RoundRecord.model_validate(json.loads((ws.root / "rounds" / "r01.json").read_text()))
assert saved.judgment is not None and saved.judgment.overall == pytest.approx(0.85)
# audit f2: the recovery re-emits a CORRECTED cost.round so the audit stream stops
diff --git a/harness/tests/orchestrator_tracks/test_fix_generation.py b/harness/tests/orchestrator_tracks/test_fix_generation.py
index d72480c9..78e5ee50 100644
--- a/harness/tests/orchestrator_tracks/test_fix_generation.py
+++ b/harness/tests/orchestrator_tracks/test_fix_generation.py
@@ -112,7 +112,7 @@ def test_run_agent_task_passes_files_hint_and_attributes_fallback_diff(tmp_path)
agent = NonReportingAgent({"src/parts/seat.js": "export function buildSeat(){}\n"})
task = GenerationTask(label="refine_seat", prompt="p", files_hint=["src/parts/seat.js"], round=1, kind="refine")
res = run_agent_task(ws, agent=agent, task=task)
- assert agent.jobs[0].extra["files_hint"] == ["src/parts/seat.js"] # per-session attribution key
+ assert agent.jobs[0].files_hint == ["src/parts/seat.js"] # per-session attribution key
assert res.ok and [c.path for c in res.files_changed] == ["src/parts/seat.js"]