{"record":{"id":"470adcfa033972d9","repo":"jackwener/OpenCLI","slug":"unexpected-grok-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected Grok probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Grok probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/grok/auth.js","lineNumber":35,"sourceCode":"      const res = await fetch('/api/auth/session', { credentials: 'include', headers: { 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Grok /api/auth/session HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      const user = d && d.user;\n      if (!user || !user.id) {\n        return { kind: 'auth', detail: 'Grok /api/auth/session has no user — anonymous' };\n      }\n      return { ok: true, user_id: String(user.id), name: String(user.name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('grok.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/auth/session`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Grok whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'grok',\n  domain: 'grok.com',\n  loginUrl: 'https://grok.com/auth/sign-in',\n  columns: ['user_id', 'name'],\n  quickCheck: hasGrokSessionCookie,\n  verify: verifyGrokIdentity,\n  poll: async (page) => {\n    if (!await hasGrokSessionCookie(page)) {\n      throw new AuthRequiredError('grok.com', 'Waiting for Grok session cookie');\n    }\n    return verifyGrokIdentity(page);\n  },\n});\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/grok/auth.js#L17-L53","documentation":"verifyGrokIdentity's probe returned an object that matched none of the expected shapes (kind auth/http/exception, or ok:true). The library throws CommandExecutionError('Unexpected Grok probe: ...') with the raw result JSON-serialized, because a well-formed probe can only produce those four shapes — anything else means the automation bridge returned undefined/garbage.","triggerScenarios":"page.evaluate resolves to undefined/null/non-object (evaluate string not executed as an async IIFE, or the automation layer failed to serialize the return), or Grok's endpoint starts returning a new result shape not covered by the probe (auth.js:35).","commonSituations":"OpenCLI/browser-driver version mismatch where page.evaluate returns undefined for async expressions; a Grok front-end change altering the /api/auth/session response so the probe returns an unmapped kind; corrupted persistent session state.","solutions":["Check the JSON in the message to see what the probe actually returned","Verify your @jackwener/opencli and browser-driver versions match (evaluate returning undefined is a driver issue) — upgrade both together","Re-login to grok.com and retry, ruling out corrupted session state","If Grok changed its API, update the probe in clis/grok/auth.js to map the new response shape"],"exampleFix":"// before\nif (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);\n// after\nif (!result || typeof result !== 'object') throw new CommandExecutionError(`Grok probe returned non-object: ${JSON.stringify(result)}`);\nif (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);","handlingStrategy":"type-guard","validationCode":"if (typeof page.evaluate !== 'function') throw new Error('Incompatible page/driver: page.evaluate missing');","typeGuard":"function isGrokProbeOk(r) {\n  return typeof r === 'object' && r !== null && r.ok === true && typeof r.user_id === 'string';\n}","tryCatchPattern":"try {\n  const who = await verifyGrokIdentity(page);\n  if (!isGrokProbeOk(who)) throw new Error('Verify returned malformed user record');\n} catch (e) {\n  if (String(e.message).startsWith('Unexpected Grok probe:')) {\n    console.error('Probe contract broken — check opencli/browser driver versions:', e.message);\n  }\n  throw e;\n}","preventionTips":["Keep @jackwener/opencli and the browser automation driver on compatible versions","Log the raw result JSON from the error message before escalating","Re-login after Grok front-end deploys that may change /api/auth/session shape","Wrap verify calls in a check that the probe result object exists before trusting user_id/name"],"tags":["browser-automation","contract-violation","grok","whoami"],"backgroundTag":"unexpected-probe-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}