feat(ai): implemented environment override for codex websockets

- Added getCodexWebSocketEnvValue to evaluate the PI_CODEX_WEBSOCKET environment flag.
- Updated shouldUseCodexWebSocket and getOpenAICodexTransportDetails to prioritize environment settings over model and session-level preferences.
- Configured logic to treat negative preference overrides as authoritative to explicitly disable websocket usage.
This commit is contained in:
can1357
2026-06-29 08:05:02 +02:00
parent ba2add1374
commit 3fc3977eae
@@ -2151,14 +2151,29 @@ function recordCodexWebSocketFailure(state: CodexWebSocketSessionState, activate
}
}
function getCodexWebSocketEnvValue(): boolean | undefined {
const envVal = $env.PI_CODEX_WEBSOCKET;
if (envVal !== undefined) {
return $flag("PI_CODEX_WEBSOCKET");
}
return undefined;
}
function shouldUseCodexWebSocket(
model: Model<"openai-codex-responses">,
state: CodexWebSocketSessionState | undefined,
preferWebsockets?: boolean,
): boolean {
// Explicitly disabled by the model or session state.
if (model.preferWebsockets === false) return false;
// Explicitly disabled by the session state.
if (!state || state.disableWebsocket) return false;
// Env val > Preference
const envVal = getCodexWebSocketEnvValue();
if (envVal !== undefined) return envVal;
// Negative preference overrides model preference; otherwise use the model's preference.
if (preferWebsockets === false) return false;
return $flag("PI_CODEX_WEBSOCKET") || preferWebsockets === true || model.preferWebsockets === true;
return true;
}
export interface OpenAICodexTransportDetails {
@@ -2214,10 +2229,13 @@ export function getOpenAICodexTransportDetails(
providerSessionState?: Map<string, ProviderSessionState>;
},
): OpenAICodexTransportDetails {
const envVal = getCodexWebSocketEnvValue();
const websocketPreferred =
options?.preferWebsockets === false
? false
: $flag("PI_CODEX_WEBSOCKET") || options?.preferWebsockets === true || model.preferWebsockets === true;
envVal !== undefined
? envVal
: options?.preferWebsockets === false
? false
: options?.preferWebsockets === true || model.preferWebsockets === true;
const state = getCodexWebSocketStateForPublicSession(model, options);
return {