Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(crash-robot): count consumer:claiming in claim epochs so a requested fault is always reachable (#6896)
garrytand7f2535b0f24
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4af381a94a..4a40794d5f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,6 +27,8 @@ identifiers and attribution are available in the pre-removal Git revision- The batch cache lives in process memory in `src/core/persistence/page-purge.ts` (`sweepForPurge`); the journal still never stores claims. No schema change and no compaction default changed.- `readOutstandingRoom` (`src/core/persistence/journal.ts`) reads the tighter of the principal's and the brain's outstanding caps.- Tests: `test/page-purge-batch-sweep-6884.test.ts` (PGLite and Postgres), `test/purge-deleted-capacity-6884.test.ts`.+- Crash robot (#6896): `consumer:claiming` fires before every claim attempt, idle ticks included, so its pass count followed wall-clock time and a fault picked from the count role's total could go unreached (`competing_writers_one_page consumer:claiming#19`). `seamCounter` (`scripts/persistence/crash-robot.ts`) now counts that seam in claim epochs (distinct requests prepared so far); the unreached-fault check is unchanged.+- `scripts/postgres-arm-weights.json` re-mined from the latest runs, so the Postgres-arm shards stay under their 20-minute step limit.## [0.60.280.0] - 2026-10-17diff --git a/scripts/persistence/crash-robot.ts b/scripts/persistence/crash-robot.tsindex c8e70010e0..75c63d3879 100644--- a/scripts/persistence/crash-robot.ts+++ b/scripts/persistence/crash-robot.ts@@ -177,16 +177,31 @@ function freeze(event: Record<string, unknown>): never {* share one `requestId`.*/const PER_REQUEST_SEAMS: ReadonlySet<FaultPoint> = new Set<FaultPoint>(['consumer:preparing', 'consumer:prepared']);-/** True when this pass counts toward the seam's nth: always, except a repeat of the same request at a per-request seam. */-export function seamCounter(): (point: FaultPoint, detail: FaultDetail) => boolean {- const seen = new Set<string>();+/**+ * #6896: `consumer:claiming` fires before every claim attempt, the consumer's idle ticks and the passes that find+ * the root busy included, so how many passes a run makes follows wall-clock time, not the schedule (a count role+ * saw 19, the run made fewer and its fault at #19 went unreached). It counts in claim epochs instead: the number of+ * distinct write request rows that have reached `consumer:preparing`. The first pass at epoch e or later advances+ * the count to e + 1, so slot n is the first claim attempt after n - 1 requests were prepared; requests of one root+ * are claimed one after another, so every slot the count role saw comes again in the run.+ */+/** How far this pass advances the seam's count: 1, 0 for a repeat of the same request at a per-request seam, the epochs passed at the claim seam. */+export function seamCounter(): (point: FaultPoint, detail: FaultDetail) => number {+ const seen = new Set<string>(), prepared = new Set<string>();+ let claimSlots = 0;return (point, detail) => {const request = detail.writeId ?? detail.requestId;- if (!PER_REQUEST_SEAMS.has(point) || !request) return true;+ if (point === 'consumer:preparing' && request) prepared.add(request);+ if (point === 'consumer:claiming') {+ const advanced = Math.max(0, prepared.size + 1 - claimSlots);+ claimSlots += advanced;+ return advanced;+ }+ if (!PER_REQUEST_SEAMS.has(point) || !request) return 1;const key = `${point}\u0000${request}`;- if (seen.has(key)) return false;+ if (seen.has(key)) return 0;seen.add(key);- return true;+ return 1;};}@@ -201,7 +216,10 @@ export function robotFaultHook(fault: NonNullable<RobotConfig['fault']>): (pointlet seen = 0;const counts = seamCounter();return (point, detail) => {- if (point !== fault.point || (fault.operation && detail.operation !== fault.operation) || !counts(point, detail) || ++seen !== fault.nth) return;+ const advanced = counts(point, detail);+ if (point !== fault.point || (fault.operation && detail.operation !== fault.operation) || !advanced) return;+ seen += advanced;+ if (seen < fault.nth) return;try { freeze({ event: 'fault', point, nth: seen, detail }); }catch (error) { freeze({ event: 'fault_hook_error', point, nth: seen, message: error instanceof Error ? error.message : String(error) }); }};@@ -372,7 +390,7 @@ export async function robotWorker(role: 'count' | 'run' | 'recover', config: RobinstallLockOrderTrace();const counts: Record<string, number> = {};const counted = seamCounter();- if (role === 'count') installFaultHook((point, detail) => { if (counted(point, detail)) counts[point] = (counts[point] ?? 0) + 1; });+ if (role === 'count') installFaultHook((point, detail) => { const advanced = counted(point, detail); if (advanced) counts[point] = (counts[point] ?? 0) + advanced; });if (role === 'run' && config.fault) installFaultHook(robotFaultHook(config.fault));if (role === 'run') {let next = 0; let inFlight: string[] = [];diff --git a/test/persistence-crash-robot.test.ts b/test/persistence-crash-robot.test.tsindex ab01767193..1a808dc7ae 100644--- a/test/persistence-crash-robot.test.ts+++ b/test/persistence-crash-robot.test.ts@@ -395,6 +395,43 @@ process.stdout.write('{"event":"continued"}\\n');} finally { child.kill('SIGKILL'); await child.exited; rmSync(dir, { recursive: true, force: true }); }}, 90_000);+ test('#6896: consumer:claiming counts claim epochs, so a run with fewer idle claim passes still reaches every slot the count role saw', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-crash-robot-claim-'));+ const path = join(dir, 'claim.ts');+ // Count role: busy and idle claim attempts around two preparations (and a re-run one). Run: the same requests, no idle ticks.+ writeFileSync(path, `import { faultPoint, installFaultHook } from ${JSON.stringify(join(import.meta.dir, '../src/core/persistence/fault-points.ts'))};+import { robotFaultHook, seamCounter } from ${JSON.stringify(join(import.meta.dir, '../scripts/persistence/crash-robot.ts'))};+const counted = seamCounter(); let slots = 0;+installFaultHook((point, detail) => { const advanced = counted(point, detail); if (point === 'consumer:claiming') slots += advanced; });+const claim = () => faultPoint('consumer:claiming');+const prepare = (writeId: string) => faultPoint('consumer:preparing', { requestId: writeId, writeId });+await claim(); await claim(); await prepare('w1'); await claim(); await claim(); await claim(); await prepare('w1'); await prepare('w2'); await claim(); await claim();+process.stdout.write(JSON.stringify({ event: 'counts', slots }) + '\\n');+installFaultHook(robotFaultHook({ point: 'consumer:claiming', nth: slots }));+await claim(); await prepare('w1'); await claim(); await prepare('w2'); await claim();+process.stdout.write('{"event":"continued"}\\n');+`);+ const child = Bun.spawn([process.execPath, '--no-env-file', path], { stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' });+ try {+ const lines: Record<string, unknown>[] = [];+ const reader = child.stdout.getReader(); const decoder = new TextDecoder(); let pending = '';+ const deadline = Date.now() + 60_000;+ while (lines.length < 2 && Date.now() < deadline) {+ const chunk = await Promise.race([reader.read(), Bun.sleep(deadline - Date.now()).then(() => null)]);+ if (!chunk || chunk.done) break;+ pending += decoder.decode(chunk.value, { stream: true });+ for (let newline = pending.indexOf('\n'); newline >= 0; newline = pending.indexOf('\n')) {+ lines.push(JSON.parse(pending.slice(0, newline))); pending = pending.slice(newline + 1);+ }+ }+ reader.releaseLock();+ expect(lines).toEqual([+ { event: 'counts', slots: 3 },+ { event: 'fault', point: 'consumer:claiming', nth: 3, detail: {} },+ ]);+ } finally { child.kill('SIGKILL'); await child.exited; rmSync(dir, { recursive: true, force: true }); }+ }, 90_000);+test('a hook that cannot report its fault emits fault_hook_error and still freezes', async () => {const { lines, alive } = await hookChild(`const cyclic: Record<string, unknown> = {}; cyclic.self = cyclic;await faultPoint('effect:git:mid', { requestId: 'r1', signal: cyclic as never });`);