can1357/oh-my-pi · error
V2 compaction expected exactly one compaction output item…
Error message
V2 compaction expected exactly one compaction output item, got ${state.compactionItems.length} from ${state.outputItemCount} output items What it means
After the stream completes, finishCompactionV2Collection expects exactly one compaction-type output item among the response's output items; any other count means the server produced malformed or unexpected compaction output. The error reports how many compaction items were found and the total number of output items seen.
Solutions
- Verify the endpoint is the dedicated compaction endpoint (correct base URL + compaction route/deployment), not a generic Responses endpoint
- Log state.outputItemCount and event types to see what the server actually returned; compare against the expected compaction event schema
- Pin/align the Azure OpenAI API version and deployment used for compaction after provider updates
- Retry once in case of a transient server anomaly, then fall back to local compaction if it reproduces
Example fix
// before endpoint: "https://res.openai.azure.com/openai/v1/responses" // generic endpoint // after endpoint: getCompactionV2Endpoint(model) // compaction-specific endpoint/deployment
Defensive patterns
Strategy: validation
Validate before calling
// verify you target the compaction endpoint, not a generic Responses endpoint
const endpoint = getCompactionV2Endpoint(model);
if (!endpoint || !endpoint.includes("compaction")) {
console.warn("unexpected compaction endpoint:", endpoint);
} Try / catch
try {
return await requestCompactionV2Streaming({ model, ... });
} catch (err) {
if (err instanceof Error && err.message.includes("exactly one compaction output item")) {
logServerEventsForDebugging(); // capture outputItemCount/types
return compactLocally(session); // deterministic fallback
}
throw err;
} Prevention
- Point at the dedicated compaction endpoint/deployment, never a generic Responses route
- Pin the provider API version and re-verify after upgrades
- Log SSE event types when counts deviate; fall back to local compaction
When it happens
Trigger: The V2 compaction endpoint returns a completed response whose output items contain zero or multiple compaction items — e.g. API behavior change, wrong endpoint/deployment returning normal model output instead of a compaction item, or event filtering dropping/duplicating compaction events.
Common situations: Pointing at a regular Responses endpoint instead of the compaction endpoint; provider API version drift changing output item types; proxy rewriting responses; bugs after upgrading the server-side compaction model/deployment.
Related errors
- formatCompactionV2Failure(event, type)
- Model does not support V2 streaming compaction
- OpenAI Responses compaction input contains a non-object item
- V2 remote compaction failed
- Already compacted
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e94c8e29731b5be3.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/compaction/compaction-v2-streaming.ts:532
}
}
dispatch();
} finally {
reader.releaseLock();
}
return finishCompactionV2Collection(state, request);
}
function finishCompactionV2Collection(
state: CompactionV2CollectionState,
request: CompactionV2Request,
): CompactionV2Response {
if (!state.sawCompleted) {
throw new Error("V2 compaction stream closed before response.completed");
}
if (state.compactionItems.length !== 1) {
throw new Error(
`V2 compaction expected exactly one compaction output item, got ${state.compactionItems.length} from ${state.outputItemCount} output items`,
);
}
const compactionItem = state.compactionItems[0];
const { replacementHistory, retainedImageCount } = buildCompactionV2ReplacementHistory(
request.input,
compactionItem,
request.retainedMessageBudget,
);
return {
compactionItem,
replacementHistory,
usedTokens: state.usage?.inputTokens ?? 0,
usage: state.usage,
retainedImageCount,
};
}View on GitHub (pinned to 9690622007)