@@ -126,6 +126,7 @@ import type { EffectiveSubagentRoster, SpawnAgentSurface } from "../../codex/cat
126126import { codexAuthContextLogLabel } from "../../codex/account-label" ;
127127
128128import {
129+ codexAccountGatedCanonicalWireModel ,
129130 decodeRequestErrorResponse ,
130131 handleResponses ,
131132 preAuthUpstreamHostCircuitKey ,
@@ -304,6 +305,7 @@ export async function handleResponsesCompact(
304305 return formatErrorResponse ( 404 , "invalid_request_error" , err instanceof Error ? err . message : String ( err ) ) ;
305306 }
306307 const selectedModelId = route . modelId ;
308+ const accountGatedCompactWireModel = codexAccountGatedCanonicalWireModel ( String ( raw . model ) ) ;
307309 logCtx . requestedModel = raw . model ;
308310 logCtx . model = selectedModelId ;
309311 logCtx . routeDecision = route . routeDecision ;
@@ -334,7 +336,7 @@ export async function handleResponsesCompact(
334336 // Native /responses/compact exists on the canonical ChatGPT backend and on the
335337 // official OpenAI API. Any other Responses-shaped gateway must take the routed
336338 // summarizer path below, or compaction fails against an endpoint it never had (#422).
337- if ( supportsNativeResponsesCompactEndpoint ( route . providerName , route . provider ) ) {
339+ if ( supportsNativeResponsesCompactEndpoint ( route . providerName , route . provider ) && ! accountGatedCompactWireModel ) {
338340 if ( req . signal . aborted ) {
339341 return formatErrorResponse ( 499 , "client_cancelled" , "Client cancelled compact request" ) ;
340342 }
@@ -666,7 +668,10 @@ export async function handleResponsesCompact(
666668 const inputItems = Array . isArray ( raw . input ) ? ( raw . input as unknown [ ] ) : [ ] ;
667669 const internalBody = {
668670 ...raw ,
669- stream : false ,
671+ // Canonical ChatGPT Responses rejects non-streaming turns. Daybreak cannot use the
672+ // native compact endpoint either, so run its synthetic compaction as SSE and collapse
673+ // the completed event back into the v1 compact JSON contract below.
674+ stream : accountGatedCompactWireModel ? true : false ,
670675 input : [ ...inputItems , { type : "compaction_trigger" } ] ,
671676 } ;
672677 const internalHeaders = new Headers ( { "content-type" : "application/json" } ) ;
@@ -682,10 +687,36 @@ export async function handleResponsesCompact(
682687 const response = await handleResponses ( internalReq , config , logCtx , { abortSignal : req . signal , turnAdmissionLease, ...( admission ? { admission } : { } ) } ) ;
683688 if ( ! response . ok ) return response ;
684689 let json : { output ?: unknown [ ] ; status ?: unknown ; error ?: unknown } ;
685- try {
686- json = await response . json ( ) as { output ?: unknown [ ] ; status ?: unknown ; error ?: unknown } ;
687- } catch {
688- return formatErrorResponse ( 502 , "server_error" , "compaction turn returned a non-JSON response" ) ;
690+ if ( response . headers . get ( "content-type" ) ?. includes ( "text/event-stream" ) ) {
691+ if ( ! response . body ) {
692+ return formatErrorResponse ( 502 , "server_error" , "compaction turn returned an empty event stream" ) ;
693+ }
694+ const terminal = { status : "incomplete" as "completed" | "failed" | "incomplete" } ;
695+ let completed : { id ?: unknown ; output ?: unknown ; status ?: unknown } | undefined ;
696+ await new Promise < void > ( resolve => {
697+ consumeForInspection (
698+ response . body ! ,
699+ status => { terminal . status = status ; } ,
700+ req . signal ,
701+ resolve ,
702+ undefined ,
703+ undefined ,
704+ value => { completed = value ; } ,
705+ ) ;
706+ } ) ;
707+ if ( req . signal . aborted ) {
708+ return formatErrorResponse ( 499 , "client_cancelled" , "Client cancelled compact request" ) ;
709+ }
710+ if ( terminal . status !== "completed" || ! completed ) {
711+ return formatErrorResponse ( 502 , "upstream_error" , `compaction turn did not complete (status: ${ terminal . status } )` ) ;
712+ }
713+ json = completed as { output ?: unknown [ ] ; status ?: unknown ; error ?: unknown } ;
714+ } else {
715+ try {
716+ json = await response . json ( ) as { output ?: unknown [ ] ; status ?: unknown ; error ?: unknown } ;
717+ } catch {
718+ return formatErrorResponse ( 502 , "server_error" , "compaction turn returned a non-JSON response" ) ;
719+ }
689720 }
690721 // The internal turn answers 200 even when it failed or was truncated, so the body
691722 // has to be inspected. Reporting a failure beats installing "(no summary
@@ -714,6 +745,13 @@ export async function handleResponsesCompact(
714745 `compaction turn produced ${ compactionItems . length } compaction items, expected exactly 1` ,
715746 ) ;
716747 }
748+ // The canonical Responses stream returns a real OpenAI-encrypted compaction item. OCX cannot
749+ // and should not decrypt it; /responses/compact callers can consume that item directly.
750+ if ( accountGatedCompactWireModel ) {
751+ return new Response ( JSON . stringify ( { output : compactionItems } ) , {
752+ headers : { "Content-Type" : "application/json" } ,
753+ } ) ;
754+ }
717755 const encrypted = compactionItems [ 0 ] ! . encrypted_content ;
718756 const decoded = typeof encrypted === "string" ? decodeCompactionSummary ( encrypted ) : null ;
719757 // An empty `ocx1:` envelope decodes to "" rather than null, so length is what matters.
0 commit comments