gogcli-mcp 2.21.0 → 2.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
10
- "version": "2.21.0"
10
+ "version": "2.21.1"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "gogcli",
16
16
  "source": "./",
17
17
  "description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
18
- "version": "2.21.0",
18
+ "version": "2.21.1",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gogcli-mcp",
3
3
  "displayName": "gogcli",
4
- "version": "2.21.0",
4
+ "version": "2.21.1",
5
5
  "description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/dist/index.js CHANGED
@@ -31140,6 +31140,21 @@ import { delimiter, join } from "node:path";
31140
31140
  function isGogFileArg(arg) {
31141
31141
  return typeof arg !== "string";
31142
31142
  }
31143
+ var RUNNER_TRANSPORT_BRAND = /* @__PURE__ */ Symbol.for("gogcli.RunnerTransportError");
31144
+ var RunnerTransportError = class extends Error {
31145
+ kind;
31146
+ status;
31147
+ constructor(message, kind, status) {
31148
+ super(message);
31149
+ this.name = "RunnerTransportError";
31150
+ this.kind = kind;
31151
+ this.status = status;
31152
+ Object.defineProperty(this, RUNNER_TRANSPORT_BRAND, { value: true });
31153
+ }
31154
+ };
31155
+ function isRunnerTransportError(err) {
31156
+ return err instanceof Error && err[RUNNER_TRANSPORT_BRAND] === true;
31157
+ }
31143
31158
  var runExecutor = new AsyncLocalStorage();
31144
31159
  var defaultExecutor;
31145
31160
  function setDefaultGogExecutor(executor) {
@@ -31320,7 +31335,11 @@ async function run(args, options = {}) {
31320
31335
  }
31321
31336
  return redact(output);
31322
31337
  } catch (err) {
31323
- throw new Error(redact(err instanceof Error ? err.message : String(err)));
31338
+ const message = redact(err instanceof Error ? err.message : String(err));
31339
+ if (isRunnerTransportError(err)) {
31340
+ throw new RunnerTransportError(message, err.kind, err.status);
31341
+ }
31342
+ throw new Error(message);
31324
31343
  }
31325
31344
  }
31326
31345
  async function runBinary(args, options = {}) {
@@ -31589,7 +31608,7 @@ function registerRunTool(server, options) {
31589
31608
  function errorText(err) {
31590
31609
  return err instanceof Error ? `Error: ${err.message}` : String(err);
31591
31610
  }
31592
- var DEFINITE_AUTH_PATTERN = /\b(401|unauthorized|invalid_grant)\b/i;
31611
+ var DEFINITE_AUTH_PATTERN = /\b(?:unauthorized|invalid_grant)\b|\b(?:error|status|code|http|responded|response)["']?[\s:=(,]{0,4}401\b/i;
31593
31612
  var STALE_TOKEN_PATTERN = /\b(?:access[ _-]?)?token\b[^.;\n]{0,40}\b(?:has\s+)?(?:been\s+)?(?:expired|revoked)\b|\b(?:expired|revoked)\s+(?:access[ _-]?)?token\b/i;
31594
31613
  var AUTH_ERROR_PATTERN = new RegExp(`${DEFINITE_AUTH_PATTERN.source}|${STALE_TOKEN_PATTERN.source}`, "i");
31595
31614
  var INVALID_GRANT_PATTERN = /invalid_grant|token has been expired or revoked/i;
@@ -31599,6 +31618,14 @@ var AUTH_HINT = "\n\nAuthentication may have expired. Use gog_auth_add to re-aut
31599
31618
  var INVALID_GRANT_HINT = '\n\nThe stored refresh token was rejected (invalid_grant): it has expired or been revoked, so the whole account is signed out and re-authorization is required. The most common cause is the 7-day refresh-token limit Google applies to OAuth apps whose consent screen is still in "Testing" mode. Re-authorize with gog_auth_add (opens a browser) or gog_auth_add_url + gog_auth_add_complete (remote/headless). To stop this recurring, publish the OAuth consent screen to "In production" in the Google Cloud project that owns the OAuth client. Ask the user if they would like to re-authenticate.';
31600
31619
  var TRANSIENT_HINT = "\n\nThis error is often transient. Retry the same call before trying a different approach (do not fall back to smaller writes or row-by-row operations).";
31601
31620
  var GRID_LIMIT_HINT = "\n\nThe target range is outside the sheet's current grid. Add the missing rows or columns first with gog_sheets_insert (dimension: rows or cols), then retry the write.";
31621
+ var RUNNER_TRANSPORT_AUTH_HINT = "\n\nThis is the CONNECTOR's own transport auth failing, not your Google sign-in. The gog-runner backend rejected the bearer token this server sent, so the request never reached gog and no Google credential was checked \u2014 the Google account is not the problem and re-authorizing it cannot fix this. An operator must make the Worker secret GOG_RUNNER_KEY equal RUNNER_KEY on the Fly app (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY), then retry.";
31622
+ var RUNNER_TRANSPORT_HINTS = {
31623
+ "transport-auth": RUNNER_TRANSPORT_AUTH_HINT,
31624
+ // The request itself was malformed, so the runner will refuse it identically
31625
+ // every time. Nothing to advise beyond the message the runner already gave.
31626
+ "transport-request": "",
31627
+ "transport-retryable": TRANSIENT_HINT
31628
+ };
31602
31629
  function formatAccountList(raw) {
31603
31630
  try {
31604
31631
  const parsed = JSON.parse(raw);
@@ -31611,11 +31638,12 @@ function formatAccountList(raw) {
31611
31638
  }
31612
31639
  async function diagnose(err) {
31613
31640
  const errText = errorText(err);
31641
+ const transportHint = isRunnerTransportError(err) ? RUNNER_TRANSPORT_HINTS[err.kind] : void 0;
31614
31642
  const isInvalidGrant = INVALID_GRANT_PATTERN.test(errText);
31615
31643
  const isTransientError = !DEFINITE_AUTH_PATTERN.test(errText) && TRANSIENT_ERROR_PATTERN.test(errText);
31616
31644
  const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
31617
31645
  const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
31618
- const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
31646
+ const hint = transportHint ?? (isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "");
31619
31647
  try {
31620
31648
  const accounts = formatAccountList(await run(["auth", "list"]));
31621
31649
  return errorResult(`${errText}
@@ -33103,7 +33131,7 @@ function registerTasksTools(server) {
33103
33131
  }
33104
33132
 
33105
33133
  // src/server.ts
33106
- var VERSION = true ? "2.21.0" : "0.0.0";
33134
+ var VERSION = true ? "2.21.1" : "0.0.0";
33107
33135
  var BASE_TOOL_REGISTRARS = [
33108
33136
  registerApiTools,
33109
33137
  registerAuthTools,
@@ -33118,6 +33146,24 @@ var BASE_TOOL_REGISTRARS = [
33118
33146
  registerTasksTools
33119
33147
  ];
33120
33148
 
33149
+ // src/auth-log.ts
33150
+ var FAILURES = /* @__PURE__ */ new Set([
33151
+ "token.mint-failed",
33152
+ "grant.dead",
33153
+ "replay.failed",
33154
+ "runner.auth-failed"
33155
+ ]);
33156
+ var PREFIX = "gog-auth ";
33157
+ var TAG_CHARS = 12;
33158
+ function credentialTag(cacheKeyHash) {
33159
+ return cacheKeyHash.slice(0, TAG_CHARS);
33160
+ }
33161
+ function logAuthTransition(event, context) {
33162
+ const record2 = JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), event, ...context });
33163
+ const write = FAILURES.has(event) ? console.error : console.warn;
33164
+ write(PREFIX + redactSecrets2(record2));
33165
+ }
33166
+
33121
33167
  // src/google-token.ts
33122
33168
  var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
33123
33169
  var EXPIRY_MARGIN_MS = 12e4;
@@ -33143,22 +33189,73 @@ function makeAccessTokenSource(env) {
33143
33189
  );
33144
33190
  };
33145
33191
  }
33146
- return async () => {
33147
- const key = await cacheKey(refreshToken, clientId);
33148
- const hit = cache.get(key);
33149
- if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) return hit.accessToken;
33150
- let pending = inFlight.get(key);
33192
+ let keyPromise;
33193
+ const key = () => keyPromise ??= cacheKey(refreshToken, clientId);
33194
+ const logCacheHits = parseBoolEnv("GOG_AUTH_LOG_CACHE_HITS", { env });
33195
+ const read = async () => {
33196
+ const k = await key();
33197
+ const hit = cache.get(k);
33198
+ if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) {
33199
+ if (logCacheHits) logAuthTransition("token.cache-hit", { credential: credentialTag(k) });
33200
+ return hit.accessToken;
33201
+ }
33202
+ let pending = inFlight.get(k);
33151
33203
  if (!pending) {
33152
33204
  pending = exchange(refreshToken, clientId, clientSecret).then((minted2) => {
33153
- cache.set(key, minted2);
33205
+ cache.set(k, minted2);
33206
+ logAuthTransition("token.minted", {
33207
+ credential: credentialTag(k),
33208
+ reason: `valid for ${Math.round((minted2.expiresAt - Date.now()) / 1e3)}s`
33209
+ });
33154
33210
  return minted2;
33155
- }).finally(() => inFlight.delete(key));
33156
- inFlight.set(key, pending);
33211
+ }).catch((err) => {
33212
+ logAuthTransition(err.grantDead ? "grant.dead" : "token.mint-failed", {
33213
+ credential: credentialTag(k),
33214
+ reason: err.message
33215
+ });
33216
+ throw err;
33217
+ }).finally(() => inFlight.delete(k));
33218
+ inFlight.set(k, pending);
33157
33219
  }
33158
33220
  const minted = await pending;
33159
33221
  return minted.accessToken;
33160
33222
  };
33223
+ const invalidate = async (rejected) => {
33224
+ const k = await key();
33225
+ const hit = cache.get(k);
33226
+ if (!hit || hit.accessToken !== rejected) {
33227
+ logAuthTransition("token.evict-noop", {
33228
+ credential: credentialTag(k),
33229
+ reason: hit ? "a concurrent caller had already replaced this credential\u2019s token" : "no token was cached for this credential"
33230
+ });
33231
+ return false;
33232
+ }
33233
+ cache.delete(k);
33234
+ logAuthTransition("token.evicted", {
33235
+ credential: credentialTag(k),
33236
+ reason: "Google rejected this access token; the next read will mint a new one"
33237
+ });
33238
+ return true;
33239
+ };
33240
+ return Object.assign(read, {
33241
+ invalidate,
33242
+ credentialId: async () => credentialTag(await key())
33243
+ });
33161
33244
  }
33245
+ var TokenExchangeError = class extends Error {
33246
+ /**
33247
+ * The REFRESH token is dead (Google's `invalid_grant`), not merely the access
33248
+ * token. Carried as a flag rather than re-read from the message, because
33249
+ * inferring the author of a failure from prose several authors can produce is
33250
+ * precisely the mistake this branch exists to undo. `instanceof` is safe: the
33251
+ * class is thrown and caught inside this one module.
33252
+ */
33253
+ grantDead;
33254
+ constructor(message, grantDead) {
33255
+ super(message);
33256
+ this.grantDead = grantDead;
33257
+ }
33258
+ };
33162
33259
  async function exchange(refreshToken, clientId, clientSecret) {
33163
33260
  let res;
33164
33261
  try {
@@ -33173,23 +33270,29 @@ async function exchange(refreshToken, clientId, clientSecret) {
33173
33270
  }).toString()
33174
33271
  });
33175
33272
  } catch (err) {
33176
- throw new Error(
33177
- `the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`
33273
+ throw new TokenExchangeError(
33274
+ `the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`,
33275
+ false
33178
33276
  );
33179
33277
  }
33180
33278
  const body = await res.json().catch(() => ({}));
33181
33279
  if (!res.ok) {
33182
33280
  if (body.error === "invalid_grant") {
33183
- throw new Error(
33184
- 'the stored refresh token has expired or been revoked, so this account must be re-authorized (commonly the 7-day limit on OAuth consent screens still in "Testing" mode). Re-enrol with gog_auth_add_url + gog_auth_add_complete and store the new refresh token.'
33281
+ throw new TokenExchangeError(
33282
+ 'the stored refresh token was rejected (invalid_grant): it has expired or been revoked, so this account must be re-authorized (commonly the 7-day limit on OAuth consent screens still in "Testing" mode). Re-enrol with gog_auth_add_url + gog_auth_add_complete and store the new refresh token.',
33283
+ true
33185
33284
  );
33186
33285
  }
33187
- throw new Error(
33188
- `the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`
33286
+ throw new TokenExchangeError(
33287
+ `the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`,
33288
+ false
33189
33289
  );
33190
33290
  }
33191
33291
  if (!body.access_token) {
33192
- throw new Error("the access token could not be refreshed: Google returned no access_token");
33292
+ throw new TokenExchangeError(
33293
+ "the access token could not be refreshed: Google returned no access_token",
33294
+ false
33295
+ );
33193
33296
  }
33194
33297
  const expiresInMs = (body.expires_in ?? 3600) * 1e3;
33195
33298
  return { accessToken: body.access_token, expiresAt: Date.now() + expiresInMs };
@@ -33198,54 +33301,218 @@ async function exchange(refreshToken, clientId, clientSecret) {
33198
33301
  // src/connector-runtime.ts
33199
33302
  var DEFAULT_TIMEOUT_MS = 3e4;
33200
33303
  var DEADLINE_GRACE_MS = 5e3;
33304
+ var MIN_REPLAY_BUDGET_MS = 1e3;
33201
33305
  var RUNNER_GOG_FAILED = 422;
33202
33306
  var RUNNER_DRAINING = 503;
33307
+ var RUNNER_BAD_REQUEST = 400;
33308
+ var RUNNER_BAD_KEY = 401;
33309
+ var GogFailedError = class extends Error {
33310
+ /** gog's stderr alone, with no echoed argv mixed in. */
33311
+ stderr;
33312
+ constructor(message, stderr) {
33313
+ super(message);
33314
+ this.stderr = stderr;
33315
+ }
33316
+ };
33317
+ var GOOGLE_TOKEN_REJECTED_PATTERN = /Google API error \(401\b|invalid[ _]authentication[ _]credentials|\bACCESS_TOKEN_EXPIRED\b|\binvalid_token\b/i;
33318
+ var REFRESH_TOKEN_DEAD_PATTERN = /\binvalid_grant\b/i;
33319
+ var READ_ONLY_SUBCOMMANDS = /* @__PURE__ */ new Set([
33320
+ "cat",
33321
+ "describe",
33322
+ "get",
33323
+ "info",
33324
+ "list",
33325
+ "list-slides",
33326
+ "ls",
33327
+ "metadata",
33328
+ "read-slide",
33329
+ "search",
33330
+ "services",
33331
+ "status",
33332
+ "structure"
33333
+ ]);
33334
+ function gogTarget(args) {
33335
+ const words = args.filter((arg) => typeof arg === "string");
33336
+ let service;
33337
+ for (let i = 0; i < words.length; i += 1) {
33338
+ const word = words[i];
33339
+ if (word.startsWith("-")) {
33340
+ if (word === "--account") i += 1;
33341
+ continue;
33342
+ }
33343
+ if (service === void 0) {
33344
+ service = word;
33345
+ continue;
33346
+ }
33347
+ return { service, subcommand: word };
33348
+ }
33349
+ return { service };
33350
+ }
33351
+ async function remintAfterGoogleRejection(err, used, args, readAccessToken, deadlineAt) {
33352
+ if (!(err instanceof GogFailedError)) return void 0;
33353
+ const grantDead = REFRESH_TOKEN_DEAD_PATTERN.test(err.stderr);
33354
+ if (!grantDead && !GOOGLE_TOKEN_REJECTED_PATTERN.test(err.stderr)) return void 0;
33355
+ const { service, subcommand } = gogTarget(args);
33356
+ const credential = await readAccessToken?.credentialId?.();
33357
+ const where = { credential, service };
33358
+ if (grantDead) {
33359
+ logAuthTransition("grant.dead", {
33360
+ ...where,
33361
+ reason: "gog reported invalid_grant: the stored refresh token is dead, so no token can be minted and this account must be re-authorized"
33362
+ });
33363
+ return void 0;
33364
+ }
33365
+ if (!used) {
33366
+ logAuthTransition("replay.declined", {
33367
+ ...where,
33368
+ reason: "no access token was supplied with the call, so gog acted as the backend volume\u2019s own identity"
33369
+ });
33370
+ return void 0;
33371
+ }
33372
+ if (!readAccessToken?.invalidate) {
33373
+ logAuthTransition("replay.declined", {
33374
+ ...where,
33375
+ reason: "this token source cannot mint a replacement, so a replay would resend the rejected token"
33376
+ });
33377
+ return void 0;
33378
+ }
33379
+ const evicted = await readAccessToken.invalidate(used);
33380
+ if (subcommand === void 0 || !READ_ONLY_SUBCOMMANDS.has(subcommand)) {
33381
+ logAuthTransition("replay.declined", {
33382
+ ...where,
33383
+ reason: `not replayable: '${subcommand ?? "(none)"}' is not a known read-only subcommand and a write could double-apply`
33384
+ });
33385
+ return void 0;
33386
+ }
33387
+ if (!evicted) {
33388
+ logAuthTransition("replay.declined", {
33389
+ ...where,
33390
+ reason: "the rejected token was already superseded, so the cache holds the token a replay would send"
33391
+ });
33392
+ return void 0;
33393
+ }
33394
+ const fresh = await readAccessToken();
33395
+ if (!fresh) {
33396
+ logAuthTransition("replay.declined", {
33397
+ ...where,
33398
+ reason: "the token source produced no token after eviction; replaying without one would act as the backend"
33399
+ });
33400
+ return void 0;
33401
+ }
33402
+ const budgetMs = deadlineAt - Date.now();
33403
+ if (budgetMs < MIN_REPLAY_BUDGET_MS) {
33404
+ logAuthTransition("replay.declined", {
33405
+ ...where,
33406
+ reason: `only ${budgetMs}ms of the call\u2019s deadline remained, so a replay could only time out; the rejected token was evicted, so the next call mints a fresh one`
33407
+ });
33408
+ return void 0;
33409
+ }
33410
+ return { token: fresh, budgetMs, invalidate: readAccessToken.invalidate, ...where };
33411
+ }
33203
33412
  function makeFlyExecutor(endpoint, key, readAccessToken) {
33204
33413
  return async (args, opts) => {
33205
33414
  const deadlineMs = (opts?.timeout ?? DEFAULT_TIMEOUT_MS) + DEADLINE_GRACE_MS;
33206
33415
  const accessToken = await readAccessToken?.();
33207
- let res;
33416
+ const deadlineAt = Date.now() + deadlineMs;
33208
33417
  try {
33209
- res = await fetch(endpoint + "/run", {
33210
- method: "POST",
33211
- headers: {
33212
- Authorization: "Bearer " + key,
33213
- "Content-Type": "application/json"
33214
- },
33215
- body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
33216
- signal: AbortSignal.timeout(deadlineMs)
33217
- });
33418
+ return await attempt(endpoint, key, args, accessToken, deadlineMs);
33218
33419
  } catch (err) {
33219
- const name = err instanceof Error ? err.name : "";
33220
- if (name === "TimeoutError" || name === "AbortError") {
33221
- throw new Error(
33222
- `gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`
33223
- );
33420
+ const replay = await remintAfterGoogleRejection(
33421
+ err,
33422
+ accessToken,
33423
+ args,
33424
+ readAccessToken,
33425
+ deadlineAt
33426
+ );
33427
+ if (replay === void 0) throw err;
33428
+ const where = { credential: replay.credential, service: replay.service, endpoint };
33429
+ logAuthTransition("replay.attempted", {
33430
+ ...where,
33431
+ reason: "Google rejected the access token; replaying this read once with a freshly minted one"
33432
+ });
33433
+ try {
33434
+ const stdout = await attempt(endpoint, key, args, replay.token, replay.budgetMs);
33435
+ logAuthTransition("replay.succeeded", where);
33436
+ return stdout;
33437
+ } catch (replayErr) {
33438
+ logAuthTransition("replay.failed", { ...where, reason: String(replayErr) });
33439
+ if (replayErr instanceof GogFailedError && GOOGLE_TOKEN_REJECTED_PATTERN.test(replayErr.stderr)) {
33440
+ await replay.invalidate(replay.token);
33441
+ }
33442
+ throw replayErr;
33224
33443
  }
33225
- throw err;
33226
33444
  }
33227
- if (!res.ok) {
33228
- const body = await res.json().catch(() => null);
33229
- const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
33445
+ };
33446
+ }
33447
+ async function attempt(endpoint, key, args, accessToken, deadlineMs) {
33448
+ let res;
33449
+ try {
33450
+ res = await fetch(endpoint + "/run", {
33451
+ method: "POST",
33452
+ headers: {
33453
+ Authorization: "Bearer " + key,
33454
+ "Content-Type": "application/json"
33455
+ },
33456
+ body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
33457
+ signal: AbortSignal.timeout(deadlineMs)
33458
+ });
33459
+ } catch (err) {
33460
+ const name = err instanceof Error ? err.name : "";
33461
+ if (name === "TimeoutError" || name === "AbortError") {
33462
+ throw new RunnerTransportError(
33463
+ `gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`,
33464
+ "transport-retryable"
33465
+ );
33466
+ }
33467
+ throw err;
33468
+ }
33469
+ if (!res.ok) {
33470
+ const body = await res.json().catch(() => null);
33471
+ const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
33230
33472
  ${body.stderr}` : body.error : "";
33231
- if (res.status === RUNNER_GOG_FAILED) {
33232
- throw new Error(detail || "gog failed on the runner (no detail supplied)");
33233
- }
33234
- if (res.status === RUNNER_DRAINING || body?.retryable === true) {
33235
- throw new Error(
33236
- `gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`
33237
- );
33238
- }
33239
- if (detail) {
33240
- throw new Error(detail);
33241
- }
33242
- throw new Error(
33243
- `gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`
33473
+ if (res.status === RUNNER_GOG_FAILED) {
33474
+ throw new GogFailedError(
33475
+ detail || "gog failed on the runner (no detail supplied)",
33476
+ typeof body?.stderr === "string" ? body.stderr : ""
33244
33477
  );
33245
33478
  }
33246
- const { stdout } = await res.json();
33247
- return stdout;
33248
- };
33479
+ if (res.status === RUNNER_BAD_KEY) {
33480
+ logAuthTransition("runner.auth-failed", {
33481
+ service: gogTarget(args).service,
33482
+ endpoint,
33483
+ reason: "the gog-runner rejected the connector\u2019s bearer token, so gog never ran and no Google credential was read; GOG_RUNNER_KEY does not match the Fly app\u2019s RUNNER_KEY"
33484
+ });
33485
+ throw new RunnerTransportError(
33486
+ "gog-runner rejected the connector's bearer token, so the request never reached gog and no Google credential was involved. The Worker secret GOG_RUNNER_KEY no longer matches RUNNER_KEY on the Fly app; set them to the same value (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY) and retry.",
33487
+ "transport-auth",
33488
+ res.status
33489
+ );
33490
+ }
33491
+ if (res.status === RUNNER_BAD_REQUEST) {
33492
+ throw new RunnerTransportError(
33493
+ detail || "gog-runner rejected the request (no detail supplied)",
33494
+ "transport-request",
33495
+ res.status
33496
+ );
33497
+ }
33498
+ if (res.status === RUNNER_DRAINING || body?.retryable === true) {
33499
+ throw new RunnerTransportError(
33500
+ `gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`,
33501
+ "transport-retryable",
33502
+ res.status
33503
+ );
33504
+ }
33505
+ if (detail) {
33506
+ throw new Error(detail);
33507
+ }
33508
+ throw new RunnerTransportError(
33509
+ `gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`,
33510
+ "transport-retryable",
33511
+ res.status
33512
+ );
33513
+ }
33514
+ const { stdout } = await res.json();
33515
+ return stdout;
33249
33516
  }
33250
33517
 
33251
33518
  // src/remote-runner.ts