@@ -54,6 +54,7 @@ const { countPermissionDeniedIssues, hasNumerousPermissionDeniedIssues, extractD
5454const { detectNonRetryableHarnessGuard, buildSoftTimeoutGuard, emitSoftTimeoutSignal, isAuthenticationFailedError } = require ( "./harness_retry_guard.cjs" ) ;
5555const { MODEL_NOT_SUPPORTED_PATTERN : INVALID_MODEL_ERROR_PATTERN } = require ( "./detect_agent_errors.cjs" ) ;
5656const { resolveRetryConfig } = require ( "./harness_retry_config.cjs" ) ;
57+ const { applyModelFallback, injectModelFlagAfterExec } = require ( "./model_fallback.cjs" ) ;
5758
5859// Pattern to detect OpenAI rate-limit errors.
5960// Matches the JSON error type field ("rate_limit_exceeded"), the HTTP status code
@@ -221,6 +222,16 @@ function injectJsonFlag(args) {
221222 return [ "exec" , "--json" , ...args . slice ( 1 ) ] ;
222223}
223224
225+ function getCodexModelEnvVar ( env = process . env ) {
226+ if ( "GH_AW_MODEL_DETECTION_CODEX" in env ) {
227+ return "GH_AW_MODEL_DETECTION_CODEX" ;
228+ }
229+ if ( "GH_AW_MODEL_AGENT_CODEX" in env ) {
230+ return "GH_AW_MODEL_AGENT_CODEX" ;
231+ }
232+ return "" ;
233+ }
234+
224235/**
225236 * Build child process environment for Codex execution.
226237 * Preserve API keys captured at harness startup, even if the parent environment
@@ -425,6 +436,10 @@ async function main() {
425436 process . exit ( 1 ) ;
426437 }
427438
439+ const codexModelEnvVar = getCodexModelEnvVar ( process . env ) ;
440+ const resolvedModel = codexModelEnvVar ? applyModelFallback ( process . env , codexModelEnvVar , log ) : "" ;
441+ resolvedArgs = injectModelFlagAfterExec ( resolvedArgs , resolvedModel ) ;
442+
428443 // Safe arg list for logging: when --prompt-file was present, the last element of
429444 // resolvedArgs is the resolved prompt content. Replace it with a placeholder so that
430445 // task instructions are never written to stderr or captured in agent logs.
@@ -641,6 +656,9 @@ if (typeof module !== "undefined" && module.exports) {
641656 hasNoopInSafeOutputs,
642657 hasExpectedSafeOutputs,
643658 resolveRetryConfig,
659+ applyModelFallback,
660+ injectModelFlagAfterExec,
661+ getCodexModelEnvVar,
644662 } ;
645663}
646664
0 commit comments