OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(sdk): keep scans running while Codex waits for the network (#2411)
Lanre Shittu7aa2cd139907
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.tsindex 9536d3cec..d40069ede 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -6234,8 +6234,9 @@ async function readCodexTurn(options: {throw new CodexSecurityError(message);}const reconnect = reconnectAttempt(message);- if (reconnect === null) throw new CodexSecurityError(message);- options.onReconnect?.(message, reconnect);+ if (reconnect !== null) options.onReconnect?.(message, reconnect);+ else if (!waitingForNetwork(message))+ throw new CodexSecurityError(message);}},});@@ -7059,6 +7060,13 @@ function reconnectAttempt(message: string): [number, number] | null {return attempt <= maxAttempts ? [attempt, maxAttempts] : null;}+// Codex keeps retrying a dropped connection without a retry count.+function waitingForNetwork(message: string): boolean {+ return /^Reconnecting(?:\.\.\.|…)[ \t]+waiting for network(?=[ \t(]|$)/u.test(+ message,+ );+}+function reconnectDetails(message: string): ScanReconnectDetails | undefined {const classification = classifyConnectionFailure(message);if (classification !== "rate_limited") {diff --git a/sdk/typescript/tests-ts/api-events.test.ts b/sdk/typescript/tests-ts/api-events.test.tsindex d286b7fb4..065b87a16 100644--- a/sdk/typescript/tests-ts/api-events.test.ts+++ b/sdk/typescript/tests-ts/api-events.test.ts@@ -781,10 +781,30 @@ describe("one-shot scan events", () => {});});+ test("continues while Codex waits for the network to reconnect", async () => {+ const scanDir = await copyCompletedScan(await temporaryDirectory());+ const onReconnect = mock();+ async function* events(): AsyncGenerator<ThreadEvent> {+ yield {+ type: "error",+ message:+ "Reconnecting... waiting for network (error sending request for url (https://api.example.test/v1/responses))",+ };+ yield { type: "error", message: "Reconnecting... waiting for network" };+ yield* completedEvents();+ }+ await runEvents(scanDir, events(), { onReconnect });+ expect(onReconnect).not.toHaveBeenCalled();+ });+test("keeps non-reconnect stream errors terminal", async () => {const scanDir = join(await temporaryDirectory(), "partial-scan");await mkdir(scanDir, { mode: 0o700 });- for (const message of ["stream disconnected", "Reconnecting... 6/5"]) {+ for (const message of [+ "stream disconnected",+ "Reconnecting... 6/5",+ "Reconnecting... waiting for networking",+ ]) {async function* failedEvents(): AsyncGenerator<ThreadEvent> {yield { type: "thread.started", thread_id: "thread-1" };yield { type: "turn.started" };