Skip to content

Commit 004f6a7

Browse files
test(server): cover the Codex discovery deadline counted from initialize
AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a6c7657 commit 004f6a7

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import { assert, it } from "@effect/vitest";
22

3-
import { applyPreferredCodexDefaultModel, mapCodexModelCapabilities } from "./CodexProvider.ts";
3+
import {
4+
applyPreferredCodexDefaultModel,
5+
codexDiscoveryDeadlineMs,
6+
mapCodexModelCapabilities,
7+
} from "./CodexProvider.ts";
8+
9+
it("counts the Codex discovery budget from initialize, capped by the probe timeout (#27230)", () => {
10+
// [initialized after spawn, deadline after spawn]
11+
const cases = [
12+
[500, 20_250],
13+
[25_000, 44_750],
14+
[50_000, 59_750],
15+
] as const;
16+
for (const [initializedAtMs, expected] of cases) {
17+
assert.strictEqual(codexDiscoveryDeadlineMs(0, initializedAtMs), expected);
18+
}
19+
});
420

521
it("maps current Codex model capability fields", () => {
622
const capabilities = mapCodexModelCapabilities({

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ const readCodexModelsCacheFetchedAt = Effect.fn("readCodexModelsCacheFetchedAt")
399399
);
400400
});
401401

402+
// Discovery gets its own budget from `initialize`, so a slow start still lists models, and must
403+
// finish before the outer timeout can discard the account result.
404+
export const codexDiscoveryDeadlineMs = (spawnedAtMs: number, initializedAtMs: number) =>
405+
Math.min(
406+
spawnedAtMs + CODEX_APP_SERVER_PROBE_TIMEOUT_MS,
407+
initializedAtMs + CODEX_DISCOVERY_BUDGET_MS,
408+
) - CODEX_DISCOVERY_MARGIN_MS;
409+
402410
const withCodexDiscoveryDeadline = Effect.fnUntraced(function* <A, E, R>(
403411
effect: Effect.Effect<A, E, R>,
404412
deadlineMs: number,
@@ -553,12 +561,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
553561
} satisfies CodexAppServerProviderSnapshot;
554562
}
555563

556-
// Optional discovery must finish before the outer timeout can discard the account result.
557-
const deadlineMs =
558-
Math.min(
559-
spawnedAtMs + CODEX_APP_SERVER_PROBE_TIMEOUT_MS,
560-
initializedAtMs + CODEX_DISCOVERY_BUDGET_MS,
561-
) - CODEX_DISCOVERY_MARGIN_MS;
564+
const deadlineMs = codexDiscoveryDeadlineMs(spawnedAtMs, initializedAtMs);
562565
const [skillsResponse, models, serviceTier, rateLimits] = yield* Effect.all(
563566
[
564567
withCodexDiscoveryDeadline(client.request("skills/list", { cwds: [input.cwd] }), deadlineMs),

0 commit comments

Comments
 (0)