can1357/oh-my-pi · error · AIError.ProviderHttpError
V2 remote compaction failed (${response.status} ${response.s
Error message
V2 remote compaction failed (${response.status} ${response.statusText}) What it means
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.
Source
Thrown at packages/agent/src/compaction/compaction-v2-streaming.ts:378
return collectCompactionV2Events(eventStream, request);
}
const response = await fetchImpl(endpoint, {
method: "POST",
headers: buildCompactionV2Headers(model, apiKey, request, options.codexMetadata),
body: stringifyJson(body),
signal,
});
if (!response.ok) {
const cause = await captureOpenAIHttpError(response);
logger.warn("V2 remote compaction failed", {
endpoint,
status: response.status,
statusText: response.statusText,
errorText: cause.captured.bodyText ?? "",
});
throw new AIError.ProviderHttpError(
`V2 remote compaction failed (${response.status} ${response.statusText})`,
response.status,
{
headers: response.headers,
cause,
},
);
}
return collectCompactionV2Output(response, request);
}
function buildCompactionV2Headers(
model: Model,
apiKey: string,
request: CompactionV2Request,
codexMetadata?: OpenAICodexCompatibilityMetadata,
): Record<string, string> {View on GitHub (pinned to 9690622007)
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
Example fix
// before
await requestCompactionV2Streaming({ model, ... }); // throws on 429
// after
try {
await requestCompactionV2Streaming({ model, ... });
} catch (err) {
if (err instanceof AIError.ProviderHttpError && (err.status === 429 || err.status >= 500)) {
await Bun.sleep(backoff); // then retry
} else throw err;
} Defensive patterns
Strategy: retry
Validate before calling
// pre-check credentials cheaply
if (!process.env.AZURE_OPENAI_API_KEY && !process.env.OPENAI_API_KEY) {
throw new Error("No API key configured for compaction endpoint");
} Type guard
import { AIError } from "@mariozechner/pi-ai";
function isProviderHttpError(err: unknown): err is AIError.ProviderHttpError {
return err instanceof AIError.ProviderHttpError;
} Try / catch
try {
await requestCompactionV2Streaming({ model, ... });
} catch (err) {
if (isProviderHttpError(err) && (err.status === 429 || err.status >= 500)) {
await Bun.sleep(retryDelay);
return retryCompaction();
}
throw err; // 4xx: config/auth problem, do not retry blindly
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Model ${model.id} does not support V2 streaming compaction
- No response body for V2 compaction streaming
- V2 compaction stream closed before response.completed
- V2 compaction expected exactly one compaction output item, g
- formatCompactionV2Failure(event, type)
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/af62ee315dd5b291.
Report an issue: GitHub.