Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): extract_health dates a high halt rate by its last halt, not the last rollup write (#5863)
time-attackcfa7ebd48acc
diff --git a/src/commands/doctor/checks/extraction-sync.ts b/src/commands/doctor/checks/extraction-sync.tsindex 1d935ee1c2..0a59a2355d 100644--- a/src/commands/doctor/checks/extraction-sync.ts+++ b/src/commands/doctor/checks/extraction-sync.ts@@ -1003,6 +1003,7 @@ export async function computeExtractHealthCheck(expected_limit_count: number;rollup_write_failures: number;last_updated_at: Date | string | null;+ last_halt_age_days: number | string | null;};// #4482: expected_limit_count (migration v141) counts runs that stopped@@ -1019,7 +1020,8 @@ export async function computeExtractHealthCheck(SUM(round_completed_count) AS round_completed_count,${withExpected ? 'SUM(expected_limit_count)' : '0'} AS expected_limit_count,SUM(rollup_write_failures) AS rollup_write_failures,- MAX(updated_at) AS last_updated_at+ MAX(updated_at) AS last_updated_at,+ CURRENT_DATE - MAX(day) FILTER (WHERE halt_count > 0) AS last_halt_age_daysFROM extract_rollup_7dWHERE day >= CURRENT_DATE - 7GROUP BY kind@@ -1055,6 +1057,7 @@ export async function computeExtractHealthCheck(expected_limit_count: number;halt_rate: number;last_updated_at: string | null;+ last_halt_age_days: number | null;};const kinds: KindAggregate[] = rows.map(r => {@@ -1078,6 +1081,7 @@ export async function computeExtractHealthCheck(last_updated_at: r.last_updated_at? new Date(r.last_updated_at).toISOString(): null,+ last_halt_age_days: r.last_halt_age_days == null ? null : Number(r.last_halt_age_days),};});@@ -1097,16 +1101,15 @@ export async function computeExtractHealthCheck(// high halt rate from entirely historical failures with nothing// currently wrong — the operator has no way to tell "actively// failing" from "hasn't run since a bug that's already fixed" without- // this. last_updated_at is already computed (MAX(updated_at) above)- // but wasn't surfaced in the message text, only in `details`.+ // this. The age is the most recent day with a halt, not the last+ // rollup write: a kind that halted 4 days ago and ran cleanly today+ // reads "last halt 4d ago".const top3 = [...highHaltKinds].sort((a, b) => b.halt_rate - a.halt_rate).slice(0, 3).map(k => {- const ageDays = k.last_updated_at- ? Math.floor((Date.now() - new Date(k.last_updated_at).getTime()) / 86_400_000)- : null;- const ageSuffix = ageDays === null ? '' : ageDays <= 0 ? ', today' : `, ${ageDays}d ago`;+ const ageDays = k.last_halt_age_days;+ const ageSuffix = ageDays === null ? '' : ageDays <= 0 ? ', last halt today' : `, last halt ${ageDays}d ago`;return `${k.kind}=${(k.halt_rate * 100).toFixed(1)}%${ageSuffix}`;}).join(', ');diff --git a/test/doctor-extract-health.test.ts b/test/doctor-extract-health.test.tsindex 7c0048f7a6..2722656bbf 100644--- a/test/doctor-extract-health.test.ts+++ b/test/doctor-extract-health.test.ts@@ -102,6 +102,21 @@ describe('computeExtractHealthCheck — WARN paths', () => {expect(check.message).not.toContain('0d ago');});+ test('the age is the last halt, not the last clean run (#5863)', async () => {+ await clearRollup();+ await engine.executeRaw(+ `INSERT INTO extract_rollup_7d (kind, source_id, day, cost_usd, eval_pass_count, eval_fail_count, halt_count, round_completed_count, rollup_write_failures, updated_at)+ VALUES ('atoms', 'default', CURRENT_DATE - 4, 1.00, 0, 0, 9, 1, 0, NOW() - INTERVAL '4 days'),+ ('atoms', 'default', CURRENT_DATE, 1.00, 0, 0, 0, 2, 0, NOW())`,+ [],+ );+ const check = await computeExtractHealthCheck(engine);+ expect(check.status).toBe('warn');+ expect(check.message).toContain('atoms=75.0%, last halt 4d ago');+ expect(check.message).not.toContain('today');+ expect((check.details as any)?.kinds[0].last_halt_age_days).toBe(4);+ });+test('multiple kinds with high halt rate: top-3 listed in message', async () => {await clearRollup();await engine.executeRaw(