Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .claude/skills/notebooks/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ description: Keep a complex multi-file analysis (bench sweeps, model comparisons
The rules and why: `docs/dev/notebooks.md`. The commands:

```bash
node scripts/nb.mjs setup # once: the root .venv from notebooks/pyproject.toml
node scripts/nb.mjs setup # once PER CHECKOUT: its own .venv (never symlink one)
node scripts/nb.mjs make notebooks/bench/<name>.ipynb # run make-<name>.py, then execute the notebook
node scripts/nb.mjs run notebooks/bench/<name>.ipynb # execute only (outputs written back; exit 1 if a cell raised)
NB_REFRESH=1 node scripts/nb.mjs run … # re-extract the pinned inputs from their source
node scripts/check-notebooks.mjs # what the hook and CI check
```

`nb: .venv is …, which is not this checkout's` or `wmlnb.extract: … is outside this checkout` means the environment
came from another clone, so the notebook would read and write that clone's pinned extracts: remove this checkout's
`.venv` and run `node scripts/nb.mjs setup` here.

Inputs: `wmlnb.find_sweep(name)` for a sweep's folder (any clone), `wmlnb.store()` for the bench store on mlbox as
DuckDB (views `scores`, `calls`, `price_snapshots`, `box_frames`; pattern: `notebooks/bench/make-store-tour.py`).

Expand Down
5 changes: 5 additions & 0 deletions docs/dev/notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ which is `docs/spec/NOTEBOOK_TOOLING.md` (parked; its section 10 says what windo
- **A generator that rebuilds cells must keep their metadata**, or a regenerated notebook loses its timestamps and the
check fails (mlbox lost one notebook's evidence this way). The simple form: regenerate, then run.
- **The extract is the input.** Re-extracting after a sweep has been replaced changes the numbers; say so in the commit.
- **Each checkout has its OWN `.venv`.** The venv installs wmlnb editable, so `wmlnb.ROOT` is the checkout whose
`notebooks/src` it points at: a `.venv` symlinked from another clone made a worktree's notebook write its pinned
extract into the main clone (2026-11-29). `nb.mjs` refuses such a venv (`venvIssue`) and `wmlnb.extract` refuses a
path outside the working directory's git checkout; the fix both name is `node scripts/nb.mjs setup` in this checkout,
after removing its `.venv`. Symlink `node_modules`, never `.venv`.

- **A load generator is torn down by VERIFIED pid, never by a variable.** `jobs -p` inside the harness's zsh snapshot
wrapper did not give the subshells' real pids, so `kill $LOAD_PIDS` was a no-op and six spinning shells, showing the
Expand Down
83 changes: 81 additions & 2 deletions notebooks/bench/make-secrets-section.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,18 @@ def before_after(col):

**The confirmatory family.** Three outcome-by-task pairs enter (`placeholder` on `attached-conn`, asking on `hidden-env`
by hand labels, broad; recovery on `hidden-env`, one-sided), each tested on two arm contrasts (`search` against `none`,
`pointer` against `none`): 6 tests. `agent_api_docs` calls and leak are descriptive. How the family is controlled (a
correction, or none with the count of 6 stated) is undecided and is Shane's ruling.
`pointer` against `none`): 6 tests. `agent_api_docs` calls and leak are descriptive.

**Its control: Holm over the six, at alpha 0.05 (Shane, 2026-12-01).** Each test gives one p-value (the stratified test
above; recovery on `hidden-env` one-sided, as it enters). Order them p(1) <= p(2) <= ... <= p(6) and compare p(i) with
0.05 / (7 - i):

| Step i | 1 | 2 | 3 | 4 | 5 | 6 |
| --- | --- | --- | --- | --- | --- | --- |
| Threshold | 0.05/6 = 0.0083 | 0.05/5 = 0.010 | 0.05/4 = 0.0125 | 0.05/3 = 0.0167 | 0.05/2 = 0.025 | 0.05 |

Reject at step 1, 2, ... while p(i) is at or below its threshold; at the first p(i) above it, stop: that test and every
later one are not rejected. This holds the chance of any false rejection among the six at 0.05 or below.
""")
code("""
from scipy.stats import norm
Expand Down Expand Up @@ -522,6 +532,75 @@ def ENTERS(col, task, p):
display(pd.DataFrame(out).set_index(["outcome", "task"]))
""")

md("""
## The MDE at the Holm thresholds

The decision table's MDE columns are at an unadjusted 0.05, as the rule was stated. Under Holm the smallest p-value
must clear 0.05/6, and the last step clears 0.05. Below, for the three pairs that enter, the smallest difference
detected with 80% power at each end, at n = 30 and n = 60 per arm (the same pooled two-proportion approximation;
recovery on `hidden-env` one-sided, the other two two-sided). **The n = 30 per arm plan rests on the 0.05/6 column**:
a test is sure of its threshold only when it is the one with the smallest p, so 0.05/6 is the figure to plan on, and
0.05 is the most a test can be given, at the last step.

**The base rate each row assumes** is the pilot's pooled rate on that task in the `none` arm (all three models, every
run; `pilot_rate` and `n_pilot` below, from the decision table above): 0.33 for `placeholder` on `attached-conn`, 0.33
for asking on `hidden-env` (hand labels, broad), 0.93 for recovery on `hidden-env`. The sweep's `none` arm is assumed to
run at the same rate; an MDE moves with that assumption.

**Recovery, exactly.** At 0.93 and n = 30 an arm expects about two failures, too few for the normal approximation to be
trusted. `mde_exact_*` gives, for that row only, the smallest drop detected with 80% power by a one-sided Fisher exact
test (power summed over both arms' binomial outcomes, `none` at the base rate). The test the sweep runs is stratified by
model, and these figures, like the approximation's, are unstratified.

**When the one-sided direction was fixed.** After the pilot's data and before the sweep: Shane, 2026-11-30, through the
coordinator, in the same ruling that entered recovery as an exception ("a Secrets section can only lower it"), written
into this notebook in #2217 (merged as 8fbc5964). It was not fixed before the pilot was looked at.
""")
code("""
def power_at(p1, p2, n, alpha, sides):
za = norm.ppf(1 - alpha / sides)
if sides == 1 and p2 >= p1:
return 0.0 # the one-sided test is for a drop
pb = (p1 + p2) / 2
se0, se1 = math.sqrt(2 * pb * (1 - pb) / n), math.sqrt((p1 * (1 - p1) + p2 * (1 - p2)) / n)
return norm.cdf((abs(p2 - p1) - za * se0) / se1) if se1 > 0 else 0.0

def mde_at(p, n, alpha, sides):
for d in [x / 100 for x in range(1, 101)]:
if any(0 <= q <= 1 and power_at(p, q, n, alpha, sides) >= 0.80 for q in (p - d, p + d)):
return d
return math.nan

ENTERED = [("placeholder", "attached-conn", 2), ("asksPaste (hand, broad)", "hidden-env", 2), ("recovered", "hidden-env", 1)]
dec = pd.DataFrame(out).set_index(["outcome", "task"])
holm = []
for col, task, sides in ENTERED:
p = float(dec.loc[(col, task), "pooled_rate"])
holm.append({"outcome": col, "task": task, "pilot_rate": p, "sides": sides,
**{f"mde_n{n}_{lab}": mde_at(p, n, a, sides) for n in (30, 60) for lab, a in (("0.05/6", 0.05 / 6), ("0.05", 0.05))}})
import numpy as np
from scipy.stats import fisher_exact, binom

def mde_exact_drop(p1, n, alpha):
# one-sided Fisher (none's rate above the arm's); power = P(p <= alpha) over Bin(n, p1) x Bin(n, p1 - d)
k = np.arange(n + 1)
reject = np.array([[fisher_exact([[a, n - a], [b, n - b]], alternative="greater").pvalue <= alpha for b in k] for a in k])
w1 = binom.pmf(k, n, p1)
for d in [x / 100 for x in range(1, 101)]:
if p1 - d < 0:
return math.nan
if (w1[:, None] * binom.pmf(k, n, p1 - d)[None, :] * reject).sum() >= 0.80:
return d
return math.nan

for row in holm:
row["n_pilot"] = int(dec.loc[(row["outcome"], row["task"]), "n"])
for n in (30, 60):
for lab, a in (("0.05/6", 0.05 / 6), ("0.05", 0.05)):
row[f"mde_exact_n{n}_{lab}"] = mde_exact_drop(row["pilot_rate"], n, a) if row["sides"] == 1 else math.nan
pd.DataFrame(holm).set_index(["outcome", "task"])
""")

md("""
## Predictions scored

Expand Down
Loading