jackwener/OpenCLI · error · CommandExecutionError

Unexpected Grok probe: ${JSON.stringify(result)}

Error message

Unexpected Grok probe: ${JSON.stringify(result)}

What it means

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.

Source

Thrown at clis/grok/auth.js:35

      const res = await fetch('/api/auth/session', { credentials: 'include', headers: { 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Grok /api/auth/session HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      const user = d && d.user;
      if (!user || !user.id) {
        return { kind: 'auth', detail: 'Grok /api/auth/session has no user — anonymous' };
      }
      return { ok: true, user_id: String(user.id), name: String(user.name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('grok.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/auth/session`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Grok whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, name: result.name };
}

registerSiteAuthCommands({
  site: 'grok',
  domain: 'grok.com',
  loginUrl: 'https://grok.com/auth/sign-in',
  columns: ['user_id', 'name'],
  quickCheck: hasGrokSessionCookie,
  verify: verifyGrokIdentity,
  poll: async (page) => {
    if (!await hasGrokSessionCookie(page)) {
      throw new AuthRequiredError('grok.com', 'Waiting for Grok session cookie');
    }
    return verifyGrokIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the JSON in the message to see what the probe actually returned
  2. Verify your @jackwener/opencli and browser-driver versions match (evaluate returning undefined is a driver issue) — upgrade both together
  3. Re-login to grok.com and retry, ruling out corrupted session state
  4. If Grok changed its API, update the probe in clis/grok/auth.js to map the new response shape

Example fix

// before
if (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);
// after
if (!result || typeof result !== 'object') throw new CommandExecutionError(`Grok probe returned non-object: ${JSON.stringify(result)}`);
if (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof page.evaluate !== 'function') throw new Error('Incompatible page/driver: page.evaluate missing');

Type guard

function isGrokProbeOk(r) {
  return typeof r === 'object' && r !== null && r.ok === true && typeof r.user_id === 'string';
}

Try / catch

try {
  const who = await verifyGrokIdentity(page);
  if (!isGrokProbeOk(who)) throw new Error('Verify returned malformed user record');
} catch (e) {
  if (String(e.message).startsWith('Unexpected Grok probe:')) {
    console.error('Probe contract broken — check opencli/browser driver versions:', e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/470adcfa033972d9. Report an issue: GitHub.