@tangle-network/agent-bench 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +13 -1
  3. package/dist/adapters.d.ts +15 -0
  4. package/dist/adapters.js +43 -0
  5. package/dist/adapters.js.map +1 -0
  6. package/dist/benchmarks/_harness.d.ts +125 -0
  7. package/dist/benchmarks/_harness.js +33 -0
  8. package/dist/benchmarks/_harness.js.map +1 -0
  9. package/dist/benchmarks/aec-bench.d.ts +27 -0
  10. package/dist/benchmarks/aec-bench.js +8 -0
  11. package/dist/benchmarks/aec-bench.js.map +1 -0
  12. package/dist/benchmarks/agentbench.d.ts +16 -0
  13. package/dist/benchmarks/agentbench.js +10 -0
  14. package/dist/benchmarks/agentbench.js.map +1 -0
  15. package/dist/benchmarks/appworld.d.ts +37 -0
  16. package/dist/benchmarks/appworld.js +14 -0
  17. package/dist/benchmarks/appworld.js.map +1 -0
  18. package/dist/benchmarks/bfcl.d.ts +18 -0
  19. package/dist/benchmarks/bfcl.js +10 -0
  20. package/dist/benchmarks/bfcl.js.map +1 -0
  21. package/dist/benchmarks/cad-design.d.ts +45 -0
  22. package/dist/benchmarks/cad-design.js +7 -0
  23. package/dist/benchmarks/cad-design.js.map +1 -0
  24. package/dist/benchmarks/cadbench.d.ts +19 -0
  25. package/dist/benchmarks/cadbench.js +8 -0
  26. package/dist/benchmarks/cadbench.js.map +1 -0
  27. package/dist/benchmarks/cadgenbench.d.ts +22 -0
  28. package/dist/benchmarks/cadgenbench.js +8 -0
  29. package/dist/benchmarks/cadgenbench.js.map +1 -0
  30. package/dist/benchmarks/commit0.d.ts +31 -0
  31. package/dist/benchmarks/commit0.js +10 -0
  32. package/dist/benchmarks/commit0.js.map +1 -0
  33. package/dist/benchmarks/crag.d.ts +14 -0
  34. package/dist/benchmarks/crag.js +9 -0
  35. package/dist/benchmarks/crag.js.map +1 -0
  36. package/dist/benchmarks/dabstep.d.ts +18 -0
  37. package/dist/benchmarks/dabstep.js +10 -0
  38. package/dist/benchmarks/dabstep.js.map +1 -0
  39. package/dist/benchmarks/enterpriseops-gym.d.ts +38 -0
  40. package/dist/benchmarks/enterpriseops-gym.js +10 -0
  41. package/dist/benchmarks/enterpriseops-gym.js.map +1 -0
  42. package/dist/benchmarks/finresearchbench.d.ts +15 -0
  43. package/dist/benchmarks/finresearchbench.js +8 -0
  44. package/dist/benchmarks/finresearchbench.js.map +1 -0
  45. package/dist/benchmarks/finsearchcomp.d.ts +49 -0
  46. package/dist/benchmarks/finsearchcomp.js +7 -0
  47. package/dist/benchmarks/finsearchcomp.js.map +1 -0
  48. package/dist/benchmarks/frames.d.ts +59 -0
  49. package/dist/benchmarks/frames.js +13 -0
  50. package/dist/benchmarks/frames.js.map +1 -0
  51. package/dist/benchmarks/hotpotqa.d.ts +48 -0
  52. package/dist/benchmarks/hotpotqa.js +15 -0
  53. package/dist/benchmarks/hotpotqa.js.map +1 -0
  54. package/dist/benchmarks/humaneval.d.ts +62 -0
  55. package/dist/benchmarks/humaneval.js +17 -0
  56. package/dist/benchmarks/humaneval.js.map +1 -0
  57. package/dist/benchmarks/mind2web.d.ts +41 -0
  58. package/dist/benchmarks/mind2web.js +9 -0
  59. package/dist/benchmarks/mind2web.js.map +1 -0
  60. package/dist/benchmarks/nomiracl.d.ts +15 -0
  61. package/dist/benchmarks/nomiracl.js +9 -0
  62. package/dist/benchmarks/nomiracl.js.map +1 -0
  63. package/dist/benchmarks/open-rag-bench.d.ts +14 -0
  64. package/dist/benchmarks/open-rag-bench.js +9 -0
  65. package/dist/benchmarks/open-rag-bench.js.map +1 -0
  66. package/dist/benchmarks/programbench.d.ts +38 -0
  67. package/dist/benchmarks/programbench.js +10 -0
  68. package/dist/benchmarks/programbench.js.map +1 -0
  69. package/dist/benchmarks/rag-shared.d.ts +42 -0
  70. package/dist/benchmarks/rag-shared.js +39 -0
  71. package/dist/benchmarks/rag-shared.js.map +1 -0
  72. package/dist/benchmarks/ragbench.d.ts +16 -0
  73. package/dist/benchmarks/ragbench.js +9 -0
  74. package/dist/benchmarks/ragbench.js.map +1 -0
  75. package/dist/benchmarks/simpleqa.d.ts +64 -0
  76. package/dist/benchmarks/simpleqa.js +11 -0
  77. package/dist/benchmarks/simpleqa.js.map +1 -0
  78. package/dist/benchmarks/swe-bench.d.ts +56 -0
  79. package/dist/benchmarks/swe-bench.js +14 -0
  80. package/dist/benchmarks/swe-bench.js.map +1 -0
  81. package/dist/benchmarks/t2-ragbench.d.ts +14 -0
  82. package/dist/benchmarks/t2-ragbench.js +9 -0
  83. package/dist/benchmarks/t2-ragbench.js.map +1 -0
  84. package/dist/benchmarks/tau-bench-shared.d.ts +26 -0
  85. package/dist/benchmarks/tau-bench-shared.js +10 -0
  86. package/dist/benchmarks/tau-bench-shared.js.map +1 -0
  87. package/dist/benchmarks/tau2-bench.d.ts +7 -0
  88. package/dist/benchmarks/tau2-bench.js +11 -0
  89. package/dist/benchmarks/tau2-bench.js.map +1 -0
  90. package/dist/benchmarks/tau3-banking.d.ts +15 -0
  91. package/dist/benchmarks/tau3-banking.js +9 -0
  92. package/dist/benchmarks/tau3-banking.js.map +1 -0
  93. package/dist/benchmarks/terminal-bench.d.ts +24 -0
  94. package/dist/benchmarks/terminal-bench.js +8 -0
  95. package/dist/benchmarks/terminal-bench.js.map +1 -0
  96. package/dist/benchmarks/toollm.d.ts +16 -0
  97. package/dist/benchmarks/toollm.js +10 -0
  98. package/dist/benchmarks/toollm.js.map +1 -0
  99. package/dist/benchmarks/trata-hedge.d.ts +32 -0
  100. package/dist/benchmarks/trata-hedge.js +7 -0
  101. package/dist/benchmarks/trata-hedge.js.map +1 -0
  102. package/dist/benchmarks/types.d.ts +107 -0
  103. package/dist/benchmarks/types.js +1 -0
  104. package/dist/benchmarks/types.js.map +1 -0
  105. package/dist/benchmarks/webarena-verified.d.ts +16 -0
  106. package/dist/benchmarks/webarena-verified.js +10 -0
  107. package/dist/benchmarks/webarena-verified.js.map +1 -0
  108. package/dist/chunk-2PVVP7GN.js +197 -0
  109. package/dist/chunk-2PVVP7GN.js.map +1 -0
  110. package/dist/chunk-2XU6OGEN.js +170 -0
  111. package/dist/chunk-2XU6OGEN.js.map +1 -0
  112. package/dist/chunk-53UPUNBZ.js +325 -0
  113. package/dist/chunk-53UPUNBZ.js.map +1 -0
  114. package/dist/chunk-5H5XV76F.js +240 -0
  115. package/dist/chunk-5H5XV76F.js.map +1 -0
  116. package/dist/chunk-7WSD27QQ.js +118 -0
  117. package/dist/chunk-7WSD27QQ.js.map +1 -0
  118. package/dist/chunk-C7T7WEK2.js +103 -0
  119. package/dist/chunk-C7T7WEK2.js.map +1 -0
  120. package/dist/chunk-CKUVRZ2T.js +251 -0
  121. package/dist/chunk-CKUVRZ2T.js.map +1 -0
  122. package/dist/chunk-HBSWHQNJ.js +30 -0
  123. package/dist/chunk-HBSWHQNJ.js.map +1 -0
  124. package/dist/chunk-HHXFIHXC.js +116 -0
  125. package/dist/chunk-HHXFIHXC.js.map +1 -0
  126. package/dist/chunk-IFAV6KEM.js +276 -0
  127. package/dist/chunk-IFAV6KEM.js.map +1 -0
  128. package/dist/chunk-INNOYXCP.js +387 -0
  129. package/dist/chunk-INNOYXCP.js.map +1 -0
  130. package/dist/chunk-J3KDJNX2.js +182 -0
  131. package/dist/chunk-J3KDJNX2.js.map +1 -0
  132. package/dist/chunk-JRWWGMK7.js +148 -0
  133. package/dist/chunk-JRWWGMK7.js.map +1 -0
  134. package/dist/chunk-JTHWEDEW.js +32 -0
  135. package/dist/chunk-JTHWEDEW.js.map +1 -0
  136. package/dist/chunk-KDIKRJGB.js +120 -0
  137. package/dist/chunk-KDIKRJGB.js.map +1 -0
  138. package/dist/chunk-LRRD7NAG.js +301 -0
  139. package/dist/chunk-LRRD7NAG.js.map +1 -0
  140. package/dist/chunk-ODT47UAY.js +221 -0
  141. package/dist/chunk-ODT47UAY.js.map +1 -0
  142. package/dist/chunk-PA2ZKHJC.js +230 -0
  143. package/dist/chunk-PA2ZKHJC.js.map +1 -0
  144. package/dist/chunk-PUIRNYI7.js +189 -0
  145. package/dist/chunk-PUIRNYI7.js.map +1 -0
  146. package/dist/chunk-PWQVGAJB.js +144 -0
  147. package/dist/chunk-PWQVGAJB.js.map +1 -0
  148. package/dist/chunk-R36V2VP7.js +169 -0
  149. package/dist/chunk-R36V2VP7.js.map +1 -0
  150. package/dist/chunk-R67DFVLO.js +142 -0
  151. package/dist/chunk-R67DFVLO.js.map +1 -0
  152. package/dist/chunk-SEVJPLZC.js +260 -0
  153. package/dist/chunk-SEVJPLZC.js.map +1 -0
  154. package/dist/chunk-SYDW647C.js +318 -0
  155. package/dist/chunk-SYDW647C.js.map +1 -0
  156. package/dist/chunk-TBKU5XQI.js +228 -0
  157. package/dist/chunk-TBKU5XQI.js.map +1 -0
  158. package/dist/chunk-TSWPNOYM.js +147 -0
  159. package/dist/chunk-TSWPNOYM.js.map +1 -0
  160. package/dist/chunk-UAIOHCUK.js +27 -0
  161. package/dist/chunk-UAIOHCUK.js.map +1 -0
  162. package/dist/chunk-UPAMRDX4.js +233 -0
  163. package/dist/chunk-UPAMRDX4.js.map +1 -0
  164. package/dist/chunk-VQRS7VUC.js +342 -0
  165. package/dist/chunk-VQRS7VUC.js.map +1 -0
  166. package/dist/chunk-X3BTXCJ4.js +262 -0
  167. package/dist/chunk-X3BTXCJ4.js.map +1 -0
  168. package/dist/chunk-X5YKXC6V.js +211 -0
  169. package/dist/chunk-X5YKXC6V.js.map +1 -0
  170. package/dist/chunk-Y6O2OCUO.js +130 -0
  171. package/dist/chunk-Y6O2OCUO.js.map +1 -0
  172. package/dist/chunk-YCGY7UIZ.js +208 -0
  173. package/dist/chunk-YCGY7UIZ.js.map +1 -0
  174. package/dist/chunk-Z7ML6L77.js +162 -0
  175. package/dist/chunk-Z7ML6L77.js.map +1 -0
  176. package/dist/chunk-ZEWMTR5M.js +136 -0
  177. package/dist/chunk-ZEWMTR5M.js.map +1 -0
  178. package/dist/index.d.ts +355 -0
  179. package/dist/index.js +1908 -0
  180. package/dist/index.js.map +1 -0
  181. package/package.json +26 -9
  182. package/scripts/run-package-tests.mjs +30 -8
  183. package/scripts/verify-packed-consumer.mjs +12 -1
  184. package/scripts/verify-pier-agent.mts +1 -0
  185. package/src/benchmarks/humaneval.test.mts +122 -0
  186. package/src/benchmarks/humaneval.ts +100 -27
  187. package/src/david-attribution.mts +78 -0
  188. package/src/david-goliath.mts +149 -0
  189. package/src/hev-improve.mts +25 -6
  190. package/src/humaneval-object-ablation.mts +201 -0
  191. package/src/live-improve-campaign-mbpp.mts +641 -0
  192. package/src/live-improve-campaign.mts +500 -0
  193. package/src/mbpp-structural.mts +12 -7
  194. package/src/stream-observe.py +45 -0
  195. package/src/stream-observe.tpl.html +247 -0
  196. package/src/supervisor-arena.mts +816 -0
  197. package/src/swe-arena/analyze.ts +211 -0
  198. package/src/swe-arena/arms.ts +788 -0
  199. package/src/swe-arena/bootstrap-meta.mts +188 -0
  200. package/src/swe-arena/bootstrap-meta.test.mts +51 -0
  201. package/src/swe-arena/calibrate.ts +116 -0
  202. package/src/swe-arena/capabilities.mts +76 -0
  203. package/src/swe-arena/capabilities.test.mts +57 -0
  204. package/src/swe-arena/capacity.ts +194 -0
  205. package/src/swe-arena/cell-evidence.mts +405 -0
  206. package/src/swe-arena/cell-evidence.test.mts +248 -0
  207. package/src/swe-arena/diagnosis-ensemble.test.mts +210 -0
  208. package/src/swe-arena/diagnosis-ensemble.ts +520 -0
  209. package/src/swe-arena/execution.test.mts +1170 -0
  210. package/src/swe-arena/fixtures/analyze.py +80 -0
  211. package/src/swe-arena/fixtures/excludes.txt +8 -0
  212. package/src/swe-arena/fixtures/gen1-salvage/README.md +45 -0
  213. package/src/swe-arena/fixtures/gen1-salvage/cand0-e6d7361.diff +116 -0
  214. package/src/swe-arena/fixtures/gen1-salvage/cand1-76a8590.diff +293 -0
  215. package/src/swe-arena/fixtures/holdout-preregister.log +12 -0
  216. package/src/swe-arena/fixtures/holdout.json +44 -0
  217. package/src/swe-arena/fixtures/instances.json +146 -0
  218. package/src/swe-arena/fixtures/ledger.jsonl +12 -0
  219. package/src/swe-arena/fixtures/patches/pallets__flask-5014.solo.patch +36 -0
  220. package/src/swe-arena/fixtures/patches/pydata__xarray-4687.sup.patch +33 -0
  221. package/src/swe-arena/fixtures/rejudge.jsonl +15 -0
  222. package/src/swe-arena/fixtures/rematch.jsonl +3 -0
  223. package/src/swe-arena/fixtures/rematch2.jsonl +3 -0
  224. package/src/swe-arena/fixtures/rematch3.jsonl +3 -0
  225. package/src/swe-arena/fixtures/sup-journal-true.json +19 -0
  226. package/src/swe-arena/fixtures/verify/astropy__astropy-13033.sh +48 -0
  227. package/src/swe-arena/fixtures/verify/django__django-11532.sh +50 -0
  228. package/src/swe-arena/fixtures/verify/matplotlib__matplotlib-20826.sh +76 -0
  229. package/src/swe-arena/fixtures/verify/pydata__xarray-4687.sh +44 -0
  230. package/src/swe-arena/fixtures/verify/pytest-dev__pytest-6197.sh +32 -0
  231. package/src/swe-arena/fixtures/verify/sphinx-doc__sphinx-9658.sh +51 -0
  232. package/src/swe-arena/fixtures/worker-tokens.json +42 -0
  233. package/src/swe-arena/fixtures.ts +104 -0
  234. package/src/swe-arena/holdout-certify.mts +408 -0
  235. package/src/swe-arena/holdout-certify.test.mts +160 -0
  236. package/src/swe-arena/judge-child.mts +37 -0
  237. package/src/swe-arena/manifest.mts +293 -0
  238. package/src/swe-arena/manifest.test.mts +169 -0
  239. package/src/swe-arena/materialize.ts +142 -0
  240. package/src/swe-arena/outer-loop.mts +2145 -0
  241. package/src/swe-arena/outer-loop.test.mts +696 -0
  242. package/src/swe-arena/parity.test.mts +87 -0
  243. package/src/swe-arena/proc.test.mts +174 -0
  244. package/src/swe-arena/proc.ts +260 -0
  245. package/src/swe-arena/profiles/default-author.profile.json +4 -0
  246. package/src/swe-arena/proposer-fanout.mts +489 -0
  247. package/src/swe-arena/proposer-fanout.test.mts +372 -0
  248. package/src/swe-arena/reconcile.ts +0 -0
  249. package/src/swe-arena/replay.mts +183 -0
  250. package/src/swe-arena/replay.test.mts +300 -0
  251. package/src/swe-arena/run-experiment.mts +361 -0
  252. package/src/swe-arena/run-supervisor.mjs +297 -0
  253. package/src/swe-arena/run-supervisor.test.mts +498 -0
  254. package/src/swe-arena/serialized-judge.ts +414 -0
  255. package/src/swe-arena/types.ts +166 -0
  256. package/src/swe-code-improve.mts +328 -0
  257. package/src/swe-emit-patch.mts +104 -0
  258. package/src/swe-improve.mts +232 -0
  259. package/src/swe-jail.ts +2 -2
  260. package/src/swe-local-proof.mts +169 -0
  261. package/src/swe-repro-calibrate.mts +446 -0
  262. package/src/swe-stream.mts +1497 -0
@@ -0,0 +1,51 @@
1
+ set -euo pipefail
2
+ IMG="swebench/sweb.eval.x86_64.sphinx-doc_1776_sphinx-9658:latest"
3
+ WS="${1:-$PWD}"
4
+ TMP="$(mktemp -d)"
5
+ trap 'rm -rf "$TMP"' EXIT
6
+ mkdir -p "$TMP/proj"
7
+ cat > "$TMP/proj/conf.py" <<'PY'
8
+ import os
9
+ import sys
10
+
11
+ sys.path.insert(0, os.path.abspath('.'))
12
+ extensions = ['sphinx.ext.autodoc']
13
+ # The issue: a class inheriting from a MOCKED base is documented with a
14
+ # truncated "Bases" entry ("mocklib.nn." instead of "mocklib.nn.Module").
15
+ autodoc_mock_imports = ['mocklib']
16
+ PY
17
+ cat > "$TMP/proj/mymod.py" <<'PY'
18
+ import mocklib
19
+
20
+
21
+ class DeepKernel(mocklib.nn.Module):
22
+ """A kernel inheriting a mocked torch-style base class."""
23
+ PY
24
+ cat > "$TMP/proj/index.rst" <<'RST'
25
+ Test
26
+ ====
27
+
28
+ .. autoclass:: mymod.DeepKernel
29
+ :show-inheritance:
30
+ RST
31
+ cat > "$TMP/repro.sh" <<'SH'
32
+ set -u
33
+ PROJ="$(mktemp -d)"
34
+ cp /repro/proj/* "$PROJ"/
35
+ OUT="$(mktemp -d)"
36
+ PYTHONPATH=/testbed python -m sphinx -b text -q "$PROJ" "$OUT" || {
37
+ echo "VERIFY FAIL: sphinx build errored"
38
+ exit 1
39
+ }
40
+ cat "$OUT/index.txt"
41
+ if grep -q 'mocklib\.nn\.Module' "$OUT/index.txt"; then
42
+ echo "VERIFY PASS: mocked base class documented as mocklib.nn.Module"
43
+ exit 0
44
+ fi
45
+ echo "VERIFY FAIL: Bases entry does not name mocklib.nn.Module (mocked base truncated)"
46
+ exit 1
47
+ SH
48
+ exec timeout -k 10 240 docker run --rm --network none \
49
+ -v "$WS":/testbed:ro -v "$TMP":/repro:ro -w /testbed \
50
+ -e PYTHONDONTWRITEBYTECODE=1 \
51
+ "$IMG" bash -lc 'source /opt/miniconda3/etc/profile.d/conda.sh && conda activate testbed && timeout -s KILL 180 bash /repro/repro.sh'
@@ -0,0 +1,42 @@
1
+ {
2
+ "astropy__astropy-13033": {
3
+ "worker_sessions": 3,
4
+ "worker_tok": 180000
5
+ },
6
+ "django__django-11532": {
7
+ "worker_sessions": 4,
8
+ "worker_tok": 287038
9
+ },
10
+ "matplotlib__matplotlib-20826": {
11
+ "worker_sessions": 3,
12
+ "worker_tok": 242121
13
+ },
14
+ "pallets__flask-5014": {
15
+ "worker_sessions": 1,
16
+ "worker_tok": 46737
17
+ },
18
+ "psf__requests-1766": {
19
+ "worker_sessions": 2,
20
+ "worker_tok": 67541
21
+ },
22
+ "psf__requests-2317": {
23
+ "worker_sessions": 1,
24
+ "worker_tok": 57555
25
+ },
26
+ "psf__requests-2931": {
27
+ "worker_sessions": 2,
28
+ "worker_tok": 124545
29
+ },
30
+ "pydata__xarray-4687": {
31
+ "worker_sessions": 1,
32
+ "worker_tok": 64243
33
+ },
34
+ "sympy__sympy-14976": {
35
+ "worker_sessions": 1,
36
+ "worker_tok": 55937
37
+ },
38
+ "sympy__sympy-23534": {
39
+ "worker_sessions": 1,
40
+ "worker_tok": 36119
41
+ }
42
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Hermetic fixture loaders. All artifacts live under `./fixtures/` (copied
3
+ * from the live experiment's scratchpad on 2026-07-15 so the replay survives
4
+ * scratchpad deletion). Loaders fail loud on shape drift — a silent default
5
+ * here would let the pinned reproduction pass against corrupted fixtures.
6
+ */
7
+
8
+ import { readFileSync } from 'node:fs'
9
+ import { fileURLToPath } from 'node:url'
10
+ import type {
11
+ HoldoutEntry,
12
+ HoldoutRegistry,
13
+ LedgerRow,
14
+ RejudgeRow,
15
+ RematchRow,
16
+ WorkerTokens,
17
+ } from './types'
18
+
19
+ const fixturePath = (name: string): string =>
20
+ fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url))
21
+
22
+ export function readFixture(name: string): string {
23
+ return readFileSync(fixturePath(name), 'utf8')
24
+ }
25
+
26
+ function parseJsonl<T>(name: string): T[] {
27
+ return readFixture(name)
28
+ .split('\n')
29
+ .filter((l) => l.trim().length > 0)
30
+ .map((l, i) => {
31
+ try {
32
+ return JSON.parse(l) as T
33
+ } catch (err) {
34
+ throw new Error(`${name}:${i + 1}: invalid JSON — ${(err as Error).message}`)
35
+ }
36
+ })
37
+ }
38
+
39
+ export function loadLedger(): LedgerRow[] {
40
+ const rows = parseJsonl<LedgerRow>('ledger.jsonl')
41
+ for (const r of rows) {
42
+ if (typeof r.iid !== 'string' || typeof r.solo_resolved !== 'boolean') {
43
+ throw new Error(`ledger.jsonl: malformed row ${JSON.stringify(r).slice(0, 80)}`)
44
+ }
45
+ }
46
+ return rows
47
+ }
48
+
49
+ export function loadRejudge(): RejudgeRow[] {
50
+ const rows = parseJsonl<RejudgeRow>('rejudge.jsonl')
51
+ for (const r of rows) {
52
+ if (typeof r.iid !== 'string' || typeof r.tag !== 'string') {
53
+ throw new Error(`rejudge.jsonl: malformed row ${JSON.stringify(r).slice(0, 80)}`)
54
+ }
55
+ }
56
+ return rows
57
+ }
58
+
59
+ /** Evolution rounds in order: SUP2, SUP3, SUP4. */
60
+ export function loadRematchRounds(): RematchRow[][] {
61
+ return ['rematch.jsonl', 'rematch2.jsonl', 'rematch3.jsonl'].map((f) => parseJsonl<RematchRow>(f))
62
+ }
63
+
64
+ export function loadHoldout(): HoldoutRegistry {
65
+ const entries = JSON.parse(readFixture('holdout.json')) as HoldoutEntry[]
66
+ if (!Array.isArray(entries) || entries.length === 0) {
67
+ throw new Error('holdout.json: expected a non-empty array')
68
+ }
69
+ const commits = new Set(entries.map((e) => e.selected_at_commit))
70
+ if (commits.size !== 1) {
71
+ throw new Error(`holdout.json: expected one selection commit, got ${[...commits].join(', ')}`)
72
+ }
73
+ return { entries, selectedAtCommit: entries[0].selected_at_commit }
74
+ }
75
+
76
+ export function loadPreregisterLog(): string[] {
77
+ return readFixture('holdout-preregister.log')
78
+ .split('\n')
79
+ .filter((l) => l.trim().length > 0)
80
+ }
81
+
82
+ /** Per-instance worker-session token spend (instances with 0 workers are absent). */
83
+ export function loadWorkerTokens(): Record<string, WorkerTokens> {
84
+ return JSON.parse(readFixture('worker-tokens.json')) as Record<string, WorkerTokens>
85
+ }
86
+
87
+ /**
88
+ * Journal-true supervisor brain tokens per instance — extracted from the
89
+ * supervisor journals' `metered` events with the same logic as
90
+ * `analyze.py::_true_sup_tok`, captured into a fixture because the raw
91
+ * journals (runs/) are too large to commit. `null` = no journal found.
92
+ */
93
+ export function loadSupJournalTrue(): Record<string, number | null> {
94
+ const raw = JSON.parse(readFixture('sup-journal-true.json')) as Record<string, unknown>
95
+ const out: Record<string, number | null> = {}
96
+ for (const [k, v] of Object.entries(raw)) {
97
+ if (k === '_provenance') continue
98
+ if (v !== null && typeof v !== 'number') {
99
+ throw new Error(`sup-journal-true.json: ${k} must be number|null`)
100
+ }
101
+ out[k] = v as number | null
102
+ }
103
+ return out
104
+ }
@@ -0,0 +1,408 @@
1
+ /**
2
+ * 2-rep holdout certification — the operator-approved run that decides whether
3
+ * a would-be-KEEP winner ships. Encodes the gen-2 postmortem: the winner
4
+ * failed certification 3/6 vs 4/6 on a ONE-REP holdout with exactly one
5
+ * discordant cell — a known single-rep noise class — so the protocol now
6
+ * pins:
7
+ *
8
+ * - `holdoutRepsPerInstance` (default 2) replicate cells per instance,
9
+ * - resolved = ALL reps resolved (fail-closed, identical to the improvement
10
+ * set's AND-rule in cell-evidence.mts),
11
+ * - the certification bar compares against a SAME-PROTOCOL parent
12
+ * measurement: `config.holdoutBaseline` is either an explicit
13
+ * `{iid -> bool}` verdict map measured under this exact protocol, or
14
+ * 'measure' — the incumbent runs the same 2-rep holdout FIRST in this run.
15
+ *
16
+ * Certification rule (pre-registered, gen-2 bar unchanged in kind):
17
+ * non-regression — the candidate's AND-resolved count must be >= the parent's,
18
+ * with complete conclusive coverage on the candidate side. The improvement-set
19
+ * gate already demanded a strict gain; the holdout certifies that the gain did
20
+ * not cost held-out performance.
21
+ *
22
+ * The operator-release valve is unchanged: the outer loop always runs with
23
+ * `holdout: 'deferred'` and only reports a would-be-KEEP brief; THIS module is
24
+ * the separate, operator-fired run:
25
+ *
26
+ * tsx src/swe-arena/holdout-certify.mts <config.json> --candidate <loops-commit> [--out <dir>]
27
+ */
28
+
29
+ import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises'
30
+ import { existsSync } from 'node:fs'
31
+ import { join } from 'node:path'
32
+ import { pathToFileURL } from 'node:url'
33
+ import process from 'node:process'
34
+ import { createSweBenchAdapter } from '../benchmarks/swe-bench.ts'
35
+ import { loadExcludes, runSupervisorArm, type SecretsEnv, type SupervisorArmSpec } from './arms.ts'
36
+ import { gatesForArmKind, waitForCapacity } from './capacity.ts'
37
+ import {
38
+ replicateCoverageComplete,
39
+ resolvedInstanceCount,
40
+ type ReplicateRun,
41
+ } from './cell-evidence.mts'
42
+ import {
43
+ acquireInstanceLock,
44
+ addEvalWorktree,
45
+ assertFrozenArm,
46
+ assertLaunchEnv,
47
+ removeEvalWorktree,
48
+ runWithPostGateClock,
49
+ type OuterLoopConfig,
50
+ } from './outer-loop.mts'
51
+ import { installProcessSignalAbort, runOk } from './proc.ts'
52
+ import { loadInstanceImages } from './run-experiment.mts'
53
+ import { createSerializedJudge, type SerializedJudge } from './serialized-judge.ts'
54
+
55
+ // ---------------------------------------------------------------------------
56
+ // Pure protocol pieces — unit-tested against synthetic replicate runs.
57
+ // ---------------------------------------------------------------------------
58
+
59
+ export const DEFAULT_HOLDOUT_REPS = 2
60
+
61
+ export function holdoutReps(config: Pick<OuterLoopConfig, 'holdoutRepsPerInstance'>): number {
62
+ const reps = config.holdoutRepsPerInstance ?? DEFAULT_HOLDOUT_REPS
63
+ if (!Number.isInteger(reps) || reps < 1) {
64
+ throw new Error(`holdout-certify: holdoutRepsPerInstance must be a positive integer, got ${JSON.stringify(reps)}`)
65
+ }
66
+ return reps
67
+ }
68
+
69
+ /** Validate an explicit same-protocol parent verdict map: every holdout
70
+ * instance must carry a boolean (a partial map cannot anchor the bar). */
71
+ export function assertHoldoutBaselineMap(
72
+ baseline: Record<string, boolean>,
73
+ holdoutInstances: string[],
74
+ ): void {
75
+ const missing = holdoutInstances.filter((iid) => typeof baseline[iid] !== 'boolean')
76
+ if (missing.length > 0) {
77
+ throw new Error(
78
+ `holdout-certify: holdoutBaseline map is missing same-protocol verdicts for: ${missing.join(', ')} — ` +
79
+ "provide all instances or use holdoutBaseline: 'measure'",
80
+ )
81
+ }
82
+ const extras = Object.keys(baseline).filter((iid) => !holdoutInstances.includes(iid))
83
+ if (extras.length > 0) {
84
+ throw new Error(`holdout-certify: holdoutBaseline names non-holdout instances: ${extras.join(', ')}`)
85
+ }
86
+ }
87
+
88
+ export interface HoldoutCertification {
89
+ candResolved: number
90
+ parentResolved: number
91
+ coverageComplete: boolean
92
+ certified: boolean
93
+ reasons: string[]
94
+ perInstance: Array<{ iid: string; candidate: boolean | null; parent: boolean | null; discordant: boolean }>
95
+ }
96
+
97
+ /** The certification decision over fail-closed AND-verdicts. Pure. */
98
+ export function decideHoldoutCertification(input: {
99
+ candidateRuns: ReplicateRun[]
100
+ /** Parent AND-verdict per instance, measured under the SAME protocol
101
+ * (reps, fail-closed rule). */
102
+ parentVerdicts: Record<string, boolean>
103
+ iids: string[]
104
+ reps: number
105
+ }): HoldoutCertification {
106
+ const { candidateRuns, parentVerdicts, iids, reps } = input
107
+ assertHoldoutBaselineMap(parentVerdicts, iids)
108
+ const candResolved = resolvedInstanceCount(candidateRuns, iids, reps)
109
+ const parentResolved = iids.filter((iid) => parentVerdicts[iid] === true).length
110
+ const coverageComplete = replicateCoverageComplete(candidateRuns, iids, reps)
111
+ const perInstance = iids.map((iid) => {
112
+ const mine = candidateRuns.filter((r) => r.iid === iid)
113
+ const candidate =
114
+ mine.length === reps && mine.every((r) => r.resolved !== null)
115
+ ? mine.every((r) => r.resolved === true)
116
+ : null
117
+ const parent = parentVerdicts[iid] ?? null
118
+ return { iid, candidate, parent, discordant: candidate !== null && parent !== null && candidate !== parent }
119
+ })
120
+ const reasons: string[] = []
121
+ if (!coverageComplete) reasons.push(`candidate coverage incomplete: not every instance has ${reps} conclusive reps`)
122
+ if (candResolved < parentResolved) {
123
+ reasons.push(`regression: candidate ${candResolved} < parent ${parentResolved} (same-protocol AND-verdicts)`)
124
+ }
125
+ const certified = coverageComplete && candResolved >= parentResolved
126
+ if (certified) reasons.push(`non-regression met: candidate ${candResolved} >= parent ${parentResolved} at ${reps} reps, fail-closed`)
127
+ return { candResolved, parentResolved, coverageComplete, certified, reasons, perInstance }
128
+ }
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // The runner — real arms + the official judge, resumable per (commit,iid,rep).
132
+ // ---------------------------------------------------------------------------
133
+
134
+ export interface HoldoutCellRow {
135
+ schema: 'swe-arena.holdout-cell.v1'
136
+ at: string
137
+ commit: string
138
+ side: 'candidate' | 'parent'
139
+ iid: string
140
+ rep: number
141
+ resolved: boolean | null
142
+ verifyPass: boolean | null
143
+ wallS: number | null
144
+ runDir: string
145
+ error?: string
146
+ }
147
+
148
+ /** Read prior cells (resume): conclusive rows are reused, inconclusive re-run. */
149
+ export async function loadHoldoutCells(cellsPath: string): Promise<HoldoutCellRow[]> {
150
+ if (!existsSync(cellsPath)) return []
151
+ const raw = await readFile(cellsPath, 'utf8')
152
+ return raw
153
+ .split('\n')
154
+ .filter((l) => l.trim().length > 0)
155
+ .map((l) => JSON.parse(l) as HoldoutCellRow)
156
+ .filter((r) => r.schema === 'swe-arena.holdout-cell.v1')
157
+ }
158
+
159
+ const log = (msg: string): void => console.log(`[${new Date().toISOString().slice(11, 19)}] ${msg}`)
160
+
161
+ export async function runHoldoutCertification(
162
+ config: OuterLoopConfig,
163
+ opts: { candidateCommit: string; outDir?: string },
164
+ signal?: AbortSignal,
165
+ ): Promise<HoldoutCertification> {
166
+ signal?.throwIfAborted()
167
+ assertFrozenArm(config.arm)
168
+ const reps = holdoutReps(config)
169
+ const iids = config.holdoutInstances
170
+ if (iids.length === 0) throw new Error('holdout-certify: empty holdout set')
171
+ const outDir = opts.outDir ?? join(config.outDir, 'holdout-certification')
172
+ await mkdir(outDir, { recursive: true })
173
+ const cellsPath = join(outDir, 'cells.jsonl')
174
+
175
+ const secrets: SecretsEnv = { secretsDir: config.secretsDir, envFiles: config.envFiles }
176
+ const excludes = await loadExcludes()
177
+ const images = await loadInstanceImages(config.instanceImagesPath)
178
+ const adapter = createSweBenchAdapter()
179
+ const tasks = await adapter.loadTasks({ ids: iids, split: 'test' })
180
+ const problemById = new Map<string, string>()
181
+ for (const iid of iids) {
182
+ const task = tasks.find((t) => t.id === iid)
183
+ if (!task) throw new Error(`holdout-certify: ${iid} not found in SWE-bench_Verified`)
184
+ const problem = String(task.metadata?.problem_statement ?? '')
185
+ if (!problem) throw new Error(`holdout-certify: ${iid} has an empty problem_statement`)
186
+ if (!images[iid]) throw new Error(`holdout-certify: ${iid} has no image mapping`)
187
+ if (!existsSync(join(config.verifyDir, `${iid}.sh`))) {
188
+ throw new Error(`holdout-certify: missing verify script ${join(config.verifyDir, `${iid}.sh`)}`)
189
+ }
190
+ problemById.set(iid, problem)
191
+ }
192
+
193
+ const judge: SerializedJudge = createSerializedJudge(
194
+ config.judgeTimeoutMs !== undefined ? { timeoutMs: config.judgeTimeoutMs } : {},
195
+ )
196
+ const prior = await loadHoldoutCells(cellsPath)
197
+
198
+ const awaitGates = async (gateSignal: AbortSignal | undefined = signal): Promise<void> => {
199
+ for (const gate of gatesForArmKind('supervisor', secrets, {
200
+ ...(config.gateWaitCeilingMs !== undefined ? { waitCeilingMs: config.gateWaitCeilingMs } : {}),
201
+ ...(config.capacityModel !== undefined ? { model: config.capacityModel } : {}),
202
+ onStatus: log,
203
+ })) {
204
+ if (!(await waitForCapacity(gate, gateSignal))) throw new Error(`no capacity on ${gate.name} within ceiling`)
205
+ }
206
+ }
207
+
208
+ const runSide = async (side: 'candidate' | 'parent', commit: string): Promise<ReplicateRun[]> => {
209
+ signal?.throwIfAborted()
210
+ const runs: ReplicateRun[] = []
211
+ for (const iid of iids) {
212
+ for (let rep = 0; rep < reps; rep++) {
213
+ signal?.throwIfAborted()
214
+ const cached = prior.find(
215
+ (r) => r.side === side && r.commit === commit && r.iid === iid && r.rep === rep && r.resolved !== null,
216
+ )
217
+ if (cached) {
218
+ log(`holdout ${side} ${iid} rep=${rep}: cached resolved=${cached.resolved}`)
219
+ runs.push({ iid, resolved: cached.resolved })
220
+ continue
221
+ }
222
+ const tag = `${side}-${commit.slice(0, 10)}`
223
+ const evalWt = join(outDir, 'eval-wt', `${tag}-${iid}-r${rep}`)
224
+ const armOutDir = join(outDir, 'arm-runs', tag, iid, `rep-${rep}`)
225
+ let row: HoldoutCellRow
226
+ try {
227
+ try {
228
+ await addEvalWorktree(config.loopsRepo, commit, evalWt, signal)
229
+ const spec: SupervisorArmSpec = {
230
+ kind: 'supervisor',
231
+ name: config.armName,
232
+ workerModel: config.arm.workerModel,
233
+ driverModel: config.arm.driverModel,
234
+ budget: config.arm.budget,
235
+ maxSandboxes: config.arm.maxSandboxes,
236
+ maxUsd: config.arm.maxUsd,
237
+ maxDepth: config.arm.maxDepth,
238
+ ...(config.arm.envKnobs ? { envKnobs: config.arm.envKnobs } : {}),
239
+ loopsRepo: evalWt,
240
+ extensionPath: join(evalWt, 'extensions', 'pi', 'loops.ts'),
241
+ timeoutMs: config.arm.timeoutMs,
242
+ }
243
+ log(`>>> holdout ${side} ${iid} rep=${rep} @ ${commit.slice(0, 10)}`)
244
+ const entry = images[iid]!
245
+ const { armRes, verdict } = await runWithPostGateClock({
246
+ awaitGates,
247
+ work: async (signal) => {
248
+ const armRes = await runSupervisorArm(spec, {
249
+ instanceId: iid,
250
+ image: entry.image,
251
+ baseCommit: entry.base_commit,
252
+ problemStatement: problemById.get(iid)!,
253
+ verifyCmd: `bash ${join(config.verifyDir, `${iid}.sh`)}`,
254
+ outDir: armOutDir,
255
+ secrets,
256
+ excludes,
257
+ signal,
258
+ })
259
+ signal.throwIfAborted()
260
+ const verdict = await judge.judge(iid, armRes.patchPath, `holdout-${tag}`, signal)
261
+ return { armRes, verdict }
262
+ },
263
+ timeoutMs: config.dispatchTimeoutMs,
264
+ label: `holdout ${side} ${iid} r${rep}`,
265
+ signal,
266
+ })
267
+ row = {
268
+ schema: 'swe-arena.holdout-cell.v1',
269
+ at: new Date().toISOString(),
270
+ commit,
271
+ side,
272
+ iid,
273
+ rep,
274
+ resolved: verdict.resolved,
275
+ verifyPass: armRes.verify_pass,
276
+ wallS: armRes.wall_s,
277
+ runDir: join(armOutDir, 'runs', iid, config.armName),
278
+ ...(verdict.resolved === null ? { error: verdict.error ?? 'inconclusive judge verdict' } : {}),
279
+ }
280
+ } finally {
281
+ await removeEvalWorktree(config.loopsRepo, evalWt)
282
+ }
283
+ } catch (cause) {
284
+ if (signal?.aborted) throw cause
285
+ // An errored cell is an INCONCLUSIVE replicate (resolved: null) —
286
+ // fail-closed downstream, never a fabricated boolean.
287
+ row = {
288
+ schema: 'swe-arena.holdout-cell.v1',
289
+ at: new Date().toISOString(),
290
+ commit,
291
+ side,
292
+ iid,
293
+ rep,
294
+ resolved: null,
295
+ verifyPass: null,
296
+ wallS: null,
297
+ runDir: armOutDir,
298
+ error: (cause as Error).message,
299
+ }
300
+ }
301
+ await appendFile(cellsPath, JSON.stringify(row) + '\n')
302
+ log(`holdout ${side} ${iid} rep=${rep}: resolved=${row.resolved}${row.error ? ` (${row.error})` : ''}`)
303
+ runs.push({ iid, resolved: row.resolved })
304
+ }
305
+ }
306
+ return runs
307
+ }
308
+
309
+ // SAME-PROTOCOL parent verdicts: an explicit operator-provided map, or the
310
+ // incumbent measured FIRST under the identical 2-rep fail-closed protocol.
311
+ let parentVerdicts: Record<string, boolean>
312
+ let parentSource: 'provided' | 'measured'
313
+ let parentCommit: string | null = null
314
+ const baseline = config.holdoutBaseline ?? 'measure'
315
+ if (baseline !== 'measure') {
316
+ assertHoldoutBaselineMap(baseline, iids)
317
+ parentVerdicts = baseline
318
+ parentSource = 'provided'
319
+ } else {
320
+ parentCommit = (
321
+ await runOk('git', ['-C', config.loopsRepo, 'rev-parse', config.loopsBaseRef], { signal })
322
+ ).stdout.trim()
323
+ log(`holdout parent: measuring incumbent ${parentCommit.slice(0, 10)} under the same ${reps}-rep protocol`)
324
+ const parentRuns = await runSide('parent', parentCommit)
325
+ parentVerdicts = {}
326
+ for (const iid of iids) {
327
+ const mine = parentRuns.filter((r) => r.iid === iid)
328
+ // Fail-closed: an inconclusive/missing parent replicate reads as NOT
329
+ // resolved for the parent — it can only make the bar EASIER, never
330
+ // stricter, so a broken parent measurement cannot fail a good candidate.
331
+ parentVerdicts[iid] = mine.length === reps && mine.every((r) => r.resolved === true)
332
+ }
333
+ parentSource = 'measured'
334
+ }
335
+
336
+ const candidateRuns = await runSide('candidate', opts.candidateCommit)
337
+ signal?.throwIfAborted()
338
+ const decision = decideHoldoutCertification({ candidateRuns, parentVerdicts, iids, reps })
339
+
340
+ const record = {
341
+ schema: 'swe-arena.holdout-certification.v1',
342
+ at: new Date().toISOString(),
343
+ round: config.round,
344
+ reps,
345
+ instances: iids,
346
+ candidateCommit: opts.candidateCommit,
347
+ parent: { source: parentSource, commit: parentCommit, verdicts: parentVerdicts },
348
+ ...decision,
349
+ }
350
+ const recordPath = join(outDir, `certification-${opts.candidateCommit.slice(0, 10)}.json`)
351
+ await writeFile(recordPath, JSON.stringify(record, null, 2))
352
+ log(
353
+ `holdout certification: candidate ${decision.candResolved}/${iids.length} vs parent ` +
354
+ `${decision.parentResolved}/${iids.length} at ${reps} reps — ${decision.certified ? 'CERTIFIED' : 'NOT CERTIFIED'}`,
355
+ )
356
+ for (const r of decision.reasons) log(` - ${r}`)
357
+ log(`certification record → ${recordPath}`)
358
+ signal?.throwIfAborted()
359
+ return decision
360
+ }
361
+
362
+ // ---------------------------------------------------------------------------
363
+ // CLI.
364
+ // ---------------------------------------------------------------------------
365
+
366
+ const isMain = process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href
367
+
368
+ if (isMain) {
369
+ const interrupt = installProcessSignalAbort('holdout-certify')
370
+ try {
371
+ const argv = process.argv.slice(2)
372
+ const configPath = argv[0]
373
+ const flag = (name: string): string | undefined => {
374
+ const i = argv.indexOf(name)
375
+ return i !== -1 ? argv[i + 1] : undefined
376
+ }
377
+ const candidate = flag('--candidate')
378
+ if (!configPath || configPath.startsWith('--') || !candidate) {
379
+ console.error(
380
+ 'usage: tsx src/swe-arena/holdout-certify.mts <config.json> --candidate <loops-commit> [--out <dir>] # SPENDS: arms + judges',
381
+ )
382
+ process.exit(2)
383
+ }
384
+ const config = JSON.parse(await readFile(configPath, 'utf8')) as OuterLoopConfig
385
+ assertLaunchEnv()
386
+ interrupt.signal.throwIfAborted()
387
+ const out = flag('--out')
388
+ const lockDir = out ?? join(config.outDir, 'holdout-certification')
389
+ await mkdir(lockDir, { recursive: true })
390
+ const lock = await acquireInstanceLock(lockDir)
391
+ try {
392
+ const decision = await runHoldoutCertification(config, {
393
+ candidateCommit: candidate,
394
+ ...(out ? { outDir: out } : {}),
395
+ }, interrupt.signal)
396
+ interrupt.signal.throwIfAborted()
397
+ process.exitCode = decision.certified ? 0 : 1
398
+ } finally {
399
+ await lock.release()
400
+ }
401
+ } catch (cause) {
402
+ if (!interrupt.signal.aborted) throw cause
403
+ const detail = cause instanceof Error ? cause.message : String(cause)
404
+ console.error(`holdout-certify stopped after cleanup: ${detail}`)
405
+ } finally {
406
+ interrupt.dispose()
407
+ }
408
+ }