Skip to content

Official Codebase of 3DCodeVerse

Python

pool budget: a battery launched as `-m bench.ab_plan` was invisible to the accounting

gaoypengd3ef6896f43f
diff --git a/harness/codeverse/models/health.py b/harness/codeverse/models/health.py
index e8c46a75..eed9caca 100644
--- a/harness/codeverse/models/health.py
+++ b/harness/codeverse/models/health.py
@@ -117,24 +117,63 @@ def _bare_model(model_id: str, timeout_s: float):
#: how a harness process appears in its own argv. Matched on ARGUMENTS, never on the
#: whole command line: the repo path itself contains "3dcodeverse", so a substring test
#: counts every shell that merely `cd`s into the tree.
-_MODULE = "codeverse.cli.main"
+#:
+#: BOTH spellings of every entry point are listed, because a program launched two ways is
+#: still one program. Measured 2026-08-24: an eight-prompt A/B running as
+#: ``python -m bench.ab_plan`` (driver + two 16-in-flight cell children) was invisible to
+#: :func:`pool_budget`, which reported "headroom 48" on a machine already sitting at the
+#: 64 knee — the exact over-launch ``docs/COST.md`` §23 exists to prevent.
+_MODULES = ("codeverse.cli.main", "bench.ab_plan", "bench.compare_backends", "bench.run_bench")
_SCRIPTS = ("compare_backends.py", "run_bench.py", "ab_plan.py")
_ENTRY_POINTS = ("3dcv", "3dcodeverse")
-def _is_harness_argv(args: list[str]) -> bool:
+def _harness_token(args: list[str]) -> str | None:
+ """The argv token that makes this a harness process, or ``None`` if it is not one.
+
+ Returned rather than a bool so callers can ask WHICH entry point is running without
+ re-scanning the command line (see :func:`_is_delegating_driver`).
+ """
if not args:
- return False
+ return None
from pathlib import PurePath
if PurePath(args[0]).name in _ENTRY_POINTS:
- return True
+ return args[0]
for i, a in enumerate(args):
- if a == "-m" and i + 1 < len(args) and args[i + 1] == _MODULE:
- return True
+ if a == "-m" and i + 1 < len(args) and args[i + 1] in _MODULES:
+ return args[i + 1]
if PurePath(a).name in _SCRIPTS:
- return True
- return False
+ return a
+ return None
+
+
+def _is_harness_argv(args: list[str]) -> bool:
+ return _harness_token(args) is not None
+
+
+#: the ``ab_plan`` entry point under either spelling
+_AB_PLAN = ("ab_plan.py", "bench.ab_plan")
+
+
+def _is_delegating_driver(args: list[str]) -> bool:
+ """Does this process spend its in-flight budget only through capped CHILDREN?
+
+ ``bench/ab_plan.py`` in driver mode spawns one ``… cell`` child per arm and makes no
+ model calls of its own past a 6-key preflight probe; the children carry the caps and
+ are counted in their own right. Charging the driver as well would double-count the
+ same traffic — and since ``--max-in-flight`` is the cap it hands its children, not one
+ it sets on itself, :func:`_cap_of` would charge it the 64 default, i.e. the whole knee,
+ and every sibling would refuse to launch. Counting heads instead of budget is the
+ failure that stalled a whole A/B wave on 2026-08-24; this is its mirror image.
+ """
+ from pathlib import PurePath
+
+ tok = _harness_token(args)
+ if tok is None or PurePath(tok).name not in _AB_PLAN:
+ return False
+ i = args.index(tok)
+ return args[i + 1 : i + 2] != ["cell"]
def sibling_processes() -> int:
@@ -241,7 +280,11 @@ def pool_budget() -> PoolBudget:
raw = (entry / "cmdline").read_bytes()
except OSError:
continue
- if _is_harness_argv([a for a in raw.decode(errors="replace").split("\0") if a]):
- n += 1
- used += _cap_of(entry)
+ argv = [a for a in raw.decode(errors="replace").split("\0") if a]
+ if not _is_harness_argv(argv):
+ continue
+ n += 1
+ if _is_delegating_driver(argv):
+ continue # its capped children are counted separately; see _is_delegating_driver
+ used += _cap_of(entry)
return PoolBudget(n, used)
diff --git a/harness/docs/COST.md b/harness/docs/COST.md
index d1ccc202..9e241d4d 100644
--- a/harness/docs/COST.md
+++ b/harness/docs/COST.md
@@ -1092,6 +1092,17 @@ Three consequences:
The first version of this rule counted *processes* and made every agent wait for an
empty machine — which stalled an entire A/B wave behind two batteries that were
themselves parked. A budget, not a head-count.
+4. **The accounting only works if every process is visible to it.** `pool_budget()`
+ matches on argv, and until 2026-08-24 it matched only the *script path* spelling
+ (`python bench/ab_plan.py`). A live eight-prompt A/B launched as
+ `python -m bench.ab_plan` — driver plus two 16-in-flight cell children — was therefore
+ invisible: the budget read `16/64, headroom 48` on a machine already at 48, and the
+ next agent to check it would have launched 32 more and taken the machine to 80. Both
+ spellings of every entry point are now listed (`health._MODULES` / `_SCRIPTS`). The
+ mirror-image error is just as bad: an `ab_plan` *driver* spends its budget only through
+ capped children, and it sets no cap on itself, so charging it too would book the 64
+ default on top of the children and stall every sibling — `_is_delegating_driver` skips
+ it. Whenever an entry point is added or renamed, update both lists.
The real fix is a machine-wide limiter — a file-locked token bucket under
`~/.cache/codeverse/` that every process shares — so the quota is enforced where it
diff --git a/harness/tests/models/test_health.py b/harness/tests/models/test_health.py
index a9d02492..d053508a 100644
--- a/harness/tests/models/test_health.py
+++ b/harness/tests/models/test_health.py
@@ -68,6 +68,12 @@ def test_sibling_detection_matches_arguments_not_the_repo_path():
assert _is_harness_argv(["python", "bench/compare_backends.py", "--arms", "x"])
assert _is_harness_argv(["/home/u/.local/bin/3dcv", "doctor"])
assert _is_harness_argv(["/usr/bin/python3", "/x/y/run_bench.py"])
+ # a bench script launched as a MODULE is the same program and must weigh the same:
+ # a live `python -m bench.ab_plan` A/B was invisible here on 2026-08-24 and
+ # pool_budget reported headroom 48 on a machine already at the 64 knee
+ assert _is_harness_argv(["python", "-m", "bench.ab_plan", "--prompts", "x"])
+ assert _is_harness_argv(["python", "-m", "bench.compare_backends", "--arms", "x"])
+ assert _is_harness_argv(["python", "-m", "bench.run_bench", "b.yaml"])
# the false positives
assert not _is_harness_argv(["/bin/bash", "-c", "cd /home/u/3dcodeverse/harness && ls"])
assert not _is_harness_argv(["vim", "/home/u/3dcodeverse/harness/codeverse/cli/main.py"])
@@ -171,6 +177,30 @@ def test_a_sibling_that_set_no_cap_counts_at_the_default(monkeypatch):
assert pb.used == 64 and pb.headroom == 0 and not pb.fits(1)
+def test_an_ab_plan_driver_is_not_charged_for_its_children(monkeypatch):
+ """The driver spawns one capped cell child per arm and makes no model calls of its own.
+
+ It sets no cap on itself (``--max-in-flight`` is the CHILD cap), so charging it would
+ book the 64 default — the whole knee — on top of the children that actually hold the
+ traffic, and every sibling would refuse to launch."""
+ health = _fake_proc(monkeypatch, {
+ 301: (["python", "-m", "bench.ab_plan", "--prompts", "p.yaml", "--max-in-flight", "16"], {}),
+ 302: (["python", "-m", "bench.ab_plan", "cell", "--arm", "control"], {"CV3D_MAX_IN_FLIGHT": "16"}),
+ 303: (["python", "-m", "bench.ab_plan", "cell", "--arm", "variant"], {"CV3D_MAX_IN_FLIGHT": "16"}),
+ })
+ pb = health.pool_budget()
+ assert (pb.siblings, pb.used, pb.headroom) == (3, 32, 32), str(pb)
+ # the same three processes under the script spelling read identically
+ health = _fake_proc(monkeypatch, {
+ 311: (["python", "bench/ab_plan.py", "--prompts", "p.yaml"], {}),
+ 312: (["python", "bench/ab_plan.py", "cell", "--arm", "control"], {"CV3D_MAX_IN_FLIGHT": "8"}),
+ })
+ assert health.pool_budget().used == 8
+ # a compare_backends driver runs its cells in THREADS, in itself: it is charged
+ health = _fake_proc(monkeypatch, {321: (["python", "-m", "bench.compare_backends"], {"CV3D_MAX_IN_FLIGHT": "16"})})
+ assert health.pool_budget().used == 16
+
+
def test_pool_budget_never_raises(monkeypatch):
from pathlib import Path