Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(connectors): report unreadable hold state in sources status (#5866)

garrytan9f3b42245723
diff --git a/src/core/persistence/connector-status.ts b/src/core/persistence/connector-status.ts
index d65432ed5e..6da81ad019 100644
--- a/src/core/persistence/connector-status.ts
+++ b/src/core/persistence/connector-status.ts
@@ -20,17 +20,26 @@ export interface ConnectorSourceStatus {
last_run: ConnectorRunCounts | null;
/** Fix wave 4: every held item (the human view shows HELD_STATUS_LIMIT). */
held: ItemHoldRecord[];
+ /** Set when this source's hold state could not be read: coverage is unknown, not hold-free. */
+ held_error?: string;
}
export async function readConnectorSourceStatuses(engine: Pick<BrainEngine, 'executeRaw'>): Promise<Map<string, ConnectorSourceStatus>> {
const sources = await engine.executeRaw<{ id: string; incarnation: string }>(
"SELECT id,incarnation::text FROM sources WHERE NOT archived AND config->>'kind' IN ('google','github')");
const statuses = new Map<string, ConnectorSourceStatus>();
- const holds = new Map((await readAllSourceHolds(engine).catch(() => [])).map(entry => [entry.sourceId, entry.held]));
for (const source of sources) {
const state = await readManagedConnectorState(engine, source.id, source.incarnation);
+ let held: ItemHoldRecord[] = [];
+ let heldError: string | undefined;
+ try {
+ held = (await readAllSourceHolds(engine, { sourceIds: [source.id] }))[0]?.held ?? [];
+ } catch (error) {
+ heldError = (error instanceof Error ? error.message : String(error)).split('\n')[0].slice(0, 160) || 'unknown error';
+ }
statuses.set(source.id, { upgrade_recovery: state.upgrade_recovery, resumed_from: state.resumed_from, account_pinned: state.account !== null,
- continuity_unverified: state.continuity_unverified, pending: state.pending.length, last_run: state.last_run, held: holds.get(source.id) ?? [] });
+ continuity_unverified: state.continuity_unverified, pending: state.pending.length, last_run: state.last_run, held,
+ ...(heldError ? { held_error: heldError } : {}) });
}
return statuses;
}
@@ -47,7 +56,8 @@ export function connectorStatusLines(sourceId: string, status: ConnectorSourceSt
lines.push(' re-walking its window once after the upgrade (an expected admission spike, not #5470 churn)');
}
if (status.continuity_unverified) lines.push(' account pinned on its first post-upgrade run; continuity before the upgrade is unverified');
- lines.push(...heldItemLines(sourceId, status.held));
+ if (status.held_error) lines.push(` hold state unreadable: ${status.held_error}; coverage is unknown until it can be read`);
+ else lines.push(...heldItemLines(sourceId, status.held));
return lines;
}
diff --git a/test/connector-holds.test.ts b/test/connector-holds.test.ts
index b12c4ac98f..f9b148f682 100644
--- a/test/connector-holds.test.ts
+++ b/test/connector-holds.test.ts
@@ -16,6 +16,8 @@ import { createConnectorFixture, options, sourceCheckpoint, sourceCursor, withGo
import { HOLD_CAP } from '../src/core/connectors/item-holds.ts';
import { addThread, fakeGitHub, fakeGmail, githubHoldsFetch, gmailFetch } from './helpers/connector-holds-fixture.ts';
import { withEnv } from './helpers/with-env.ts';
+import { rmSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
const { engines, env, source, setup, teardown } = createConnectorFixture();
beforeAll(setup, 120_000);
@@ -69,6 +71,26 @@ async function sourceHolds(engine: BrainEngine, id: string) {
return (await readAllSourceHolds(engine, { sourceIds: [id] }))[0]?.held ?? [];
}
+test('sources status reports an unreadable hold state for that source only', async () => withEnv(env, async () => {
+ const { readConnectorSourceStatuses, connectorStatusLines } = await import('../src/core/persistence/connector-status.ts');
+ for (const engine of engines) {
+ const broken = await githubSource(engine, false);
+ const healthy = await githubSource(engine, false);
+ const before = (await readConnectorSourceStatuses(engine)).get(healthy.id);
+ writeFileSync(join(broken.dir, '.github-source.json'), '{not json');
+ const statuses = await readConnectorSourceStatuses(engine);
+ const status = statuses.get(broken.id)!;
+ expect(status.held).toEqual([]);
+ expect(typeof status.held_error).toBe('string');
+ expect(connectorStatusLines(broken.id, status).filter(line => line.startsWith(' hold state unreadable: '))).toHaveLength(1);
+ expect(statuses.get(healthy.id)).toEqual(before);
+ expect(statuses.get(healthy.id)!.held_error).toBeUndefined();
+ await expect(readAllSourceHolds(engine, { sourceIds: [broken.id] })).rejects.toThrow();
+ rmSync(join(broken.dir, '.github-source.json'));
+ expect((await readConnectorSourceStatuses(engine)).get(broken.id)!.held_error).toBeUndefined();
+ }
+}));
+
test('#5740: a GitHub item failing 3 runs is held, the watermark advances past it, and retry-held clears it on recovery', async () => withEnv(env, async () => {
for (const engine of engines) for (const managed of [false, true]) {
const f = await githubSource(engine, managed);