Official Codebase of 3DCodeVerse
Python
lifecycle: plan_stage_key owns the plan stage's key — pin_plan calls it, and the AST test pinning two copies of it goes
gaoypengccca64a75a04
diff --git a/eval/bench/pin_plan.py b/eval/bench/pin_plan.pyindex a631deee..5d528b10 100644--- a/eval/bench/pin_plan.py+++ b/eval/bench/pin_plan.py@@ -93,7 +93,7 @@ def plan_once(spec: Any, ws_root: Path) -> str:from codeverse3d.orchestrator import RunState, StageRunnerfrom codeverse3d.proc import EventLogfrom codeverse3d.tracks import get_track- from codeverse3d.tracks.lifecycle import plan_stage_inputs+ from codeverse3d.tracks.lifecycle import plan_stage_keyfrom codeverse3d.workspace import Workspacews = Workspace(Path(ws_root))@@ -105,7 +105,7 @@ def plan_once(spec: Any, ws_root: Path) -> str:ctx = track.build_context(spec, ws, events, state)runner = StageRunner(ws, events, state)runner.stage("plan", lambda: track._plan_stage(ctx), # noqa: SLF001 — see docstring- inputs={"spec": plan_stage_inputs(spec), "track": track.track.value},+ inputs=plan_stage_key(spec, track.track),model=track.plan_model)entry = state.stages.get(STAGE_NAME)if entry is None or not entry.inputs_hash: # pragma: no cover — stage() always records onediff --git a/eval/docs/EVAL.md b/eval/docs/EVAL.mdindex 3ddeee02..4aec0224 100644--- a/eval/docs/EVAL.md+++ b/eval/docs/EVAL.md@@ -452,7 +452,7 @@ Three details are the whole correctness of it:finished run. Seeding off the control would serialise the pair, and the pair is launchedtogether precisely so both arms see the same provider weather.* **The `inputs_hash` is asserted equal for every arm.** It is derived from the spec- (`plan_stage_inputs`), so a mismatch means the seed is a cache MISS and the pair would+ (`lifecycle.plan_stage_key`, the one key a run and the seed both use), so a mismatch means the seed is a cache MISS and the pair wouldre-plan per arm while reporting itself pinned — the one failure this must not have.* **`pin_plan_blockers` gates the flag** and `main` refuses the run when it is non-empty.Pinning a plan-side switch deletes the thing under test and the rig would then reportdiff --git a/eval/tests/test_pin_plan.py b/eval/tests/test_pin_plan.pyindex b3c57fc7..5dddf584 100644--- a/eval/tests/test_pin_plan.py+++ b/eval/tests/test_pin_plan.py@@ -163,56 +163,3 @@ def test_a_plan_side_variant_env_is_refused_by_the_cli():ab_plan.main(["--prompts", str(Path(ab_plan.__file__).resolve().parent / "prompts" / "compare_v1.yaml"),"--out", "/tmp/never", "--pin-plan", "--no-preflight","--variant-env", "C3D_PLAN_BRIEF=1"])---# --------------------------------------------------------------------------- the key-# THE load-bearing invariant. `plan_once` seeds a plan whose stage-cache key is computed-# in bench/pin_plan.py; the arm that consumes it computes its key in-# tracks/lifecycle.BaseTrack.run. If those two expressions ever drift apart, the seeded-# plan is a cache MISS, both arms silently re-plan, and the rig reports "no effect" for a-# switch whose experiment it just deleted -- expensively, and with no error anywhere.-# Pinning that does not pin is worse than no pinning, because it looks like a result.--def _stage_call_inputs(path: Path, func: str) -> str:- """The literal source of the ``inputs={...}`` argument of the ``plan`` stage call."""- import ast-- tree = ast.parse(path.read_text())- scope = next((n for n in ast.walk(tree)- if isinstance(n, ast.FunctionDef) and n.name == func), None)- assert scope is not None, f"{path.name} has no {func}()"- for node in ast.walk(scope):- if (isinstance(node, ast.Call)- and getattr(node.func, "attr", "") == "stage"- and node.args- and isinstance(node.args[0], ast.Constant)- and node.args[0].value == "plan"):- for kw in node.keywords:- if kw.arg == "inputs":- return ast.dump(kw.value)- raise AssertionError(f"{path.name}::{func} has no runner.stage('plan', ..., inputs=...) call")---def test_the_seeded_plan_and_the_running_plan_share_one_stage_key():- """`plan_once` and `BaseTrack.run` must key the plan stage by the same expression.-- The only legitimate difference is the receiver holding the track: `plan_once` keeps it- in a local named `track`, `run` is a method and says `self`. Everything else -- the- keys, the helper called on the spec, the attribute path -- must match exactly.- """-- here = Path(__file__).resolve().parents[1] # eval/- seeded = _stage_call_inputs(here / "bench" / "pin_plan.py", "plan_once")- running = _stage_call_inputs(here.parent / "harness" / "codeverse3d" / "tracks" / "lifecycle.py", "run")-- def norm(dump: str) -> str:- return dump.replace("Name(id='self',", "Name(id='track',")-- assert norm(seeded) == norm(running), (- "the pinned plan and the arm that consumes it no longer compute the same "- "stage-cache key.\n pin_plan.plan_once: " + seeded- + "\n lifecycle.run: " + running- + "\nA seeded plan would be a cache MISS: both arms re-plan, neither is pinned, and "- "the A/B reports 'no effect' for an experiment it silently deleted."- )- assert "plan_stage_inputs" in seeded, "the key stopped going through plan_stage_inputs"diff --git a/harness/codeverse3d/tracks/lifecycle.py b/harness/codeverse3d/tracks/lifecycle.pyindex 3089133c..0b1ac016 100644--- a/harness/codeverse3d/tracks/lifecycle.py+++ b/harness/codeverse3d/tracks/lifecycle.py@@ -86,6 +86,12 @@ def plan_stage_inputs(spec: Spec) -> dict[str, Any]:}+def plan_stage_key(spec: Spec, track: Track) -> dict[str, Any]:+ """The plan stage's cache key: a run's, and the one a pinned A/B plan is seeded under+ (``eval/bench/pin_plan``) — a seed under any other key is a cache MISS and re-plans."""+ return {"spec": plan_stage_inputs(spec), "track": track.value}++def spec_fingerprint(spec: Spec) -> str:"""Identity of the spec THE PLAN depends on (hash of :func:`plan_stage_inputs`).@@ -250,7 +256,7 @@ class BaseTrack:stop = RunStatus.FAILEDerror = ""try:- ctx.plan = runner.stage("plan", lambda: self._plan_stage(ctx), inputs={"spec": plan_stage_inputs(spec), "track": self.track.value},+ ctx.plan = runner.stage("plan", lambda: self._plan_stage(ctx), inputs=plan_stage_key(spec, self.track),model=self.plan_model)self.after_plan(ctx)self.prepare(ctx, runner)