Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): API connector sources never read as upstream unknown (#5255 review)
garrytan21137ae09486
diff --git a/src/core/sync-upstream.ts b/src/core/sync-upstream.tsindex 3116970b20..99aeb3d5a8 100644--- a/src/core/sync-upstream.ts+++ b/src/core/sync-upstream.ts@@ -12,7 +12,7 @@ import { execFileSync } from 'node:child_process';import { statSync } from 'node:fs';import type { BrainEngine } from './engine.ts';import { ERROR_CATALOGUE } from './error-catalogue.ts';-import { sourceConfigHasRemoteUrl } from './sources-load.ts';+import { parseSourceConfig, sourceConfigHasRemoteUrl } from './sources-load.ts';export const UPSTREAM_OBSERVATION_MAX_AGE_HOURS = 24;@@ -88,8 +88,8 @@ export function managedPullWarning(sourceId: string, checkout: string): ManagedP/*** O-DX-8: doctor's "upstream checked" verdict, separate from "local projection- * current". A source with a `remote_url` and no observation, or one older than- * 24 h, is upstream unknown; any source whose last observation saw upstream+ * current". A Git source (no connector `kind`) with a `remote_url` and no+ * observation, or one older than 24 h, is upstream unknown; any source whose last observation saw upstream* commits its synced commit lacks is behind. Null when neither applies.*/export function upstreamFreshness(@@ -99,7 +99,8 @@ export function upstreamFreshness(const checkedMs = source.upstream_checked_at ? new Date(source.upstream_checked_at).getTime() : null;const behind = source.upstream_behind ?? 0;const ageHours = checkedMs === null ? null : Math.floor((now - checkedMs) / 3_600_000);- const unknown = sourceConfigHasRemoteUrl(source.config) && (ageHours === null || ageHours >= UPSTREAM_OBSERVATION_MAX_AGE_HOURS);+ const gitRemote = sourceConfigHasRemoteUrl(source.config) && parseSourceConfig(source.config).kind == null;+ const unknown = gitRemote && (ageHours === null || ageHours >= UPSTREAM_OBSERVATION_MAX_AGE_HOURS);if (!unknown && behind <= 0) return null;const fix = managed ? managedRefreshFix(source.id, source.local_path ?? '<checkout>') : `gbrain sync --source ${source.id}`;const fact = unknowndiff --git a/test/managed-cycle-pull-upstream.test.ts b/test/managed-cycle-pull-upstream.test.tsindex d0f8c98111..9e0b1bdee8 100644--- a/test/managed-cycle-pull-upstream.test.ts+++ b/test/managed-cycle-pull-upstream.test.ts@@ -165,13 +165,17 @@ for (const backend of backends) {const sourceId = `never-${backend}`;await engine().executeRaw('INSERT INTO sources(id,name,local_path,config,last_sync_at) VALUES($1,$1,$2,$3::text::jsonb,now())',[sourceId, '/example/never-observed', JSON.stringify({ remote_url: 'https://example.invalid/repo.git' })]);+ // An API connector source is not a Git remote: it never reads as upstream unknown.+ await engine().executeRaw('INSERT INTO sources(id,name,local_path,config,last_sync_at) VALUES($1,$1,$2,$3::text::jsonb,now())',+ [`${sourceId}-connector`, '/example/connector', JSON.stringify({ kind: 'github', remote_url: 'https://example.invalid/repo.git' })]);try {const result = await checkSyncFreshness(engine());expect(result.status).toBe('warn');expect(result.message).toContain(`'${sourceId}' upstream unknown (never checked)`);- expect(result.details).toMatchObject({ synced_recently_count: 1, upstream_unknown_count: 1 });+ expect(result.message).not.toContain(`'${sourceId}-connector'`);+ expect(result.details).toMatchObject({ upstream_unknown_count: 1 });} finally {- await engine().executeRaw('DELETE FROM sources WHERE id=$1', [sourceId]);+ await engine().executeRaw('DELETE FROM sources WHERE id=ANY($1::text[])', [[sourceId, `${sourceId}-connector`]]);}});}