{"record":{"id":"1d0a3f3b10f340f1","repo":"can1357/oh-my-pi","slug":"response-errormessage-completion-request-f","errorCode":null,"errorMessage":"${response.errorMessage ?? \"completion() request failed.\"}","messagePattern":"\\$\\{response\\.errorMessage \\?\\? \"completion\\(\\) request failed\\.\"\\}","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/completion-bridge.ts","lineNumber":174,"sourceCode":"\t\tinstrumentedCompleteSimple(\n\t\t\tmodel,\n\t\t\t{\n\t\t\t\tsystemPrompt,\n\t\t\t\tmessages: [{ role: \"user\", content: [{ type: \"text\", text: prompt }], timestamp: Date.now() }],\n\t\t\t\ttools,\n\t\t\t},\n\t\t\t{\n\t\t\t\tapiKey: registry.resolver(model, options.session.getSessionId?.() ?? undefined),\n\t\t\t\tsignal: options.signal,\n\t\t\t\treasoning: reasoningForTier(finalTier, model),\n\t\t\t\ttoolChoice: schema ? { type: \"tool\", name: STRUCTURED_TOOL_NAME } : undefined,\n\t\t\t},\n\t\t\t{ telemetry, oneshotKind: \"eval_completion\" },\n\t\t),\n\t);\n\n\tif (response.stopReason === \"error\") {\n\t\tthrow new ToolError(response.errorMessage ?? \"completion() request failed.\");\n\t}\n\tif (response.stopReason === \"aborted\") {\n\t\tthrow new ToolError(\"completion() request aborted.\");\n\t}\n\n\tlet resultText: string;\n\tif (schema) {\n\t\tconst call = extractToolCall(response, STRUCTURED_TOOL_NAME);\n\t\tlet value: unknown;\n\t\tif (call) {\n\t\t\tvalue = call.arguments;\n\t\t} else {\n\t\t\tconst text = extractTextContent(response);\n\t\t\tif (!text) throw new ToolError(\"completion() returned no structured response.\");\n\t\t\ttry {\n\t\t\t\tvalue = parseJsonPayload(text);\n\t\t\t} catch {\n\t\t\t\tthrow new ToolError(\"completion() did not return a structured response matching the schema.\");","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/completion-bridge.ts#L156-L192","documentation":"The bridge performs a oneshot completion via `instrumentedCompleteSimple`. When the response's `stopReason` is \"error\", this ToolError surfaces the provider-reported `errorMessage` (or a generic fallback) to the eval cell. It wraps any upstream LLM request failure — auth rejection, rate limit, malformed request, provider outage, context overflow.","triggerScenarios":"`completion(prompt, ...)` sends a request and the provider responds with an error stop reason; `response.errorMessage` from the provider layer is non-null and is used verbatim as the thrown message.","commonSituations":"Expired/revoked API key (401); rate limiting (429) during parallel eval cells; prompt exceeding the model's context window; unsupported parameter combination (e.g. reasoning effort on a non-reasoning model — though the bridge clamps this); transient provider 5xx during a CI run.","solutions":["Read the surfaced provider message in the error text — it names the root cause (auth, quota, context length) and fix accordingly.","For 401/403: refresh or correct the provider credentials.","For 429: add retry/backoff or reduce concurrent eval cells.","For context-length errors: shorten the prompt or target a larger-context model/tier.","Retry the call if the message indicates a transient provider outage (5xx)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let out;\ntry {\n  out = await completion(prompt);\n} catch (e) {\n  const msg = String(e);\n  if (/429|rate limit/i.test(msg)) await Bun.sleep(2000), retry();\n  else if (/401|unauthorized/i.test(msg)) fixCredentials();\n  else throw e;\n}","preventionTips":["Add exponential backoff/retry for transient provider errors in eval helpers.","Throttle concurrent completion() calls to avoid rate limits.","Keep prompts well under the target model's context window.","Rotate/validate API keys before long eval runs."],"tags":["network","llm-provider","request-failed"],"backgroundTag":"llm-request-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}