Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(scale): budgets phase timer is stats-dependent and flips with PLANNER_HEALTH_ENFORCED (F4c, integrator decision)
garrytan07fe8c41bd7e
diff --git a/.github/workflows/scale-tier.yml b/.github/workflows/scale-tier.ymlindex 83ad8a79cc..575ad8f102 100644--- a/.github/workflows/scale-tier.yml+++ b/.github/workflows/scale-tier.yml@@ -11,8 +11,9 @@ name: Scale tier# - workflow_dispatch: the size you pass.## Enforced from day one: import rate, known answers, no-op re-import, no-# duplicates across sources, phase timers. Planner health is report-only until-# F4b (PLANNER_HEALTH_ENFORCED in scripts/scale/gates.ts). Interactive ceilings+# duplicates across sources, the import phase timer. Planner health and the+# budgets phase timer are report-only until F4b (PLANNER_HEALTH_ENFORCED in+# scripts/scale/gates.ts). Interactive ceilings# and calibrated budgets stay report-only until `bun scripts/scale/trend.ts`# prints "ceilings stable" and a reviewer sets the repo variable# GBRAIN_SCALE_ENFORCE_CEILINGS=1.diff --git a/docs/TESTING.md b/docs/TESTING.mdindex 926fcf5173..d74ce7a0cd 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -300,8 +300,9 @@ Exit codes: 0 when every enforced gate passes, or always without `--enforce`;its EXPLAIN; the JSON report and a `.explain.txt` land next to `--out`);2 on a usage error; 3 when the harness itself crashed (not a verdict).Enforced under `--enforce`: import rate, known answers, no-op re-import,-no duplicates across sources, phase timers. Planner health is report-only-until F4b lands (`PLANNER_HEALTH_ENFORCED` in `scripts/scale/gates.ts`).+no duplicates across sources, the import phase timer. The stats-dependent+gates, planner health and the budgets phase timer, are report-only until F4b+lands (`PLANNER_HEALTH_ENFORCED` in `scripts/scale/gates.ts`).Interactive ceilings and calibrated budgets (`scripts/scale/budgets.json`,written by `--calibrate`) stay report-only until`bun scripts/scale/trend.ts` prints "ceilings stable" over the last fivediff --git a/scripts/scale/gates.ts b/scripts/scale/gates.tsindex 97bbfbe8f6..c91b007266 100644--- a/scripts/scale/gates.ts+++ b/scripts/scale/gates.ts@@ -7,16 +7,19 @@** Enforced from day one (under --enforce): import rate, known answers for* every timed op and data check, no-op re-import, no duplicate documents- * across sources, phase timers.- * Planner health is enforced only when PLANNER_HEALTH_ENFORCED is true.+ * across sources, the import phase timer.+ * The stats-dependent gates (planner health and the budgets phase timer) are+ * enforced only when PLANNER_HEALTH_ENFORCED is true.* Interactive ceilings and calibrated budgets stay report-only until* scripts/scale/trend.ts says "ceilings stable" and a reviewer sets the repo* variable GBRAIN_SCALE_ENFORCE_CEILINGS=1.*//**- * The one switch for the planner-health gate (hot-table statistics after- * import, Nested Loop inner loops in the key plans). Report-only until F4b+ * The one switch for the stats-dependent gates: planner health (hot-table+ * statistics after import, Nested Loop inner loops in the key plans) and the+ * budgets phase timer, whose time un-analyzed plans dominate (12 s get_health,+ * 40 s source-scoped search at 10k PGLite pages). Report-only until F4b* (planner-stats ANALYZE during import, after GBRA-39's ad7252a) lands:* before it, PGLite has no statistics after an import and this gate would* fail every run. Flip to true in the commit that merges F4b.@@ -134,7 +137,8 @@ export function evaluateScaleGates(report: ScaleReport, policy: GatePolicy): Gatconst limits = phaseLimitsMs(report.pages);for (const phase of ['import', 'budgets'] as const) {const ms = report.phases_ms[phase] ?? 0;- add(`phase:${phase}`, ms <= limits[phase], true,+ // The budgets phase times the ops, so un-analyzed plans dominate it: it is stats-dependent and flips with planner health.+ add(`phase:${phase}`, ms <= limits[phase], phase === 'import' || policy.enforcePlanner,`phase timer: ${phase} took ${Math.round(ms / 1000)} s (ceiling ${Math.round(limits[phase] / 1000)} s at ${report.pages} pages). Reproduce: ${repro}`);}@@ -170,7 +174,7 @@ export function verdictLines(report: ScaleReport, verdict: GateVerdict, policy:} else if (verdict.failures.length > 0) {lines.push(`[scale] ${verdict.failures.length} enforced gate(s) failed; exit 1. Fix the named op or phase, then rerun: ${reproduceCommand(report)}`);} else {- lines.push(`[scale] all enforced gates passed (planner health ${policy.enforcePlanner ? 'enforced' : 'report-only until F4b'}, `+ lines.push(`[scale] all enforced gates passed (planner health and the budgets phase timer ${policy.enforcePlanner ? 'enforced' : 'report-only until F4b'}, `+ `ceilings ${policy.enforceCeilings ? 'enforced' : 'report-only until GBRAIN_SCALE_ENFORCE_CEILINGS=1'}).`);}return lines;diff --git a/test/scripts/scale-gates.test.ts b/test/scripts/scale-gates.test.tsindex a79c54aec4..e05204b1c9 100644--- a/test/scripts/scale-gates.test.ts+++ b/test/scripts/scale-gates.test.ts@@ -76,6 +76,18 @@ describe('scale gates under --enforce', () => {expect(evaluateScaleGates(report, { ...ENFORCE, enforceCeilings: true }).results.some(r => r.gate.startsWith('ceiling:'))).toBe(false);});+ test('an over-cap budgets phase is report-only behind the planner switch and fails when it is on', () => {+ const report = passingReport();+ report.phases_ms.budgets = 5 * 60_000 + 1;+ const off = evaluateScaleGates(report, { ...ENFORCE, enforcePlanner: false });+ expect(off.exitCode).toBe(0);+ expect(off.reportOnlyBreaches.map(b => b.gate)).toEqual(['phase:budgets']);+ expect(verdictLines(report, off, { ...ENFORCE, enforcePlanner: false }).join('\n')).toContain('REPORT-ONLY phase:budgets: phase timer: budgets took 300 s');+ const on = evaluateScaleGates(report, { ...ENFORCE, enforcePlanner: true });+ expect(on.exitCode).toBe(1);+ expect(on.failures.map(f => f.gate)).toEqual(['phase:budgets']);+ });+test('a phase over its timer fails naming the phase; limits are 20 min at 10k and 100 min at 50k', () => {expect(phaseLimitsMs(10_000)).toEqual({ import: 15 * 60_000, budgets: 5 * 60_000 });expect(phaseLimitsMs(50_000)).toEqual({ import: 75 * 60_000, budgets: 25 * 60_000 });