Skip to content

Commit d675cda

Browse files
committed
Report five-lane ContextBench phase costs explicitly
1 parent b1c3f8d commit d675cda

1 file changed

Lines changed: 62 additions & 13 deletions

File tree

scripts/contextbench-five-lane-candidate-pack.mjs

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function run(cmd, args, opts = {}) {
3939
};
4040
}
4141

42+
function durationOf(commands) {
43+
return commands.reduce((sum, command) => sum + command.durationMs, 0);
44+
}
45+
4246
function queryOf(text) {
4347
const stop = new Set([
4448
'that',
@@ -217,7 +221,7 @@ function writeCommands(lane, commands) {
217221
}
218222
}
219223

220-
function laneResult(lane, commands, locs, setupStatus = 'completed', indexStatus = 'completed') {
224+
function laneResult(lane, commands, locs, setupStatus, indexStatus, setupIndex) {
221225
writeCommands(lane, commands);
222226
const candidates = uniq(locs);
223227
return {
@@ -226,11 +230,7 @@ function laneResult(lane, commands, locs, setupStatus = 'completed', indexStatus
226230
indexStatus,
227231
toolCallable: commands.some((command) => command.status === 0),
228232
candidateCount: candidates.length,
229-
setupIndex: {
230-
setupDurationMs: commands.slice(0, 1).reduce((sum, command) => sum + command.durationMs, 0),
231-
indexDurationMs: commands.slice(1, 2).reduce((sum, command) => sum + command.durationMs, 0),
232-
queryDurationMs: commands.slice(2).reduce((sum, command) => sum + command.durationMs, 0),
233-
},
233+
setupIndex,
234234
commands: commands.map((command) => ({
235235
command: command.command,
236236
status: command.status,
@@ -279,7 +279,13 @@ const lanes = [];
279279
collect(r.stdout, locs, 'raw-native');
280280
collect(r.stderr, locs, 'raw-native');
281281
}
282-
lanes.push(laneResult('raw-native', commands, locs));
282+
lanes.push(
283+
laneResult('raw-native', commands, locs, 'not_required', 'not_required', {
284+
setupDurationMs: 0,
285+
indexDurationMs: 0,
286+
queryDurationMs: durationOf(commands),
287+
}),
288+
);
283289
}
284290

285291
{
@@ -290,16 +296,24 @@ const lanes = [];
290296
commands.push(setup);
291297
const index = run('node', ['dist/index.js', 'reindex'], { env, timeoutMs: 1200000 });
292298
commands.push(index);
299+
const searches = [];
293300
for (const q of queryVariants) {
294301
const search = run('node', ['dist/index.js', 'search', '--query', q, '--intent', 'edit', '--limit', '40', '--json'], {
295302
env,
296303
timeoutMs: 300000,
297304
});
298305
commands.push(search);
306+
searches.push(search);
299307
collect(search.stdout, locs, 'codebase-context');
300308
collect(search.stderr, locs, 'codebase-context');
301309
}
302-
lanes.push(laneResult('codebase-context', commands, locs, setup.status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed'));
310+
lanes.push(
311+
laneResult('codebase-context', commands, locs, setup.status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed', {
312+
setupDurationMs: setup.durationMs,
313+
indexDurationMs: index.durationMs,
314+
queryDurationMs: durationOf(searches),
315+
}),
316+
);
303317
}
304318

305319
{
@@ -315,13 +329,15 @@ const lanes = [];
315329
});
316330
commands.push(index);
317331
const project = (jsonish(index.stdout) || jsonish(index.stderr) || {}).project || basename(repo);
332+
const searches = [];
318333
for (const q of queryVariants) {
319334
const graph = run(process.env.CBM_BIN, ['cli', 'search_graph', JSON.stringify({ project, query: q, limit: 50 })], {
320335
cwd: repo,
321336
env,
322337
timeoutMs: 120000,
323338
});
324339
commands.push(graph);
340+
searches.push(graph);
325341
collect(graph.stdout, locs, 'codebase-memory-mcp');
326342
collect(graph.stderr, locs, 'codebase-memory-mcp');
327343
}
@@ -332,10 +348,17 @@ const lanes = [];
332348
{ cwd: repo, env, timeoutMs: 120000 },
333349
);
334350
commands.push(code);
351+
searches.push(code);
335352
collect(code.stdout, locs, 'codebase-memory-mcp');
336353
collect(code.stderr, locs, 'codebase-memory-mcp');
337354
}
338-
lanes.push(laneResult('codebase-memory-mcp', commands, locs, setup.status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed'));
355+
lanes.push(
356+
laneResult('codebase-memory-mcp', commands, locs, setup.status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed', {
357+
setupDurationMs: setup.durationMs,
358+
indexDurationMs: index.durationMs,
359+
queryDurationMs: durationOf(searches),
360+
}),
361+
);
339362
}
340363

341364
{
@@ -347,53 +370,79 @@ const lanes = [];
347370
commands.push(init);
348371
const watch = run('grepai', ['watch', '--background'], { cwd: repo, timeoutMs: 120000 });
349372
commands.push(watch);
373+
const statusChecks = [];
350374
for (let i = 0; i < 12; i += 1) {
351375
const status = run('grepai', ['status', '--no-ui'], { cwd: repo, timeoutMs: 60000 });
352376
commands.push(status);
377+
statusChecks.push(status);
353378
if (/chunks?\D+[1-9]|indexed files?\D+[1-9]/i.test(`${status.stdout}\n${status.stderr}`)) break;
354379
run('sleep', ['5'], { timeoutMs: 10000 });
355380
}
381+
const searches = [];
356382
for (const q of queryVariants) {
357383
const search = run('grepai', ['search', q, '--json', '--compact', '--limit', '40'], { cwd: repo, timeoutMs: 180000 });
358384
commands.push(search);
385+
searches.push(search);
359386
collect(search.stdout, locs, 'grepai');
360387
collect(search.stderr, locs, 'grepai');
361388
}
362389
const stop = run('grepai', ['watch', '--stop'], { cwd: repo, timeoutMs: 60000 });
363390
commands.push(stop);
364-
lanes.push(laneResult('grepai', commands, locs, setup.status === 0 && init.status === 0 ? 'completed' : 'setup_failed', watch.status === 0 ? 'completed' : 'index_failed'));
391+
lanes.push(
392+
laneResult('grepai', commands, locs, setup.status === 0 && init.status === 0 ? 'completed' : 'setup_failed', watch.status === 0 ? 'completed' : 'index_failed', {
393+
setupDurationMs: setup.durationMs + init.durationMs,
394+
indexDurationMs: watch.durationMs + durationOf(statusChecks),
395+
queryDurationMs: durationOf(searches),
396+
teardownDurationMs: stop.durationMs,
397+
}),
398+
);
365399
}
366400

367401
{
368402
const commands = [];
369403
const locs = [];
370404
const commandProbe = run('codegraphcontext', ['--help'], { timeoutMs: 60000 });
371405
const cgcCommand = commandProbe.status === 0 ? 'codegraphcontext' : 'cgc';
372-
commands.push(commandProbe.status === 0 ? commandProbe : run(cgcCommand, ['--help'], { timeoutMs: 60000 }));
406+
const setup = commandProbe.status === 0 ? commandProbe : run(cgcCommand, ['--help'], { timeoutMs: 60000 });
407+
commands.push(setup);
373408
const index = run(cgcCommand, ['index', '.'], { cwd: repo, timeoutMs: 1200000 });
374409
commands.push(index);
410+
const queries = [];
375411
for (const pattern of ['Metrics', 'Prometheus', 'Authorization', 'Bearer', 'Token', 'Subsonic', 'Header']) {
376412
const found = run(cgcCommand, ['find', 'pattern', pattern], { cwd: repo, timeoutMs: 180000 });
377413
commands.push(found);
414+
queries.push(found);
378415
collect(found.stdout, locs, 'codegraphcontext');
379416
collect(found.stderr, locs, 'codegraphcontext');
380417
}
381418
for (const symbol of ['main', 'init', 'WriteInitialMetrics', 'ServeHTTP', 'GetUser']) {
382419
const callers = run(cgcCommand, ['analyze', 'callers', symbol], { cwd: repo, timeoutMs: 180000 });
383420
commands.push(callers);
421+
queries.push(callers);
384422
collect(callers.stdout, locs, 'codegraphcontext');
385423
collect(callers.stderr, locs, 'codegraphcontext');
386424
}
387425
const complexity = run(cgcCommand, ['analyze', 'complexity', '--limit', '80'], { cwd: repo, timeoutMs: 180000 });
388426
commands.push(complexity);
427+
queries.push(complexity);
389428
collect(complexity.stdout, locs, 'codegraphcontext');
390429
collect(complexity.stderr, locs, 'codegraphcontext');
391-
lanes.push(laneResult('codegraphcontext', commands, locs, commands[0].status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed'));
430+
lanes.push(
431+
laneResult('codegraphcontext', commands, locs, setup.status === 0 ? 'completed' : 'setup_failed', index.status === 0 ? 'completed' : 'index_failed', {
432+
setupDurationMs: setup.durationMs,
433+
indexDurationMs: index.durationMs,
434+
queryDurationMs: durationOf(queries),
435+
}),
436+
);
392437
}
393438

394439
const readiness = lanes.map((lane) => ({
395440
lane: lane.lane,
396-
ready: lane.setupStatus === 'completed' && lane.indexStatus === 'completed' && lane.toolCallable && lane.candidateCount > 0,
441+
ready:
442+
(lane.setupStatus === 'completed' || lane.setupStatus === 'not_required') &&
443+
(lane.indexStatus === 'completed' || lane.indexStatus === 'not_required') &&
444+
lane.toolCallable &&
445+
lane.candidateCount > 0,
397446
setupStatus: lane.setupStatus,
398447
indexStatus: lane.indexStatus,
399448
toolCallable: lane.toolCallable,

0 commit comments

Comments
 (0)