{"record":{"id":"442eb31c6fdb1999","repo":"can1357/oh-my-pi","slug":"response-errormessage-auto-repair-completion-f","errorCode":null,"errorMessage":"response.errorMessage ?? \"auto-repair completion failed\"","messagePattern":"response\\.errorMessage \\?\\? \"auto-repair completion failed\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/edit/auto-repair.ts","lineNumber":328,"sourceCode":"\tconst timeout = AbortSignal.timeout(REPAIR_TIMEOUT_MS);\n\tconst signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;\n\tconst complete = async (builtPrompt: string): Promise<string> => {\n\t\tconst response = await retryTransientCompletion(\n\t\t\t() =>\n\t\t\t\tcompleteSimple(\n\t\t\t\t\tmodel,\n\t\t\t\t\t{ messages: [{ role: \"user\", content: builtPrompt, timestamp: Date.now() }] },\n\t\t\t\t\t{\n\t\t\t\t\t\tapiKey: registry.resolver(model, sessionId),\n\t\t\t\t\t\tmaxTokens: COMPLETION_MAX_TOKENS,\n\t\t\t\t\t\tdisableReasoning: true,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t{ signal },\n\t\t);\n\t\tif (response.stopReason === \"error\") {\n\t\t\tthrow new Error(response.errorMessage ?? \"auto-repair completion failed\");\n\t\t}\n\t\treturn response.content.map(block => (block.type === \"text\" ? block.text : \"\")).join(\"\");\n\t};\n\n\tconst repair = await repairParseRegression({ ...snapshot, next: current }, complete);\n\tif (!repair) return undefined;\n\n\tawait writethrough(snapshot.path, repair.content, options.signal, Bun.file(snapshot.path));\n\tinvalidateFsScanAfterWrite(snapshot.path);\n\tlogger.debug(\"Edit auto-repair applied\", {\n\t\tpath: snapshot.path,\n\t\tattempts: repair.attempts,\n\t\tregionLines: repair.region.bEnd - repair.region.bStart,\n\t});\n\tconst diffResult = generateDiffString(current, repair.content, undefined, { path: snapshot.path });\n\treturn { diff: diffResult.diff, model: `${model.provider}/${model.id}`, attempts: repair.attempts };\n}\n","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/edit/auto-repair.ts#L310-L346","documentation":"In auto-repair's `complete` callback, when the LLM completion call returns stopReason 'error', the raw provider error message is thrown (or a generic fallback if none). This aborts the parse-regression repair flow, which needs a model completion to synthesize a corrected patch.","triggerScenarios":"Calling complete (via repairParseRegression, invoked from the `candidate` path in auto-repair) when the underlying provider request fails: stopReason === 'error' with response.errorMessage set (e.g. rate limit, auth failure, context overflow) or undefined.","commonSituations":"API key expired/invalid during a long session; provider rate limits hit after a failed apply triggered repair; network outage; model returned an error stop reason due to oversized context after accumulating patch history.","solutions":["Check the underlying errorMessage (rate limit, auth, network) and fix that root cause first","Verify provider credentials/API key validity and billing status","Retry the apply/repair after backoff if the provider error is transient","Reduce context/prompt size if the error is context-overflow; or skip auto-repair and apply the patch manually"],"exampleFix":"// before\nconst repaired = await autoRepair(snapshot); // throws on provider error\n// after\nlet repaired;\ntry {\n\trepaired = await autoRepair(snapshot);\n} catch (err) {\n\tlogger.warn('auto-repair unavailable', { err });\n\trepaired = undefined; // fall back to surfacing the original parse error\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n\tconst repaired = await autoRepair(snapshot);\n} catch (err) {\n\tlogger.warn('auto-repair completion failed', { err });\n\t// fall back to reporting the original parse failure unrepaired\n}","preventionTips":["Check API key/billing health before long repair flows","Handle provider stopReason 'error' upstream and retry with backoff","Cap context growth so repair completions stay within limits"],"tags":["llm","auto-repair","provider-error","completion"],"backgroundTag":"llm-completion-error","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}