Skip to content

Commit 0909016

Browse files
fix(server): Codex discovery keeps main's spawn-based deadline
Drop the separate post-initialize discovery budget. It shortened discovery for anyone who had raised T3CODE_CODEX_PROBE_TIMEOUT_MS or a per-instance override; the 60s default alone covers a slow app-server start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7139fa1 commit 0909016

2 files changed

Lines changed: 4 additions & 34 deletions

File tree

‎apps/server/src/provider/CodexProvider.test.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,10 @@ import { assert, it } from "@effect/vitest";
22

33
import {
44
applyPreferredCodexDefaultModel,
5-
codexDiscoveryDeadlineMs,
65
codexRoutesSpendNativeQuota,
76
mapCodexModelCapabilities,
87
} from "./CodexProvider.ts";
98

10-
it("counts the Codex discovery budget from initialize, capped by the probe timeout (#27230)", () => {
11-
// [initialized after spawn, probe timeout, deadline after spawn]
12-
const cases = [
13-
[500, 60_000, 20_250],
14-
[25_000, 60_000, 44_750],
15-
[50_000, 60_000, 59_750],
16-
// A raised T3CODE_CODEX_PROBE_TIMEOUT_MS also extends discovery.
17-
[2_000, 90_000, 51_750],
18-
] as const;
19-
for (const [initializedAtMs, probeTimeoutMs, expected] of cases) {
20-
assert.strictEqual(codexDiscoveryDeadlineMs(0, initializedAtMs, probeTimeoutMs), expected);
21-
}
22-
});
23-
249
it("maps current Codex model capability fields", () => {
2510
const capabilities = mapCodexModelCapabilities({
2611
additionalSpeedTiers: [],

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ const CODEX_CATALOG_REFRESH_TIMEOUT_MS = 3_000;
125125
const CODEX_CONFIG_PROBE_TIMEOUT_MS = 3_000;
126126
const CODEX_CATALOG_REFRESH_POLL = "100 millis" as const;
127127
const CODEX_CLIENT_NAME = "T3 Code";
128-
// Old machines can take ~25s to start app-server and answer initialize.
128+
// Old machines can take ~25s to start app-server and answer initialize, before
129+
// account/models/skills discovery runs.
129130
export const CODEX_APP_SERVER_PROBE_TIMEOUT_MS = 60_000;
130-
// Account/models/skills requests after initialize can exceed the shared 10s probe budget.
131-
const CODEX_DISCOVERY_BUDGET_MS = 20_000;
132131
const CODEX_DISCOVERY_MARGIN_MS = 250;
133132
// `codex-cli 0.159.0`, `codex-cli 0.160.0-alpha.1` or the npm CLI's bare `0.1.4161006`.
134133
// Keep a prerelease suffix so compatibility stays unknown for it, as it does for `initialize`.
@@ -536,20 +535,6 @@ const readCodexModelsCacheFetchedAt = Effect.fn("readCodexModelsCacheFetchedAt")
536535
);
537536
});
538537

539-
// Discovery gets its own budget from `initialize`, so a slow start still lists models, and must
540-
// finish before the outer timeout can discard the account result. A raised probe timeout extends it.
541-
export const codexDiscoveryDeadlineMs = (
542-
spawnedAtMs: number,
543-
initializedAtMs: number,
544-
probeTimeoutMs: number,
545-
) =>
546-
Math.min(
547-
spawnedAtMs + probeTimeoutMs,
548-
initializedAtMs +
549-
CODEX_DISCOVERY_BUDGET_MS +
550-
Math.max(0, probeTimeoutMs - CODEX_APP_SERVER_PROBE_TIMEOUT_MS),
551-
) - CODEX_DISCOVERY_MARGIN_MS;
552-
553538
const withCodexDiscoveryDeadline = Effect.fnUntraced(function* <A, E, R>(
554539
effect: Effect.Effect<A, E, R>,
555540
deadlineMs: number,
@@ -714,7 +699,6 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
714699
}) {
715700
const spawnedAtMs = DateTime.toEpochMillis(yield* DateTime.now);
716701
const { client, initialize } = yield* withCodexAppServerClient(input);
717-
const initializedAtMs = DateTime.toEpochMillis(yield* DateTime.now);
718702

719703
const versionMatch = initialize.userAgent.match(/\/([^\s]+)/);
720704
const version = versionMatch ? versionMatch[1] : undefined;
@@ -729,7 +713,8 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
729713
} satisfies CodexAppServerProviderSnapshot;
730714
}
731715

732-
const deadlineMs = codexDiscoveryDeadlineMs(spawnedAtMs, initializedAtMs, input.probeTimeoutMs);
716+
// Optional discovery must finish before the outer timeout can discard the account result.
717+
const deadlineMs = spawnedAtMs + input.probeTimeoutMs - CODEX_DISCOVERY_MARGIN_MS;
733718
const [skillsResponse, models, { config, nativeUsage, rateLimits }] = yield* Effect.all(
734719
[
735720
withCodexDiscoveryDeadline(client.request("skills/list", { cwds: [input.cwd] }), deadlineMs),

0 commit comments

Comments
 (0)