@tangle-network/agent-bench 0.14.2 → 1.0.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.
- package/CHANGELOG.md +48 -0
- package/README.md +2 -3
- package/dist/adapters.d.ts +2 -5
- package/dist/adapters.js +3 -4
- package/dist/benchmarks/_harness.d.ts +17 -20
- package/dist/benchmarks/_harness.js +4 -4
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +1 -4
- package/dist/benchmarks/aec-bench.js +1 -2
- package/dist/benchmarks/agentbench.d.ts +2 -5
- package/dist/benchmarks/agentbench.js +1 -2
- package/dist/benchmarks/appworld.d.ts +8 -10
- package/dist/benchmarks/appworld.js +23 -23
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +2 -5
- package/dist/benchmarks/bfcl.js +1 -2
- package/dist/benchmarks/cad-design.d.ts +2 -5
- package/dist/benchmarks/cad-design.js +2 -3
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +1 -4
- package/dist/benchmarks/cadbench.js +1 -2
- package/dist/benchmarks/cadgenbench.d.ts +1 -4
- package/dist/benchmarks/cadgenbench.js +1 -2
- package/dist/benchmarks/commit0.d.ts +2 -5
- package/dist/benchmarks/commit0.js +1 -2
- package/dist/benchmarks/crag.d.ts +1 -4
- package/dist/benchmarks/crag.js +3 -3
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +2 -5
- package/dist/benchmarks/dabstep.js +2 -3
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
- package/dist/benchmarks/enterpriseops-gym.js +1 -2
- package/dist/benchmarks/finresearchbench.d.ts +2 -5
- package/dist/benchmarks/finresearchbench.js +2 -3
- package/dist/benchmarks/finsearchcomp.d.ts +2 -5
- package/dist/benchmarks/finsearchcomp.js +4 -4
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +3 -19
- package/dist/benchmarks/frames.js +13 -39
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -14
- package/dist/benchmarks/hotpotqa.js +12 -32
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +9 -12
- package/dist/benchmarks/humaneval.js +2 -3
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mcad-bench.d.ts +13 -16
- package/dist/benchmarks/mcad-bench.js +2 -3
- package/dist/benchmarks/mcad-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
- package/dist/benchmarks/mcad-cq-bench.js +2 -3
- package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
- package/dist/benchmarks/mcad-cq-golds.js +1 -2
- package/dist/benchmarks/mcad-golds.d.ts +1 -4
- package/dist/benchmarks/mcad-golds.js +0 -1
- package/dist/benchmarks/mcad-tasks.d.ts +5 -8
- package/dist/benchmarks/mcad-tasks.js +7 -8
- package/dist/benchmarks/mcad-tasks.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +3 -5
- package/dist/benchmarks/mind2web.js +2 -3
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +1 -4
- package/dist/benchmarks/nomiracl.js +1 -2
- package/dist/benchmarks/open-rag-bench.d.ts +1 -4
- package/dist/benchmarks/open-rag-bench.js +3 -3
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +2 -5
- package/dist/benchmarks/programbench.js +1 -2
- package/dist/benchmarks/rag-shared.d.ts +30 -22
- package/dist/benchmarks/rag-shared.js +8 -2
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +1 -4
- package/dist/benchmarks/ragbench.js +3 -3
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +2 -18
- package/dist/benchmarks/simpleqa.js +5 -31
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +7 -10
- package/dist/benchmarks/swe-bench.js +4 -4
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +1 -4
- package/dist/benchmarks/t2-ragbench.js +3 -3
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
- package/dist/benchmarks/tau-bench-shared.js +4 -4
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +2 -5
- package/dist/benchmarks/tau2-bench.js +1 -2
- package/dist/benchmarks/tau3-banking.d.ts +1 -4
- package/dist/benchmarks/tau3-banking.js +1 -2
- package/dist/benchmarks/terminal-bench.d.ts +1 -4
- package/dist/benchmarks/terminal-bench.js +4 -4
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +2 -5
- package/dist/benchmarks/toollm.js +1 -2
- package/dist/benchmarks/trata-hedge.d.ts +1 -4
- package/dist/benchmarks/trata-hedge.js +2 -3
- package/dist/benchmarks/types.d.ts +6 -9
- package/dist/benchmarks/webarena-verified.d.ts +2 -5
- package/dist/benchmarks/webarena-verified.js +1 -2
- package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
- package/dist/cadbench-DhAndllg.js.map +1 -0
- package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
- package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.js +16 -24
- package/dist/index.js.map +1 -1
- package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
- package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
- package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
- package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
- package/package.json +10 -10
- package/pier_agents/tangle_candidate.py +15 -23
- package/scripts/run-package-tests.mjs +8 -15
- package/scripts/verify-packed-consumer.mjs +0 -1
- package/src/atom-mcp-e2e.mts +16 -4
- package/src/benchmarks/frames.ts +10 -44
- package/src/benchmarks/hotpotqa.ts +9 -29
- package/src/benchmarks/rag-shared.ts +12 -0
- package/src/benchmarks/simpleqa.ts +2 -36
- package/src/commit0-prereqs.sh +0 -0
- package/src/corpus-replay.mts +8 -8
- package/src/corpus-report.mts +21 -21
- package/src/corpus.test.mts +5 -5
- package/src/corpus.ts +16 -16
- package/src/directives.ts +0 -38
- package/src/examples/lean-verify.ts +1 -1
- package/src/gate.ts +8 -8
- package/src/generate-eval/certify.ts +2 -2
- package/src/index.ts +1 -0
- package/src/refine-loop.ts +5 -5
- package/src/resolve-client.ts +1 -1
- package/src/router-turn.ts +3 -11
- package/src/run-benchmarks.test.mts +0 -4
- package/src/run-pool.ts +1 -1
- package/src/runtime-hook-recorder.ts +2 -2
- package/src/search-bench/tasks.ts +1 -1
- package/src/selector.test.mts +13 -13
- package/src/selector.ts +19 -19
- package/src/swe-bench-env.ts +4 -12
- package/src/swe-jail.ts +5 -156
- package/src/swe-structural-judge-policy.ts +3 -3
- package/src/swe-structural-policy.ts +3 -3
- package/src/swe-structural-provenance.ts +4 -4
- package/src/terminal-compare.ts +10 -10
- package/src/worker-blender.ts +2 -106
- package/src/worker-build123d.ts +2 -81
- package/tb_agents/opencode_router_agent.py +1 -1
- package/dist/cadbench-BRF-59Mt.js.map +0 -1
- package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
- package/dist/router-turn-uTYO6KQ1.js.map +0 -1
- package/scripts/cadbench_prepare.py +0 -22
- package/scripts/cadgenbench_hard_parts.py +0 -48
- package/scripts/clbench_codebase_judge.py +0 -73
- package/scripts/render-gate-chart.mjs +0 -176
- package/scripts/trata-hedge/README.md +0 -57
- package/scripts/trata-hedge/run.sh +0 -64
- package/src/browser/adapters/bad-design-audit.ts +0 -153
- package/src/browser/adapters/bad-design-audit.verify.ts +0 -85
- package/src/browser/adapters/bad.ts +0 -165
- package/src/browser/agent-adapter.ts +0 -145
- package/src/browser/process-adapter.ts +0 -146
- package/src/browser/run-to-spans.ts +0 -105
- package/src/browser/run-to-spans.verify.ts +0 -89
- package/src/browser/ui-reviewer.ts +0 -200
- package/src/browser/ui-reviewer.verify.ts +0 -94
- package/src/browser/verify.ts +0 -96
- package/src/clbench-codebase-gate.mts +0 -314
- package/src/clbench-context-gate.mts +0 -341
- package/src/cloud-loop.mts +0 -156
- package/src/commit0-env-run.mts +0 -62
- package/src/commit0-env.ts +0 -172
- package/src/commit0-gate.mts +0 -558
- package/src/coordination-mcp-container-reach.mts +0 -182
- package/src/egress-probe.mts +0 -26
- package/src/fleet.mts +0 -143
- package/src/hev-structural.mts +0 -697
- package/src/humaneval-gate.mts +0 -220
- package/src/humaneval-repair-gate.mts +0 -182
- package/src/mbpp-structural.mts +0 -676
- package/src/mcp-mount-probe.mts +0 -139
- package/src/profile-coordinates.ts +0 -134
- package/src/profiles.ts +0 -128
- package/src/research-gate.mts +0 -132
- package/src/research-shot.ts +0 -144
- package/src/router-executor.ts +0 -51
- package/src/run-benchmarks-report.ts +0 -66
- package/src/sandbox-run.ts +0 -108
- package/src/search-bench/bridge.ts +0 -182
- package/src/search-bench/export.mts +0 -0
- package/src/search-bench/parametric-check.mts +0 -78
- package/src/search-bench/profiles.ts +0 -113
- package/src/search-bench/run.mts +0 -286
- package/src/search-bench/tasks-fresh.ts +0 -688
- package/src/skill-sandbox-smoke.mts +0 -101
- package/src/smoke-structural-rollout.mts +0 -415
- package/src/stats.mts +0 -90
- package/src/supervisor-arena.mts +0 -825
- package/src/swe-code-improve.mts +0 -306
- package/src/swe-emit-patch.mts +0 -125
- package/src/swe-improve.mts +0 -284
- package/src/swe-local-proof.mts +0 -265
- package/src/swe-repro-calibrate.mts +0 -451
- package/src/swe-stream.mts +0 -1561
- package/src/swe-structural.mts +0 -707
- package/src/tb-container-executor.mts +0 -266
- package/src/tb-container-executor.test.mts +0 -134
- package/src/tb-supervisor-sidecar.mts +0 -208
- package/src/trajectory-assemble.mjs +0 -130
- package/src/trata-gepa.mts +0 -381
- package/src/trata-hedge-solve.mts +0 -81
- package/src/worker-browser.ts +0 -115
- package/src/worker-cad.ts +0 -470
- package/src/workspace-loop.mts +0 -133
- package/tb_agents/opencode_refine_agent.py +0 -117
- package/tb_agents/opencode_supervisor_agent.py +0 -239
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Proof that a SKILL.md from an AgentProfile actually materializes inside the sandbox where the
|
|
3
|
-
* coding harness loads it — the "are we on the right surface" check before any benchmark.
|
|
4
|
-
* Creates one opencode box with resources.skills, then asks the IN-SESSION agent to read the
|
|
5
|
-
* skill back. PASS keys on a UNIQUE MARKER in the skill body, so a hit is unambiguously OUR
|
|
6
|
-
* skill — not opencode's bundled /nix/store skills and not the agent's prose.
|
|
7
|
-
*
|
|
8
|
-
* Two gotchas this guards against (both produced false readings during bring-up):
|
|
9
|
-
* 1. PATH: opencode's discovery dir is ~/.opencode/skill/<name>/SKILL.md (SINGULAR "skill");
|
|
10
|
-
* claude-code uses ~/.claude/skills/. resources.skills lands in the backend's own dir.
|
|
11
|
-
* 2. VIEW: a bare box.exec() WITHOUT a sessionId sees a DIFFERENT filesystem than the agent
|
|
12
|
-
* session (SDK ExecOptions docs). So we verify through the in-SESSION agent (streamPrompt),
|
|
13
|
-
* the path the bench actually runs — not a detached exec.
|
|
14
|
-
*
|
|
15
|
-
* Run: dotenvx run -f ~/company/devops/secrets/.env.keys -- pnpm exec tsx bench/src/skill-sandbox-smoke.mts
|
|
16
|
-
*/
|
|
17
|
-
import { defineInlineResource } from '@tangle-network/agent-interface'
|
|
18
|
-
import { Sandbox } from '@tangle-network/sandbox'
|
|
19
|
-
|
|
20
|
-
const must = (k: string): string => {
|
|
21
|
-
const v = process.env[k]
|
|
22
|
-
if (!v) throw new Error(`env ${k} required`)
|
|
23
|
-
return v
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const skillName = 'reproduce-first'
|
|
27
|
-
// A unique token that cannot occur in opencode's bundled skills or in plausible prose.
|
|
28
|
-
const marker = 'SKILLMAT-OK-7f3c91'
|
|
29
|
-
const skillMd = [
|
|
30
|
-
'---',
|
|
31
|
-
`name: ${skillName}`,
|
|
32
|
-
'description: Reproduce the failing test before changing any code.',
|
|
33
|
-
'---',
|
|
34
|
-
'',
|
|
35
|
-
`Materialization proof token: ${marker}`,
|
|
36
|
-
'When fixing a bug: run the failing test FIRST to observe the real error, make the smallest',
|
|
37
|
-
'change that turns it green, then re-run to confirm.',
|
|
38
|
-
].join('\n')
|
|
39
|
-
|
|
40
|
-
async function main(): Promise<void> {
|
|
41
|
-
const client = new Sandbox({
|
|
42
|
-
baseUrl: process.env.SANDBOX_BASE_URL ?? 'https://sandbox.tangle.tools',
|
|
43
|
-
apiKey: must('TANGLE_API_KEY'),
|
|
44
|
-
timeoutMs: 600_000,
|
|
45
|
-
} as never)
|
|
46
|
-
|
|
47
|
-
console.error(`[smoke] creating opencode box with resources.skills=[${skillName}]…`)
|
|
48
|
-
const box: Record<string, (...a: never[]) => unknown> & { id?: string } = (await client.create({
|
|
49
|
-
backend: {
|
|
50
|
-
type: 'opencode',
|
|
51
|
-
model: {
|
|
52
|
-
provider: process.env.WORKER_PROVIDER ?? 'openai',
|
|
53
|
-
model: process.env.WORKER_MODEL ?? 'deepseek-v4-flash',
|
|
54
|
-
baseUrl: process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1',
|
|
55
|
-
},
|
|
56
|
-
profile: { name: 'skill-smoke', resources: { skills: [defineInlineResource(skillName, skillMd)] } },
|
|
57
|
-
},
|
|
58
|
-
} as never)) as never
|
|
59
|
-
console.error('[smoke] box id:', box.id, '— waiting for running…')
|
|
60
|
-
await box.waitFor('running' as never, { timeoutMs: 180_000 } as never)
|
|
61
|
-
console.error('[smoke] box running; asking the IN-SESSION agent to read the materialized skill back…')
|
|
62
|
-
|
|
63
|
-
// cat the skill at BOTH backend discovery dirs (opencode singular, claude-code plural) + a
|
|
64
|
-
// name-scoped find; the marker appears wherever resources.skills actually landed it.
|
|
65
|
-
const prompt =
|
|
66
|
-
'Run this exact shell command and paste its raw output verbatim, nothing else:\n' +
|
|
67
|
-
`\`cat ~/.opencode/skill/${skillName}/SKILL.md ~/.claude/skills/${skillName}/SKILL.md 2>/dev/null; ` +
|
|
68
|
-
`echo "--FIND--"; find / -name SKILL.md 2>/dev/null | grep -i ${skillName} | grep -vi /nix/store || echo NOFILE\``
|
|
69
|
-
let out = ''
|
|
70
|
-
const ac = new AbortController()
|
|
71
|
-
const timer = setTimeout(() => ac.abort(), 220_000)
|
|
72
|
-
try {
|
|
73
|
-
for await (const ev of box.streamPrompt(prompt as never, { signal: ac.signal } as never) as AsyncGenerator<unknown>) {
|
|
74
|
-
out += (typeof ev === 'string' ? ev : JSON.stringify(ev)) + '\n'
|
|
75
|
-
}
|
|
76
|
-
} finally {
|
|
77
|
-
clearTimeout(timer)
|
|
78
|
-
}
|
|
79
|
-
console.error(`[smoke] stream chars: ${out.length}`)
|
|
80
|
-
console.error('[smoke] tail of stream:\n' + out.slice(-1500))
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
await box.delete?.()
|
|
84
|
-
} catch {
|
|
85
|
-
/* best-effort cleanup */
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Deterministic: PASS only if the agent read OUR unique marker out of the file — not a loose
|
|
89
|
-
// match on the skill name (which appears in the prompt/prose) or on "SKILL.md" (bundled skills).
|
|
90
|
-
const landed = out.includes(marker)
|
|
91
|
-
const path = /\.opencode\/skill\//.test(out) ? '~/.opencode/skill (opencode)' : /\.claude\/skills\//.test(out) ? '~/.claude/skills (claude-code)' : '(path not surfaced)'
|
|
92
|
-
console.error(
|
|
93
|
-
`\n[smoke] VERDICT: ${landed ? `PASS — resources.skills materialized + the in-session agent read the marker at ${path}` : 'FAIL — marker NOT read back; resources.skills did not land where the harness reads (check backend discovery dir)'}`,
|
|
94
|
-
)
|
|
95
|
-
process.exit(landed ? 0 : 2)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
main().catch((e) => {
|
|
99
|
-
console.error('[smoke] FAILED:', e instanceof Error ? (e.stack ?? e.message) : e)
|
|
100
|
-
process.exit(1)
|
|
101
|
-
})
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* smoke-structural-rollout — the ship gate for the PORTED structuralRollout strategy
|
|
3
|
-
* (src/runtime/structural-rollout.ts): prove the RUNTIME code path works against a REAL
|
|
4
|
-
* model on REAL HumanEval tasks. This runs `runAgentic` with the strategy over a
|
|
5
|
-
* `createVerifierEnvironment` surface — routerToolLoop, the conserved pool, the metered
|
|
6
|
-
* consult channel, `sandboxCheckRunner`, receipts — NOT the bench rig (hev-structural.mts).
|
|
7
|
-
*
|
|
8
|
-
* Honesty split (the rig's Phase A / Phase B, preserved):
|
|
9
|
-
* - The strategy sees ONLY task-visible information. The surface's check is INERT
|
|
10
|
-
* (always 0/1), so no hidden-test signal can reach selection or repair; the visible
|
|
11
|
-
* checks are the strategy's own default CheckSource (model-authored asserts, frozen
|
|
12
|
-
* before sampling), executed by the shipped `sandboxCheckRunner` over a docker
|
|
13
|
-
* `--network=none` exec channel (the thin adapter this script provides).
|
|
14
|
-
* - The task's own hidden check() suite grades every locked candidate HERE, in the
|
|
15
|
-
* script, AFTER the strategy has finished the task (`runChecker`, docker,
|
|
16
|
-
* --network=none). Nothing flows back.
|
|
17
|
-
*
|
|
18
|
-
* Per task we collect: the k per-sample hidden grades, the selected candidate's grade
|
|
19
|
-
* (argmax over samples by the exported `selectBestIndex` — the strategy's own order),
|
|
20
|
-
* the final (post-repair) grade (the receipt marked `selected`), authored-check counts,
|
|
21
|
-
* and the SelectionReceipts (cross-checked against the recorded outcomes).
|
|
22
|
-
*
|
|
23
|
-
* Run (key via dotenvx; never in the shell history):
|
|
24
|
-
* cd ~/company/devops/secrets && dotenvx run -f agent-state.env -- bash -c ' \
|
|
25
|
-
* cd /home/drew/code/agent-runtime-swe && \
|
|
26
|
-
* HUMANEVAL_GZ=/abs/HumanEval.jsonl.gz N=20 OFFSET=0 npx tsx bench/src/smoke-structural-rollout.mts'
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { execFile } from 'node:child_process'
|
|
30
|
-
import { appendFileSync } from 'node:fs'
|
|
31
|
-
import {
|
|
32
|
-
type AgenticRunResult,
|
|
33
|
-
type CheckExecChannel,
|
|
34
|
-
type CheckOutcome,
|
|
35
|
-
type CheckRunner,
|
|
36
|
-
createVerifierEnvironment,
|
|
37
|
-
defaultStructuralRolloutPolicy,
|
|
38
|
-
runAgentic,
|
|
39
|
-
type StructuralRolloutResult,
|
|
40
|
-
defaultAnalystInstruction,
|
|
41
|
-
sandboxCheckRunner,
|
|
42
|
-
selectBestIndex,
|
|
43
|
-
structuralRollout,
|
|
44
|
-
visibleCheckScore,
|
|
45
|
-
} from '../../src/runtime/index'
|
|
46
|
-
import { basePrompt, type HumanEvalTask, loadHumanEval, runChecker } from './benchmarks/humaneval'
|
|
47
|
-
import { withBenchProfile } from './router-turn'
|
|
48
|
-
|
|
49
|
-
function must(name: string): string {
|
|
50
|
-
const v = process.env[name]
|
|
51
|
-
if (!v) throw new Error(`env ${name} is required`)
|
|
52
|
-
return v
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const N = Number(process.env.N ?? 20)
|
|
56
|
-
const OFFSET = Number(process.env.OFFSET ?? 0)
|
|
57
|
-
const MODEL = process.env.MODEL ?? 'meta-llama/Meta-Llama-3-8B-Instruct-Lite'
|
|
58
|
-
const BASE = process.env.ROUTER_BASE ?? 'https://api.together.xyz/v1'
|
|
59
|
-
const TEMP = Number(process.env.TEMPERATURE ?? 0.8)
|
|
60
|
-
const MAX_TOKENS = Number(process.env.MAX_TOKENS ?? 2500)
|
|
61
|
-
const CONCURRENCY = Number(process.env.CONCURRENCY ?? 3)
|
|
62
|
-
const OUT = process.env.OUT // optional JSONL of raw per-task rows
|
|
63
|
-
|
|
64
|
-
const systemPrompt = 'You are an expert Python programmer.'
|
|
65
|
-
const dockerImage = 'python:3.12-slim'
|
|
66
|
-
|
|
67
|
-
// ── The thin adapter: a docker --network=none exec channel for sandboxCheckRunner ────
|
|
68
|
-
// The runner pipes its check program as `printf '%s' '<b64>' | base64 -d | python3 -`;
|
|
69
|
-
// this channel runs that command inside a jailed container. Infra faults (no docker,
|
|
70
|
-
// daemon down) fail loud; a candidate crash/hang is a real outcome (non-zero exit / no
|
|
71
|
-
// sentinel), returned, never thrown. Modeled on bench/src/benchmarks/humaneval.ts.
|
|
72
|
-
let containerSeq = 0
|
|
73
|
-
function dockerExecChannel(): CheckExecChannel {
|
|
74
|
-
return {
|
|
75
|
-
exec(command, options) {
|
|
76
|
-
const timeoutMs = options?.timeoutMs ?? 20000
|
|
77
|
-
const name = `srck-${process.pid}-${containerSeq++}`
|
|
78
|
-
return new Promise((resolve, reject) => {
|
|
79
|
-
let settled = false
|
|
80
|
-
const reap = () => execFile('docker', ['rm', '-f', name], () => {})
|
|
81
|
-
const finish = (r: { exitCode: number; stdout: string; stderr: string }) => {
|
|
82
|
-
if (settled) return
|
|
83
|
-
settled = true
|
|
84
|
-
clearTimeout(backstop)
|
|
85
|
-
reap()
|
|
86
|
-
resolve(r)
|
|
87
|
-
}
|
|
88
|
-
const fail = (e: Error) => {
|
|
89
|
-
if (settled) return
|
|
90
|
-
settled = true
|
|
91
|
-
clearTimeout(backstop)
|
|
92
|
-
reap()
|
|
93
|
-
reject(e)
|
|
94
|
-
}
|
|
95
|
-
// execFile's timeout kills the docker CLIENT; a hung container could leave the
|
|
96
|
-
// callback unfired. The backstop guarantees resolution (no sentinel ⇒ the runner
|
|
97
|
-
// scores it crashed) and the named reap kills the stray container.
|
|
98
|
-
const backstop = setTimeout(
|
|
99
|
-
() => finish({ exitCode: 124, stdout: '', stderr: 'timed out (backstop)' }),
|
|
100
|
-
timeoutMs + 3000,
|
|
101
|
-
)
|
|
102
|
-
execFile(
|
|
103
|
-
'docker',
|
|
104
|
-
['run', '--rm', '--name', name, '--network=none', '--cpus=1', '--memory=512m', dockerImage, 'sh', '-c', command],
|
|
105
|
-
{ timeout: timeoutMs, killSignal: 'SIGKILL', maxBuffer: 4 * 1024 * 1024 },
|
|
106
|
-
(err, stdout, stderr) => {
|
|
107
|
-
if (err) {
|
|
108
|
-
const e = err as NodeJS.ErrnoException & { code?: number | string }
|
|
109
|
-
if (e.code === 'ENOENT') {
|
|
110
|
-
fail(new Error('docker binary not found on PATH — cannot run visible checks'))
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
if (/cannot connect to the docker daemon|is the docker daemon running|permission denied while trying to connect/i.test(stderr ?? '')) {
|
|
114
|
-
fail(new Error(`docker daemon unreachable: ${(stderr ?? '').slice(0, 200)}`))
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
const exitCode = typeof e.code === 'number' ? e.code : 1
|
|
118
|
-
finish({ exitCode, stdout: stdout ?? '', stderr: stderr ?? '' })
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
finish({ exitCode: 0, stdout: stdout ?? '', stderr: stderr ?? '' })
|
|
122
|
-
},
|
|
123
|
-
)
|
|
124
|
-
})
|
|
125
|
-
},
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ── Recording wrapper: capture each (candidate, outcome) the strategy scores, in order.
|
|
130
|
-
// Delegates verbatim to the shipped runner — the code under test stays the strategy.
|
|
131
|
-
interface ScoredCandidate {
|
|
132
|
-
candidate: string
|
|
133
|
-
outcome: CheckOutcome
|
|
134
|
-
}
|
|
135
|
-
function recordingRunner(inner: CheckRunner, log: ScoredCandidate[]): CheckRunner {
|
|
136
|
-
return {
|
|
137
|
-
async run(candidate, checks, ctx) {
|
|
138
|
-
const outcome = await inner.run(candidate, checks, ctx)
|
|
139
|
-
log.push({ candidate, outcome })
|
|
140
|
-
return outcome
|
|
141
|
-
},
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
interface TaskRow {
|
|
146
|
-
taskId: string
|
|
147
|
-
error?: string
|
|
148
|
-
officialChecks: number
|
|
149
|
-
authoredChecks: number
|
|
150
|
-
repairStop: string
|
|
151
|
-
shots: number
|
|
152
|
-
sampleHidden: number[]
|
|
153
|
-
blindMean: number
|
|
154
|
-
selectedIdx: number
|
|
155
|
-
selectedHidden: number
|
|
156
|
-
finalIdx: number
|
|
157
|
-
finalHidden: number
|
|
158
|
-
selectedVisible: number
|
|
159
|
-
receipts: Array<{ candidateIndex: number; selected: boolean; score: number; reason: string }>
|
|
160
|
-
tokens: { input: number; output: number }
|
|
161
|
-
usd: number
|
|
162
|
-
ms: number
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async function runTask(t: HumanEvalTask): Promise<TaskRow> {
|
|
166
|
-
const scored: ScoredCandidate[] = []
|
|
167
|
-
const policy = { ...defaultStructuralRolloutPolicy, temperature: TEMP }
|
|
168
|
-
const strategy = structuralRollout({
|
|
169
|
-
policy,
|
|
170
|
-
checkRunner: recordingRunner(sandboxCheckRunner({ box: dockerExecChannel() }), scored),
|
|
171
|
-
})
|
|
172
|
-
// INERT check: the strategy's harness-verified score channel must carry no hidden
|
|
173
|
-
// signal — hidden grading is this script's job, after the rollout locks its artifacts.
|
|
174
|
-
const surface = createVerifierEnvironment({
|
|
175
|
-
name: 'humaneval-inert',
|
|
176
|
-
check: () => ({ passes: 0, total: 1, errored: 0 }),
|
|
177
|
-
})
|
|
178
|
-
const workerProfile = withBenchProfile(
|
|
179
|
-
{
|
|
180
|
-
name: 'humaneval-structural-worker',
|
|
181
|
-
harness: 'cli-base',
|
|
182
|
-
model: { provider: 'together', default: MODEL },
|
|
183
|
-
tools: { submit_answer: true },
|
|
184
|
-
},
|
|
185
|
-
{ systemPrompt, temperature: TEMP, maxTokens: MAX_TOKENS, maxTurns: 2 },
|
|
186
|
-
)
|
|
187
|
-
const analystProfile = withBenchProfile(
|
|
188
|
-
{
|
|
189
|
-
name: 'humaneval-structural-analyst',
|
|
190
|
-
harness: 'cli-base',
|
|
191
|
-
model: { provider: 'together', default: MODEL },
|
|
192
|
-
},
|
|
193
|
-
{ systemPrompt: defaultAnalystInstruction, temperature: TEMP, maxTokens: MAX_TOKENS },
|
|
194
|
-
)
|
|
195
|
-
const result = (await runAgentic({
|
|
196
|
-
surface,
|
|
197
|
-
task: {
|
|
198
|
-
id: t.taskId,
|
|
199
|
-
userPrompt: basePrompt(t),
|
|
200
|
-
meta: { entryPoint: t.entryPoint },
|
|
201
|
-
},
|
|
202
|
-
routerBaseUrl: BASE,
|
|
203
|
-
routerKey: must('TOGETHER_API_KEY'),
|
|
204
|
-
workerProfile,
|
|
205
|
-
analystProfile,
|
|
206
|
-
strategy,
|
|
207
|
-
// The strategy's documented sizing: k samples + repair rounds + the check-author consult.
|
|
208
|
-
budget: policy.k + policy.repairRounds + 1,
|
|
209
|
-
})) as AgenticRunResult & StructuralRolloutResult
|
|
210
|
-
|
|
211
|
-
// Receipts ↔ recorded outcomes must agree exactly (candidateIndex is the recording
|
|
212
|
-
// order: samples first, then repairs). A mismatch is an adapter or strategy defect.
|
|
213
|
-
if (result.selection.length !== scored.length) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
`${t.taskId}: ${result.selection.length} receipts vs ${scored.length} scored candidates`,
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
const receipts = result.selection.map((receipt) => {
|
|
219
|
-
if (receipt.score === undefined || receipt.reason === undefined) {
|
|
220
|
-
throw new Error(`${t.taskId}: receipt #${receipt.candidateIndex} is missing score or reason`)
|
|
221
|
-
}
|
|
222
|
-
return {
|
|
223
|
-
candidateIndex: receipt.candidateIndex,
|
|
224
|
-
selected: receipt.selected,
|
|
225
|
-
score: receipt.score,
|
|
226
|
-
reason: receipt.reason,
|
|
227
|
-
}
|
|
228
|
-
})
|
|
229
|
-
for (const r of receipts) {
|
|
230
|
-
const rec = scored[r.candidateIndex]
|
|
231
|
-
if (!rec || Math.abs(r.score - visibleCheckScore(rec.outcome)) > 1e-9) {
|
|
232
|
-
throw new Error(`${t.taskId}: receipt #${r.candidateIndex} score ${r.score} does not match the recorded outcome`)
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const sampleCount = receipts.filter((r) => r.reason.startsWith('sample')).length
|
|
237
|
-
const samples = scored.slice(0, sampleCount)
|
|
238
|
-
if (samples.length === 0) throw new Error(`${t.taskId}: no sample candidates settled`)
|
|
239
|
-
|
|
240
|
-
// Hidden grading (script-side, docker --network=none): every distinct candidate once.
|
|
241
|
-
const gradeCache = new Map<string, Promise<number>>()
|
|
242
|
-
const grade = (candidate: string): Promise<number> => {
|
|
243
|
-
let p = gradeCache.get(candidate)
|
|
244
|
-
if (!p) {
|
|
245
|
-
p = runChecker(t, candidate).then((r) => r.pass)
|
|
246
|
-
gradeCache.set(candidate, p)
|
|
247
|
-
}
|
|
248
|
-
return p
|
|
249
|
-
}
|
|
250
|
-
const sampleHidden = await Promise.all(samples.map((s) => grade(s.candidate)))
|
|
251
|
-
const selectedIdx = selectBestIndex(samples.map((s) => s.outcome))
|
|
252
|
-
const selectedHidden = sampleHidden[selectedIdx] as number
|
|
253
|
-
const winner = receipts.find((r) => r.selected)
|
|
254
|
-
if (!winner) throw new Error(`${t.taskId}: no receipt marked selected`)
|
|
255
|
-
const finalIdx = winner.candidateIndex
|
|
256
|
-
const finalHidden = await grade((scored[finalIdx] as ScoredCandidate).candidate)
|
|
257
|
-
|
|
258
|
-
return {
|
|
259
|
-
taskId: t.taskId,
|
|
260
|
-
officialChecks: result.officialChecks,
|
|
261
|
-
authoredChecks: result.authoredChecks,
|
|
262
|
-
repairStop: result.repairStop,
|
|
263
|
-
shots: result.shots,
|
|
264
|
-
sampleHidden,
|
|
265
|
-
blindMean: sampleHidden.reduce((a, b) => a + b, 0) / sampleHidden.length,
|
|
266
|
-
selectedIdx,
|
|
267
|
-
selectedHidden,
|
|
268
|
-
finalIdx,
|
|
269
|
-
finalHidden,
|
|
270
|
-
selectedVisible: visibleCheckScore((samples[selectedIdx] as ScoredCandidate).outcome),
|
|
271
|
-
receipts,
|
|
272
|
-
tokens: result.tokens,
|
|
273
|
-
usd: result.usd,
|
|
274
|
-
ms: result.ms,
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async function pooled<T, R>(items: T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]> {
|
|
279
|
-
const out: R[] = new Array(items.length)
|
|
280
|
-
let next = 0
|
|
281
|
-
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
282
|
-
while (next < items.length) {
|
|
283
|
-
const i = next
|
|
284
|
-
next += 1
|
|
285
|
-
out[i] = await fn(items[i] as T)
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
await Promise.all(workers)
|
|
289
|
-
return out
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
let unhandled = 0
|
|
293
|
-
process.on('unhandledRejection', (e) => {
|
|
294
|
-
unhandled += 1
|
|
295
|
-
console.error('UNHANDLED REJECTION:', e)
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
const pct = (x: number) => `${(100 * x).toFixed(1)}%`
|
|
299
|
-
|
|
300
|
-
async function main(): Promise<void> {
|
|
301
|
-
must('TOGETHER_API_KEY')
|
|
302
|
-
const tasks = await loadHumanEval(N, OFFSET)
|
|
303
|
-
const { k, repairRounds, testgen } = defaultStructuralRolloutPolicy
|
|
304
|
-
console.log(
|
|
305
|
-
`=== structuralRollout RUNTIME smoke · n=${tasks.length} offset=${OFFSET} · k=${k} repairs<=${repairRounds} testgen=${testgen} temp=${TEMP} ===`,
|
|
306
|
-
)
|
|
307
|
-
console.log(` model=${MODEL} base=${BASE} maxTokens=${MAX_TOKENS} task-concurrency=${CONCURRENCY}`)
|
|
308
|
-
console.log(` path: runAgentic → structuralRollout(default policy) → createVerifierEnvironment(inert) → sandboxCheckRunner(docker --network=none)`)
|
|
309
|
-
|
|
310
|
-
const started = Date.now()
|
|
311
|
-
const rows = await pooled(tasks, CONCURRENCY, async (t): Promise<TaskRow> => {
|
|
312
|
-
try {
|
|
313
|
-
const row = await runTask(t)
|
|
314
|
-
const hid = row.sampleHidden.join(' ')
|
|
315
|
-
console.log(
|
|
316
|
-
` ${t.taskId.padEnd(14)} auth=${row.authoredChecks} samples=[${hid}] sel=#${row.selectedIdx}:${row.selectedHidden ? 'PASS' : 'fail'} final=#${row.finalIdx}:${row.finalHidden ? 'PASS' : 'fail'} ${row.repairStop}`,
|
|
317
|
-
)
|
|
318
|
-
if (OUT) appendFileSync(OUT, `${JSON.stringify(row)}\n`)
|
|
319
|
-
return row
|
|
320
|
-
} catch (e) {
|
|
321
|
-
const msg = e instanceof Error ? e.message : String(e)
|
|
322
|
-
console.error(` ${t.taskId.padEnd(14)} ERROR: ${msg}`)
|
|
323
|
-
if (OUT) appendFileSync(OUT, `${JSON.stringify({ taskId: t.taskId, error: msg })}\n`)
|
|
324
|
-
return {
|
|
325
|
-
taskId: t.taskId,
|
|
326
|
-
error: msg,
|
|
327
|
-
officialChecks: 0,
|
|
328
|
-
authoredChecks: 0,
|
|
329
|
-
repairStop: 'error',
|
|
330
|
-
shots: 0,
|
|
331
|
-
sampleHidden: [],
|
|
332
|
-
blindMean: 0,
|
|
333
|
-
selectedIdx: -1,
|
|
334
|
-
selectedHidden: 0,
|
|
335
|
-
finalIdx: -1,
|
|
336
|
-
finalHidden: 0,
|
|
337
|
-
selectedVisible: 0,
|
|
338
|
-
receipts: [],
|
|
339
|
-
tokens: { input: 0, output: 0 },
|
|
340
|
-
usd: 0,
|
|
341
|
-
ms: 0,
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
const ok = rows.filter((r) => !r.error)
|
|
347
|
-
const errored = rows.filter((r) => r.error)
|
|
348
|
-
|
|
349
|
-
console.log('\n── per-task ──')
|
|
350
|
-
console.log(
|
|
351
|
-
'task auth samples(hidden) blind% sel final visSel repairStop shots tok(in/out) ms',
|
|
352
|
-
)
|
|
353
|
-
for (const r of rows) {
|
|
354
|
-
if (r.error) {
|
|
355
|
-
console.log(`${r.taskId.padEnd(15)} ERROR ${r.error.slice(0, 90)}`)
|
|
356
|
-
continue
|
|
357
|
-
}
|
|
358
|
-
console.log(
|
|
359
|
-
[
|
|
360
|
-
r.taskId.padEnd(15),
|
|
361
|
-
String(r.authoredChecks).padEnd(5),
|
|
362
|
-
r.sampleHidden.join(' ').padEnd(16),
|
|
363
|
-
pct(r.blindMean).padEnd(8),
|
|
364
|
-
`#${r.selectedIdx}:${r.selectedHidden ? 'PASS' : 'fail'}`.padEnd(8),
|
|
365
|
-
`#${r.finalIdx}:${r.finalHidden ? 'PASS' : 'fail'}`.padEnd(8),
|
|
366
|
-
r.selectedVisible.toFixed(3).padEnd(7),
|
|
367
|
-
r.repairStop.padEnd(17),
|
|
368
|
-
String(r.shots).padEnd(6),
|
|
369
|
-
`${r.tokens.input}/${r.tokens.output}`.padEnd(15),
|
|
370
|
-
String(r.ms),
|
|
371
|
-
].join(' '),
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const blind = ok.reduce((a, r) => a + r.blindMean, 0) / Math.max(1, ok.length)
|
|
376
|
-
const selected = ok.reduce((a, r) => a + r.selectedHidden, 0) / Math.max(1, ok.length)
|
|
377
|
-
const final = ok.reduce((a, r) => a + r.finalHidden, 0) / Math.max(1, ok.length)
|
|
378
|
-
const sample0 = ok.reduce((a, r) => a + (r.sampleHidden[0] ?? 0), 0) / Math.max(1, ok.length)
|
|
379
|
-
const oracleAtK = ok.reduce((a, r) => a + (r.sampleHidden.some((x) => x === 1) ? 1 : 0), 0) / Math.max(1, ok.length)
|
|
380
|
-
const tokens = ok.reduce((a, r) => ({ input: a.input + r.tokens.input, output: a.output + r.tokens.output }), { input: 0, output: 0 })
|
|
381
|
-
|
|
382
|
-
console.log('\n── summary ──')
|
|
383
|
-
console.log(`tasks: ${ok.length} scored, ${errored.length} errored (of ${rows.length})`)
|
|
384
|
-
console.log(`blind mean-of-k : ${pct(blind)} (sample-0 only: ${pct(sample0)}; oracle@k ceiling: ${pct(oracleAtK)})`)
|
|
385
|
-
console.log(`selected@1 : ${pct(selected)} (lift over blind: ${(100 * (selected - blind)).toFixed(1)}pp)`)
|
|
386
|
-
console.log(`final (repaired): ${pct(final)} (lift over blind: ${(100 * (final - blind)).toFixed(1)}pp)`)
|
|
387
|
-
console.log(`spend: tokens ${tokens.input} in / ${tokens.output} out · wall ${((Date.now() - started) / 1000).toFixed(0)}s`)
|
|
388
|
-
|
|
389
|
-
// ── Acceptance (mechanism, not significance — n is small) ──
|
|
390
|
-
const authoredTasks = ok.filter((r) => r.authoredChecks > 0).length
|
|
391
|
-
const receiptsSane = ok.every((r) => r.receipts.length > 0 && r.receipts.length === r.shots)
|
|
392
|
-
const ordering = final >= selected && selected >= blind
|
|
393
|
-
const liftPp = 100 * (final - blind)
|
|
394
|
-
const rescued = ok.filter((r) => r.finalHidden === 1 && (r.sampleHidden[0] ?? 0) === 0)
|
|
395
|
-
const checks: Array<[string, boolean, string]> = [
|
|
396
|
-
['authored checks on >=17/20 tasks', authoredTasks >= 17, `${authoredTasks}/${rows.length} tasks`],
|
|
397
|
-
['selection receipts present, scores match recorded outcomes', receiptsSane && ok.length > 0, `verified on ${ok.length} tasks (hard-checked per receipt)`],
|
|
398
|
-
['final >= selected >= blind and final-blind >= +5pp', ordering && liftPp >= 5, `blind ${pct(blind)} → selected ${pct(selected)} → final ${pct(final)} (+${liftPp.toFixed(1)}pp)`],
|
|
399
|
-
['>=1 task rescued (final passes, sample 0 fails)', rescued.length >= 1, rescued.map((r) => r.taskId).join(', ') || 'none'],
|
|
400
|
-
['zero crashes / unhandled rejections', errored.length === 0 && unhandled === 0, `${errored.length} task errors, ${unhandled} unhandled rejections`],
|
|
401
|
-
]
|
|
402
|
-
console.log('\n── acceptance ──')
|
|
403
|
-
let allPass = true
|
|
404
|
-
for (const [label, pass, detail] of checks) {
|
|
405
|
-
if (!pass) allPass = false
|
|
406
|
-
console.log(` [${pass ? 'PASS' : 'FAIL'}] ${label} — ${detail}`)
|
|
407
|
-
}
|
|
408
|
-
console.log(allPass ? '\nSMOKE: PASS' : '\nSMOKE: FAIL')
|
|
409
|
-
process.exit(allPass ? 0 : 1)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
main().catch((e) => {
|
|
413
|
-
console.error(e)
|
|
414
|
-
process.exit(1)
|
|
415
|
-
})
|
package/src/stats.mts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared statistics + scheduling helpers for the gate runners.
|
|
3
|
-
*
|
|
4
|
-
* The gate runners (humaneval / commit0 / aec / clbench-context / clbench-codebase)
|
|
5
|
-
* each hand-rolled the same three primitives: a bounded-concurrency pool, the
|
|
6
|
-
* mulberry32 PRNG, and the paired-bootstrap lift. They live here once.
|
|
7
|
-
*
|
|
8
|
-
* Two pools coexist on purpose, because the gates and the batch runners want
|
|
9
|
-
* different fault contracts:
|
|
10
|
-
* - `runPool` (re-exported from ./run-pool) catches a per-item throw and yields
|
|
11
|
-
* `{ ok, error }` for THAT item — the batch never aborts. Used by the batch
|
|
12
|
-
* runners / experiment harness that aggregate partial results.
|
|
13
|
-
* - `pool` (here) lets the worker throw and propagates the rejection — the gates
|
|
14
|
-
* want a router/sandbox fault to abort the arm loudly rather than score a
|
|
15
|
-
* phantom 0. It returns `R[]` in item order. This matches the gates' existing
|
|
16
|
-
* private `pool()` exactly; it is NOT a re-export of `runPool`.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export { runPool, type PoolOutcome } from './run-pool'
|
|
20
|
-
|
|
21
|
-
/** Bounded-concurrency pool: run `fn` over `items`, at most `limit` in flight,
|
|
22
|
-
* results returned in item order. A worker that throws propagates the rejection
|
|
23
|
-
* (fail-loud) — the gates rely on this so a router/judge fault aborts the arm
|
|
24
|
-
* rather than being silently scored. */
|
|
25
|
-
export async function pool<T, R>(items: T[], limit: number, fn: (item: T, idx: number) => Promise<R>): Promise<R[]> {
|
|
26
|
-
const results: R[] = new Array(items.length)
|
|
27
|
-
let next = 0
|
|
28
|
-
async function worker(): Promise<void> {
|
|
29
|
-
for (;;) {
|
|
30
|
-
const idx = next
|
|
31
|
-
next += 1
|
|
32
|
-
if (idx >= items.length) return
|
|
33
|
-
results[idx] = await fn(items[idx] as T, idx)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, () => worker()))
|
|
37
|
-
return results
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** mulberry32 — deterministic PRNG (Math.imul). Seeded once at 0x9e3779b9 by
|
|
41
|
-
* `pairedLift` so every gate's bootstrap CI is reproducible and identical. */
|
|
42
|
-
export function makeRng(seed: number): () => number {
|
|
43
|
-
let s = seed | 0
|
|
44
|
-
return () => {
|
|
45
|
-
s = (s + 0x6d2b79f5) | 0
|
|
46
|
-
let t = Math.imul(s ^ (s >>> 15), 1 | s)
|
|
47
|
-
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
|
|
48
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface PairedLift {
|
|
53
|
-
point: number
|
|
54
|
-
low: number
|
|
55
|
-
high: number
|
|
56
|
-
pairs: number
|
|
57
|
-
discordant: number
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Paired lift = mean over tasks of (treatment − baseline) with a 95% bootstrap
|
|
61
|
-
* CI from resampling the paired tasks (mulberry32 seeded 0x9e3779b9, B=10000).
|
|
62
|
-
* Works on {0,1} arms (humaneval/aec/commit0) and continuous values (clbench
|
|
63
|
-
* rubric fractions) alike. `discordant` uses a |d| > 1e-9 tolerance, which equals
|
|
64
|
-
* the exact `d !== 0` test on integer-delta (binary) arms and avoids counting
|
|
65
|
-
* float noise as a discordant pair on continuous arms. */
|
|
66
|
-
export function pairedLift(baseline: number[], treatment: number[], bootstrapN = 10000): PairedLift {
|
|
67
|
-
if (baseline.length !== treatment.length) throw new Error('pairedLift: misaligned arms')
|
|
68
|
-
const n = baseline.length
|
|
69
|
-
if (n === 0) throw new Error('pairedLift: no pairs')
|
|
70
|
-
const deltas = baseline.map((b, i) => (treatment[i] as number) - b)
|
|
71
|
-
const mean = (a: number[]) => a.reduce((s, x) => s + x, 0) / a.length
|
|
72
|
-
const point = mean(deltas)
|
|
73
|
-
const discordant = deltas.filter((d) => Math.abs(d) > 1e-9).length
|
|
74
|
-
const rng = makeRng(0x9e3779b9)
|
|
75
|
-
const rint = (m: number) => Math.floor(rng() * m)
|
|
76
|
-
const boots: number[] = []
|
|
77
|
-
for (let b = 0; b < bootstrapN; b += 1) {
|
|
78
|
-
let acc = 0
|
|
79
|
-
for (let j = 0; j < n; j += 1) acc += deltas[rint(n)] as number
|
|
80
|
-
boots.push(acc / n)
|
|
81
|
-
}
|
|
82
|
-
boots.sort((x, y) => x - y)
|
|
83
|
-
return {
|
|
84
|
-
point,
|
|
85
|
-
low: boots[Math.floor(0.025 * bootstrapN)] ?? Number.NaN,
|
|
86
|
-
high: boots[Math.floor(0.975 * bootstrapN)] ?? Number.NaN,
|
|
87
|
-
pairs: n,
|
|
88
|
-
discordant,
|
|
89
|
-
}
|
|
90
|
-
}
|