Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(connectors): sync --dry-run writes no state and reports a truncated listing as partial (#7689)

garrytan1f9b0ae84c70
diff --git a/skills/chat-connectors/SKILL.md b/skills/chat-connectors/SKILL.md
index a5b5e3a183..267240e655 100644
--- a/skills/chat-connectors/SKILL.md
+++ b/skills/chat-connectors/SKILL.md
@@ -176,7 +176,8 @@ This skill guarantees:
- Sync is incremental: a durable config-scalar watermark plus a trailing-window
re-list; the watermark advances ONLY on a fully clean run (no fetch errors, no
`--limit` cap, clean ingest), so a partial run never creates a silent gap.
-- `--dry-run` fetches nothing and writes nothing; `--limit N` caps a run and does
+- `--dry-run` fetches nothing and writes nothing; a listing that stopped early
+ reports `partial` with `listComplete: false`. `--limit N` caps a run and does
not advance the watermark.
- Scheduled auto-sync is opt-in per provider (`connectors.<provider>.auto_sync`),
daily by default, credential-gated and auth-error-gated; it fires for nobody
diff --git a/src/core/connectors/sync.ts b/src/core/connectors/sync.ts
index 68c2880b53..507b1a1ca3 100644
--- a/src/core/connectors/sync.ts
+++ b/src/core/connectors/sync.ts
@@ -119,6 +119,10 @@ export interface ConnectorSyncResult {
* request ceiling or deadline (#7515: MAX_CONNECTOR_REQUESTS_PER_RUN, --max-requests, --deadline).
*/
stopReason?: 'consecutive_fetch_failures' | 'max_requests' | 'deadline';
+ /** Dry run: whether the listing reached its end; a listing that stopped early makes the preview `partial`. */
+ listComplete?: boolean;
+ /** Dry run: conversations a real run would fetch from what was listed. */
+ wouldFetch?: number;
hint?: string;
}
@@ -268,7 +272,7 @@ export async function runConnectorSync(
const probe = await provider.probe(client, opts.signal);
if (!probe.ok) {
const term = PROBE_TERMINAL[probe.kind];
- if (term === 'auth_required') await stampAuthError(engine, opts.provider, now);
+ if (term === 'auth_required' && !opts.dryRun) await stampAuthError(engine, opts.provider, now);
if (term) return { ...base, status: term, hint: probe.kind === 'invalid_credential' ? probe.detail : terminalHint(term, provider) };
// drift / network → surface as forbidden-ish partial with the detail.
return { ...base, status: 'partial', hint: `probe failed: ${probe.detail}` };
@@ -301,7 +305,7 @@ export async function runConnectorSync(
if (e instanceof ConnectorRunLimitError) base.stopReason = e.reason;
const term = classifyThrow(e);
if (term) {
- if (term === 'auth_required') await stampAuthError(engine, opts.provider, now);
+ if (term === 'auth_required' && !opts.dryRun) await stampAuthError(engine, opts.provider, now);
return { ...base, status: term, hint: terminalHint(term, provider) };
}
log(`[connector] list error: ${e instanceof Error ? e.message : String(e)}`);
@@ -321,7 +325,7 @@ export async function runConnectorSync(
}
if (stubs.length === 0 && !listErrored && Object.keys(failed).length === 0) {
- await writeConnectorState(engine, opts.provider, sourceId, 'last_sync_at', new Date(now()).toISOString());
+ if (!opts.dryRun) await writeConnectorState(engine, opts.provider, sourceId, 'last_sync_at', new Date(now()).toISOString());
return { ...base, status: 'nothing_new' };
}
@@ -339,7 +343,17 @@ export async function runConnectorSync(
const toFetch = [...plan.retries, ...plan.listed];
if (opts.dryRun) {
- return { ...base, status: 'dry_run', listed: stubs.length, unresolved: Object.keys(failed).length, hint: `${toFetch.length} conversation(s) would be fetched` };
+ return {
+ ...base,
+ status: listErrored ? 'partial' : 'dry_run',
+ listed: stubs.length,
+ unresolved: Object.keys(failed).length,
+ listComplete: !listErrored,
+ wouldFetch: toFetch.length,
+ hint: listErrored
+ ? `the listing stopped early; ${toFetch.length} conversation(s) listed so far would be fetched`
+ : `${toFetch.length} conversation(s) would be fetched`,
+ };
}
// FETCH details + spool + ingest, in batches (memory-bounded; banks progress).
diff --git a/test/connectors-dry-run-7689.test.ts b/test/connectors-dry-run-7689.test.ts
new file mode 100644
index 0000000000..6e888992bb
--- /dev/null
+++ b/test/connectors-dry-run-7689.test.ts
@@ -0,0 +1,115 @@
+/**
+ * #7689 (part 2): `connectors sync --dry-run` is a preview, yet it stamped
+ * `last_sync_at` when the listing came back empty and `auth_error_at` when the
+ * probe or listing hit an auth error, and a dry run whose listing stopped part
+ * way (a 5xx on page 2) still reported `dry_run`, so a caller could not tell a
+ * complete preview from a truncated one.
+ *
+ * Protects: a dry run writes no connector config state on any of those paths;
+ * a dry run whose listing did not finish returns `partial` with
+ * `listComplete: false` and the count it would fetch; a complete one returns
+ * `dry_run` with `listComplete: true`. Part 1 (stop at the first 429) is a
+ * policy question and is not covered here.
+ * Seams: the real ConnectorClient against the Bun.serve fixture backend; PGLite.
+ */
+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { runConnectorSync } from '../src/core/connectors/sync.ts';
+import { saveCredential } from '../src/core/connectors/credentials.ts';
+import { CHATGPT_BASE_URL } from '../src/core/connectors/providers/chatgpt.ts';
+import type { ConnectorFetch } from '../src/core/connectors/client.ts';
+import { type FixtureConversation, type FixtureState, chatgptHandler, newFixtureState, startFixture } from './fixtures/connectors/fixture-server.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+let engine: PGLiteEngine;
+let home: string;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+}, 120_000);
+
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+beforeEach(async () => {
+ await resetPgliteState(engine);
+ home = mkdtempSync(join(tmpdir(), 'gb-connectors-7689-'));
+ return () => rmSync(home, { recursive: true, force: true });
+});
+
+const T0 = 1_786_000_000;
+const NOW_MS = (T0 + 100_000) * 1000;
+
+function conv(id: string, updateTime: number): FixtureConversation {
+ return { id, title: `Synthetic ${id}`, createTime: updateTime - 100, updateTime, turns: [{ role: 'user', text: 'q' }, { role: 'assistant', text: 'a' }] };
+}
+
+async function dryRun(state: FixtureState) {
+ const srv = startFixture(chatgptHandler(state));
+ try {
+ return await withEnv({ GBRAIN_HOME: home }, async () => {
+ saveCredential({ provider: 'chatgpt', strategy: 'browser-session', cookie: 'sessionKey=fixture', savedAt: new Date(0).toISOString() });
+ const rewrite: ConnectorFetch = (url, init) => fetch(url.replace(CHATGPT_BASE_URL, srv.baseUrl), init);
+ return runConnectorSync(engine, {
+ provider: 'chatgpt',
+ sourceId: 'default',
+ dryRun: true,
+ deps: { fetchImpl: rewrite, now: () => NOW_MS, sleep: () => Promise.resolve() },
+ });
+ });
+ } finally {
+ srv.stop();
+ }
+}
+
+async function connectorConfig(): Promise<Array<{ key: string; value: string }>> {
+ return engine.executeRaw<{ key: string; value: string }>("SELECT key, value FROM config WHERE key LIKE 'connectors.%' ORDER BY key");
+}
+
+describe('#7689: connectors sync --dry-run is a pure preview', () => {
+ test('an empty listing writes no last_sync_at', async () => {
+ const r = await dryRun(newFixtureState([]));
+ expect(r.status).toBe('nothing_new');
+ expect(await connectorConfig()).toEqual([]);
+ });
+
+ test('an auth error on the probe writes no auth_error_at', async () => {
+ const state = newFixtureState([conv('c-1', T0 + 10)]);
+ state.script.push({ pathIncludes: 'conversations?offset=0&limit=1&', status: 401, body: { detail: 'unauthorized' } });
+ const r = await dryRun(state);
+ expect(r.status).toBe('auth_required');
+ expect(await connectorConfig()).toEqual([]);
+ });
+
+ test('an auth error on the listing writes no auth_error_at', async () => {
+ const state = newFixtureState([conv('c-1', T0 + 10)]);
+ state.script.push({ pathIncludes: 'conversations?offset=0&limit=28&', status: 401, body: { detail: 'unauthorized' } });
+ const r = await dryRun(state);
+ expect(r.status).toBe('auth_required');
+ expect(await connectorConfig()).toEqual([]);
+ });
+
+ test('a listing that fails part way reports partial with listComplete false', async () => {
+ const convs = Array.from({ length: 40 }, (_, i) => conv(`c-${i}`, T0 + i));
+ const state = newFixtureState(convs);
+ state.script.push({ pathIncludes: 'conversations?offset=28', status: 500, body: { detail: 'server error' } });
+ const r = await dryRun(state);
+ expect(r).toMatchObject({ status: 'partial', listed: 28, listComplete: false, wouldFetch: 28 });
+ expect(state.hits.detail ?? 0).toBe(0);
+ expect(await connectorConfig()).toEqual([]);
+ });
+
+ test('a complete listing reports dry_run with listComplete true', async () => {
+ const state = newFixtureState([conv('c-1', T0 + 10), conv('c-2', T0 + 20)]);
+ const r = await dryRun(state);
+ expect(r).toMatchObject({ status: 'dry_run', listed: 2, listComplete: true, wouldFetch: 2 });
+ expect(await connectorConfig()).toEqual([]);
+ });
+});