Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(advisor): stale_sync skips archived sources (#7281)

garrytanaaf3bd6d43b7
diff --git a/src/core/advisor/collect-stalled-jobs.ts b/src/core/advisor/collect-stalled-jobs.ts
index 8f917c9628..47361f97da 100644
--- a/src/core/advisor/collect-stalled-jobs.ts
+++ b/src/core/advisor/collect-stalled-jobs.ts
@@ -2,7 +2,7 @@
* advisor/collect-stalled-jobs.ts — stuck background work + stale sync.
*
* #14: `minion_jobs` may be ABSENT on older/partial brains, and very old
- * brains lack `sources` or `sources.last_sync_at`: exactly those missing
+ * brains lack `sources`, `sources.last_sync_at` or `sources.archived`: exactly those missing
* objects yield no finding. Any other read failure is rethrown so runAdvisor
* reports `collector_failed:stalled-jobs` instead of a clean check. Engine-agnostic
* SQL via executeRaw (works on Postgres + PGLite); timestamps compared with
@@ -52,6 +52,7 @@ export const collectStalledJobs: AdvisorCollector = {
FROM sources
WHERE last_sync_at IS NOT NULL
AND last_sync_at < now() - interval '7 days'
+ AND NOT archived
ORDER BY id`,
);
for (const r of rows) {
@@ -66,7 +67,7 @@ export const collectStalledJobs: AdvisorCollector = {
});
}
} catch (err) {
- if (!isMissingSchemaObject(err, 'table', 'sources') && !isMissingSchemaObject(err, 'column', 'last_sync_at')) throw err;
+ if (!isMissingSchemaObject(err, 'table', 'sources') && !isMissingSchemaObject(err, 'column', 'last_sync_at') && !isMissingSchemaObject(err, 'column', 'archived')) throw err;
}
return findings;
diff --git a/test/advisor-core.test.ts b/test/advisor-core.test.ts
index 659f1cbbda..ba95e52337 100644
--- a/test/advisor-core.test.ts
+++ b/test/advisor-core.test.ts
@@ -2,7 +2,8 @@
* Tests for the advisor core: ranking, collector resilience, individual
* collectors with a stub engine, and finding-history deltas.
*/
-import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
+import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
@@ -247,6 +248,25 @@ describe('collect-stalled-jobs', () => {
});
});
+// Value: protects=an archived source never gets a stale_sync finding (its gbrain sync fix cannot run); fails_when=the weekly checkup nags about a source the user retired; why_new=#7281; seam=none; no_claim=a purge finding for archived sources
+describe('collect-stalled-jobs on a real brain (#7281)', () => {
+ let engine: PGLiteEngine;
+ beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({ database_url: '' });
+ await engine.initSchema();
+ });
+ afterAll(async () => { await engine.disconnect(); });
+
+ test('an archived stale source is skipped; a live stale source is still reported', async () => {
+ await engine.executeRaw(`INSERT INTO sources (id, name, last_sync_at) VALUES ('source-a', 'source-a', now() - interval '30 days'), ('source-b', 'source-b', now() - interval '30 days')`);
+ await engine.executeRaw(`UPDATE sources SET archived = true, archived_at = now() WHERE id = 'source-a'`);
+ const ids = (await collectStalledJobs.collect(ctx(engine))).map((f) => f.id);
+ expect(ids).toContain('stale_sync:source-b');
+ expect(ids).not.toContain('stale_sync:source-a');
+ });
+});
+
describe('collect-setup-smells', () => {
test('embeddings disabled → warn', async () => {
const engine = { getConfig: async () => null };