can1357/oh-my-pi · error
formatCompactionV2Failure(event, type)
Error message
formatCompactionV2Failure(event, type)
What it means
The compaction stream delivered a response.failed or response.incomplete event; the library formats the failure details from the event (via formatCompactionV2Failure) and throws. This is the server explicitly reporting that the compaction response did not finish successfully, with the reason carried in the event payload.
Source
Thrown at packages/agent/src/compaction/compaction-v2-streaming.ts:589
): void {
const type = typeof event.type === "string" ? event.type : eventName;
if (type === "response.output_item.done") {
state.outputItemCount++;
const item = event.item;
if (isRecord(item) && item.type === "compaction") {
state.compactionItems.push(item);
}
return;
}
if (type === "response.completed" || type === "response.done") {
state.sawCompleted = true;
state.usage = parseCompactionV2Usage(event);
return;
}
if (type === "response.failed" || type === "response.incomplete") {
throw new Error(formatCompactionV2Failure(event, type));
}
}
function parseCompactionV2Usage(event: Record<string, unknown>): CompactionV2Usage | undefined {
const response = isRecord(event.response) ? event.response : undefined;
const usage = response && isRecord(response.usage) ? response.usage : undefined;
if (!usage) return undefined;
const inputTokens = numberField(usage, "input_tokens");
const outputTokens = numberField(usage, "output_tokens");
const totalTokens = numberField(usage, "total_tokens");
if (inputTokens === undefined || outputTokens === undefined || totalTokens === undefined) return undefined;
const inputDetails = isRecord(usage.input_tokens_details) ? usage.input_tokens_details : undefined;
const outputDetails = isRecord(usage.output_tokens_details) ? usage.output_tokens_details : undefined;
const cachedInputTokens = inputDetails ? numberField(inputDetails, "cached_tokens") : undefined;
const reasoningOutputTokens = outputDetails ? numberField(outputDetails, "reasoning_tokens") : undefined;
return {View on GitHub (pinned to 9690622007)
Solutions
- Read the formatted message for the failure reason/code (e.g. server_error vs incomplete due to max_output_tokens)
- For response.incomplete, reduce input size or raise output limits, then retry the compaction
- For server_error/5xx-style failures, retry with backoff (retryWait option in requestCompactionV2Streaming)
- For invalid_request errors, check API version and request fields (model id, instructions, tools) against the current compaction API
- Fall back to local compaction when remote compaction repeatedly fails
Example fix
// before
await requestCompactionV2Streaming({ model, ... }); // incomplete: max_output_tokens
// after
try {
await requestCompactionV2Streaming({ model, ... });
} catch (err) {
if (String(err.message).includes("incomplete")) {
await compactInSmallerChunks(session); // or fall back locally
} else throw err;
} Defensive patterns
Strategy: retry
Try / catch
try {
return await requestCompactionV2Streaming({ model, ... });
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes("response.failed") && /server_error|5\d\d/.test(msg)) {
await Bun.sleep(backoff);
return requestCompactionV2Streaming({ model, ... });
}
if (msg.includes("response.incomplete")) {
return compactLocally(session); // or shrink input and retry
}
throw err;
} Prevention
- Parse the formatted failure message for the provider error code before choosing retry vs fallback
- Keep input within context/output limits to avoid response.incomplete
- Retry only transient server errors; treat invalid_request as a config fix
When it happens
Trigger: OpenAI Responses-style compaction emits response.failed (e.g. server_error, invalid_request, context length issues) or response.incomplete (output truncated, e.g. max_output_tokens hit) during the SSE stream.
Common situations: Compaction request exceeding the model's output/context limits; transient provider outage reported as server_error; invalid request fields after API version changes; incomplete output when the compaction summary is too large for max_output_tokens.
Related errors
- Model ${model.id} does not support V2 streaming compaction
- V2 remote compaction failed (${response.status} ${response.s
- No response body for V2 compaction streaming
- V2 compaction stream closed before response.completed
- V2 compaction expected exactly one compaction output item, g
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/10a66f694c670070.
Report an issue: GitHub.