@tangle-network/agent-bench 0.11.2 → 0.13.0

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 (174) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/HARNESS.md +6 -2
  3. package/README.md +1 -4
  4. package/dist/benchmarks/swe-bench.js +4 -9
  5. package/dist/benchmarks/swe-bench.js.map +1 -1
  6. package/package.json +5 -5
  7. package/scripts/run-package-tests.mjs +2 -2
  8. package/src/benchmarks/swe-bench.test.mts +49 -0
  9. package/src/benchmarks/swe-bench.ts +4 -9
  10. package/src/quant-arena/README.md +0 -144
  11. package/src/quant-arena/backtest.test.mts +0 -135
  12. package/src/quant-arena/backtest.ts +0 -218
  13. package/src/quant-arena/data.test.mts +0 -44
  14. package/src/quant-arena/data.ts +0 -141
  15. package/src/quant-arena/driver.test.mts +0 -253
  16. package/src/quant-arena/driver.ts +0 -219
  17. package/src/quant-arena/fixtures/data/PROVENANCE.md +0 -26
  18. package/src/quant-arena/fixtures/data/holdout/IDX.csv +0 -523
  19. package/src/quant-arena/fixtures/data/holdout/S01.csv +0 -523
  20. package/src/quant-arena/fixtures/data/holdout/S02.csv +0 -523
  21. package/src/quant-arena/fixtures/data/holdout/S03.csv +0 -523
  22. package/src/quant-arena/fixtures/data/holdout/S04.csv +0 -523
  23. package/src/quant-arena/fixtures/data/holdout/S05.csv +0 -523
  24. package/src/quant-arena/fixtures/data/holdout/S06.csv +0 -523
  25. package/src/quant-arena/fixtures/data/holdout/S07.csv +0 -523
  26. package/src/quant-arena/fixtures/data/holdout/S08.csv +0 -523
  27. package/src/quant-arena/fixtures/data/holdout/S09.csv +0 -523
  28. package/src/quant-arena/fixtures/data/holdout/S10.csv +0 -523
  29. package/src/quant-arena/fixtures/data/insample/IDX.csv +0 -2087
  30. package/src/quant-arena/fixtures/data/insample/S01.csv +0 -2087
  31. package/src/quant-arena/fixtures/data/insample/S02.csv +0 -2087
  32. package/src/quant-arena/fixtures/data/insample/S03.csv +0 -2087
  33. package/src/quant-arena/fixtures/data/insample/S04.csv +0 -2087
  34. package/src/quant-arena/fixtures/data/insample/S05.csv +0 -2087
  35. package/src/quant-arena/fixtures/data/insample/S06.csv +0 -2087
  36. package/src/quant-arena/fixtures/data/insample/S07.csv +0 -2087
  37. package/src/quant-arena/fixtures/data/insample/S08.csv +0 -2087
  38. package/src/quant-arena/fixtures/data/insample/S09.csv +0 -2087
  39. package/src/quant-arena/fixtures/data/insample/S10.csv +0 -2087
  40. package/src/quant-arena/fixtures/demo-campaign/cost-ledger.jsonl +0 -16
  41. package/src/quant-arena/fixtures/demo-campaign/notebook.jsonl +0 -5
  42. package/src/quant-arena/fixtures/demo-campaign/rollout-manifest.json +0 -171
  43. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-001-default-author/strategy.ts +0 -119
  44. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-002-default-author/strategy.ts +0 -119
  45. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-003-quant-researcher/strategy.ts +0 -105
  46. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-004-quant-researcher/strategy.ts +0 -102
  47. package/src/quant-arena/fixtures/demo-campaign-v2/cost-ledger.jsonl +0 -4
  48. package/src/quant-arena/fixtures/demo-campaign-v2/notebook.jsonl +0 -2
  49. package/src/quant-arena/fixtures/demo-campaign-v2/rollout-manifest.json +0 -84
  50. package/src/quant-arena/fixtures/demo-campaign-v2/strategies/cand-001-quant-researcher/strategy.ts +0 -117
  51. package/src/quant-arena/holdout-certify.mts +0 -206
  52. package/src/quant-arena/holdout-certify.test.mts +0 -82
  53. package/src/quant-arena/leak-audit.test.mts +0 -79
  54. package/src/quant-arena/leak-audit.ts +0 -95
  55. package/src/quant-arena/make-fixtures.mts +0 -161
  56. package/src/quant-arena/multiplicity.test.mts +0 -68
  57. package/src/quant-arena/multiplicity.ts +0 -87
  58. package/src/quant-arena/nautilus-certify.ts +0 -31
  59. package/src/quant-arena/oms.ts +0 -90
  60. package/src/quant-arena/profiles/quant-researcher.profile.json +0 -12
  61. package/src/quant-arena/python/pyproject.toml +0 -8
  62. package/src/quant-arena/python/uv.lock +0 -1297
  63. package/src/quant-arena/python/vbt-worker.py +0 -192
  64. package/src/quant-arena/quant-loop.mts +0 -840
  65. package/src/quant-arena/quant-loop.test.mts +0 -75
  66. package/src/quant-arena/strategies/buy-hold-index/strategy.ts +0 -11
  67. package/src/quant-arena/strategies/equal-weight/strategy.ts +0 -20
  68. package/src/quant-arena/strategies/sma-crossover/strategy.ts +0 -42
  69. package/src/quant-arena/types.ts +0 -133
  70. package/src/quant-arena/vbt-client.ts +0 -321
  71. package/src/quant-arena/vbt-parity.test.mts +0 -183
  72. package/src/quant-arena/windows.test.mts +0 -45
  73. package/src/quant-arena/windows.ts +0 -54
  74. package/src/rollout-ledger/backfill-swe-arena.mts +0 -610
  75. package/src/rollout-ledger/backfill-swe-arena.test.mts +0 -347
  76. package/src/rollout-ledger/settle-capture.mts +0 -448
  77. package/src/rollout-ledger/settle-capture.test.mts +0 -270
  78. package/src/swe-arena/activation.mts +0 -225
  79. package/src/swe-arena/activation.test.mts +0 -300
  80. package/src/swe-arena/analyze.ts +0 -211
  81. package/src/swe-arena/arms.ts +0 -862
  82. package/src/swe-arena/bootstrap-meta.mts +0 -188
  83. package/src/swe-arena/bootstrap-meta.test.mts +0 -51
  84. package/src/swe-arena/briefing.mts +0 -217
  85. package/src/swe-arena/briefing.test.mts +0 -179
  86. package/src/swe-arena/calibrate.ts +0 -217
  87. package/src/swe-arena/capabilities.mts +0 -76
  88. package/src/swe-arena/capabilities.test.mts +0 -57
  89. package/src/swe-arena/capacity.ts +0 -198
  90. package/src/swe-arena/cell-evidence.mts +0 -437
  91. package/src/swe-arena/cell-evidence.test.mts +0 -248
  92. package/src/swe-arena/diagnosis-ensemble.test.mts +0 -210
  93. package/src/swe-arena/diagnosis-ensemble.ts +0 -523
  94. package/src/swe-arena/execution.test.mts +0 -1171
  95. package/src/swe-arena/factory-command-container.ts +0 -284
  96. package/src/swe-arena/factory-judge-child.mts +0 -228
  97. package/src/swe-arena/factory.test.mts +0 -645
  98. package/src/swe-arena/fixtures/analyze.py +0 -80
  99. package/src/swe-arena/fixtures/excludes.txt +0 -8
  100. package/src/swe-arena/fixtures/factory/agent-eval-309/calibration.md +0 -51
  101. package/src/swe-arena/fixtures/factory/agent-eval-309/manifest.json +0 -29
  102. package/src/swe-arena/fixtures/factory/agent-eval-309/spec.md +0 -64
  103. package/src/swe-arena/fixtures/factory/agent-runtime-232/calibration.md +0 -48
  104. package/src/swe-arena/fixtures/factory/agent-runtime-232/manifest.json +0 -29
  105. package/src/swe-arena/fixtures/factory/agent-runtime-232/spec.md +0 -48
  106. package/src/swe-arena/fixtures/factory/loops-28/calibration.md +0 -47
  107. package/src/swe-arena/fixtures/factory/loops-28/manifest.json +0 -30
  108. package/src/swe-arena/fixtures/factory/loops-28/spec.md +0 -50
  109. package/src/swe-arena/fixtures/gen1-salvage/README.md +0 -45
  110. package/src/swe-arena/fixtures/gen1-salvage/cand0-e6d7361.diff +0 -116
  111. package/src/swe-arena/fixtures/gen1-salvage/cand1-76a8590.diff +0 -293
  112. package/src/swe-arena/fixtures/holdout-preregister.log +0 -12
  113. package/src/swe-arena/fixtures/holdout.json +0 -44
  114. package/src/swe-arena/fixtures/instances.json +0 -146
  115. package/src/swe-arena/fixtures/ledger.jsonl +0 -12
  116. package/src/swe-arena/fixtures/patches/pallets__flask-5014.solo.patch +0 -36
  117. package/src/swe-arena/fixtures/patches/pydata__xarray-4687.sup.patch +0 -33
  118. package/src/swe-arena/fixtures/rejudge.jsonl +0 -15
  119. package/src/swe-arena/fixtures/rematch.jsonl +0 -3
  120. package/src/swe-arena/fixtures/rematch2.jsonl +0 -3
  121. package/src/swe-arena/fixtures/rematch3.jsonl +0 -3
  122. package/src/swe-arena/fixtures/run-report/README.md +0 -43
  123. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.json +0 -173
  124. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.md +0 -100
  125. package/src/swe-arena/fixtures/run-report/gen3-rollup.json +0 -551
  126. package/src/swe-arena/fixtures/run-report/gen3-rollup.md +0 -64
  127. package/src/swe-arena/fixtures/sup-journal-true.json +0 -19
  128. package/src/swe-arena/fixtures/verify/astropy__astropy-13033.sh +0 -48
  129. package/src/swe-arena/fixtures/verify/django__django-11532.sh +0 -50
  130. package/src/swe-arena/fixtures/verify/matplotlib__matplotlib-20826.sh +0 -76
  131. package/src/swe-arena/fixtures/verify/pydata__xarray-4687.sh +0 -44
  132. package/src/swe-arena/fixtures/verify/pytest-dev__pytest-6197.sh +0 -32
  133. package/src/swe-arena/fixtures/verify/sphinx-doc__sphinx-9658.sh +0 -51
  134. package/src/swe-arena/fixtures/worker-tokens.json +0 -42
  135. package/src/swe-arena/fixtures.ts +0 -237
  136. package/src/swe-arena/gepa-seat.mts +0 -886
  137. package/src/swe-arena/gepa-seat.test.mts +0 -1136
  138. package/src/swe-arena/holdout-certify.mts +0 -408
  139. package/src/swe-arena/holdout-certify.test.mts +0 -160
  140. package/src/swe-arena/implementation-ref.test.mts +0 -64
  141. package/src/swe-arena/implementation-ref.ts +0 -62
  142. package/src/swe-arena/judge-child.mts +0 -37
  143. package/src/swe-arena/ledger-orphans.mts +0 -77
  144. package/src/swe-arena/ledger-orphans.test.mts +0 -149
  145. package/src/swe-arena/manifest.mts +0 -293
  146. package/src/swe-arena/manifest.test.mts +0 -169
  147. package/src/swe-arena/materialize.ts +0 -142
  148. package/src/swe-arena/outer-loop.mts +0 -2854
  149. package/src/swe-arena/outer-loop.test.mts +0 -714
  150. package/src/swe-arena/parity.test.mts +0 -87
  151. package/src/swe-arena/premeasured-from-cells.mts +0 -296
  152. package/src/swe-arena/premeasured-from-cells.test.mts +0 -201
  153. package/src/swe-arena/proc.test.mts +0 -172
  154. package/src/swe-arena/proc.ts +0 -260
  155. package/src/swe-arena/profiles/deepseek-author.profile.json +0 -12
  156. package/src/swe-arena/profiles/default-author.profile.json +0 -12
  157. package/src/swe-arena/proposer-fanout.mts +0 -736
  158. package/src/swe-arena/proposer-fanout.test.mts +0 -660
  159. package/src/swe-arena/proposer-provenance.mts +0 -176
  160. package/src/swe-arena/proposer-provenance.test.mts +0 -106
  161. package/src/swe-arena/reconcile.ts +0 -0
  162. package/src/swe-arena/replay.mts +0 -183
  163. package/src/swe-arena/replay.test.mts +0 -300
  164. package/src/swe-arena/run-experiment.mts +0 -729
  165. package/src/swe-arena/run-report.mts +0 -75
  166. package/src/swe-arena/run-supervisor.mjs +0 -297
  167. package/src/swe-arena/run-supervisor.test.mts +0 -539
  168. package/src/swe-arena/score-split.mts +0 -140
  169. package/src/swe-arena/score-split.test.mts +0 -123
  170. package/src/swe-arena/scratch-worktree-serialization.test.mts +0 -72
  171. package/src/swe-arena/scratch-worktree.test.mts +0 -56
  172. package/src/swe-arena/scratch-worktree.ts +0 -64
  173. package/src/swe-arena/serialized-judge.ts +0 -414
  174. package/src/swe-arena/types.ts +0 -218
@@ -1,408 +0,0 @@
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
- }
@@ -1,160 +0,0 @@
1
- import { mkdtemp, rm, writeFile } from 'node:fs/promises'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
- import { afterEach, beforeEach, describe, expect, it } from 'vitest'
5
- import type { ReplicateRun } from './cell-evidence.mts'
6
- import {
7
- assertHoldoutBaselineMap,
8
- decideHoldoutCertification,
9
- DEFAULT_HOLDOUT_REPS,
10
- holdoutReps,
11
- loadHoldoutCells,
12
- type HoldoutCellRow,
13
- } from './holdout-certify.mts'
14
-
15
- const IIDS = ['a', 'b', 'c']
16
-
17
- const runs = (spec: Record<string, Array<boolean | null>>): ReplicateRun[] =>
18
- Object.entries(spec).flatMap(([iid, reps]) => reps.map((resolved) => ({ iid, resolved })))
19
-
20
- describe('holdoutReps', () => {
21
- it('defaults to 2 — the gen-2 postmortem protocol', () => {
22
- expect(DEFAULT_HOLDOUT_REPS).toBe(2)
23
- expect(holdoutReps({})).toBe(2)
24
- expect(holdoutReps({ holdoutRepsPerInstance: 3 })).toBe(3)
25
- })
26
-
27
- it('rejects non-positive/non-integer reps', () => {
28
- expect(() => holdoutReps({ holdoutRepsPerInstance: 0 })).toThrow(/positive integer/)
29
- expect(() => holdoutReps({ holdoutRepsPerInstance: 1.5 })).toThrow(/positive integer/)
30
- })
31
- })
32
-
33
- describe('assertHoldoutBaselineMap', () => {
34
- it('requires a same-protocol verdict for EVERY holdout instance', () => {
35
- expect(() => assertHoldoutBaselineMap({ a: true }, IIDS)).toThrow(/missing same-protocol verdicts.*b, c/)
36
- })
37
-
38
- it('rejects verdicts for non-holdout instances', () => {
39
- expect(() => assertHoldoutBaselineMap({ a: true, b: false, c: true, z: true }, IIDS)).toThrow(/non-holdout/)
40
- })
41
-
42
- it('accepts a complete map', () => {
43
- expect(() => assertHoldoutBaselineMap({ a: true, b: false, c: true }, IIDS)).not.toThrow()
44
- })
45
- })
46
-
47
- describe('decideHoldoutCertification — 2-rep fail-closed aggregation', () => {
48
- const parent = { a: true, b: false, c: true } // parent 2/3 same-protocol
49
-
50
- it('an instance resolves only when BOTH reps resolve (T/F counts as unresolved)', () => {
51
- const d = decideHoldoutCertification({
52
- candidateRuns: runs({ a: [true, true], b: [true, false], c: [true, true] }),
53
- parentVerdicts: parent,
54
- iids: IIDS,
55
- reps: 2,
56
- })
57
- expect(d.candResolved).toBe(2) // a + c; b's discordant pair is fail-closed
58
- expect(d.parentResolved).toBe(2)
59
- expect(d.coverageComplete).toBe(true)
60
- expect(d.certified).toBe(true) // non-regression: 2 >= 2
61
- expect(d.perInstance.find((p) => p.iid === 'b')).toMatchObject({ candidate: false, parent: false, discordant: false })
62
- })
63
-
64
- it('regression fails certification even with complete coverage', () => {
65
- const d = decideHoldoutCertification({
66
- candidateRuns: runs({ a: [true, true], b: [false, false], c: [false, true] }),
67
- parentVerdicts: parent,
68
- iids: IIDS,
69
- reps: 2,
70
- })
71
- expect(d.candResolved).toBe(1)
72
- expect(d.certified).toBe(false)
73
- expect(d.reasons.join(' ')).toMatch(/regression: candidate 1 < parent 2/)
74
- expect(d.perInstance.find((p) => p.iid === 'c')).toMatchObject({ candidate: false, parent: true, discordant: true })
75
- })
76
-
77
- it('an inconclusive replicate (errored cell) blocks coverage and certification — fail-closed', () => {
78
- const d = decideHoldoutCertification({
79
- candidateRuns: runs({ a: [true, true], b: [false, false], c: [true, null] }),
80
- parentVerdicts: parent,
81
- iids: IIDS,
82
- reps: 2,
83
- })
84
- expect(d.coverageComplete).toBe(false)
85
- expect(d.certified).toBe(false)
86
- expect(d.reasons.join(' ')).toMatch(/coverage incomplete/)
87
- expect(d.perInstance.find((p) => p.iid === 'c')).toMatchObject({ candidate: null, discordant: false })
88
- })
89
-
90
- it('a missing replicate (only 1 of 2 reps ran) blocks coverage', () => {
91
- const d = decideHoldoutCertification({
92
- candidateRuns: runs({ a: [true, true], b: [true, true], c: [true] }),
93
- parentVerdicts: parent,
94
- iids: IIDS,
95
- reps: 2,
96
- })
97
- expect(d.coverageComplete).toBe(false)
98
- expect(d.certified).toBe(false)
99
- })
100
-
101
- it('gen-2 shape: one discordant instance under 1-rep would have failed; the same data at 2 reps needs both reps', () => {
102
- // At 1 rep a single flipped cell decided the gen-2 verdict. The 2-rep
103
- // protocol requires the flip to REPLICATE before it counts either way.
104
- const oneRep = decideHoldoutCertification({
105
- candidateRuns: runs({ a: [true], b: [false], c: [false] }),
106
- parentVerdicts: parent,
107
- iids: IIDS,
108
- reps: 1,
109
- })
110
- expect(oneRep.certified).toBe(false) // 1 < 2 — the gen-2 outcome
111
- const twoRep = decideHoldoutCertification({
112
- candidateRuns: runs({ a: [true, true], b: [false, false], c: [true, true] }),
113
- parentVerdicts: parent,
114
- iids: IIDS,
115
- reps: 2,
116
- })
117
- expect(twoRep.certified).toBe(true) // c held up under replication
118
- })
119
-
120
- it('validates the parent map before deciding', () => {
121
- expect(() =>
122
- decideHoldoutCertification({
123
- candidateRuns: runs({ a: [true, true] }),
124
- parentVerdicts: { a: true },
125
- iids: IIDS,
126
- reps: 2,
127
- }),
128
- ).toThrow(/missing same-protocol verdicts/)
129
- })
130
- })
131
-
132
- describe('loadHoldoutCells', () => {
133
- let dir: string
134
- beforeEach(async () => {
135
- dir = await mkdtemp(join(tmpdir(), 'holdout-cells-'))
136
- })
137
- afterEach(async () => {
138
- await rm(dir, { recursive: true, force: true })
139
- })
140
-
141
- it('returns [] for a missing file and round-trips schema-valid rows', async () => {
142
- const path = join(dir, 'cells.jsonl')
143
- expect(await loadHoldoutCells(path)).toEqual([])
144
- const row: HoldoutCellRow = {
145
- schema: 'swe-arena.holdout-cell.v1',
146
- at: new Date(0).toISOString(),
147
- commit: 'abc123',
148
- side: 'candidate',
149
- iid: 'a',
150
- rep: 0,
151
- resolved: true,
152
- verifyPass: true,
153
- wallS: 100,
154
- runDir: '/tmp/x',
155
- }
156
- await writeFile(path, `${JSON.stringify(row)}\n${JSON.stringify({ schema: 'other' })}\n`)
157
- const rows = await loadHoldoutCells(path)
158
- expect(rows).toEqual([row]) // foreign schemas are dropped
159
- })
160
- })
@@ -1,64 +0,0 @@
1
- import { mkdir, mkdtemp, rm, symlink, writeFile } from 'node:fs/promises'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
- import { afterEach, describe, expect, it } from 'vitest'
5
- import {
6
- fileTreeImplementationRef,
7
- pythonDistributionImplementationRef,
8
- } from './implementation-ref.ts'
9
-
10
- describe('implementation refs', () => {
11
- const roots: string[] = []
12
-
13
- afterEach(async () => {
14
- await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })))
15
- })
16
-
17
- it('is stable across creation order and changes with file content or symlink targets', async () => {
18
- const first = await mkdtemp(join(tmpdir(), 'implementation-ref-a-'))
19
- const second = await mkdtemp(join(tmpdir(), 'implementation-ref-b-'))
20
- roots.push(first, second)
21
- await mkdir(join(first, 'nested'))
22
- await writeFile(join(first, 'nested', 'b.ts'), 'export const b = 2\n')
23
- await writeFile(join(first, 'a.ts'), 'export const a = 1\n')
24
- await symlink('a.ts', join(first, 'entry.ts'))
25
- await writeFile(join(second, 'a.ts'), 'export const a = 1\n')
26
- await symlink('a.ts', join(second, 'entry.ts'))
27
- await mkdir(join(second, 'nested'))
28
- await writeFile(join(second, 'nested', 'b.ts'), 'export const b = 2\n')
29
-
30
- const initial = await fileTreeImplementationRef(first)
31
- expect(await fileTreeImplementationRef(second)).toBe(initial)
32
-
33
- await writeFile(join(second, 'nested', 'b.ts'), 'export const b = 3\n')
34
- expect(await fileTreeImplementationRef(second)).not.toBe(initial)
35
- await writeFile(join(second, 'nested', 'b.ts'), 'export const b = 2\n')
36
- await rm(join(second, 'entry.ts'))
37
- await symlink('nested/b.ts', join(second, 'entry.ts'))
38
- expect(await fileTreeImplementationRef(second)).not.toBe(initial)
39
- })
40
-
41
- it('binds a Python distribution to its complete manifest', async () => {
42
- const runPython = async (_script: string, args: string[]): Promise<string> =>
43
- `import warning\n${JSON.stringify({
44
- distribution: args[0],
45
- version: '1.0.0',
46
- python: '3.12.4',
47
- files: [{ path: '__init__.py', sha256: 'a'.repeat(64) }],
48
- })}`
49
- const original = await pythonDistributionImplementationRef('swebench', runPython)
50
- const changed = await pythonDistributionImplementationRef(
51
- 'swebench',
52
- async (_script, args) =>
53
- JSON.stringify({
54
- distribution: args[0],
55
- version: '1.0.1',
56
- python: '3.12.4',
57
- files: [{ path: '__init__.py', sha256: 'b'.repeat(64) }],
58
- }),
59
- )
60
-
61
- expect(original).toMatch(/^sha256:[a-f0-9]{64}$/)
62
- expect(changed).not.toBe(original)
63
- })
64
- })