Skip to content

Official Codebase of 3DCodeVerse

Python

plan_features: the switch nothing reads now makes ab_plan refuse the no-op A/B

gaoypeng887718adfb79
diff --git a/harness/bench/ab_plan.py b/harness/bench/ab_plan.py
index 407a877d..c84e9955 100644
--- a/harness/bench/ab_plan.py
+++ b/harness/bench/ab_plan.py
@@ -402,6 +402,18 @@ def main(argv: Sequence[str] | None = None) -> int:
if not opts.variant_env and not opts.aa:
_parser().error("--variant-env KEY=VALUE is required: an A/B with identical arms measures only the noise "
"(pass --aa if measuring the noise is the point)")
+ if not opts.aa:
+ # A KEY no code path reads makes the variant arm byte-identical to the control, so
+ # the battery costs a full run and yields a verdict about nothing. One such A/B is
+ # on record printing "keep, mean delta +0.344" (CQ-5).
+ from codeverse.tracks.plan_features import DEAD_SWITCHES, dead_env_keys
+
+ dead = dead_env_keys(opts.variant_env)
+ if dead and len(dead) == len(opts.variant_env):
+ _parser().error(
+ "--variant-env only sets switches nothing reads, so both arms would be identical: "
+ + "; ".join(f"{k} ({DEAD_SWITCHES[k]})" for k in dead)
+ + " (pass --aa if an identical-arms calibration run is the point)")
from codeverse.models.health import pool_budget
# the rule is a BUDGET, not a head-count: the provider sees one machine, so the sum of
diff --git a/harness/codeverse/tracks/plan_features.py b/harness/codeverse/tracks/plan_features.py
index 87d11b4a..1a5e1ed5 100644
--- a/harness/codeverse/tracks/plan_features.py
+++ b/harness/codeverse/tracks/plan_features.py
@@ -11,6 +11,14 @@ turns into a variant.
one on and ``all,-graph`` all but one. Unknown names are ignored (and logged once)
rather than fatal: a typo in a bench command must produce a control run, not a crash
half-way through a battery.
+
+STATUS (CQ-5): none of the six features below is implemented, and nothing outside this
+module reads ``CV3D_PLAN_FEATURES`` — the plan-loop changes that DID land each invented
+their own spelling instead (see :data:`LIVE_SWITCHES`). The switch is therefore DEAD,
+and an A/B whose arms differ only by it is a no-op by construction: one such run is on
+record printing "keep, mean delta +0.344" for two byte-identical arms. :data:`DEAD_SWITCHES`
+exists so ``bench/ab_plan.py`` refuses that A/B instead of producing a verdict. Delete
+this module, or implement a feature and move its variable into ``LIVE_SWITCHES``.
"""
from __future__ import annotations
@@ -33,6 +41,29 @@ GRAPH_EXAMPLE = "graph_example" # the planner's worked example written as a gra
CONSISTENCY = "consistency" # plan overall bbox checked against the brief's dimension rows
KNOWN_FEATURES: tuple[str, ...] = (FIT, CONTACTS, GRAPH, GRAPH_BUDGET, GRAPH_EXAMPLE, CONSISTENCY)
+#: Plan-loop switches the tree ACTUALLY reads, name → the module that reads it. Kept
+#: honest by tests/orchestrator_tracks/test_plan_features.py, which greps the tree.
+LIVE_SWITCHES: dict[str, str] = {
+ "CV3D_PLAN_BRIEF": "codeverse/tracks/brief.py",
+ "CV3D_SCOPED_PARTS": "codeverse/tracks/depth.py",
+ "CV3D_DETAIL_ROUNDS": "codeverse/tracks/lifecycle.py",
+ "CV3D_REFERENCE_DIFF": "codeverse/judges/reference.py",
+}
+
+#: Switches that are DECLARED but read by no code path, with the reason. An A/B arm that
+#: differs only by one of these is byte-identical to its control, so ``ab_plan`` refuses
+#: it: a rig that cannot tell a live switch from a dead one produces confident verdicts
+#: about nothing. A name leaves this dict in the same commit as the code that reads it.
+DEAD_SWITCHES: dict[str, str] = {
+ PLAN_FEATURES_ENV: "no feature in KNOWN_FEATURES is implemented; nothing reads this variable",
+}
+
+
+def dead_env_keys(env: dict[str, str]) -> list[str]:
+ """The keys of ``env`` that no code path reads — empty when the arm really differs."""
+ return sorted(k for k in env if k in DEAD_SWITCHES)
+
+
_warned: set[str] = set()
@@ -75,5 +106,6 @@ def plan_feature_on(name: str) -> bool:
return name in plan_features()
-__all__ = ["CONSISTENCY", "CONTACTS", "FIT", "GRAPH", "GRAPH_BUDGET", "GRAPH_EXAMPLE", "KNOWN_FEATURES",
- "PLAN_FEATURES_ENV", "parse_features", "plan_feature_on", "plan_features"]
+__all__ = ["CONSISTENCY", "CONTACTS", "DEAD_SWITCHES", "FIT", "GRAPH", "GRAPH_BUDGET", "GRAPH_EXAMPLE",
+ "KNOWN_FEATURES", "LIVE_SWITCHES", "PLAN_FEATURES_ENV", "dead_env_keys", "parse_features",
+ "plan_feature_on", "plan_features"]
diff --git a/harness/tests/orchestrator_tracks/test_plan_features.py b/harness/tests/orchestrator_tracks/test_plan_features.py
index e932a3d4..04e9b3ae 100644
--- a/harness/tests/orchestrator_tracks/test_plan_features.py
+++ b/harness/tests/orchestrator_tracks/test_plan_features.py
@@ -1,7 +1,10 @@
-"""The one env switch every plan-loop-engineering change reads (``tracks/plan_features.py``)."""
+"""``tracks/plan_features.py``: the plan-loop switch registry, and the guard that keeps
+it honest about which switches any code actually reads (CQ-5)."""
from __future__ import annotations
+from pathlib import Path
+
import pytest
from codeverse.tracks import plan_features as F
@@ -42,3 +45,71 @@ def test_reads_env_at_call_time(monkeypatch):
def test_asking_about_an_undefined_feature_is_a_bug():
with pytest.raises(ValueError):
F.plan_feature_on("not_a_feature")
+
+
+# --------------------------------------------------------------------------- CQ-5
+HARNESS = Path(__file__).resolve().parents[2]
+
+
+def _sources() -> list[Path]:
+ return [p for d in ("codeverse", "bench") for p in (HARNESS / d).rglob("*.py")
+ if p.name != "plan_features.py"]
+
+
+def _readers(name: str) -> list[str]:
+ return [str(p.relative_to(HARNESS)) for p in _sources() if name in p.read_text(errors="replace")]
+
+
[email protected]("name", sorted(F.LIVE_SWITCHES))
+def test_every_live_switch_is_really_read(name: str):
+ """A name in LIVE_SWITCHES that nothing reads is the CQ-5 bug all over again."""
+ readers = _readers(name)
+ assert readers, f"{name} is listed as live but no module reads it"
+ assert F.LIVE_SWITCHES[name] in readers, f"{name} is read by {readers}, not {F.LIVE_SWITCHES[name]}"
+
+
[email protected]("name", sorted(F.DEAD_SWITCHES))
+def test_every_dead_switch_is_really_dead(name: str):
+ """The mirror guard: once something reads the variable, it must leave DEAD_SWITCHES —
+ otherwise ab_plan would refuse a legitimate A/B."""
+ assert not _readers(name), f"{name} is now read by {_readers(name)}; move it to LIVE_SWITCHES"
+
+
+def test_the_plan_features_switch_is_declared_dead():
+ """It is: the six KNOWN_FEATURES are not implemented anywhere, so an arm that differs
+ only by CV3D_PLAN_FEATURES is byte-identical to its control."""
+ assert F.PLAN_FEATURES_ENV in F.DEAD_SWITCHES
+ assert F.dead_env_keys({F.PLAN_FEATURES_ENV: "all"}) == [F.PLAN_FEATURES_ENV]
+ assert F.dead_env_keys({"CV3D_PLAN_BRIEF": "off"}) == []
+ assert F.dead_env_keys({F.PLAN_FEATURES_ENV: "all", "CV3D_PLAN_BRIEF": "off"}) == [F.PLAN_FEATURES_ENV]
+
+
+def test_ab_plan_refuses_an_ab_whose_only_switch_is_dead(capsys):
+ """`--variant-env CV3D_PLAN_FEATURES=all` produced a full battery and the verdict
+ 'keep, mean delta +0.344' for two byte-identical arms. It must not start."""
+ import bench.ab_plan as A
+
+ with pytest.raises(SystemExit):
+ A.main(["--prompts", "p.yaml", "--out", "o", "--variant-env", "CV3D_PLAN_FEATURES=all"])
+ err = capsys.readouterr().err
+ assert "nothing reads" in err and "CV3D_PLAN_FEATURES" in err
+
+
+def test_ab_plan_still_accepts_a_live_switch(monkeypatch, capsys):
+ """The guard must not block a real A/B: it fires only when EVERY key is dead.
+
+ Offline — --no-preflight and --allow-siblings keep the provider health check and the
+ docs/COST.md §23 admission check out of it, and run_ab itself is stubbed."""
+ import bench.ab_plan as A
+
+ seen: list[dict[str, str]] = []
+ class _V:
+ decision, reason, caution = "keep", "stubbed", ""
+
+ monkeypatch.setattr(A, "run_ab", lambda battery, out, opts, **kw: (seen.append(opts.variant_env), _V())[1])
+ for argv in (["--variant-env", "CV3D_PLAN_BRIEF=off"],
+ ["--variant-env", "CV3D_PLAN_FEATURES=all", "--variant-env", "CV3D_PLAN_BRIEF=off"]):
+ A.main(["--prompts", "p.yaml", "--out", "o", "--no-preflight", "--allow-siblings", *argv])
+
+ assert len(seen) == 2, capsys.readouterr()
+ assert "CV3D_PLAN_BRIEF" in seen[0]