Skip to content

Official Codebase of 3DCodeVerse

Python

ab_plan: two A/A runs of the same prompt returned "keep" and "revert"

gaoypengcd7ab913e1e5
diff --git a/harness/bench/_ab_report.py b/harness/bench/_ab_report.py
index 6d3d931c..d3796072 100644
--- a/harness/bench/_ab_report.py
+++ b/harness/bench/_ab_report.py
@@ -40,14 +40,19 @@ REVERT_REGRESSIONS = 2
#: SEPARATED the change from run-to-run noise. 2 is the usual ~95 % two-sided band.
#:
#: This is reported, never enforced: the keep/revert rule above is the protocol
-#: (docs/EVAL.md §7) and a report must not be able to argue itself out of it. But the
-#: rule alone is dangerously confident. Measured 2026-08-24: an A/A run of this rig —
-#: `CV3D_PLAN_FEATURES=all` when nothing on main read that variable, so both arms were
-#: byte-identical code — scored control 0.591 vs variant 0.934 on one prompt and the
-#: verdict line read **keep, mean delta +0.344**. The generator is stochastic; a paired
-#: delta carries the spread of two independent generations, not the judge's ±0.02 sample
-#: noise. So every summary states the spread beside the verdict, and says plainly when
-#: the decision threshold sits inside it.
+#: (docs/EVAL.md §8) and a report must not be able to argue itself out of it. But the
+#: rule alone is dangerously confident. Measured 2026-08-24 with two A/A runs — arms
+#: identical by construction — on the SAME prompt (`ctrl_med_dining_chair`, rounds 1):
+#:
+#: 0.591 vs 0.934 -> delta +0.344 -> verdict **keep**
+#: 0.700 vs 0.600 -> delta -0.100 -> verdict **revert**
+#:
+#: Nothing was under test either time, and the rule returned opposite decisions. Those
+#: four same-code measurements of one prompt have sd 0.160, so a paired delta has
+#: sd ~0.226 and an 8-prompt mean has a 2 SE band of ±0.16 — eight times the ±0.02 the
+#: decision turns on. The generator is stochastic; a paired delta carries the spread of
+#: two independent generations, not the judge's ±0.02 sampling noise. So every summary
+#: states the spread beside the verdict, and says plainly when the threshold is inside it.
NOISE_SIGMAS = 2.0
@@ -76,6 +81,9 @@ class Verdict(BaseModel):
se_delta: float | None = Field(default=None, description="standard error of the mean delta, sd/sqrt(n)")
separated: bool = Field(default=False, description="|mean delta| >= NOISE_SIGMAS * se: the decision is outside the noise")
n_for_power: int | None = Field(default=None, description="pairs this spread needs for NOISE_SIGMAS*se to fit inside KEEP_DELTA")
+ n_up: int = Field(default=0, description="pairs where the variant scored higher (delta > 0)")
+ n_down: int = Field(default=0, description="pairs where the variant scored lower (delta < 0)")
+ sign_p: float | None = Field(default=None, description="two-sided exact sign test on n_up vs n_down; None with no non-zero deltas")
@property
def caution(self) -> str:
@@ -83,8 +91,9 @@ class Verdict(BaseModel):
if self.n_pairs == 0:
return ""
if self.se_delta is None:
- return ("one pair cannot separate a change from run-to-run noise: an A/A run of this rig "
- "(identical arms) measured a paired delta of +0.344 on a single prompt.")
+ return ("one pair cannot separate a change from run-to-run noise: two A/A runs of this rig "
+ "(identical arms, same prompt) measured +0.344 and -0.100 — 'keep' and 'revert' from "
+ "nothing at all.")
if self.separated:
return ""
need = f"~{self.n_for_power} paired prompts" if self.n_for_power else "more paired prompts"
@@ -135,7 +144,7 @@ def verdict_of(pairs: list[PairOutcome]) -> Verdict:
reason="no prompt has both arms scored")
mean, median = round(statistics.fmean(deltas), 4), round(statistics.median(deltas), 4)
v = Verdict(decision="inconclusive", n_pairs=len(deltas), mean_delta=mean, median_delta=median,
- regressions=regressions, **_spread(deltas, mean))
+ regressions=regressions, **_spread(deltas, mean), **_sign_test(deltas))
if mean <= REVERT_DELTA or len(regressions) >= REVERT_REGRESSIONS:
v.decision, v.reason = "revert", (f"mean delta {mean:+.3f} <= {REVERT_DELTA:+.2f}" if mean <= REVERT_DELTA
else f"{len(regressions)} regressions (>= {REVERT_REGRESSIONS})")
@@ -147,6 +156,26 @@ def verdict_of(pairs: list[PairOutcome]) -> Verdict:
return v
+def _sign_test(deltas: list[float]) -> dict[str, object]:
+ """How CONSISTENT the change is, as opposed to how big its mean is.
+
+ The mean is hostage to the generation spread (see :data:`NOISE_SIGMAS`): at a paired
+ sd near 0.23 an eight-prompt mean cannot resolve 0.02 and never will. The SIGN of
+ each paired delta is far cheaper to move — a real improvement tends to help most
+ prompts a little, and 7 of 8 in one direction is p = 0.07 on the exact two-sided sign
+ test, a bar an eight-prompt battery can actually clear. Reported, not enforced: the
+ keep/revert rule is the protocol. Zero deltas are dropped, as the test requires.
+ """
+ up = sum(d > 0 for d in deltas)
+ down = sum(d < 0 for d in deltas)
+ n = up + down
+ if n == 0:
+ return {"n_up": 0, "n_down": 0, "sign_p": None}
+ k = max(up, down)
+ tail = sum(math.comb(n, i) for i in range(k, n + 1)) / 2 ** n
+ return {"n_up": up, "n_down": down, "sign_p": round(min(1.0, 2 * tail), 4)}
+
+
def _spread(deltas: list[float], mean: float) -> dict[str, object]:
"""The noise block of a :class:`Verdict`: how wide the paired deltas are, and what
that width does to the decision.
@@ -230,6 +259,8 @@ def render_summary(pairs: list[PairOutcome], rows: list[CellResult], *, title: s
f"paired sd {_fmt(v.sd_delta)} · SE {_fmt(v.se_delta)} · {NOISE_SIGMAS:g} SE band "
f"{_fmt(v.mean_delta, True)} ± {_fmt(NOISE_SIGMAS * v.se_delta if v.se_delta else None)} · "
f"separated from noise: {'yes' if v.separated else 'NO'}",
+ f"sign consistency: {v.n_up} up / {v.n_down} down · exact two-sided sign test p = "
+ f"{'—' if v.sign_p is None else f'{v.sign_p:.3f}'} — the signal an 8-prompt battery can actually carry",
*([f"\n**{v.caution}**"] if v.caution else []), "",
"## Arms", "",
"| arm | n | scored | infra_failed | budget_exhausted | other unscored | mean | median | cost $ | mean min |",
diff --git a/harness/bench/ab_plan.py b/harness/bench/ab_plan.py
index 7cf100ac..08563085 100644
--- a/harness/bench/ab_plan.py
+++ b/harness/bench/ab_plan.py
@@ -31,8 +31,8 @@ What the verdict does NOT tell you: the generator is stochastic, so a paired del
the spread of two independent generations, not the judge's ±0.02 sampling noise. Run
``--aa`` (both arms identical) on the same battery to measure that floor; every summary
prints the paired sd, the 2 SE band and how many pairs this spread would need before
-±0.02 is resolvable (``bench/_ab_report.NOISE_SIGMAS``). Measured 2026-08-24: one A/A
-prompt came back +0.344 and the rule said "keep".
+±0.02 is resolvable (``bench/_ab_report.NOISE_SIGMAS``). Measured 2026-08-24: two A/A
+runs of one prompt came back +0.344 and -0.100 — "keep" and "revert" from identical code.
Layout of ``--out``: ``ab.json`` (the arms, options and variant env) ·
``results.jsonl`` (one ``CellResult`` per (prompt, arm); resume source) ·
diff --git a/harness/docs/EVAL.md b/harness/docs/EVAL.md
index 4cd60f4b..093ad975 100644
--- a/harness/docs/EVAL.md
+++ b/harness/docs/EVAL.md
@@ -226,10 +226,20 @@ verdict rule is blunt on purpose (`bench/_ab_report.verdict_of`, stated once):
> **or** ≥ 2 such prompts; else inconclusive. A prompt counts only when BOTH arms scored.
**That rule is a screen, not a proof, and the numbers say by how much.** Measured
-2026-08-24: an A/A run — `--variant-env CV3D_PLAN_FEATURES=all` at a time when nothing on
-`main` read that variable, so the two arms were byte-identical code — produced
-control 0.591 vs variant 0.934 on `ctrl_med_dining_chair`, and the verdict line read
-**keep, mean delta +0.344**. Nothing was under test and the rig said ship it.
+2026-08-24 with two A/A runs — arms identical by construction — on the *same* prompt
+`ctrl_med_dining_chair` at rounds 1, `api-agent:gemini:gemini-3.7-flash`, fixed judge
+`gemini-3.1-pro-preview` n=2:
+
+| run | control | variant | delta | verdict the rule printed |
+|---|---|---|---|---|
+| `bench/out/ab_smoke_features` | 0.591 | 0.934 | **+0.344** | **keep** |
+| `bench/out/ab_aa_noise` | 0.700 | 0.600 | **−0.100** | **revert** |
+
+Nothing was under test either time, and the rule returned opposite decisions. Those four
+same-code measurements of one prompt have **sd 0.160** (mean 0.706, range 0.591–0.934), so
+a paired delta has sd ≈ 0.226 and an 8-prompt mean carries a 2 SE band of **±0.16** —
+eight times the ±0.02 the decision turns on. Resolving ±0.02 at this spread would take
+roughly **500 paired prompts**.
The reason is structural, not a bug: a paired delta is the difference of two *independent
stochastic generations*, so it carries generation spread, not the fixed judge's ±0.02
@@ -238,14 +248,19 @@ of magnitude too tight for what it is applied to. Consequences:
* every summary now prints a **Confidence** block — paired sd, SE, the 2 SE band, and
`separated from noise: yes|NO` — beside the verdict, plus `n_for_power`, the number of
- paired prompts this spread would need before ±0.02 is resolvable. At a paired sd of
- ~0.18 that is *hundreds*, not eight;
+ paired prompts this spread would need before ±0.02 is resolvable. At the spread above
+ that is *hundreds*, not eight;
* run `--aa` on the same battery and the same n to measure the floor before believing a
win. Both arms get the control environment; the report is titled `A/A` and banners
itself so no reader can mistake a calibration for a result;
* a `keep` that is not `separated` means "worth another look", never "ship it". Prefer
changes whose per-prompt deltas are *consistent in sign* over ones with a big mean and
- a big spread — the sign pattern survives this noise where the mean does not.
+ a big spread — the sign pattern survives this noise where the mean does not (a sign test
+ over 8 prompts needs 7/8 in one direction for p < 0.07, and that is a bar an 8-prompt
+ battery can actually clear);
+* the cheapest real power is not more prompts but **less per-cell variance**: more rounds,
+ or k generations per (prompt, arm) averaged before differencing, cuts the paired sd by
+ √k. Both cost the same dollars as more prompts and buy more per dollar here.
## 9. Reporting checklist
diff --git a/harness/tests/compare_bench/test_ab_plan.py b/harness/tests/compare_bench/test_ab_plan.py
index 5353f4a0..6c6673e1 100644
--- a/harness/tests/compare_bench/test_ab_plan.py
+++ b/harness/tests/compare_bench/test_ab_plan.py
@@ -131,6 +131,17 @@ def test_a_verdict_states_the_spread_it_was_decided_on():
assert v.n_for_power > 100
+def test_sign_consistency_catches_the_win_the_mean_rule_throws_away():
+ """A change that helps every prompt a little is invisible to a +-0.02 mean at this
+ spread, and obvious to the sign test — which is the whole point of reporting it."""
+ v = verdict_of(_pairs(*([0.01] * 8)))
+ assert v.decision == "inconclusive", "the mean rule cannot see it"
+ assert (v.n_up, v.n_down) == (8, 0) and v.sign_p == pytest.approx(2 / 2 ** 8, abs=1e-4)
+ v = verdict_of(_pairs(0.30, -0.20, 0.10, 0.05, -0.10, 0.25, 0.02, -0.15))
+ assert (v.n_up, v.n_down) == (5, 3) and v.sign_p > 0.7, "a big mean with a coin-flip sign pattern"
+ assert verdict_of(_pairs(0.0, 0.0)).sign_p is None, "zero deltas are dropped, as the test requires"
+
+
def test_a_tight_win_is_marked_separated_and_carries_no_caution():
v = verdict_of(_pairs(0.10, 0.11, 0.09, 0.12))
assert v.decision == "keep" and v.separated and v.caution == ""
@@ -147,6 +158,7 @@ def test_summary_prints_the_confidence_block():
for arm, s in ((CONTROL, c), (VARIANT, x))]
md = render_summary(pair_up(rows), rows, title="t", variant_env={"K": "v"}, generator="g", judge="j", rounds=1)
assert "## Confidence" in md and "separated from noise: NO" in md and "NOT separated from noise" in md
+ assert "sign consistency: 2 up / 1 down" in md and "sign test p = 1.000" in md
def test_an_aa_run_is_labelled_so_nobody_reads_it_as_a_decision():