{"record":{"id":"fdf972e1b6a0b9df","repo":"eyaltoledano/claude-task-master","slug":"grok-cli-execution-failed-error-as-error-mess","errorCode":null,"errorMessage":"Grok CLI execution failed: ${(error as Error).message}","messagePattern":"Grok CLI execution failed: (.+?)","errorType":"exception","errorClass":"APICallError","httpStatus":null,"severity":"error","filePath":"packages/ai-sdk-provider-grok-cli/src/grok-cli-language-model.ts","lineNumber":386,"sourceCode":"\t\t\t\t},\n\t\t\t\tproviderMetadata: {\n\t\t\t\t\t'grok-cli': {\n\t\t\t\t\t\texitCode: result.exitCode,\n\t\t\t\t\t\t...(result.stderr && { stderr: result.stderr })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t} catch (error) {\n\t\t\t// Re-throw our custom errors\n\t\t\tif (\n\t\t\t\t(error as any).name === 'APICallError' ||\n\t\t\t\t(error as any).name === 'LoadAPIKeyError'\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// Wrap other errors\n\t\t\tthrow createAPICallError({\n\t\t\t\tmessage: `Grok CLI execution failed: ${(error as Error).message}`,\n\t\t\t\tcode: (error as any).code,\n\t\t\t\tpromptExcerpt: prompt.substring(0, 200),\n\t\t\t\tisRetryable: false\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Stream text using Grok CLI\n\t * Note: Grok CLI doesn't natively support streaming, so this simulates streaming\n\t * by generating the full response and then streaming it in chunks\n\t */\n\tasync doStream(options: LanguageModelV2CallOptions) {\n\t\tconst prompt = createPromptFromMessages(options.prompt);\n\t\tconst warnings = this.generateAllWarnings(options, prompt);\n\n\t\tconst stream = new ReadableStream({","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/ai-sdk-provider-grok-cli/src/grok-cli-language-model.ts#L368-L404","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst result = await model.doGenerate({ prompt, abortSignal: undefined });\n// after\nconst controller = new AbortController();\nsetTimeout(() => controller.abort(), 60000);\nconst result = await model.doGenerate({ prompt, abortSignal: controller.signal });","handlingStrategy":"try-catch","validationCode":"import { execFile } from 'child_process';\nimport { promisify } from 'util';\nconst run = promisify(execFile);\nawait run('grok', ['--version']); // confirm binary exists immediately before doGenerate","typeGuard":"function isWrappedExecutionError(e) {\n  return e instanceof Error && e.message.startsWith('Grok CLI execution failed:');\n}","tryCatchPattern":"try {\n  const controller = new AbortController();\n  const timer = setTimeout(() => controller.abort(), 60000);\n  const result = await model.doGenerate({ prompt, abortSignal: controller.signal });\n  clearTimeout(timer);\n} catch (e) {\n  if (isWrappedExecutionError(e)) {\n    console.error('Underlying cause:', e.message, 'code:', e.code);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["grok-cli","unexpected-error","wrapper","subprocess"],"backgroundTag":"unexpected-execution-failure","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}