@tangle-network/agent-bench 0.3.7 → 0.4.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 +11 -0
- package/HARNESS.md +43 -0
- package/README.md +7 -0
- package/dist/adapters.js +23 -23
- package/dist/benchmarks/_harness.d.ts +1 -1
- package/dist/benchmarks/_harness.js +1 -1
- package/dist/benchmarks/aec-bench.js +2 -2
- package/dist/benchmarks/agentbench.js +2 -2
- package/dist/benchmarks/appworld.js +2 -2
- package/dist/benchmarks/bfcl.js +2 -2
- package/dist/benchmarks/commit0.js +2 -2
- package/dist/benchmarks/crag.js +2 -2
- package/dist/benchmarks/dabstep.js +2 -2
- package/dist/benchmarks/enterpriseops-gym.js +2 -2
- package/dist/benchmarks/finresearchbench.js +2 -2
- package/dist/benchmarks/nomiracl.js +2 -2
- package/dist/benchmarks/open-rag-bench.js +2 -2
- package/dist/benchmarks/programbench.js +2 -2
- package/dist/benchmarks/ragbench.js +2 -2
- package/dist/benchmarks/swe-bench.js +2 -2
- package/dist/benchmarks/t2-ragbench.js +2 -2
- package/dist/benchmarks/tau-bench-shared.js +2 -2
- package/dist/benchmarks/tau2-bench.js +3 -3
- package/dist/benchmarks/tau3-banking.js +3 -3
- package/dist/benchmarks/terminal-bench.js +2 -2
- package/dist/benchmarks/toollm.js +2 -2
- package/dist/benchmarks/webarena-verified.js +2 -2
- package/dist/{chunk-CKUVRZ2T.js → chunk-3U5TXJZS.js} +2 -2
- package/dist/{chunk-YCGY7UIZ.js → chunk-7GRVHU22.js} +2 -2
- package/dist/{chunk-Z7ML6L77.js → chunk-HWST3SED.js} +2 -2
- package/dist/{chunk-SYDW647C.js → chunk-IA2FBTWC.js} +2 -2
- package/dist/{chunk-R67DFVLO.js → chunk-IFVINJ4B.js} +2 -2
- package/dist/{chunk-R36V2VP7.js → chunk-IZ5M6OAC.js} +2 -2
- package/dist/{chunk-ODT47UAY.js → chunk-K3BQGZCT.js} +2 -2
- package/dist/{chunk-IFAV6KEM.js → chunk-KP5KD6EN.js} +2 -2
- package/dist/{chunk-ZEWMTR5M.js → chunk-MQMRLGOG.js} +2 -2
- package/dist/{chunk-TSWPNOYM.js → chunk-NQG5XDSB.js} +2 -2
- package/dist/{chunk-7WSD27QQ.js → chunk-PB64GYIG.js} +2 -2
- package/dist/{chunk-HBSWHQNJ.js → chunk-RCYQEFNX.js} +3 -3
- package/dist/{chunk-J3KDJNX2.js → chunk-RH5F53JT.js} +2 -2
- package/dist/{chunk-UAIOHCUK.js → chunk-SFLA7OH3.js} +3 -3
- package/dist/{chunk-Y6O2OCUO.js → chunk-SHM6MRRF.js} +2 -2
- package/dist/{chunk-KDIKRJGB.js → chunk-SHYIRB7I.js} +2 -2
- package/dist/{chunk-HHXFIHXC.js → chunk-SVR2LKYI.js} +2 -2
- package/dist/{chunk-PWQVGAJB.js → chunk-V7AEBY6U.js} +21 -21
- package/dist/{chunk-LRRD7NAG.js → chunk-WSKWVEQB.js} +18 -2
- package/dist/chunk-WSKWVEQB.js.map +1 -0
- package/dist/{chunk-2PVVP7GN.js → chunk-XKEFIFIC.js} +2 -2
- package/dist/{chunk-JRWWGMK7.js → chunk-XYA4XSNU.js} +2 -2
- package/dist/{chunk-X5YKXC6V.js → chunk-YSMEKBTD.js} +2 -2
- package/dist/{chunk-2XU6OGEN.js → chunk-Z4TZ76N7.js} +2 -2
- package/dist/index.js +23 -23
- package/package.json +5 -5
- package/scripts/trata-hedge/README.md +6 -5
- package/scripts/verify-packed-consumer.mjs +1 -1
- package/src/benchmarks/_harness.ts +20 -2
- package/src/benchmarks/humaneval.test.mts +2 -2
- package/src/gate.ts +1 -1
- package/src/hev-eval.mts +5 -2
- package/src/hev-improve.mts +118 -73
- package/src/official-optimizer-config.mts +89 -0
- package/src/official-optimizer-config.test.mts +88 -0
- package/src/profiles.ts +2 -2
- package/src/quant-arena/README.md +144 -0
- package/src/quant-arena/backtest.test.mts +135 -0
- package/src/quant-arena/backtest.ts +218 -0
- package/src/quant-arena/data.test.mts +44 -0
- package/src/quant-arena/data.ts +141 -0
- package/src/quant-arena/driver.test.mts +253 -0
- package/src/quant-arena/driver.ts +219 -0
- package/src/quant-arena/fixtures/data/PROVENANCE.md +26 -0
- package/src/quant-arena/fixtures/data/holdout/IDX.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S01.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S02.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S03.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S04.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S05.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S06.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S07.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S08.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S09.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S10.csv +523 -0
- package/src/quant-arena/fixtures/data/insample/IDX.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S01.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S02.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S03.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S04.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S05.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S06.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S07.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S08.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S09.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S10.csv +2087 -0
- package/src/quant-arena/fixtures/demo-campaign/cost-ledger.jsonl +16 -0
- package/src/quant-arena/fixtures/demo-campaign/notebook.jsonl +5 -0
- package/src/quant-arena/fixtures/demo-campaign/rollout-manifest.json +171 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-001-default-author/strategy.ts +119 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-002-default-author/strategy.ts +119 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-003-quant-researcher/strategy.ts +105 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-004-quant-researcher/strategy.ts +102 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/cost-ledger.jsonl +4 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/notebook.jsonl +2 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/rollout-manifest.json +84 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/strategies/cand-001-quant-researcher/strategy.ts +117 -0
- package/src/quant-arena/holdout-certify.mts +206 -0
- package/src/quant-arena/holdout-certify.test.mts +82 -0
- package/src/quant-arena/leak-audit.test.mts +79 -0
- package/src/quant-arena/leak-audit.ts +95 -0
- package/src/quant-arena/make-fixtures.mts +161 -0
- package/src/quant-arena/multiplicity.test.mts +68 -0
- package/src/quant-arena/multiplicity.ts +87 -0
- package/src/quant-arena/nautilus-certify.ts +31 -0
- package/src/quant-arena/oms.ts +90 -0
- package/src/quant-arena/profiles/quant-researcher.profile.json +7 -0
- package/src/quant-arena/python/pyproject.toml +8 -0
- package/src/quant-arena/python/uv.lock +1297 -0
- package/src/quant-arena/python/vbt-worker.py +192 -0
- package/src/quant-arena/quant-loop.mts +813 -0
- package/src/quant-arena/quant-loop.test.mts +75 -0
- package/src/quant-arena/strategies/buy-hold-index/strategy.ts +11 -0
- package/src/quant-arena/strategies/equal-weight/strategy.ts +20 -0
- package/src/quant-arena/strategies/sma-crossover/strategy.ts +42 -0
- package/src/quant-arena/types.ts +133 -0
- package/src/quant-arena/vbt-client.ts +321 -0
- package/src/quant-arena/vbt-parity.test.mts +183 -0
- package/src/quant-arena/windows.test.mts +45 -0
- package/src/quant-arena/windows.ts +54 -0
- package/src/rollout-ledger/backfill-swe-arena.mts +606 -0
- package/src/rollout-ledger/backfill-swe-arena.test.mts +342 -0
- package/src/rollout-ledger/settle-capture.mts +442 -0
- package/src/rollout-ledger/settle-capture.test.mts +270 -0
- package/src/smoke-structural-rollout.mts +15 -9
- package/src/swe-arena/activation.mts +225 -0
- package/src/swe-arena/activation.test.mts +300 -0
- package/src/swe-arena/arms.ts +30 -14
- package/src/swe-arena/briefing.mts +217 -0
- package/src/swe-arena/briefing.test.mts +178 -0
- package/src/swe-arena/calibrate.ts +102 -1
- package/src/swe-arena/cell-evidence.mts +41 -9
- package/src/swe-arena/factory-command-container.ts +284 -0
- package/src/swe-arena/factory-judge-child.mts +228 -0
- package/src/swe-arena/factory.test.mts +643 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/calibration.md +51 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/manifest.json +29 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/spec.md +64 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/calibration.md +48 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/manifest.json +29 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/spec.md +48 -0
- package/src/swe-arena/fixtures/factory/loops-28/calibration.md +47 -0
- package/src/swe-arena/fixtures/factory/loops-28/manifest.json +30 -0
- package/src/swe-arena/fixtures/factory/loops-28/spec.md +50 -0
- package/src/swe-arena/fixtures/run-report/README.md +43 -0
- package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.json +173 -0
- package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.md +100 -0
- package/src/swe-arena/fixtures/run-report/gen3-rollup.json +551 -0
- package/src/swe-arena/fixtures/run-report/gen3-rollup.md +64 -0
- package/src/swe-arena/fixtures.ts +135 -2
- package/src/swe-arena/gepa-seat.mts +877 -0
- package/src/swe-arena/gepa-seat.test.mts +1059 -0
- package/src/swe-arena/implementation-ref.test.mts +64 -0
- package/src/swe-arena/implementation-ref.ts +62 -0
- package/src/swe-arena/ledger-orphans.mts +77 -0
- package/src/swe-arena/ledger-orphans.test.mts +147 -0
- package/src/swe-arena/outer-loop.mts +710 -33
- package/src/swe-arena/premeasured-from-cells.mts +281 -0
- package/src/swe-arena/premeasured-from-cells.test.mts +180 -0
- package/src/swe-arena/proposer-fanout.mts +327 -31
- package/src/swe-arena/proposer-fanout.test.mts +246 -0
- package/src/swe-arena/proposer-provenance.mts +172 -0
- package/src/swe-arena/proposer-provenance.test.mts +106 -0
- package/src/swe-arena/run-experiment.mts +367 -1
- package/src/swe-arena/run-report.mts +75 -0
- package/src/swe-arena/run-supervisor.test.mts +5 -3
- package/src/swe-arena/score-split.mts +140 -0
- package/src/swe-arena/score-split.test.mts +123 -0
- package/src/swe-arena/scratch-worktree.test.mts +55 -0
- package/src/swe-arena/scratch-worktree.ts +34 -0
- package/src/swe-arena/types.ts +52 -0
- package/src/swe-code-improve.mts +24 -25
- package/src/swe-improve.mts +129 -96
- package/src/swe-local-proof.mts +6 -1
- package/src/swe-stream.mts +4 -2
- package/src/swe-structural.mts +245 -837
- package/src/tb-container-executor.test.mts +30 -6
- package/src/tb-supervisor-sidecar.mts +2 -1
- package/src/trata-gepa.mts +182 -245
- package/dist/chunk-LRRD7NAG.js.map +0 -1
- package/src/live-improve-campaign-mbpp.mts +0 -641
- package/src/live-improve-campaign.mts +0 -500
- /package/dist/{chunk-CKUVRZ2T.js.map → chunk-3U5TXJZS.js.map} +0 -0
- /package/dist/{chunk-YCGY7UIZ.js.map → chunk-7GRVHU22.js.map} +0 -0
- /package/dist/{chunk-Z7ML6L77.js.map → chunk-HWST3SED.js.map} +0 -0
- /package/dist/{chunk-SYDW647C.js.map → chunk-IA2FBTWC.js.map} +0 -0
- /package/dist/{chunk-R67DFVLO.js.map → chunk-IFVINJ4B.js.map} +0 -0
- /package/dist/{chunk-R36V2VP7.js.map → chunk-IZ5M6OAC.js.map} +0 -0
- /package/dist/{chunk-ODT47UAY.js.map → chunk-K3BQGZCT.js.map} +0 -0
- /package/dist/{chunk-IFAV6KEM.js.map → chunk-KP5KD6EN.js.map} +0 -0
- /package/dist/{chunk-ZEWMTR5M.js.map → chunk-MQMRLGOG.js.map} +0 -0
- /package/dist/{chunk-TSWPNOYM.js.map → chunk-NQG5XDSB.js.map} +0 -0
- /package/dist/{chunk-7WSD27QQ.js.map → chunk-PB64GYIG.js.map} +0 -0
- /package/dist/{chunk-HBSWHQNJ.js.map → chunk-RCYQEFNX.js.map} +0 -0
- /package/dist/{chunk-J3KDJNX2.js.map → chunk-RH5F53JT.js.map} +0 -0
- /package/dist/{chunk-UAIOHCUK.js.map → chunk-SFLA7OH3.js.map} +0 -0
- /package/dist/{chunk-Y6O2OCUO.js.map → chunk-SHM6MRRF.js.map} +0 -0
- /package/dist/{chunk-KDIKRJGB.js.map → chunk-SHYIRB7I.js.map} +0 -0
- /package/dist/{chunk-HHXFIHXC.js.map → chunk-SVR2LKYI.js.map} +0 -0
- /package/dist/{chunk-PWQVGAJB.js.map → chunk-V7AEBY6U.js.map} +0 -0
- /package/dist/{chunk-2PVVP7GN.js.map → chunk-XKEFIFIC.js.map} +0 -0
- /package/dist/{chunk-JRWWGMK7.js.map → chunk-XYA4XSNU.js.map} +0 -0
- /package/dist/{chunk-X5YKXC6V.js.map → chunk-YSMEKBTD.js.map} +0 -0
- /package/dist/{chunk-2XU6OGEN.js.map → chunk-Z4TZ76N7.js.map} +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { mkdir, 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 { assertRolloutLine, claudeProjectSlug, toSftRows } from '@tangle-network/agent-eval/rollout'
|
|
6
|
+
import { backfillSweArena } from './backfill-swe-arena.mts'
|
|
7
|
+
|
|
8
|
+
let dir: string
|
|
9
|
+
let outDir: string
|
|
10
|
+
let dbPath: string
|
|
11
|
+
let projectsDir: string
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
dir = await mkdtemp(join(tmpdir(), 'backfill-swe-'))
|
|
14
|
+
outDir = join(dir, 'out')
|
|
15
|
+
dbPath = join(dir, 'opencode.db')
|
|
16
|
+
projectsDir = join(dir, 'claude-projects')
|
|
17
|
+
})
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
await rm(dir, { recursive: true, force: true })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const COMMIT = '1deb554c45d31dd0d4a851efe90da875cd9b50c8'
|
|
23
|
+
const WORKER_CWD = '/tmp/loops-w-0-backfill-fixture'
|
|
24
|
+
const MISSING_CWD = '/tmp/loops-w-1-backfill-missing'
|
|
25
|
+
|
|
26
|
+
async function writeJson(path: string, value: unknown): Promise<void> {
|
|
27
|
+
await mkdir(join(path, '..'), { recursive: true })
|
|
28
|
+
await writeFile(path, JSON.stringify(value, null, 1))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function cachedResult(iid: string, resolved: boolean, runDir: string): unknown {
|
|
32
|
+
return {
|
|
33
|
+
manifestHash: 'x',
|
|
34
|
+
cellId: `${iid}:0`,
|
|
35
|
+
scenarioId: iid,
|
|
36
|
+
rep: 0,
|
|
37
|
+
artifact: {
|
|
38
|
+
kind: 'swe-arm',
|
|
39
|
+
iid,
|
|
40
|
+
commit: COMMIT,
|
|
41
|
+
resolved,
|
|
42
|
+
verifyPass: true,
|
|
43
|
+
patchLines: 12,
|
|
44
|
+
wallS: 549,
|
|
45
|
+
spentTokens: 70222,
|
|
46
|
+
spentUsd: 0.05,
|
|
47
|
+
recoveredTokens: 169560,
|
|
48
|
+
workerTokIn: 100,
|
|
49
|
+
workerTokOut: 50,
|
|
50
|
+
judgeAttempts: 1,
|
|
51
|
+
judgeWallS: 62,
|
|
52
|
+
runDir,
|
|
53
|
+
patchPath: join(runDir, 'patch.diff'),
|
|
54
|
+
},
|
|
55
|
+
judgeScores: {
|
|
56
|
+
'swe-arena-official-judge': { composite: resolved ? 1 : 0, dimensions: { resolved: resolved ? 1 : 0 } },
|
|
57
|
+
},
|
|
58
|
+
costUsd: 0.05,
|
|
59
|
+
costEstimated: false,
|
|
60
|
+
costCallIds: ['call-a'],
|
|
61
|
+
tokenUsage: { input: 100, output: 50 },
|
|
62
|
+
resolvedModel: 'zai-coding-plan/glm-5.2',
|
|
63
|
+
durationMs: 639038,
|
|
64
|
+
seed: 42,
|
|
65
|
+
cached: false,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function writeArmRun(runDir: string, iid: string, resolved: boolean, workerCwds: string[]): Promise<void> {
|
|
70
|
+
await mkdir(runDir, { recursive: true })
|
|
71
|
+
await writeJson(join(runDir, 'judge.json'), { iid, resolved, score: resolved ? 1 : 0, secs: 59, attempts: 1 })
|
|
72
|
+
await writeJson(join(runDir, 'result.json'), {
|
|
73
|
+
arm: 'R4',
|
|
74
|
+
iid,
|
|
75
|
+
driver_rc: 0,
|
|
76
|
+
wall_s: 549,
|
|
77
|
+
sup_status: 'completed',
|
|
78
|
+
sup_verdict: 'delivered',
|
|
79
|
+
spawned: 2,
|
|
80
|
+
workers: workerCwds.length,
|
|
81
|
+
settled: workerCwds.length,
|
|
82
|
+
subtasks: ['fix-it'],
|
|
83
|
+
recoveredSpend: {
|
|
84
|
+
workerTokJournal: 0,
|
|
85
|
+
workerCwds,
|
|
86
|
+
workerSessions: workerCwds.length,
|
|
87
|
+
workerTokSqlite: 150,
|
|
88
|
+
workerTokIn: 100,
|
|
89
|
+
workerTokOut: 50,
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
await writeFile(join(runDir, 'patch.diff'), 'diff --git a/x b/x\n')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function buildFixtureDb(): Promise<void> {
|
|
96
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
97
|
+
const db = new DatabaseSync(dbPath)
|
|
98
|
+
db.exec(`
|
|
99
|
+
CREATE TABLE session (
|
|
100
|
+
id text PRIMARY KEY, project_id text NOT NULL, parent_id text, slug text, directory text NOT NULL,
|
|
101
|
+
title text, version text, agent text, model text, cost real DEFAULT 0 NOT NULL,
|
|
102
|
+
tokens_input integer DEFAULT 0 NOT NULL, tokens_output integer DEFAULT 0 NOT NULL,
|
|
103
|
+
tokens_reasoning integer DEFAULT 0 NOT NULL, tokens_cache_read integer DEFAULT 0 NOT NULL,
|
|
104
|
+
tokens_cache_write integer DEFAULT 0 NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL
|
|
105
|
+
);
|
|
106
|
+
CREATE TABLE message (id text PRIMARY KEY, session_id text NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL, data text NOT NULL);
|
|
107
|
+
CREATE TABLE part (id text PRIMARY KEY, message_id text NOT NULL, session_id text NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL, data text NOT NULL);
|
|
108
|
+
`)
|
|
109
|
+
db.prepare(
|
|
110
|
+
`INSERT INTO session (id, project_id, parent_id, directory, agent, model, cost, tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write, time_created, time_updated)
|
|
111
|
+
VALUES ('ses_w0', 'prj', 'ses_root', ?, 'build', '{"id":"glm-5.2","providerID":"tangle-router"}', 0, 100, 50, 5, 30, 10, 1000, 61000)`,
|
|
112
|
+
).run(WORKER_CWD)
|
|
113
|
+
db.prepare("INSERT INTO message (id, session_id, time_created, time_updated, data) VALUES ('msg_u', 'ses_w0', 1000, 1000, ?)").run(
|
|
114
|
+
JSON.stringify({ role: 'user' }),
|
|
115
|
+
)
|
|
116
|
+
db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_u', 'msg_u', 'ses_w0', 1000, 1000, ?)").run(
|
|
117
|
+
JSON.stringify({ type: 'text', text: 'Fix the failing test.' }),
|
|
118
|
+
)
|
|
119
|
+
db.prepare("INSERT INTO message (id, session_id, time_created, time_updated, data) VALUES ('msg_a', 'ses_w0', 2000, 2000, ?)").run(
|
|
120
|
+
JSON.stringify({ role: 'assistant', modelID: 'glm-5.2', providerID: 'tangle-router' }),
|
|
121
|
+
)
|
|
122
|
+
db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_a1', 'msg_a', 'ses_w0', 2000, 2000, ?)").run(
|
|
123
|
+
JSON.stringify({ type: 'step-start' }),
|
|
124
|
+
)
|
|
125
|
+
db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_a2', 'msg_a', 'ses_w0', 2000, 2000, ?)").run(
|
|
126
|
+
JSON.stringify({ type: 'text', text: 'Patched.' }),
|
|
127
|
+
)
|
|
128
|
+
db.close()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function buildFixtureTree(): Promise<void> {
|
|
132
|
+
// Baseline (resolved=false) + gen-0 candidate-0 (resolved=true), same
|
|
133
|
+
// instance — resolvedInstanceCount scores candidates against the baseline's
|
|
134
|
+
// instance set, exactly like a real round.
|
|
135
|
+
const baselineRun = join(outDir, 'arm-runs', 'baseline', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4')
|
|
136
|
+
const candidateRun = join(outDir, 'arm-runs', 'cand-0', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4')
|
|
137
|
+
await writeArmRun(baselineRun, 'astropy__astropy-13033', false, [WORKER_CWD, MISSING_CWD])
|
|
138
|
+
await writeArmRun(candidateRun, 'astropy__astropy-13033', true, [WORKER_CWD])
|
|
139
|
+
await writeJson(
|
|
140
|
+
join(outDir, 'improve-run', 'baseline', 'astropy__astropy-13033_0', 'cached-result.json'),
|
|
141
|
+
cachedResult('astropy__astropy-13033', false, baselineRun),
|
|
142
|
+
)
|
|
143
|
+
await writeJson(
|
|
144
|
+
join(outDir, 'improve-run', 'gen-0', 'candidate-0', 'astropy__astropy-13033_0', 'cached-result.json'),
|
|
145
|
+
cachedResult('astropy__astropy-13033', true, candidateRun),
|
|
146
|
+
)
|
|
147
|
+
await writeJson(join(outDir, 'improve-run', 'loop-provenance.json'), {
|
|
148
|
+
schema: 'tangle.loop-provenance',
|
|
149
|
+
runId: `${outDir}/improve-run#42`,
|
|
150
|
+
})
|
|
151
|
+
await mkdir(join(outDir, 'candidates'), { recursive: true })
|
|
152
|
+
await writeFile(join(outDir, 'candidates', `${COMMIT.slice(0, 10)}.patch`), 'diff --git a/y b/y\n')
|
|
153
|
+
|
|
154
|
+
// Proposer shot receipt + matching claude transcript.
|
|
155
|
+
await writeJson(join(outDir, 'proposer-shots', 'default-author', 'gen0-cand0-shot1.json'), {
|
|
156
|
+
receipt: {
|
|
157
|
+
generation: 0,
|
|
158
|
+
candidateIndex: 0,
|
|
159
|
+
shot: 1,
|
|
160
|
+
maxShots: 3,
|
|
161
|
+
harness: 'claude',
|
|
162
|
+
model: null,
|
|
163
|
+
promptSha256: 'sha256:abc',
|
|
164
|
+
startedAt: '2026-07-22T19:27:18.350Z',
|
|
165
|
+
completedAt: '2026-07-22T19:34:55.925Z',
|
|
166
|
+
durationMs: 457571,
|
|
167
|
+
exitCode: 0,
|
|
168
|
+
timedOut: false,
|
|
169
|
+
costUsd: null,
|
|
170
|
+
},
|
|
171
|
+
stdoutTail: 'Done.',
|
|
172
|
+
})
|
|
173
|
+
const proposerCwd = join(outDir, 'proposer-wt', 'gen0-cand0-default-author')
|
|
174
|
+
const projectDir = join(projectsDir, claudeProjectSlug(proposerCwd))
|
|
175
|
+
await mkdir(projectDir, { recursive: true })
|
|
176
|
+
await writeFile(
|
|
177
|
+
join(projectDir, 'sess-1.jsonl'),
|
|
178
|
+
[
|
|
179
|
+
JSON.stringify({
|
|
180
|
+
type: 'user',
|
|
181
|
+
timestamp: '2026-07-22T19:27:19.104Z',
|
|
182
|
+
message: { role: 'user', content: 'Improve the supervisor.' },
|
|
183
|
+
}),
|
|
184
|
+
JSON.stringify({
|
|
185
|
+
type: 'assistant',
|
|
186
|
+
timestamp: '2026-07-22T19:27:21.583Z',
|
|
187
|
+
message: {
|
|
188
|
+
id: 'msg_p1',
|
|
189
|
+
model: 'claude-fable-5',
|
|
190
|
+
role: 'assistant',
|
|
191
|
+
content: [{ type: 'text', text: 'Diagnosed and patched the prompts.' }],
|
|
192
|
+
usage: { input_tokens: 2, output_tokens: 462, cache_read_input_tokens: 15109, cache_creation_input_tokens: 33218 },
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
].join('\n') + '\n',
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
describe('backfillSweArena', () => {
|
|
200
|
+
it('joins cells, worker sessions, and proposer shots into labeled ledger lines', async () => {
|
|
201
|
+
await buildFixtureTree()
|
|
202
|
+
await buildFixtureDb()
|
|
203
|
+
const { lines, stats } = await backfillSweArena(outDir, {
|
|
204
|
+
opencodeDb: dbPath,
|
|
205
|
+
claudeProjectsDir: projectsDir,
|
|
206
|
+
now: () => new Date('2026-07-23T00:00:00.000Z'),
|
|
207
|
+
})
|
|
208
|
+
for (const line of lines) assertRolloutLine(line)
|
|
209
|
+
|
|
210
|
+
// 2 supervisors + 3 worker cwd joins (2 found, 1 missing) + 1 proposer.
|
|
211
|
+
expect(stats.lines).toBe(6)
|
|
212
|
+
expect(stats.byRole).toEqual({ supervisor: 2, worker: 3, proposer: 1 })
|
|
213
|
+
expect(stats.fullTranscripts).toBe(3)
|
|
214
|
+
expect(stats.gapLines).toBe(3)
|
|
215
|
+
expect(stats.workerSessionsJoined).toBe(2)
|
|
216
|
+
expect(stats.workerCwdsMissed).toBe(1)
|
|
217
|
+
expect(stats.proposerShotsJoined).toBe(1)
|
|
218
|
+
expect(stats.rewardLabeled).toBe(6)
|
|
219
|
+
|
|
220
|
+
const runId = `${outDir}/improve-run#42`
|
|
221
|
+
expect(new Set(lines.map((l) => l.run_id))).toEqual(new Set([runId]))
|
|
222
|
+
|
|
223
|
+
const baselineSup = lines.find((l) => l.role === 'supervisor' && l.candidate_index === -1)
|
|
224
|
+
expect(baselineSup).toBeDefined()
|
|
225
|
+
expect(baselineSup?.candidate_id).toBe('baseline')
|
|
226
|
+
expect(baselineSup?.outcome.reward).toBe(0)
|
|
227
|
+
expect(baselineSup?.outcome.reward_source).toBe('swe-arena-official-judge')
|
|
228
|
+
expect(baselineSup?.outcome.verdict).toMatchObject({ iid: 'astropy__astropy-13033', resolved: false })
|
|
229
|
+
expect(baselineSup?.policy).toMatchObject({ harness: 'pi-loops', model: 'glm-5.2', provider: 'zai-coding-plan' })
|
|
230
|
+
expect(baselineSup?.task).toMatchObject({ split: 'search', seed: 42, rep: 0 })
|
|
231
|
+
expect(baselineSup?.provenance.gap).toMatch(/brain transcript/)
|
|
232
|
+
|
|
233
|
+
const candidateSup = lines.find((l) => l.role === 'supervisor' && l.candidate_index === 0)
|
|
234
|
+
expect(candidateSup?.outcome.reward).toBe(1)
|
|
235
|
+
expect(candidateSup?.generation).toBe(0)
|
|
236
|
+
expect(candidateSup?.candidate_id).toBe('gen0-cand0')
|
|
237
|
+
|
|
238
|
+
const workers = lines.filter((l) => l.role === 'worker')
|
|
239
|
+
const joined = workers.filter((l) => l.messages.length > 0)
|
|
240
|
+
expect(joined).toHaveLength(2)
|
|
241
|
+
for (const worker of joined) {
|
|
242
|
+
expect(worker.parent_rollout_id).toBe(
|
|
243
|
+
lines.find((l) => l.role === 'supervisor' && l.candidate_index === worker.candidate_index)?.rollout_id,
|
|
244
|
+
)
|
|
245
|
+
expect(worker.outcome.reward_source).toBe('swe-arena-official-judge/inherited')
|
|
246
|
+
expect(worker.policy).toMatchObject({ harness: 'opencode', model: 'glm-5.2', provider: 'tangle-router' })
|
|
247
|
+
expect(worker.cost).toMatchObject({ tokens_in: 100, tokens_out: 50, tokens_reasoning: 5 })
|
|
248
|
+
expect(worker.artifacts.transcript_ref).toBe('opencode:ses_w0')
|
|
249
|
+
expect(worker.messages[0]).toEqual({ role: 'user', content: 'Fix the failing test.' })
|
|
250
|
+
}
|
|
251
|
+
const missed = workers.find((l) => l.messages.length === 0)
|
|
252
|
+
expect(missed?.provenance.gap).toMatch(/no opencode session/)
|
|
253
|
+
expect(missed?.outcome.reward).toBe(0)
|
|
254
|
+
|
|
255
|
+
const proposer = lines.find((l) => l.role === 'proposer')
|
|
256
|
+
expect(proposer?.messages).toHaveLength(2)
|
|
257
|
+
expect(proposer?.outcome.reward).toBe(1)
|
|
258
|
+
expect(proposer?.outcome.reward_source).toBe('swe-arena-official-judge/candidate-resolved-fraction')
|
|
259
|
+
expect(proposer?.policy).toMatchObject({ harness: 'claude', model: 'claude-fable-5' })
|
|
260
|
+
expect(proposer?.cost.tokens_out).toBe(462)
|
|
261
|
+
expect(proposer?.task).toMatchObject({ suite: 'swe-arena-proposer', rep: 1 })
|
|
262
|
+
|
|
263
|
+
// The dataset is immediately trainable: reward==1 trainable-split lines
|
|
264
|
+
// with transcripts → SFT rows (candidate worker + proposer here).
|
|
265
|
+
expect(toSftRows(lines)).toHaveLength(2)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('joins a respawned worker cwd once, not once per recovered entry', async () => {
|
|
269
|
+
await buildFixtureTree()
|
|
270
|
+
await buildFixtureDb()
|
|
271
|
+
// A crashed-and-retried worker reuses its clone dir, so the recovered list
|
|
272
|
+
// names it twice.
|
|
273
|
+
await writeArmRun(
|
|
274
|
+
join(outDir, 'arm-runs', 'cand-0', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4'),
|
|
275
|
+
'astropy__astropy-13033',
|
|
276
|
+
true,
|
|
277
|
+
[WORKER_CWD, WORKER_CWD],
|
|
278
|
+
)
|
|
279
|
+
const { lines, stats } = await backfillSweArena(outDir, {
|
|
280
|
+
opencodeDb: dbPath,
|
|
281
|
+
claudeProjectsDir: projectsDir,
|
|
282
|
+
})
|
|
283
|
+
const candidateWorkers = lines.filter((l) => l.role === 'worker' && l.candidate_index === 0)
|
|
284
|
+
expect(candidateWorkers).toHaveLength(1)
|
|
285
|
+
expect(stats.workerSessionsJoined).toBe(2)
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it(
|
|
289
|
+
'marks a session with no readable parts as an incomplete gap line',
|
|
290
|
+
async () => {
|
|
291
|
+
await buildFixtureTree()
|
|
292
|
+
await buildFixtureDb()
|
|
293
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
294
|
+
const db = new DatabaseSync(dbPath)
|
|
295
|
+
// Session row survives; its message parts do not.
|
|
296
|
+
db.exec("DELETE FROM part; DELETE FROM message")
|
|
297
|
+
db.close()
|
|
298
|
+
|
|
299
|
+
const { lines, stats } = await backfillSweArena(outDir, {
|
|
300
|
+
opencodeDb: dbPath,
|
|
301
|
+
claudeProjectsDir: projectsDir,
|
|
302
|
+
})
|
|
303
|
+
const joinedCwd = lines.filter((l) => l.role === 'worker' && l.outcome.metrics.has_session === true)
|
|
304
|
+
expect(joinedCwd.length).toBeGreaterThan(0)
|
|
305
|
+
for (const worker of joinedCwd) {
|
|
306
|
+
expect(worker.messages).toHaveLength(0)
|
|
307
|
+
expect(worker.outcome.is_completed).toBe(false)
|
|
308
|
+
expect(worker.provenance.gap).toMatch(/no readable message parts/)
|
|
309
|
+
}
|
|
310
|
+
// The store-integrity failure is counted apart from the cwd-join failure.
|
|
311
|
+
expect(stats.workerSessionsEmpty).toBe(2)
|
|
312
|
+
expect(stats.workerCwdsMissed).toBe(1)
|
|
313
|
+
expect(stats.workerSessionsJoined).toBe(0)
|
|
314
|
+
},
|
|
315
|
+
15_000,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
it('fails loud on a cell cache that carries no scenarioId/rep identity', async () => {
|
|
319
|
+
await buildFixtureTree()
|
|
320
|
+
await writeJson(join(outDir, 'improve-run', 'baseline', 'astropy__astropy-13033_0', 'cached-result.json'), {
|
|
321
|
+
artifact: { resolved: true },
|
|
322
|
+
})
|
|
323
|
+
await expect(
|
|
324
|
+
backfillSweArena(outDir, { opencodeDb: join(dir, 'absent.db'), claudeProjectsDir: projectsDir }),
|
|
325
|
+
).rejects.toThrow(/is not a campaign cell \(scenarioId\/rep missing\)/)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('records worker gap lines when the opencode store is unavailable', async () => {
|
|
329
|
+
await buildFixtureTree()
|
|
330
|
+
const { lines, stats } = await backfillSweArena(outDir, {
|
|
331
|
+
opencodeDb: join(dir, 'absent.db'),
|
|
332
|
+
claudeProjectsDir: projectsDir,
|
|
333
|
+
})
|
|
334
|
+
expect(stats.opencodeDbAvailable).toBe(false)
|
|
335
|
+
const workers = lines.filter((l) => l.role === 'worker')
|
|
336
|
+
expect(workers).toHaveLength(3)
|
|
337
|
+
for (const worker of workers) {
|
|
338
|
+
expect(worker.messages).toHaveLength(0)
|
|
339
|
+
expect(worker.provenance.gap).toMatch(/opencode store unavailable/)
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
})
|