Skip to content

Commit 9090c6c

Browse files
committed
fix(server): step a Codex turn down to an allowed mode when Supervised is forbidden
1 parent c9cbeae commit 9090c6c

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/RuntimePolicy.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ function makeThread(input: {
6565

6666
const grokInstanceId = ProviderInstanceId.make("grok");
6767
const antigravityInstanceId = ProviderInstanceId.make("antigravity");
68+
const managedCodexInstanceId = ProviderInstanceId.make("codex-managed");
6869
const supportedRuntimeModesByInstance = new Map<ProviderInstanceId, ReadonlyArray<RuntimeMode>>([
6970
[grokInstanceId, ["approval-required", "auto", "full-access"]],
7071
[antigravityInstanceId, ["approval-required", "auto-accept-edits", "full-access"]],
72+
[managedCodexInstanceId, ["auto-accept-edits", "auto"]],
7173
]);
7274
const providerInstanceFor = (instanceId: ProviderInstanceId) =>
7375
({
@@ -156,6 +158,24 @@ it.layer(layerTest)("RuntimePolicyV2", (it) => {
156158
assert.equal(yield* modeFor(providerInstanceId, "auto-accept-edits"), "auto-accept-edits");
157159
}),
158160
);
161+
162+
it.effect("steps down to the broadest mode Codex allows when it forbids Supervised", () =>
163+
Effect.gen(function* () {
164+
const policy = yield* RuntimePolicy.RuntimePolicyV2;
165+
const now = yield* DateTime.now;
166+
const modeFor = (runtimeMode: RuntimeMode) =>
167+
policy
168+
.resolve({
169+
thread: makeThread({ now, worktreePath: null, runtimeMode }),
170+
modelSelection: { instanceId: managedCodexInstanceId, model: "gpt-5.5" },
171+
})
172+
.pipe(Effect.map((resolved) => resolved.runtimeMode));
173+
174+
assert.equal(yield* modeFor("full-access"), "auto");
175+
assert.equal(yield* modeFor("auto-accept-edits"), "auto-accept-edits");
176+
assert.equal(yield* modeFor("approval-required"), "approval-required");
177+
}),
178+
);
159179
});
160180

161181
it.layer(

‎apps/server/src/orchestration-v2/RuntimePolicy.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,21 @@ function providerRuntimeMode(
9292
runtimeMode: RuntimeMode,
9393
supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined,
9494
): RuntimeMode {
95-
return supportedRuntimeModes === undefined ||
95+
if (
96+
supportedRuntimeModes === undefined ||
9697
supportedRuntimeModes.length === 0 ||
9798
supportedRuntimeModes.includes(runtimeMode)
98-
? runtimeMode
99-
: "approval-required";
99+
) {
100+
return runtimeMode;
101+
}
102+
if (supportedRuntimeModes.includes("approval-required")) return "approval-required";
103+
// Codex's managed requirements can forbid the read-only sandbox Supervised needs, so step down
104+
// to the broadest mode it still allows rather than one it will refuse to start.
105+
return (
106+
RuntimeMode.literals.findLast(
107+
(mode) => supportedRuntimeModes.includes(mode) && !isRuntimeModeAbove(mode, runtimeMode),
108+
) ?? runtimeMode
109+
);
100110
}
101111

102112
const refuseAboveCeiling = (

0 commit comments

Comments
 (0)