Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#7073): setup stops with exit 2 (exit 3 is confirmation_required only); index the API access key-files page; list the serial test

garrytan9147f197b2f6
diff --git a/docs/architecture/KEY_FILES.md b/docs/architecture/KEY_FILES.md
index 70a54fab84..6d2be191de 100644
--- a/docs/architecture/KEY_FILES.md
+++ b/docs/architecture/KEY_FILES.md
@@ -84,8 +84,7 @@ link it here rather than raising the cap.
| [Schema packs: mutation surface](key-files/schema-mutation.md) | Cross-file contract |
| [Agent bootstrap cluster (paste-in install)](key-files/agent-bootstrap.md) | Cross-file contract |
| [Agent Bootstrap (continued)](key-files/agent-bootstrap-continued.md) | Remaining entries |
-| [Google connector + open-loop engine](key-files/google-and-loops.md) | Cross-file contract |
-| [Google And Loops (continued)](key-files/google-and-loops-continued.md) | Remaining entries |
+| [Google connector + open-loop engine](key-files/google-and-loops.md) | Cross-file contract; [more](key-files/google-and-loops-continued.md), [API](key-files/google-api-access.md) |
| [Open loops](key-files/open-loops-engine.md) | detect, extract, store |
| [Always-loaded core memory](key-files/core-memory.md) | Core tier, write-path guard and lock order, delivery lanes, pressure notice |
| [Workspace push and backup coverage](key-files/workspace-push-and-backup.md) | Workspace push, hook push backstops, backup verdicts |
diff --git a/docs/architecture/key-files/google-api-access.md b/docs/architecture/key-files/google-api-access.md
index 5e7b20a5c8..a387e7dc8f 100644
--- a/docs/architecture/key-files/google-api-access.md
+++ b/docs/architecture/key-files/google-api-access.md
@@ -5,7 +5,7 @@
- `src/core/google/api-access.ts` — #7004/#7073 account identity and API reachability. `probeGoogleAccount(clients, services, { every })` asks Gmail profile, Calendar primary and People `me` in order (stopping at the first address unless `every`), then OAuth userinfo when none named the account, and records each failure per attempt. `resolveGoogleAccount` (`persistence/connector-account.ts`) is the managed sync's stop-at-first use: when nothing names the account it rethrows `api_not_enabled` first, then another credential error, then the first other failure (a network error stays transient), so `connector_account_changed` means a resolved account that differs from the pin. `probeGoogleApiAccess` probes every service of a setup or status run (an ungranted scope is `scope_missing` with no request) and returns `{ resolved_account, resolved_via, services, problems, fix }`; `googleApiProblem` maps `GoogleApiDisabledError` and `scope_missing` to a `GoogleApiProblem`; `googleApiAccessFix` is one Action naming every problem (`ask_user` with each enable link when an API is disabled, else the user's `gbrain google connect --reauth` command), verified by `gbrain google status --json`.
- The clients (`google-clients.ts`) throw `GoogleApiDisabledError` (`api_not_enabled`) for a 403 with reason `accessNotConfigured`, ErrorInfo `SERVICE_DISABLED` or the disabled-API message, carrying the API, its title, the project and the enable link from the error body (ErrorInfo `activationUrl`, then the Help link, then the message; only console.cloud.google.com and console.developers.google.com links are relayed, otherwise the client id's project number builds it). A 403 for insufficient authentication scopes (`insufficientPermissions`, ErrorInfo `ACCESS_TOKEN_SCOPE_INSUFFICIENT`) is `scope_missing`, never `GoogleForbiddenError`, so a calendar read never names it `calendar_unreadable`.
- The sweep (`google-source.ts`) records each `api_not_enabled` / `scope_missing` failure, plus an unmanaged source's ungranted services, as `api_access: { problems, at }` in source state; a service leaves it when its sweep reaches the API again, `at` changes only when the problems do, and a partial managed run publishes it with the loop recovery state.
- - `gbrain google status` (with a probe) runs `probeGoogleApiAccess` per refreshed account over its linked sources' services (every granted service when none is linked) and reports `accounts[].api_access`; a problem makes `ok: false` and exit 1. `gbrain google setup` probes every requested service (`--services`, default all) before registering anything; a problem stops it with one report (`status: api_access_blocked`, exit 3, the rendered fix and the narrower `--services` command for the reachable services).
+ - `gbrain google status` (with a probe) runs `probeGoogleApiAccess` per refreshed account over its linked sources' services (every granted service when none is linked) and reports `accounts[].api_access`; a problem makes `ok: false` and exit 1. `gbrain google setup` probes every requested service (`--services`, default all) before registering anything; a problem stops it with one report (`status: api_access_blocked`, exit 2, the rendered fix and the narrower `--services` command for the reachable services).
- When the Gmail label list itself fails, the loop exclusion log (`loops-enqueue.ts`) says the names could not be checked, never that they are not labels of the account.
- Tests: `test/google-api-access-7073.test.ts`, `test/google-api-access-cmd-7073.serial.test.ts`, `test/google-api-access-managed-7073.test.ts` (real PGLite, and Postgres under `DATABASE_URL`).
- `src/commands/doctor/checks/google-api-access.ts` — doctor `google_api_access` (wave check, resolution operator, zero network): warns per Google source whose stored `api_access` names a service it still syncs, listing each disabled API with project and enable link, with `googleApiAccessFix` for the first source.
diff --git a/docs/guides/google-connect.md b/docs/guides/google-connect.md
index f7ef9dfdce..1829010616 100644
--- a/docs/guides/google-connect.md
+++ b/docs/guides/google-connect.md
@@ -225,7 +225,7 @@ consent. When one is not:
- `gbrain google setup` probes every service it is about to register before
it registers anything. A disabled API or an ungranted scope stops setup
- with one report (exit 3, `status: api_access_blocked` under `--json`)
+ with one report (exit 2, `status: api_access_blocked` under `--json`)
that names each API, the Google Cloud project, and the enable link from
Google's own error, plus the narrower `--services` command for the
services that already work;
diff --git a/scripts/serial-files.tsv b/scripts/serial-files.tsv
index d80b8f3dbd..218d5520d6 100644
--- a/scripts/serial-files.tsv
+++ b/scripts/serial-files.tsv
@@ -208,6 +208,7 @@ test/git-listing-memo.serial.test.ts R1 R1: puts a git-counting shim on process.
test/git-remote-durable.serial.test.ts R1 R1: mutates process.env (GBRAIN_GIT_ALLOW_FILE_TRANSPORT)
test/git-remote-pull-file-transport.serial.test.ts R1 R1: mutates process.env (GBRAIN_GIT_ALLOW_FILE_TRANSPORT)
test/google-connect-cmd.serial.test.ts global-state global-state: spyOn console.error; patches process stdout/stderr/console
+test/google-api-access-cmd-7073.serial.test.ts global-state global-state: replaces globalThis.fetch and patches process stdout/stderr for google status and setup
test/google-loops-recovery.serial.test.ts global-state global-state: process-wide test seams __setChatTransportForTests; configureGateway changes the process-wide AI gateway; patches process stdout/stderr/console
test/graduation-serve-guard.serial.test.ts global-state global-state: spawns real gbrain serve children and holds GBRAIN_HOME (withEnv) across awaited CLI runs
test/graph-query-thin-client-source-flag.serial.test.ts R2 R2: mock.module(../src/core/config.ts, ../src/core/mcp-client.ts) replaces modules for every file in the process
diff --git a/src/commands/google-setup.ts b/src/commands/google-setup.ts
index 7ff17c95b4..bf79b1408f 100644
--- a/src/commands/google-setup.ts
+++ b/src/commands/google-setup.ts
@@ -72,7 +72,7 @@ export async function runGoogleSetup(args: string[]): Promise<void> {
'Then re-run: gbrain google setup', ...(narrower ? [`Or set up only the services it can reach now: ${narrower}`] : [])].join('\n') + '\n'
+ agentBlock({ why: fix.why, actor: fix.actor, next: fix.next, verify: 'gbrain google status --json' }, { showUser: fix.user_message ?? '' }));
}
- setCliExitVerdict(3);
+ setCliExitVerdict(2);
return;
}
}
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 622354a04c..e67e0b4f72 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -952,7 +952,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.312.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.312.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.312.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` for every row. `--all` is local only: over a thin client (and from any remote caller) it is refused with `invalid_params`, so page with `--cursor` there. Remote callers also get a `listing_truncated` notice naming the next call. Rows come in link order, `link_type`, `get_backlinks` `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: 'TBD', id: 'google_api_access_probe', text: 'A managed Google source whose enabled services cannot name the account (an API disabled for the OAuth project, a scope not granted) now resolves it through the OAuth userinfo endpoint: the account pins, the services that work keep syncing, the run is `partial`, and the disabled API is reported as `api_not_enabled` instead of failing the whole sync. `connector_account_changed` is raised only when an account resolved and differs from the pin; when nothing can name the account (userinfo also failing), the sync fails with the underlying error, a network failure included, instead of refusing as an account change. `gbrain google setup` now probes every requested service before registering a source and stops (exit 3, `status: api_access_blocked`) naming each disabled API with its Google Cloud project and enable link, or each scope not granted, in one report. `gbrain google status` adds `accounts[].api_access` and exits 1 while a problem remains, and doctor adds `google_api_access`, read from what the last sync recorded. A Google 403 for insufficient authentication scopes is now `scope_missing` (before: `upstream`, and a calendar read named it `calendar_unreadable`).' },
+ { since: 'TBD', id: 'google_api_access_probe', text: 'A managed Google source whose enabled services cannot name the account (an API disabled for the OAuth project, a scope not granted) now resolves it through the OAuth userinfo endpoint: the account pins, the services that work keep syncing, the run is `partial`, and the disabled API is reported as `api_not_enabled` instead of failing the whole sync. `connector_account_changed` is raised only when an account resolved and differs from the pin; when nothing can name the account (userinfo also failing), the sync fails with the underlying error, a network failure included, instead of refusing as an account change. `gbrain google setup` now probes every requested service before registering a source and stops (exit 2, `status: api_access_blocked`) naming each disabled API with its Google Cloud project and enable link, or each scope not granted, in one report. `gbrain google status` adds `accounts[].api_access` and exits 1 while a problem remains, and doctor adds `google_api_access`, read from what the last sync recorded. A Google 403 for insufficient authentication scopes is now `scope_missing` (before: `upstream`, and a calendar read named it `calendar_unreadable`).' },
{ since: '0.60.312.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.' },
{ since: '0.60.312.0', id: 'auth_rescope_client_print_only', text: '`gbrain auth rescope --client <id>` (and `gbrain auth rescope-client <id>`) with no grant flag and no `--profile` now prints the client\'s stored grants and writes nothing (`--json`: `changed: false`, `written: false`), as the help always said, instead of refusing with `invalid_grant`. An unknown client id refuses with `client_not_found`, whose fix is `gbrain auth clients --json`. `--repair` alone still refuses.' },
{ since: '0.60.312.0', id: 'file_drift_unknown_listed', text: '`gbrain repair file-drift --all-drifted` previews and the bare `gbrain repair file-drift` survey now list a conflicted page the live check cannot classify (canonical file missing, page gone, not the owner host, a refused or failed check) as `unknown`, counted under `unknown_<reason>` with the next step for that reason. They used to drop it silently, so a preview could read as empty. Unknown pages are never repaired and get no `--class` preview command.' },
diff --git a/test/google-api-access-cmd-7073.serial.test.ts b/test/google-api-access-cmd-7073.serial.test.ts
index 75e8887425..0caa81a6dd 100644
--- a/test/google-api-access-cmd-7073.serial.test.ts
+++ b/test/google-api-access-cmd-7073.serial.test.ts
@@ -114,7 +114,7 @@ describe('#7073 gbrain google status probes every service at once', () => {
});
describe('#7073 gbrain google setup probes before registering anything', () => {
- test('two disabled APIs and an ungranted scope stop setup with one report and exit 3', async () => {
+ test('two disabled APIs and an ungranted scope stop setup with one report and exit 2', async () => {
disabledApis = new Set(['gmail', 'people']);
const dir = home(SCOPES.filter(s => !s.includes('calendar')));
const r = await withEnv(env(dir), () => run(() => runGoogleSetup(['--json'])));
@@ -122,7 +122,7 @@ describe('#7073 gbrain google setup probes before registering anything', () => {
expect(body).toMatchObject({ ok: false, status: 'api_access_blocked' });
expect(body.api_access.problems.map(p => `${p.service}:${p.code}`)).toEqual(['gmail:api_not_enabled', 'calendar:scope_missing', 'contacts:api_not_enabled']);
expect(body.api_access.fix.next).toBe('ask_user');
- expect(r.verdict).toBe(3);
+ expect(r.verdict).toBe(2);
});
test('human output names every API and the narrower setup, with the fix in one [SHOW USER] relay', async () => {
@@ -133,7 +133,7 @@ describe('#7073 gbrain google setup probes before registering anything', () => {
expect(r.err).toContain(`People API (people.googleapis.com) is disabled for Google Cloud project ${PROJECT}. Enable it: ${enableUrl('people.googleapis.com')}`);
expect(r.err).toContain(`gbrain google setup --account ${ACCOUNT} --services gmail,calendar`);
expect(r.err).not.toContain('Registered source');
- expect(r.verdict).toBe(3);
+ expect(r.verdict).toBe(2);
});
test('every API reachable: setup continues past the probe to the brain step', async () => {