Skip to content

Commit 7f00d0e

Browse files
lidge-junjun
andauthored
fix(subagents): let encrypted-task recovery run before the synthesized native chain (#3240)
#3239 synthesized a DEFAULT_SUBAGENT_MODELS chain for an unreadable encrypted spawn when the operator configured none. That chain fires in the first fallback pass, before recoverEncryptedAgentTask, so with agentTaskRecovery enabled the spawn was rerouted to native gpt-5.5 and recovery was skipped along with its caller-auth, proxy-secret and token-validity gates. tests/agent-task-recovery-security.test.ts went 13/13 -> 2/13 on dev. Synthesize the chain only when recovery is not enabled. An operator who enabled recovery chose to decrypt and stay routed; a configured chain keeps its precedence either way. Regression: recovery enabled + no chain + nativeFallbackOnly -> no fallback (red without the guard); the 13 recovery security cases are green again. Co-authored-by: jun <[email protected]>
1 parent 744d12d commit 7f00d0e

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,15 @@ export function applySubagentModelFallback(
614614
: resolvedFallbackChain;
615615
// Native-only encrypted V2 tasks need a readable ChatGPT backend even when the
616616
// operator configured no fallback chain. Keep ordinary routed spawns unchanged.
617+
//
618+
// Not when encrypted-task recovery is enabled: that operator chose to decrypt the
619+
// assignment and stay on the routed model. The synthesized chain would reroute the
620+
// spawn to native in this first pass, before recovery runs, and recovery's own
621+
// caller-auth / proxy-secret / token-validity gates would never execute
622+
// (tests/agent-task-recovery-security.test.ts went 13/13 -> 2/13 when #3239 landed
623+
// without this guard). A configured chain keeps its existing precedence.
617624
const fallbackChain = configuredFallbackChain === null && nativeFallbackOnly
625+
&& config.agentTaskRecovery?.enabled !== true
618626
? normalizedChain(parsed.modelId, config, [], DEFAULT_SUBAGENT_MODELS)
619627
: configuredFallbackChain;
620628
if (!fallbackChain) return null;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,33 @@ describe("subagent model fallback chain", () => {
10791079
expect(parsed.modelId).toBe("gpt-5.5");
10801080
});
10811081

1082+
test("the synthesized native chain yields to enabled encrypted-task recovery", () => {
1083+
// With recovery on, the first fallback pass must leave the routed spawn alone so
1084+
// recoverEncryptedAgentTask runs (and its security gates fire); rerouting here
1085+
// would bypass them.
1086+
const config = cfg({
1087+
subagentModelFallback: undefined,
1088+
defaultProvider: "xai",
1089+
agentTaskRecovery: { enabled: true },
1090+
});
1091+
const parsed = {
1092+
modelId: "xai/grok-4.5",
1093+
options: {},
1094+
context: { messages: [] },
1095+
_rawBody: { model: "xai/grok-4.5" },
1096+
};
1097+
const result = applySubagentModelFallback(
1098+
parsed as never,
1099+
new Headers({ "x-openai-subagent": "collab_spawn" }),
1100+
config,
1101+
"pool-a",
1102+
Date.now(),
1103+
true,
1104+
);
1105+
expect(result).toBeNull();
1106+
expect(parsed.modelId).toBe("xai/grok-4.5");
1107+
});
1108+
10821109
test("applySubagentModelFallback is a no-op for main turns", () => {
10831110
updateAccountQuota("pool-a", 95);
10841111
const parsed = {

0 commit comments

Comments
 (0)