Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(connectors): a disabled Google API is reported as api_not_enabled, not an account change (#7004)

time-attack97c4837680f5
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index e1ab8cba46..261c728b69 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -907,6 +907,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.307.0', text: 'A name written only in Katakana (an alias such as デン) no longer links a page that has it inside a longer Katakana word (インシデント, デンタル): the name must stand as a whole Katakana run, so 「デン」, デンに, 喫茶デン and デン・カフェ still link. A short name inside a real Katakana compound is refused too; add the compound as its own alias when it names the entity. Mention links already written that way are counted by `gbrain doctor` (`stale_mentions`) and removed by `gbrain extract links --by-mention --rebuild --source db`.', id: 'katakana_mention_boundaries' },
{ since: '0.60.307.0', text: 'On Windows, cancelling or timing out a job now ends its whole process tree with taskkill: a per-job child and a shell job first get a polite close (`taskkill /T`), then a forced one (`/T /F`) after the grace window, instead of only the direct child being killed. A windowless console program refuses the polite close, so a cancelled Windows shell job now takes up to its 5-second grace window to end. A descendant whose parent already exited is no longer in the tree and is not ended.', id: 'windows_tree_kill' },
{ since: '0.60.307.0', text: '`get_links` and `get_backlinks` (`gbrain links`, `gbrain backlinks`) now return at most 500 link rows per call instead of every edge of the page. When more match, the last row carries `truncated: true` and `next_cursor`: pass it back as `cursor` (`--cursor`) with the same filters for the next rows, raise `limit` (`--limit`, up to 5000), or use `--all` on the CLI for every row. Remote callers also get a `listing_truncated` notice naming the next call. Rows come in link order, `link_type` and the live/history filter apply before the cap so hidden former relationships never use a row, and each row\'s `context` is cut to 2000 characters (ending in an ellipsis). A cursor from another listing is refused `link_cursor_invalid`. `get_backlinks` with `limit` no longer points at `group: "page"`; it pages the rows with `cursor`.', id: 'link_read_cap' },
+ { since: '0.60.307.0', id: 'google_account_credential_refusal', text: 'A managed Google source whose account cannot be read because the Google API is disabled for the OAuth project (or the grant is missing, or Google answers 403) now fails the sync with that credential error (`api_not_enabled` with the console link to enable the API, `scope_missing`, or `upstream` naming the 403) instead of `connector_account_changed`. A credential that no service can name for another reason still refuses as before.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/persistence/connector-account.ts b/src/core/persistence/connector-account.ts
index adc880bfb7..a13cd487f5 100644
--- a/src/core/persistence/connector-account.ts
+++ b/src/core/persistence/connector-account.ts
@@ -8,10 +8,15 @@ import type { GoogleService } from '../google/types.ts';
import type { GmailClient, CalendarClient, PeopleClient } from '../google/google-clients.ts';
import type { GitHubClient, GitHubSourceConfig } from '../github-source.ts';
import type { ConnectorAccount } from './connector-state.ts';
+import { CredentialError } from '../creds/errors.ts';
/**
* Google: the first enabled service whose granted scope can name the account
* (Gmail profile, Calendar primary calendar, People `me`). Null when none can.
+ * When no service names the account and one refused with a credential error
+ * (API disabled, scope missing, forbidden), that error is rethrown, preferring
+ * api_not_enabled, so the caller reports the real cause instead of an account
+ * change (#7004).
*/
export async function resolveGoogleAccount(clients: { gmail: GmailClient; calendar: CalendarClient; people: PeopleClient },
services: readonly GoogleService[], signal?: AbortSignal): Promise<string | null> {
@@ -25,6 +30,7 @@ export async function resolveGoogleAccount(clients: { gmail: GmailClient; calend
return (me.emailAddresses?.find(address => address.metadata?.primary) ?? me.emailAddresses?.[0])?.value;
}],
];
+ const credentialErrors: CredentialError[] = [];
for (const [service, attempt] of attempts) {
if (!services.includes(service)) continue;
signal?.throwIfAborted();
@@ -33,8 +39,11 @@ export async function resolveGoogleAccount(clients: { gmail: GmailClient; calend
if (email && email.includes('@')) return email;
} catch (error) {
if (signal?.aborted) throw error;
+ if (error instanceof CredentialError) credentialErrors.push(error);
}
}
+ const refusal = credentialErrors.find(error => error.code === 'api_not_enabled') ?? credentialErrors[0];
+ if (refusal) throw refusal;
return null;
}
diff --git a/test/connector-account-api-disabled-7004.test.ts b/test/connector-account-api-disabled-7004.test.ts
new file mode 100644
index 0000000000..cfe802c97e
--- /dev/null
+++ b/test/connector-account-api-disabled-7004.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, test } from 'bun:test';
+import { CredentialError } from '../src/core/creds/errors.ts';
+import { resolveGoogleAccount } from '../src/core/persistence/connector-account.ts';
+
+const disabled = () => { throw new CredentialError('api_not_enabled'); };
+const scopeMissing = () => { throw new CredentialError('scope_missing'); };
+const network = () => { throw new Error('ECONNRESET'); };
+
+describe('#7004 resolveGoogleAccount', () => {
+ test('a disabled Gmail API surfaces as api_not_enabled, never as an unresolvable account', async () => {
+ const clients = { gmail: { getProfile: disabled }, calendar: { fetchJSON: disabled }, people: { fetchJSON: disabled } } as never;
+ const error = await resolveGoogleAccount(clients, ['gmail', 'calendar', 'contacts']).catch(e => e);
+ expect(error).toBeInstanceOf(CredentialError);
+ expect((error as CredentialError).code).toBe('api_not_enabled');
+ });
+
+ test('api_not_enabled is preferred over an earlier credential error', async () => {
+ const clients = { gmail: { getProfile: scopeMissing }, calendar: { fetchJSON: disabled }, people: { fetchJSON: scopeMissing } } as never;
+ const error = await resolveGoogleAccount(clients, ['gmail', 'calendar', 'contacts']).catch(e => e);
+ expect((error as CredentialError).code).toBe('api_not_enabled');
+ });
+
+ test('a later service that names the account wins over an earlier credential error', async () => {
+ const clients = {
+ gmail: { getProfile: disabled },
+ calendar: { fetchJSON: async () => ({ id: '[email protected]' }) },
+ people: { fetchJSON: disabled },
+ } as never;
+ expect(await resolveGoogleAccount(clients, ['gmail', 'calendar', 'contacts'])).toBe('[email protected]');
+ });
+
+ test('non-credential failures still mean no service could name the account', async () => {
+ const clients = { gmail: { getProfile: network }, calendar: { fetchJSON: network }, people: { fetchJSON: network } } as never;
+ expect(await resolveGoogleAccount(clients, ['gmail', 'calendar', 'contacts'])).toBeNull();
+ });
+});