Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
bench: gate the PGLite managed freshness cell on the median of 3 runs, same baseline and limit
garrytand6ec476d0c22
diff --git a/scripts/bench/sync-freshness-gate.ts b/scripts/bench/sync-freshness-gate.tsindex 5cfafe117b..b8a2dab3bc 100644--- a/scripts/bench/sync-freshness-gate.ts+++ b/scripts/bench/sync-freshness-gate.ts@@ -17,6 +17,10 @@* Re-baselined 2026-10-23 on the PR 4b level pass with level reuse (GBRA-133), 5 fresh runners x 5 runs (dispatch with* runs=5): the baseline is runner 1's first run and the other 24 pass against it. PGLite managed is the widest cell* there (446.7 to 912.8 ms; a fresh runner's first run, the one the nightly makes, is the slow end: 659.5 to 912.8).+ * So that cell (MEASUREMENTS) is measured 3 times in a row, each exactly as above, and gated on the median of the three+ * p50s against the same baseline and limit: in the sample, the median of each runner's first three runs spans 507.6 to+ * 698.9 ms (every 3 consecutive runs: 491.9 to 698.9) against the 916.9 ms limit, where one first run came within 4.1 ms.+ * A slow first run on a fresh runner no longer decides the cell alone; a regression that moves every run still does.** --oracle (GBRA-133 wave 4, untimed): the two managed cells once more with GBRAIN_SYNC_LEVEL_REUSE_VERIFY=1, so the* serve compares every level read it reused across passes with a whole read (persistence/sync-tree-reuse.ts) and logs@@ -38,6 +42,7 @@ const CELLS: Record<string, string[]> = {'pglite-managed-serve-watch': ['--engine', 'pglite', '--mode', 'managed', '--commit', 'single', '--trigger', 'serve', '--detection', 'watch'],'postgres-classic-serve-watch': ['--engine', 'postgres', '--mode', 'classic', '--commit', 'single', '--trigger', 'serve', '--detection', 'watch'],};+const MEASUREMENTS: Record<string, number> = { 'pglite-managed-serve-watch': 3 };const names = flag('cells', Object.keys(CELLS).join(',')).split(',').filter(Boolean);for (const n of names) if (!CELLS[n]) { console.error('unknown cell ' + n + '; known: ' + Object.keys(CELLS).join(', ')); process.exit(2); }const WORK = resolve(flag('work-dir', join(REPO, '.context/bench/sync-freshness-gate')));@@ -45,7 +50,7 @@ const BASELINE = resolve(flag('baseline', join(REPO, 'scripts/bench/sync-freshneconst WRITE = argv.includes('--write-baseline') ? resolve(flag('write-baseline', BASELINE)) : null;mkdirSync(WORK, { recursive: true });-interface CellResult { cell: string; p50_ms: number | null; counted: Array<number | null>; warmup_ms: number | null; limit_ms?: number; baseline_ms?: number; pass?: boolean; reason?: string }+interface CellResult { cell: string; p50_ms: number | null; p50s?: number[]; counted: Array<number | null>; warmup_ms: number | null; limit_ms?: number; baseline_ms?: number; pass?: boolean; reason?: string }if (argv.includes('--oracle')) process.exit(await levelReuseOracle());/** --oracle: see the header. 6 reps per managed cell, 120 s each at most; the verdict comes from the serve logs. */@@ -73,20 +78,30 @@ async function levelReuseOracle(): Promise<number> {return ok ? 0 : 1;}-const results: CellResult[] = [];-for (const name of names) {+/** One sync-freshness.ts run of the cell: the p50 of reps 1..10, or why it has none. */+async function measure(name: string): Promise<CellResult> {const p = Bun.spawn([process.execPath, join(REPO, 'scripts/bench/sync-freshness.ts'), ...CELLS[name]!, '--pages', '10000', '--reps', String(REPS), '--probe-ms', '50','--work-dir', WORK, '--label', 'gate', '--json'], { cwd: REPO, stdout: 'pipe', stderr: 'inherit' });const [out, code] = await Promise.all([new Response(p.stdout).text(), p.exited]);const line = out.trim().split('\n').reverse().find(l => l.startsWith('{'));- if (code !== 0 || !line) { results.push({ cell: name, p50_ms: null, counted: [], warmup_ms: null, pass: false, reason: 'bench exited ' + code }); continue; }+ if (code !== 0 || !line) return { cell: name, p50_ms: null, counted: [], warmup_ms: null, pass: false, reason: 'bench exited ' + code };const reps = (JSON.parse(line).reps as Array<{ search_ms: number | null }>).map(r => r.search_ms);const counted = reps.slice(1);const missing = counted.length < REPS - 1 || counted.some(x => x === null);- results.push({ cell: name, p50_ms: missing ? null : pct(counted as number[], 50), counted, warmup_ms: reps[0] ?? null, ...(missing ? { pass: false, reason: 'a counted rep never became visible' } : {}) });+ return { cell: name, p50_ms: missing ? null : pct(counted as number[], 50), counted, warmup_ms: reps[0] ?? null, ...(missing ? { pass: false, reason: 'a counted rep never became visible' } : {}) };+}++const results: CellResult[] = [];+for (const name of names) {+ const runs: CellResult[] = [];+ for (let i = 0; i < (MEASUREMENTS[name] ?? 1); i++) runs.push(await measure(name));+ const failed = runs.find(r => r.p50_ms === null);+ if (failed || runs.length === 1) { results.push(failed ?? runs[0]!); continue; }+ const p50s = runs.map(r => r.p50_ms!), median = [...p50s].sort((a, b) => a - b)[Math.floor(p50s.length / 2)]!;+ results.push({ ...runs[p50s.indexOf(median)]!, p50_ms: median, p50s });}-const run = { schema: 'gbrain-sync-freshness-gate/1', at: new Date().toISOString(), machine: machineInfo(), procedure: 'p50 of reps 1..10 of 11 (rep 0 discarded), 50 ms probe, 10k pages', cells: results };+const run = { schema: 'gbrain-sync-freshness-gate/1', at: new Date().toISOString(), machine: machineInfo(), procedure: 'p50 of reps 1..10 of 11 (rep 0 discarded), 50 ms probe, 10k pages; median of 3 such p50s for ' + Object.keys(MEASUREMENTS).join(', '), cells: results };const out = flag('out', '');if (out) writeFileSync(resolve(out), JSON.stringify(run, null, 2) + '\n');if (WRITE) {@@ -107,6 +122,6 @@ if (WRITE) {console.log('Baseline machine class: ' + base.machine_class + '\n');console.log('| cell | p50 of 10 (ms) | baseline (ms) | limit (ms) | warm-up (ms) | verdict |');console.log('|---|---|---|---|---|---|');- for (const r of results) console.log('| ' + [r.cell, r.p50_ms ?? '-', r.baseline_ms ?? '-', r.limit_ms ?? '-', r.warmup_ms ?? '-', r.pass ? 'pass' : 'FAIL: ' + r.reason].join(' | ') + ' |');+ for (const r of results) console.log('| ' + [r.cell, r.p50s ? r.p50_ms + ' (median of ' + r.p50s.join(', ') + ')' : r.p50_ms ?? '-', r.baseline_ms ?? '-', r.limit_ms ?? '-', r.warmup_ms ?? '-', r.pass ? 'pass' : 'FAIL: ' + r.reason].join(' | ') + ' |');}process.exit(results.every(r => r.pass !== false) ? 0 : 1);