Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(chronicle): retries count toward the daily limit; failures outrank more frequent skips (#5876)
garrytan24e14335a5c8
diff --git a/test/auto-chronicle-surfaces-5876.test.ts b/test/auto-chronicle-surfaces-5876.test.tsindex 4e06253a33..75705bbaa7 100644--- a/test/auto-chronicle-surfaces-5876.test.ts+++ b/test/auto-chronicle-surfaces-5876.test.ts@@ -93,10 +93,10 @@ describe('doctor auto_chronicle', () => {fix: { actor: 'user', consent: ['credentials'] } } });});- test('activity: 24 h use, largest writer share, 7-day spend with unpriced calls apart, run-now command', async () => {+ test('activity: 24 h use (retries count), largest writer share, 7-day spend with unpriced calls apart, run-now command', async () => {withChat();await engine.setConfig('chronicle.auto_daily_limit', '10');- await insertChronicleLedgerRow(engine, { slug: 'meetings/a', state: 'extracted', principal: ['oauth_client', 'client-a'], cost: 0.01 });+ await insertChronicleLedgerRow(engine, { slug: 'meetings/a', state: 'extracted', principal: ['oauth_client', 'client-a'], cost: 0.01, retries: 1 });await insertChronicleLedgerRow(engine, { slug: 'meetings/b', state: 'extracted', principal: ['oauth_client', 'client-a'], cost: 0.02 });await insertChronicleLedgerRow(engine, { slug: 'meetings/c', state: 'extracted', principal: ['local_cli', 'w1'], unpriced: true });await insertChronicleLedgerRow(engine, { slug: 'meetings/old', state: 'extracted', cost: 5, hoursAgo: 24 * 9 });@@ -105,15 +105,17 @@ describe('doctor auto_chronicle', () => {await insertChronicleLedgerRow(engine, { slug: 'meetings/f', state: 'extracted', trigger: 'backfill', cost: 1 });const main = byName(await doctor(), 'auto_chronicle');expect(main.status).toBe('ok');- expect(main.message).toContain('Last 24 h: 3 of 10 automatic extraction calls; largest writer oauth_client:client-a used 20% of the daily limit');+ expect(main.message).toContain('Last 24 h: 4 of 10 automatic extraction calls; largest writer oauth_client:client-a used 30% of the daily limit');expect(main.message).toContain('3 extracted, 0 failed, 1 skipped (history 1); $0.03 known spend + 1 unpriced call(s)');expect(main.message).toContain('gbrain dream --phase chronicle');- expect(main.details).toMatchObject({ readiness: 'ok', auto_calls_24h: 3,+ expect(main.details).toMatchObject({ readiness: 'ok', auto_calls_24h: 4,spend_7d: { knownUsd: 0.03, unpricedCalls: 1, incompleteRecords: 0 } });});- test('failures warn with the reason fix (no_pricing names the pricing command)', async () => {+ test('failures warn with the failed row\'s reason fix, not a more frequent skip (no_pricing names the pricing command)', async () => {withChat();+ await insertChronicleLedgerRow(engine, { slug: 'meetings/s1', state: 'skipped', reason: 'superseded' });+ await insertChronicleLedgerRow(engine, { slug: 'meetings/s2', state: 'skipped', reason: 'superseded' });await insertChronicleLedgerRow(engine, { slug: 'meetings/a', state: 'failed', reason: 'no_pricing' });const main = byName(await doctor(), 'auto_chronicle');expect(main).toMatchObject({ status: 'warn', details: { code: 'no_pricing', fix: { actor: 'agent' } } });diff --git a/test/helpers/chronicle-ledger-stub.ts b/test/helpers/chronicle-ledger-stub.tsindex fff2799833..025caed2ce 100644--- a/test/helpers/chronicle-ledger-stub.ts+++ b/test/helpers/chronicle-ledger-stub.ts@@ -23,6 +23,8 @@ export async function createChronicleLedgerStub(engine: BrainEngine): Promise<voexport interface LedgerRowStub {slug: string; state: 'pending' | 'skipped' | 'extracted' | 'failed'; reason?: string; trigger?: 'auto' | 'backfill';principal?: [string, string]; cost?: number | null; unpriced?: boolean; hoursAgo?: number;+ /** Extra judge calls (retries) for this content; each takes its own reservation. */+ retries?: number;}let pageSeq = 1;@@ -37,8 +39,8 @@ export async function insertChronicleLedgerRow(engine: BrainEngine, row: LedgerRattempts, cost_usd, unpriced, updated_at)VALUES ('default', $1, $2, 1, $3, $4, $5, $6, $7, $8, $9, $10, $11, now() - ($12 || ' hours')::interval)`,[pageId, hash, row.slug, row.state, row.reason ?? null, row.trigger ?? 'auto', row.principal?.[0] ?? null,- row.principal?.[1] ?? null, judged ? 1 : 0, row.cost ?? null, row.unpriced ?? false, hoursAgo]);- if (judged && (row.trigger ?? 'auto') === 'auto') {+ row.principal?.[1] ?? null, judged ? 1 + (row.retries ?? 0) : 0, row.cost ?? null, row.unpriced ?? false, hoursAgo]);+ for (let i = 0; judged && (row.trigger ?? 'auto') === 'auto' && i <= (row.retries ?? 0); i++) {await engine.executeRaw(`INSERT INTO chronicle_judge_reservations (reserved_at, source_id, page_id, content_hash)VALUES (now() - ($1 || ' hours')::interval, 'default', $2, $3)`, [hoursAgo, pageId, hash]);}