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
- 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
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
- 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
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
- Grok whoami failed: ${result.detail}
- Booking.com extractor returned an invalid status
- Ctrip cruise DOM extraction returned malformed rows
- ${context} returned malformed browser output.
- Unexpected Gitee probe: ${JSON.stringify(probe)}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/470adcfa033972d9.
Report an issue: GitHub.