Skip to content

Commit 0178c46

Browse files
committed
test(windows): pin request catalog cache boundaries
1 parent 3fe385d commit 0178c46

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎docs-site/src/content/docs/guides/sub-agent-surface.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ separately by `ocx doctor`. `stale` clears only after every detected Codex app-s
260260
the final catalog write; it does not necessarily clear `unknown`.
261261

262262
On Windows, this advisory check uses asynchronous PowerShell/CIM discovery on the v2 request path.
263-
Concurrent cold checks share one in-flight discovery and successful results are cached briefly. A
263+
Concurrent cold checks share one in-flight discovery and results are cached briefly. A
264264
slow or failing CIM query can delay or suppress only OpenCodex-authored model guidance; it does not
265265
block the Bun event loop, `/healthz`, or unrelated proxy traffic. Explicit CLI/service lifecycle
266266
operations retain the synchronous, fail-closed process collector because they may signal processes.

‎src/codex/app-server-processes.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,12 @@ export async function collectCodexAppServerCatalogStateForRequest(
888888
return flight.promise;
889889
}
890890

891-
/** Test hook: drop the memoized catalog state. */
891+
/**
892+
* Drop memoized catalog state after a relevant catalog/cache write and before
893+
* the post-write state read. Advancing the generation prevents an older
894+
* in-flight Windows CIM refresh from publishing its pre-write result after the
895+
* write has completed.
896+
*/
892897
export function resetCodexAppServerCatalogStateCache(): void {
893898
catalogStateCache = null;
894899
requestCatalogStateGeneration += 1;

‎tests/codex-app-server-processes.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ describe("collectCodexAppServerCatalogState (#857)", () => {
159159
resetCodexAppServerCatalogStateCache();
160160
});
161161

162+
test("Windows request collection briefly caches failed CIM enumeration (#1852)", async () => {
163+
resetCodexAppServerCatalogStateCache();
164+
let calls = 0;
165+
let now = 1_000;
166+
const io = {
167+
platform: "win32" as const,
168+
now: () => now,
169+
listSnapshotsAsync: async () => {
170+
calls += 1;
171+
throw new Error("windows_enum_incomplete");
172+
},
173+
catalogMtimeMs: () => 1_000,
174+
};
175+
176+
await expect(collectCodexAppServerCatalogStateForRequest(io)).resolves.toMatchObject({
177+
state: "unknown",
178+
});
179+
now += 10;
180+
await expect(collectCodexAppServerCatalogStateForRequest(io)).resolves.toMatchObject({
181+
state: "unknown",
182+
});
183+
// Failure is advisory and fail-closed, but caching it briefly prevents a
184+
// broken CIM provider from spawning one PowerShell process per request.
185+
expect(calls).toBe(1);
186+
resetCodexAppServerCatalogStateCache();
187+
});
188+
162189
test("unrelated processes never enter the comparison", () => {
163190
const status = collectCodexAppServerCatalogState({
164191
listSnapshots: () => [

‎tests/multi-agent-compat.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe("multiAgentGuidanceText", () => {
129129

130130
for (const state of ["stale", "unknown"] as const) {
131131
const text = await multiAgentGuidanceText(parsed, options, {
132-
collectCatalogState: () => ({ state }),
132+
collectCatalogState: async () => ({ state }),
133133
});
134134
// #1395: withhold OpenCodex's disk-derived claims, but do not prohibit
135135
// options the active spawn_agent tool advertises — the global catalog

0 commit comments

Comments
 (0)