{"record":{"id":"af62ee315dd5b291","repo":"can1357/oh-my-pi","slug":"v2-remote-compaction-failed-response-status","errorCode":null,"errorMessage":"V2 remote compaction failed (${response.status} ${response.statusText})","messagePattern":"V2 remote compaction failed \\((.+?) (.+?)\\)","errorType":"http","errorClass":"AIError.ProviderHttpError","httpStatus":null,"severity":"error","filePath":"packages/agent/src/compaction/compaction-v2-streaming.ts","lineNumber":378,"sourceCode":"\t\treturn collectCompactionV2Events(eventStream, request);\n\t}\n\n\tconst response = await fetchImpl(endpoint, {\n\t\tmethod: \"POST\",\n\t\theaders: buildCompactionV2Headers(model, apiKey, request, options.codexMetadata),\n\t\tbody: stringifyJson(body),\n\t\tsignal,\n\t});\n\n\tif (!response.ok) {\n\t\tconst cause = await captureOpenAIHttpError(response);\n\t\tlogger.warn(\"V2 remote compaction failed\", {\n\t\t\tendpoint,\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\terrorText: cause.captured.bodyText ?? \"\",\n\t\t});\n\t\tthrow new AIError.ProviderHttpError(\n\t\t\t`V2 remote compaction failed (${response.status} ${response.statusText})`,\n\t\t\tresponse.status,\n\t\t\t{\n\t\t\t\theaders: response.headers,\n\t\t\t\tcause,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn collectCompactionV2Output(response, request);\n}\n\nfunction buildCompactionV2Headers(\n\tmodel: Model,\n\tapiKey: string,\n\trequest: CompactionV2Request,\n\tcodexMetadata?: OpenAICodexCompatibilityMetadata,\n): Record<string, string> {","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/agent/src/compaction/compaction-v2-streaming.ts#L360-L396","documentation":"The V2 remote compaction HTTP endpoint returned a non-success status; the code wraps it in AIError.ProviderHttpError with the status, statusText, response headers, and a cause carrying the captured error body. It surfaces server-side rejections (auth, rate limit, bad request, server error) from the compaction service.","triggerScenarios":"attemptCompactionV2Streaming's fetch to the compaction endpoint returns response.ok === false — e.g. 401 invalid API key, 404 wrong deployment/endpoint, 429 throttling, 5xx Azure/OpenAI outage; the error body is logged and attached as cause.","commonSituations":"Expired or missing Azure API key; deployment name not found at the configured base URL; quota/rate limits during heavy compaction; transient 5xx from OpenAI; proxy returning HTML error pages.","solutions":["Read err.status and the attached cause bodyText to identify the server-side reason (401/403 auth, 404 endpoint, 429 throttle, 5xx outage)","For 429 or 5xx, retry with backoff — requestCompactionV2Streaming already supports retryWait; increase wait or retry count","Fix credentials/endpoint for 401/403/404: correct API key, deployment name, and AZURE_OPENAI_BASE_URL","Check provider status pages before deeper debugging if status is 5xx"],"exampleFix":"// before\nawait requestCompactionV2Streaming({ model, ... }); // throws on 429\n// after\ntry {\n  await requestCompactionV2Streaming({ model, ... });\n} catch (err) {\n  if (err instanceof AIError.ProviderHttpError && (err.status === 429 || err.status >= 500)) {\n    await Bun.sleep(backoff); // then retry\n  } else throw err;\n}","handlingStrategy":"retry","validationCode":"// pre-check credentials cheaply\nif (!process.env.AZURE_OPENAI_API_KEY && !process.env.OPENAI_API_KEY) {\n  throw new Error(\"No API key configured for compaction endpoint\");\n}","typeGuard":"import { AIError } from \"@mariozechner/pi-ai\";\nfunction isProviderHttpError(err: unknown): err is AIError.ProviderHttpError {\n  return err instanceof AIError.ProviderHttpError;\n}","tryCatchPattern":"try {\n  await requestCompactionV2Streaming({ model, ... });\n} catch (err) {\n  if (isProviderHttpError(err) && (err.status === 429 || err.status >= 500)) {\n    await Bun.sleep(retryDelay);\n    return retryCompaction();\n  }\n  throw err; // 4xx: config/auth problem, do not retry blindly\n}","preventionTips":["Retry only 429/5xx with exponential backoff; surface 401/403/404 as config bugs","Read err.status and cause.bodyText before deciding the remediation","Monitor endpoint health/API version; rotate keys before expiry"],"tags":["http","network","compaction","azure","openai","retry"],"backgroundTag":"http-error-response","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}