eyaltoledano/claude-task-master · error · APICallError
Grok CLI execution failed: ${(error as Error).message}
Error message
Grok CLI execution failed: ${(error as Error).message} What it means
This is the catch-all wrapper in doGenerate: any error thrown while preparing or executing the Grok CLI call — unless it is already a provider error (LoadAPIKeyError etc.), which is rethrown as-is — is wrapped in an API-call error with the prefix 'Grok CLI execution failed:'. It indicates an unexpected exception (spawn failure, timeout, AbortError with different shape, unexpected runtime error) rather than a classified auth/exit-code failure.
Source
Thrown at packages/ai-sdk-provider-grok-cli/src/grok-cli-language-model.ts:386
},
providerMetadata: {
'grok-cli': {
exitCode: result.exitCode,
...(result.stderr && { stderr: result.stderr })
}
}
};
} catch (error) {
// Re-throw our custom errors
if (
(error as any).name === 'APICallError' ||
(error as any).name === 'LoadAPIKeyError'
) {
throw error;
}
// Wrap other errors
throw createAPICallError({
message: `Grok CLI execution failed: ${(error as Error).message}`,
code: (error as any).code,
promptExcerpt: prompt.substring(0, 200),
isRetryable: false
});
}
}
/**
* Stream text using Grok CLI
* Note: Grok CLI doesn't natively support streaming, so this simulates streaming
* by generating the full response and then streaming it in chunks
*/
async doStream(options: LanguageModelV2CallOptions) {
const prompt = createPromptFromMessages(options.prompt);
const warnings = this.generateAllWarnings(options, prompt);
const stream = new ReadableStream({View on GitHub (pinned to c0c98d367c)
Solutions
- Read the wrapped (error).message and code to find the original underlying cause.
- Re-run the installation/auth checks (errors 774/775) since race conditions can let the CLI vanish between check and execution.
- Handle abort/timeout explicitly in your caller and pass a proper AbortSignal so cancellations surface as abort errors, not this wrapper.
- Update both the provider package and grok-cli to latest versions to rule out compatibility bugs.
- If it persists, capture the promptExcerpt from the error and file/reproduce with a minimal prompt.
Example fix
// before
const result = await model.doGenerate({ prompt, abortSignal: undefined });
// after
const controller = new AbortController();
setTimeout(() => controller.abort(), 60000);
const result = await model.doGenerate({ prompt, abortSignal: controller.signal }); Defensive patterns
Strategy: try-catch
Validate before calling
import { execFile } from 'child_process';
import { promisify } from 'util';
const run = promisify(execFile);
await run('grok', ['--version']); // confirm binary exists immediately before doGenerate Type guard
function isWrappedExecutionError(e) {
return e instanceof Error && e.message.startsWith('Grok CLI execution failed:');
} Try / catch
try {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 60000);
const result = await model.doGenerate({ prompt, abortSignal: controller.signal });
clearTimeout(timer);
} catch (e) {
if (isWrappedExecutionError(e)) {
console.error('Underlying cause:', e.message, 'code:', e.code);
}
throw e;
} Prevention
- Always pass a proper AbortSignal with a timeout so hangs surface as cancellations.
- Re-verify CLI installation right before long-running generation jobs (avoid TOCTOU races).
- Keep Node and provider package versions compatible and current.
- Log the wrapped message and code to identify the true root cause quickly.
When it happens
Trigger: doGenerate throws an unclassified error during CLI setup/exec — e.g. child process spawn ENOENT racing the install check, timeout firing, abort signal with unusual reason type, or a bug in prompt/key preparation code.
Common situations: CLI binary removed between check and spawn; extremely long-running generations hitting timeouts; aborting requests in a way the wrapper doesn't recognize; filesystem/permission problems reading grok-cli config; Node version incompatibilities.
Related errors
- Grok CLI authentication failed: ${result.stderr}
- Grok CLI failed with exit code ${result.exitCode}: ${result.
- Command failed with exit code ${result.status}: ${errorOutpu
- UNEXPECTED_ERROR
- CORE_FUNCTION_ERROR
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/fdf972e1b6a0b9df.
Report an issue: GitHub.