Skip to content

Commit f1a3c28

Browse files
committed
fix encrypted V2 spawn fallback without configured chain
1 parent 7ac4c9f commit f1a3c28

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎src/codex/subagent-model-fallback.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { existsSync, readdirSync, readFileSync } from "node:fs";
99
import { join } from "node:path";
10-
import { hasOwnProvider } from "../config";
10+
import { DEFAULT_SUBAGENT_MODELS, hasOwnProvider } from "../config";
1111
import { isRateLimitOrQuotaFailureMessage } from "../lib/errors";
1212
import type { OcxParsedRequest, OcxConfig } from "../types";
1313
import { slugsEquivalent } from "../providers/slug-codec";
@@ -609,9 +609,14 @@ export function applySubagentModelFallback(
609609
resolvedFallbackChain?: readonly string[] | null,
610610
): { from?: string; to?: string; skipped?: string[] } | null {
611611
if (!isThreadSpawnRequest(headers)) return null;
612-
const fallbackChain = resolvedFallbackChain === undefined
612+
const configuredFallbackChain = resolvedFallbackChain === undefined
613613
? resolveSubagentFallbackChain(parsed, config)
614614
: resolvedFallbackChain;
615+
// Native-only encrypted V2 tasks need a readable ChatGPT backend even when the
616+
// operator configured no fallback chain. Keep ordinary routed spawns unchanged.
617+
const fallbackChain = configuredFallbackChain === null && nativeFallbackOnly
618+
? normalizedChain(parsed.modelId, config, [], DEFAULT_SUBAGENT_MODELS)
619+
: configuredFallbackChain;
615620
if (!fallbackChain) return null;
616621
const selection = selectAvailableSubagentModel(
617622
parsed.modelId,

‎tests/subagent-model-fallback.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,29 @@ describe("subagent model fallback chain", () => {
10561056
expect((parsed._rawBody as { model?: string }).model).toBe("alibaba-token-plan/qwen3.8-max");
10571057
});
10581058

1059+
test("encrypted routed spawn gets an automatic native fallback when none is configured", () => {
1060+
const config = cfg({
1061+
subagentModelFallback: undefined,
1062+
defaultProvider: "xai",
1063+
});
1064+
const parsed = {
1065+
modelId: "xai/grok-4.5",
1066+
options: {},
1067+
context: { messages: [] },
1068+
_rawBody: { model: "xai/grok-4.5" },
1069+
};
1070+
const result = applySubagentModelFallback(
1071+
parsed as never,
1072+
new Headers({ "x-openai-subagent": "collab_spawn" }),
1073+
config,
1074+
"pool-a",
1075+
Date.now(),
1076+
true,
1077+
);
1078+
expect(result?.to).toBe("gpt-5.5");
1079+
expect(parsed.modelId).toBe("gpt-5.5");
1080+
});
1081+
10591082
test("applySubagentModelFallback is a no-op for main turns", () => {
10601083
updateAccountQuota("pool-a", 95);
10611084
const parsed = {

0 commit comments

Comments
 (0)