Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(stress): measured stress-iteration weights so slow files split across shards

garrytan47e9f961b979
diff --git a/scripts/stress/README.md b/scripts/stress/README.md
index bd5d8d127b..48eb94a7c3 100644
--- a/scripts/stress/README.md
+++ b/scripts/stress/README.md
@@ -102,7 +102,12 @@ shards.
never sampled or skipped.
- **Shards.** Work items (a file's iterations, split when ten exceed the
budget) pack into the fewest shards whose measured estimates stay under 25
- minutes. There is no shard-count cap; `max-parallel: 12` keeps a large PR
+ minutes. A file's estimate is its measured stress iteration
+ (`scripts/stress/iteration-weights.json`, mined from stress shard job logs
+ with `bun scripts/stress/gate.ts mine-iterations <log>…`, which merges into
+ the map), else its lane weight, else the lane's p75: a fresh database per
+ iteration can make a stress iteration slower than the file's lane run.
+ There is no shard-count cap; `max-parallel: 12` keeps a large PR
from starving other jobs. Shard jobs record results and exit 0 on test
failures; the result job decides, so a planned iteration without a receipt
fails the check as incomplete.
diff --git a/scripts/stress/gate.ts b/scripts/stress/gate.ts
index 3cbeeb2c9d..5ae894c500 100644
--- a/scripts/stress/gate.ts
+++ b/scripts/stress/gate.ts
@@ -28,7 +28,7 @@ import { armMode } from './plan.ts';
import { readArmsList } from '../postgres-unit-arms.ts';
import {
DEFAULT_ITERATIONS, RACE_HUNT_DOCS, STRESS_DOCS, allTestFiles, changedFiles, expandHelper, iterationEstimateMs,
- loadWeights, notStressedReason, parseFileList, planShards, profileFor, redact, reproduceLine, validRef,
+ loadWeights, mineStressIterations, notStressedReason, STRESS_ITERATION_WEIGHTS, parseFileList, planShards, profileFor, redact, reproduceLine, validRef,
type HelperExpansion, type NotStressed, type ProfileName, type Shard, type Weights,
} from './plan.ts';
@@ -424,7 +424,7 @@ function writeOutputs(plan: Plan) {
async function main(argv: string[]): Promise<number> {
const [command] = argv;
const mode = (arg(argv, '--mode') ?? 'gate') as Mode;
- if (!['gate', 'race-hunt'].includes(mode)) { console.error('usage: scripts/stress/gate.ts plan|report --mode gate|race-hunt'); return 2; }
+ if (command !== 'mine-iterations' && !['gate', 'race-hunt'].includes(mode)) { console.error('usage: scripts/stress/gate.ts plan|report --mode gate|race-hunt'); return 2; }
if (command === 'plan') {
const env = process.env;
let plan: Plan;
@@ -473,7 +473,17 @@ async function main(argv: string[]): Promise<number> {
if (result) { mkdirSync(dirname(result), { recursive: true }); writeFileSync(result, JSON.stringify({ exit: report.exit, errors: report.errors, timings }, null, 2)); }
return report.exit;
}
- console.error('usage: bun scripts/stress/gate.ts plan|report --mode gate|race-hunt [--plan <plan.json>] [--manifests <dir>] [--json <out>]');
+ if (command === 'mine-iterations') {
+ const logs = argv.slice(1);
+ const mined = mineStressIterations(logs.map(path => readFileSync(path, 'utf8')));
+ if (!mined.size) { console.error('mine-iterations: no stress iterations in the given logs'); return 1; }
+ const path = join(ROOT, STRESS_ITERATION_WEIGHTS);
+ const merged = new Map([...(existsSync(path) ? Object.entries(JSON.parse(readFileSync(path, 'utf8')) as Record<string, number>) : []), ...mined]);
+ writeFileSync(path, `${JSON.stringify(Object.fromEntries([...merged].sort(([a], [b]) => (a < b ? -1 : 1))), null, 2)}\n`);
+ console.log(`stress iteration weights: ${mined.size} file(s) mined from ${logs.length} log(s) into ${STRESS_ITERATION_WEIGHTS} (${merged.size} total)`);
+ return 0;
+ }
+ console.error('usage: bun scripts/stress/gate.ts plan|report --mode gate|race-hunt [--plan <plan.json>] [--manifests <dir>] [--json <out>] | mine-iterations <stress-shard.log>…');
return 2;
}
diff --git a/scripts/stress/iteration-weights.json b/scripts/stress/iteration-weights.json
new file mode 100644
index 0000000000..0dace3a361
--- /dev/null
+++ b/scripts/stress/iteration-weights.json
@@ -0,0 +1,59 @@
+{
+ "test/agent-journey-upgrade.serial.test.ts": 40400,
+ "test/belief-ledger-coverage.test.ts": 85800,
+ "test/config-reader-keys-registered.test.ts": 2200,
+ "test/destructive-guard.test.ts": 7150,
+ "test/doctor-content-golden.test.ts": 20100,
+ "test/doctor-day-zero.test.ts": 7700,
+ "test/doctor-early-stop-golden.serial.test.ts": 700,
+ "test/doctor-harness-smoke.test.ts": 10000,
+ "test/doctor-hot-checks-golden.test.ts": 26650,
+ "test/doctor-json-golden-latest.test.ts": 100,
+ "test/doctor-json-golden.test.ts": 14650,
+ "test/e2e/agent-journey-postgres.test.ts": 26500,
+ "test/e2e/doctor-hot-checks-golden.test.ts": 22000,
+ "test/e2e/doctor-json-golden.test.ts": 6650,
+ "test/e2e/managed-synthesis-postprocess.test.ts": 16050,
+ "test/e2e/pool-size-one-migrations.test.ts": 3900,
+ "test/import-file.test.ts": 1850,
+ "test/large-pages/projection-claim-ownership.test.ts": 28100,
+ "test/large-pages/publication-seal-bounded.test.ts": 22350,
+ "test/large-pages/purge-fact-segmented-preimage.test.ts": 17300,
+ "test/large-pages/recovery-budget-ceiling.slow.test.ts": 210350,
+ "test/large-pages/recovery-budget-default.test.ts": 6450,
+ "test/large-pages/segmented-delete-stage-crash.slow.test.ts": 124300,
+ "test/large-pages/segmented-file-drift-ledger.test.ts": 36300,
+ "test/large-pages/segmented-semantic-writes.test.ts": 74450,
+ "test/large-pages/segmented-storage-visibility.test.ts": 19750,
+ "test/large-pages/segmented-switch.test.ts": 24900,
+ "test/large-pages/segmented-withdrawal-mirror.test.ts": 240950,
+ "test/large-pages/segmented-writer-floor.test.ts": 100,
+ "test/large-pages/streamed-sync-origin-b14.test.ts": 74450,
+ "test/large-pages/stuck-recovery-large.slow.test.ts": 230300,
+ "test/managed-sync-preparation-stalled-holds.test.ts": 43400,
+ "test/managed-synthesis-postprocess.test.ts": 11250,
+ "test/pages-unsearchable.test.ts": 5950,
+ "test/pathological/a1-links-extract.test.ts": 26800,
+ "test/pathological/a10-global-maintenance-stamp.test.ts": 2600,
+ "test/pathological/a2-transcripts-ingest.test.ts": 40800,
+ "test/pathological/a21-facts-expire-deleted.test.ts": 21950,
+ "test/pathological/a22-consolidate-buckets.test.ts": 30050,
+ "test/pathological/a23-patterns-grounding.test.ts": 25750,
+ "test/pathological/a26-safe-chunks-reseal.test.ts": 7250,
+ "test/pathological/a27-credential-reseal.test.ts": 5200,
+ "test/pathological/a3-google-items.test.ts": 89450,
+ "test/pathological/a4-synthesize-postprocess.test.ts": 13100,
+ "test/pathological/a41-maintain-sources.test.ts": 36850,
+ "test/pathological/a45-repair-all-kinds.test.ts": 3300,
+ "test/pathological/a47-backfill-poison-row.test.ts": 3600,
+ "test/pathological/a9-repair-core.test.ts": 6400,
+ "test/pathological/b6-triage-verdict-surrogate.test.ts": 2000,
+ "test/pathological/inventory-deferred.test.ts": 100,
+ "test/pathological/item-failure.test.ts": 200,
+ "test/pathological/sites.test.ts": 100,
+ "test/persistence-write-interrupted.test.ts": 40700,
+ "test/repair-apply-continue-6459.test.ts": 1400,
+ "test/repair-apply-pending-6543.test.ts": 55800,
+ "test/scripts/check-item-allowlist-catches.test.ts": 800,
+ "test/transcripts-codex-subagent.test.ts": 1000
+}
diff --git a/scripts/stress/plan.ts b/scripts/stress/plan.ts
index cb04762735..a00d7331eb 100644
--- a/scripts/stress/plan.ts
+++ b/scripts/stress/plan.ts
@@ -276,7 +276,10 @@ export function planShards(files: Array<{ file: string; perIterationMs: number;
}
}
-export interface Weights { unit: Map<string, number>; serialSeconds: Map<string, number>; e2e: Map<string, number>; arms: Map<string, number> }
+export interface Weights { unit: Map<string, number>; serialSeconds: Map<string, number>; e2e: Map<string, number>; arms: Map<string, number>; stress?: Map<string, number> }
+
+/** Measured stress iterations (milliseconds), mined from stress shard logs by `gate.ts mine-iterations`; read before the lane maps. */
+export const STRESS_ITERATION_WEIGHTS = 'scripts/stress/iteration-weights.json';
const loadMap = (path: string): Map<string, number> => (existsSync(path) ? new Map(Object.entries(JSON.parse(readFileSync(path, 'utf8')) as Record<string, number>)) : new Map());
@@ -286,13 +289,34 @@ export function loadWeights(root: string): Weights {
serialSeconds: loadMap(join(root, 'scripts/serial-weights.json')),
e2e: loadMap(join(root, 'scripts/e2e-weights.json')),
arms: loadMap(join(root, 'scripts/postgres-arm-weights.json')),
+ stress: loadMap(join(root, STRESS_ITERATION_WEIGHTS)),
};
}
const p75 = (values: number[]) => { const s = [...values].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.ceil(0.75 * s.length) - 1)]! : 30_000; };
-/** Measured milliseconds for one iteration of `file` in `profile`, or the lane's p75 for an unmeasured file. */
+/**
+ * Per-file median of the stress iterations in `logs` (stress shard job logs: `✓|✗ <file> iteration N (seed S) 12.3s`), in
+ * milliseconds. A stress iteration can cost more than the file's lane run (a fresh database per iteration).
+ */
+export function mineStressIterations(logs: string[]): Map<string, number> {
+ const samples = new Map<string, number[]>();
+ for (const log of logs) {
+ for (const m of log.matchAll(/[✓✗] (test\/[\w./-]+\.test\.ts) iteration \d+ \(seed \d+\) ([\d.]+)s/g)) {
+ samples.set(m[1]!, [...(samples.get(m[1]!) ?? []), Math.round(Number(m[2]) * 1000)]);
+ }
+ }
+ return new Map([...samples].map(([file, ms]) => {
+ const sorted = [...ms].sort((a, b) => a - b);
+ const mid = Math.floor(sorted.length / 2);
+ return [file, sorted.length % 2 ? sorted[mid]! : Math.round((sorted[mid - 1]! + sorted[mid]!) / 2)];
+ }));
+}
+
+/** Measured milliseconds for one iteration of `file` in `profile`: a measured stress iteration first, else the lane's weight, else its p75. */
export function iterationEstimateMs(file: string, profile: ProfileName, w: Weights): number {
+ const stressed = w.stress?.get(file);
+ if (stressed !== undefined) return stressed;
switch (profile) {
case 'postgres-arm': return w.arms.get(file) ?? p75([...w.arms.values()]);
case 'e2e': return w.e2e.get(file) ?? p75([...w.e2e.values()]);
diff --git a/test/scripts/stress-plan.test.ts b/test/scripts/stress-plan.test.ts
index 0f29d49ec5..d1ecbde006 100644
--- a/test/scripts/stress-plan.test.ts
+++ b/test/scripts/stress-plan.test.ts
@@ -10,8 +10,8 @@ import { join } from 'node:path';
import { runInNewContext } from 'node:vm';
import { load } from 'js-yaml';
import {
- HELPER_FAN_IN_LIMIT, SPECIAL_FILES, allTestFiles, changedFiles, defaultSeed, directImporters, expandHelper,
- notStressedReason, parseFileList, planShards, profileFor, redact, reproduceLine, seededSample, validRef,
+ HELPER_FAN_IN_LIMIT, SPECIAL_FILES, allTestFiles, changedFiles, defaultSeed, directImporters, expandHelper, iterationEstimateMs,
+ mineStressIterations, notStressedReason, parseFileList, planShards, profileFor, redact, reproduceLine, seededSample, validRef,
} from '../../scripts/stress/plan.ts';
const REPO = join(import.meta.dir, '..', '..');
@@ -172,4 +172,25 @@ describe('shards', () => {
const shards = planShards([{ file: 'test/giant.slow.test.ts', perIterationMs: 40 * 60_000 }], 2, 25 * 60_000);
expect(shards).toHaveLength(2);
});
+
+ test('a measured stress iteration outranks the lane weight, so a file slower under stress than in its lane splits', () => {
+ // #6963: recovery-budget-ceiling weighs ~150 s in its arms lane but runs ~228 s a stress iteration; nine packed
+ // into one 25-minute shard ran past the 35-minute job timeout.
+ const log = [
+ '2026-10-18T05:23:43.7Z ✓ test/large-pages/x.slow.test.ts iteration 1 (seed 43165) 239.1s, 2 executed',
+ '2026-10-18T05:27:44.2Z ✓ test/large-pages/x.slow.test.ts iteration 2 (seed 43166) 227.5s, 2 executed',
+ '2026-10-18T05:31:01.0Z ✗ test/large-pages/x.slow.test.ts iteration 3 (seed 43167) 199.8s, 2 executed',
+ '2026-10-18T05:31:02.0Z ✓ test/large-pages/y.test.ts iteration 1 (seed 1) 5.0s, 1 executed',
+ ].join('\n');
+ const mined = mineStressIterations([log]);
+ expect(Object.fromEntries(mined)).toEqual({ 'test/large-pages/x.slow.test.ts': 227_500, 'test/large-pages/y.test.ts': 5_000 });
+ const lane = { unit: new Map(), serialSeconds: new Map(), e2e: new Map(), arms: new Map([['test/large-pages/x.slow.test.ts', 150_000]]) };
+ expect(iterationEstimateMs('test/large-pages/x.slow.test.ts', 'postgres-arm', lane)).toBe(150_000);
+ const measured = { ...lane, stress: mined };
+ const per = iterationEstimateMs('test/large-pages/x.slow.test.ts', 'postgres-arm', measured);
+ expect(per).toBe(227_500);
+ const shards = planShards([{ file: 'test/large-pages/x.slow.test.ts', perIterationMs: per }], 10, 25 * 60_000);
+ expect(shards.map(s => s.items.reduce((n, i) => n + i.count, 0))).toEqual([6, 4]);
+ expect(iterationEstimateMs('test/other.test.ts', 'postgres-arm', measured)).toBe(150_000);
+ });
});