|
| 1 | +name: ContextBench Real CBM Go One |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - .github/workflows/contextbench-real-cbm-go-one.yml |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + cbm-go-one: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + timeout-minutes: 45 |
| 17 | + env: |
| 18 | + ROOT: /tmp/contextbench-real-cbm-go-one |
| 19 | + TASK_PAYLOADS: /tmp/contextbench-real-cbm-go-one/task-payloads.json |
| 20 | + CHECKOUT_ROOT: /tmp/contextbench-checkouts |
| 21 | + OPENAI_MODEL: gpt-5.4-mini |
| 22 | + OPENAI_REASONING_EFFORT: high |
| 23 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 24 | + CBM_BIN: /tmp/contextbench-real-cbm-go-one/tool/codebase-memory-mcp |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - uses: pnpm/action-setup@v2 |
| 28 | + with: |
| 29 | + version: 10 |
| 30 | + - uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: '24' |
| 33 | + cache: pnpm |
| 34 | + - uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: '3.11' |
| 37 | + - name: Install and materialize |
| 38 | + run: | |
| 39 | + set -euxo pipefail |
| 40 | + mkdir -p "$ROOT" "$CHECKOUT_ROOT" "$ROOT/tool" |
| 41 | + pnpm install --frozen-lockfile |
| 42 | + python -m pip install "tree-sitter==0.20.4" "tree-sitter-languages==1.10.2" datasets pyarrow |
| 43 | + curl -fsSL "https://github.com/DeusData/codebase-memory-mcp/releases/download/v0.6.1/codebase-memory-mcp-linux-amd64.tar.gz" -o "$ROOT/tool/cbm.tar.gz" |
| 44 | + tar -xzf "$ROOT/tool/cbm.tar.gz" -C "$ROOT/tool" |
| 45 | + chmod +x "$CBM_BIN" || true |
| 46 | + git clone --depth 1 https://github.com/EuniAI/ContextBench.git "$ROOT/ContextBench-official" |
| 47 | + node scripts/contextbench-runner.mjs --validate-fixtures |
| 48 | + node scripts/contextbench-select-slice.mjs --write-task-payloads --out "$TASK_PAYLOADS" --checkout-root "$CHECKOUT_ROOT" |
| 49 | + node scripts/contextbench-select-slice.mjs --materialize-checkouts --payloads "$TASK_PAYLOADS" --max-tasks 3 |
| 50 | + - name: Run one bounded scoreable CBM row |
| 51 | + env: |
| 52 | + OFFICIAL_CONTEXTBENCH: /tmp/contextbench-real-cbm-go-one/ContextBench-official |
| 53 | + run: | |
| 54 | + cat > "$ROOT/one.mjs" <<'NODE' |
| 55 | + import { spawnSync } from 'node:child_process'; |
| 56 | + import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; |
| 57 | + import { basename, join } from 'node:path'; |
| 58 | + const root = process.env.ROOT; |
| 59 | + const payloads = JSON.parse(readFileSync(process.env.TASK_PAYLOADS, 'utf8')); |
| 60 | + const task = payloads.tasks[2]; |
| 61 | + const runDir = join(root, 'row-codebase-memory-mcp-go'); |
| 62 | + mkdirSync(runDir, { recursive: true }); |
| 63 | + function run(cmd, args, opts = {}) { const started = Date.now(); const r = spawnSync(cmd, args, { cwd: opts.cwd || process.cwd(), env: opts.env || process.env, encoding: 'utf8', timeout: opts.timeoutMs || 600000, maxBuffer: 128 * 1024 * 1024 }); return { command: [cmd, ...args].join(' '), cwd: opts.cwd || process.cwd(), status: r.status, signal: r.signal, error: r.error?.message || null, durationMs: Date.now() - started, stdout: r.stdout || '', stderr: r.stderr || '' }; } |
| 64 | + function queryOf(s) { return String(s || '').replace(/[`*_#>\[\](){},.;:!?/\\]/g, ' ').split(/\s+/).filter((w) => w.length >= 4).slice(0, 10).join(' '); } |
| 65 | + function jsonish(s) { const t = String(s || '').trim(); if (!t) return null; try { return JSON.parse(t); } catch {} for (const [a,b] of [['{','}'],['[',']']]) { const i=t.indexOf(a), j=t.lastIndexOf(b); if (i>=0 && j>i) { try { return JSON.parse(t.slice(i,j+1)); } catch {} } } return null; } |
| 66 | + function add(locs, file, start = 1, end = start, source = 'cbm') { if (!file || typeof file !== 'string' || file.includes('://')) return; const clean = file.replace(/^\/+/, '').replace(/^\.\//, ''); if (!clean || clean.includes('..')) return; const s = Math.max(1, Number(start) || 1); locs.push({ file: clean, start: s, end: Math.max(s, Number(end) || s), source }); } |
| 67 | + function walk(v, locs) { if (!v || typeof v !== 'object') return; if (Array.isArray(v)) { for (const x of v) walk(x, locs); return; } add(locs, v.file || v.path || v.file_path || v.relative_path || v.filename || v.source_path, v.start_line || v.line || 1, v.end_line || v.line || 1); for (const x of Object.values(v)) walk(x, locs); } |
| 68 | + function collect(text, locs) { const parsed = jsonish(text); if (parsed) walk(parsed, locs); const re = /([A-Za-z0-9_.\/-]+\.(?:js|jsx|ts|tsx|py|go|rs|java|c|cc|cpp|h|hpp|rb|php|cs|kt|swift|vue|svelte|json|yml|yaml|md))(?::|#L|\s+line\s+)?(\d+)?/g; let m; while ((m = re.exec(String(text || ''))) !== null) add(locs, m[1], m[2] || 1, m[2] || 1); } |
| 69 | + function uniq(locs) { const seen = new Set(), out = []; for (const loc of locs) { const k = `${loc.file}:${loc.start}:${loc.end}`; if (!seen.has(k)) { seen.add(k); out.push(loc); if (out.length >= 80) break; } } return out; } |
| 70 | + function addSpan(map, file, start = 1, end = start) { const s = Math.max(1, Number(start) || 1); const e = Math.max(s, Number(end) || s); const list = map.get(file) || []; list.push({ start: s, end: e }); map.set(file, list); } |
| 71 | + async function ask(candidates, query) { |
| 72 | + const started = Date.now(); |
| 73 | + if (!process.env.OPENAI_API_KEY) return { ok: false, status: 'model_unavailable', error: 'missing_OPENAI_API_KEY_secret', durationMs: 0 }; |
| 74 | + const candidateFiles = new Set(candidates.map((c) => c.file)); |
| 75 | + const body = { model: process.env.OPENAI_MODEL, reasoning: { effort: process.env.OPENAI_REASONING_EFFORT }, max_output_tokens: 1200, instructions: 'Select likely ContextBench edit locations using only the provided codebase-memory-mcp candidate locations. Return JSON only.', input: JSON.stringify({ taskId: task.instance_id, repo: task.repo, lane: 'codebase-memory-mcp', query, problemStatement: task.problem_statement, candidateLocations: candidates.slice(0, 60) }), text: { format: { type: 'json_schema', name: 'contextbench_selection', strict: true, schema: { type: 'object', additionalProperties: false, required: ['files','spans','notes'], properties: { files: { type: 'array', maxItems: 20, items: { type: 'string' } }, spans: { type: 'array', maxItems: 40, items: { type: 'object', additionalProperties: false, required: ['file','start','end'], properties: { file: { type: 'string' }, start: { type: 'integer', minimum: 1 }, end: { type: 'integer', minimum: 1 } } } }, notes: { type: 'string' } } } } } }; |
| 76 | + writeFileSync(join(runDir, 'openai-request.redacted.json'), JSON.stringify({ ...body, input: JSON.parse(body.input) }, null, 2)); |
| 77 | + const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 300000); |
| 78 | + try { const res = await fetch('https://api.openai.com/v1/responses', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${process.env.OPENAI_API_KEY}` }, body: JSON.stringify(body), signal: controller.signal }); const text = await res.text(); clearTimeout(timer); writeFileSync(join(runDir, 'openai-response.json'), text); if (!res.ok) return { ok: false, status: 'model_error', httpStatus: res.status, error: text.slice(0, 2000), durationMs: Date.now() - started }; const json = JSON.parse(text); const out = json.output_text || (json.output || []).flatMap((i) => i.content || []).filter((i) => i.type === 'output_text').map((i) => i.text).join('\n'); const parsed = JSON.parse(out); const files = [...new Set((parsed.files || []).filter((f) => candidateFiles.has(f)))].slice(0, 20); const spans = (parsed.spans || []).filter((s) => candidateFiles.has(s.file)).slice(0, 40); if (files.length === 0 && spans.length === 0) return { ok: false, status: 'model_empty_after_lane_filter', parsed, durationMs: Date.now() - started }; return { ok: true, status: 'completed', parsed: { files, spans, notes: parsed.notes || '' }, usage: json.usage || null, durationMs: Date.now() - started }; } catch (error) { clearTimeout(timer); return { ok: false, status: 'model_timeout_or_error', error: String(error?.message || error), durationMs: Date.now() - started }; } |
| 79 | + } |
| 80 | + const query = queryOf(task.problem_statement); |
| 81 | + const env = { ...process.env, CBM_CACHE_DIR: join(runDir, 'cbm-cache'), CBM_DIAGNOSTICS: '1' }; |
| 82 | + const setup = run(process.env.CBM_BIN, ['--version'], { env, timeoutMs: 60000 }); |
| 83 | + const index = run(process.env.CBM_BIN, ['cli', 'index_repository', JSON.stringify({ repo_path: task.repo_checkout_path })], { cwd: task.repo_checkout_path, env, timeoutMs: 2700000 }); |
| 84 | + const project = (jsonish(index.stdout) || jsonish(index.stderr) || {}).project || basename(task.repo_checkout_path); |
| 85 | + const graph = run(process.env.CBM_BIN, ['cli', 'search_graph', JSON.stringify({ project, query, limit: 25 })], { cwd: task.repo_checkout_path, env, timeoutMs: 120000 }); |
| 86 | + const code = run(process.env.CBM_BIN, ['cli', 'search_code', JSON.stringify({ project, pattern: query.split(/\s+/)[0] || '.', mode: 'compact', limit: 25 })], { cwd: task.repo_checkout_path, env, timeoutMs: 120000 }); |
| 87 | + for (const [name, value] of Object.entries({ setup, index, graph, code })) writeFileSync(join(runDir, `${name}.json`), JSON.stringify(value, null, 2)); |
| 88 | + const locs = []; for (const r of [graph, code]) { collect(r.stdout, locs); collect(r.stderr, locs); } |
| 89 | + const candidates = uniq(locs); writeFileSync(join(runDir, 'candidate-locations.json'), JSON.stringify(candidates, null, 2)); |
| 90 | + const model = await ask(candidates, query); writeFileSync(join(runDir, 'model-result.json'), JSON.stringify(model, null, 2)); |
| 91 | + const spanMap = new Map(); if (model.ok) { for (const s of model.parsed.spans || []) addSpan(spanMap, s.file, s.start, s.end); for (const f of model.parsed.files || []) addSpan(spanMap, f, 1, 1); } |
| 92 | + const predFiles = [...spanMap.keys()].slice(0, 20); const predSpans = Object.fromEntries([...spanMap.entries()].slice(0, 20)); |
| 93 | + const predPath = join(runDir, 'prediction.json'); writeFileSync(predPath, JSON.stringify({ instance_id: task.instance_id, repo_url: task.repo_checkout_path, commit: task.base_commit, traj_data: { pred_steps: [{ files: predFiles, spans: predSpans }], pred_files: predFiles, pred_spans: predSpans }, model_patch: '' }, null, 2)); |
| 94 | + const goldPath = join(runDir, 'gold.json'); const gold = run('node', ['scripts/contextbench-select-slice.mjs', '--write-gold', '--task-id', task.instance_id, '--out', goldPath, '--payloads', process.env.TASK_PAYLOADS], { timeoutMs: 600000 }); writeFileSync(join(runDir, 'gold-command.json'), JSON.stringify(gold, null, 2)); |
| 95 | + const scorePath = join(runDir, 'official-score.jsonl'); const evaluator = model.ok && predFiles.length ? run('python', ['-m', 'contextbench.evaluate', '--gold', goldPath, '--pred', predPath, '--cache', join(runDir, 'repo-cache'), '--out', scorePath], { cwd: process.env.ROOT + '/ContextBench-official', timeoutMs: 1200000 }) : { status: null, error: 'skipped_no_model_prediction', durationMs: 0 }; writeFileSync(join(runDir, 'evaluator-command.json'), JSON.stringify(evaluator, null, 2)); |
| 96 | + let score = null; if (existsSync(scorePath)) { const lines = readFileSync(scorePath, 'utf8').trim().split(/\n+/).filter(Boolean); if (lines.length) score = JSON.parse(lines.at(-1)); } |
| 97 | + const row = { lane_id: 'codebase-memory-mcp', task_id: task.instance_id, model: `${process.env.OPENAI_MODEL}-${process.env.OPENAI_REASONING_EFFORT}`, status: evaluator.status === 0 && score ? 'completed' : (model.status || 'judge_failed'), setupStatus: setup.status === 0 ? 'completed' : 'setup_failed', indexStatus: index.status === 0 ? 'completed' : 'index_failed', toolCallable: graph.status === 0 || code.status === 0, candidateCount: candidates.length, nonEmptyPrediction: predFiles.length > 0, predFiles: predFiles.length, officialEvaluatorScoreable: evaluator.status === 0 && Boolean(score), setupIndex: { setupDurationMs: setup.durationMs, indexDurationMs: index.durationMs, queryDurationMs: graph.durationMs + code.durationMs }, modelStatus: model.status, modelUsage: model.usage || null, score }; |
| 98 | + const summary = { createdAt: new Date().toISOString(), attemptedRows: 1, scoreableRows: row.officialEvaluatorScoreable ? 1 : 0, setupIndexCostReportedSeparately: true, resultsTable: row.officialEvaluatorScoreable ? [{ lane: row.lane_id, fileCoverage: score.final.file.coverage, filePrecision: score.final.file.precision, symbolCoverage: score.final.symbol.coverage, spanCoverage: score.final.span.coverage, lineCoverage: score.final.line.coverage, editlocRecall: score.editloc?.recall ?? null }] : [], rows: [row] }; |
| 99 | + writeFileSync(join(runDir, 'row.json'), JSON.stringify(row, null, 2)); writeFileSync(join(root, 'summary.json'), JSON.stringify(summary, null, 2)); console.log(JSON.stringify(summary, null, 2)); if (!row.officialEvaluatorScoreable) process.exitCode = 1; |
| 100 | + NODE |
| 101 | + node "$ROOT/one.mjs" |
| 102 | + - name: Upload one-row artifacts |
| 103 | + if: always() |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: contextbench-real-cbm-go-one |
| 107 | + path: /tmp/contextbench-real-cbm-go-one |
| 108 | + retention-days: 14 |
0 commit comments