From 61a483514a51728da28f887d3493e991c855d898 Mon Sep 17 00:00:00 2001 From: Egor Shatalov Date: Mon, 19 Oct 2026 02:36:03 +0300 Subject: [PATCH] fix(codex): every turn runs on the standard service tier Codex's model catalog can name a faster, pricier tier as a model's default; codex exec doesn't apply it today, but nothing guarantees that. Every turn now passes `-c service_tier=default`, codex's sentinel for standard routing, on both fresh and resumed turns. Co-Authored-By: Claude Opus 5.5 --- src/plugins/codex.ts | 7 +++++++ test/codex.test.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/codex.test.ts diff --git a/src/plugins/codex.ts b/src/plugins/codex.ts index 5af37c5..28ddf21 100644 --- a/src/plugins/codex.ts +++ b/src/plugins/codex.ts @@ -5,6 +5,12 @@ // The acknowledged bundle is read back from the JSONL stream when codex // echoes its configuration (session_configured / turn context events). // +// Service tier: `-c service_tier=default`, always. "default" is codex's +// sentinel for standard routing: the model catalog can name a faster, +// pricier tier as a model's default, and the sentinel keeps it from +// applying. The caller can't pick a tier; a turn never spends more quota +// than it would on the standard tier. +// // Posture: `--dangerously-bypass-approvals-and-sandbox` — codex's own // validated non-interactive full-access mode; no approval prompt exists in // exec mode with it. `--skip-git-repo-check` keeps non-repo cwds working. @@ -121,6 +127,7 @@ export const codexPlugin: Plugin = { "--json", "-m", ctx.model, "-c", `model_reasoning_effort=${ctx.effort}`, + "-c", "service_tier=default", "--dangerously-bypass-approvals-and-sandbox", "--skip-git-repo-check", "--output-last-message", lastMessageFile, diff --git a/test/codex.test.ts b/test/codex.test.ts new file mode 100644 index 0000000..3eac263 --- /dev/null +++ b/test/codex.test.ts @@ -0,0 +1,48 @@ +// test/codex.test.ts — codex launch argv, offline. The "harness" is a +// stand-in binary that exits at once; only the recorded spawn argv matters. + +import test from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { codexPlugin } from "../src/plugins/codex.ts"; +import type { LaunchContext } from "../src/plugins/types.ts"; + +const sessionDir = mkdtempSync(path.join(tmpdir(), "subturn-codex-session-")); + +test.after(() => rmSync(sessionDir, { recursive: true, force: true })); + +async function launchArgv(nativeSessionId?: string): Promise { + let argv: string[] = []; + const ctx: LaunchContext = { + binPath: process.execPath, + model: "some-model", + effort: "low", + prompt: "hi", + cwd: sessionDir, + sessionDir, + turn: nativeSessionId === undefined ? 1 : 2, + nativeSessionId, + deadlineMs: Date.now() + 30_000, + env: {}, + emit: (event) => { + if (event["type"] === "spawn") argv = event["argv"] as string[]; + }, + writeEvidence: () => {}, + onChildPid: () => {}, + onNativeSessionId: () => {}, + }; + await codexPlugin.launch(ctx); + return argv; +} + +const hasPair = (argv: string[], flag: string, value: string): boolean => + argv.some((a, i) => a === flag && argv[i + 1] === value); + +test("every codex turn pins the standard service tier", async () => { + for (const argv of [await launchArgv(), await launchArgv("some-session")]) { + assert.ok(hasPair(argv, "-c", "service_tier=default"), `argv: ${JSON.stringify(argv)}`); + } +});