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(deep-scan): recognize usage limits reported during compaction (#1844)
Lanre Shittu225110bf1ee4
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/errors.ts b/plugins/codex-security/mcp-app/src/deep-scan/errors.tsindex 98127bf34..02aae8ec5 100644--- a/plugins/codex-security/mcp-app/src/deep-scan/errors.ts+++ b/plugins/codex-security/mcp-app/src/deep-scan/errors.ts@@ -34,10 +34,11 @@ const USAGE_LIMIT_MESSAGES = new Set([// Codex exec exposes only text for failed turns. Match its native quota messages here.export function codexWorkerTurnError(message: string): Error {+ const reason = message.replace(/^Error running remote compact task: /, "");if (- USAGE_LIMIT_MESSAGES.has(message) ||- message.startsWith("You’ve hit your usage limit.") ||- message.startsWith("You’ve hit your usage limit for ")+ USAGE_LIMIT_MESSAGES.has(reason) ||+ reason.startsWith("You’ve hit your usage limit.") ||+ reason.startsWith("You’ve hit your usage limit for ")) {return new DeepScanNonRetryableError(message);}diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.tsindex 4e81cf42f..573f57ab4 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts@@ -114,6 +114,7 @@ function testUsageLimitClassification() {"You hit your spend cap set by the owner of your workspace. Ask an owner to increase your spend cap to continue.","You’ve hit your usage limit. Try again later.","You’ve hit your usage limit for the selected model. Switch to another model to continue.",+ "Error running remote compact task: You’ve hit your usage limit. Try again later.",]) {const error = codexWorkerTurnError(message);assert.ok(error instanceof DeepScanNonRetryableError);@@ -122,6 +123,7 @@ function testUsageLimitClassification() {for (const message of ["429 Too Many Requests","Command failed: Quota exceeded. Check your plan and billing details.",+ "Error running remote compact task: stream disconnected before completion: synthetic reset",]) {const error = codexWorkerTurnError(message);assert.equal(error.name, "Error");diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.tsindex abd1cb990..3db039286 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts@@ -3701,30 +3701,16 @@ async function withWorkerFixture<Result>(}async function testWorkerTerminalEvents() {- const fixture = await fakeCodexFixture();- const previousPath = process.env.CODEX_CLI_PATH;- const originalSpawn = childProcess.spawn;- childProcess.spawn = ((- command: string,- args: readonly string[] = [],- options: SpawnOptions = {},- ) =>- originalSpawn(- command,- command === process.execPath ||- command === path.toNamespacedPath(process.execPath)- ? [fixture.executablePath, ...args]- : args,- options,- )) as typeof childProcess.spawn;- syncBuiltinESMExports();- process.env.CODEX_CLI_PATH = process.execPath;- try {- const promptPath = path.join(fixture.root, "prompt.md");+ await withWorkerFixture(async (_fixture, promptPath, workingDirectory) => {const quotaMessage = "Quota exceeded. Check your plan and billing details.";+ const wrappedQuota = `Error running remote compact task: ${quotaMessage}`;+ const disconnect =+ "Error running remote compact task: stream disconnected before completion: stream closed before response.completed";for (const event of [undefined,{ type: "turn.failed", error: { message: quotaMessage } },+ { type: "turn.failed", error: { message: wrappedQuota } },+ { type: "turn.failed", error: { message: disconnect } },{ type: "turn.failed", error: { message: "429 Too Many Requests" } },{ type: "error", message: quotaMessage },{@@ -3740,19 +3726,14 @@ async function testWorkerTerminalEvents() {);for (const resumeThreadId of [undefined, "fixture-resumed-thread"]) {const onNonRetryableError = mock.fn();- const execution = new CodexSdkWorkerExecutor({- parentSandbox: trustedParentSandbox,- }).run({- kind: "discovery",- promptPath,- workingDirectory: fixture.root,- subagents: 0,+ const execution = runWorker(promptPath, workingDirectory, {resumeThreadId,- signal: new AbortController().signal,onNonRetryableError,});if (event?.type === "turn.failed") {- const isQuota = event.error.message === quotaMessage;+ const isQuota = [quotaMessage, wrappedQuota].includes(+ event.error.message,+ );await assert.rejects(execution, {name: isQuota ? "DeepScanNonRetryableError" : "Error",message: event.error.message,@@ -3761,7 +3742,7 @@ async function testWorkerTerminalEvents() {onNonRetryableError.mock.calls.map(({ arguments: [error] }) => error.message,),- isQuota ? [quotaMessage] : [],+ isQuota ? [event.error.message] : [],);continue;}@@ -3770,9 +3751,5 @@ async function testWorkerTerminalEvents() {assert.equal(result.threadId, resumeThreadId ?? "fixture-thread-id");}}- } finally {- childProcess.spawn = originalSpawn;- syncBuiltinESMExports();- restoreEnv("CODEX_CLI_PATH", previousPath);- }+ });}