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(mcp): isolate optional Deep Scan logger failures (#1818)
Michael D'Angeloabed28879b62
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.tsindex 584bb3cf1..d09cfbd3e 100644--- a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts+++ b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts@@ -130,7 +130,13 @@ export class DeepScanCoordinator {constructor(private readonly options: CoordinatorOptions) {this.state = cloneState(options.run);this.clock = options.clock ?? systemClock;- this.log = options.log ?? (() => undefined);+ this.log = (event) => {+ try {+ void Promise.resolve(options.log?.(event)).catch(() => {});+ } catch {+ // Optional logging must not interrupt scan control flow.+ }+ };this.artifacts = createDeepScanArtifacts(this.state.scanDir);const workerOptions = {run: this.state,diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.tsnew file mode 100644index 000000000..0be35c79a--- /dev/null+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts@@ -0,0 +1,102 @@+import assert from "node:assert/strict";+import { setImmediate } from "node:timers/promises";+import { test } from "node:test";+import type { DeepScanLogEvent } from "../src/deep-scan/types.js";+import {+ coordinatorFixture,+ createCoordinator,+ FakeExecutor,+ runCoordinator,+ temporaryDirectories,+} from "./deep_scan_coordinator_fixture.ts";++try {+ for (const failure of ["throwing", "rejecting"] as const) {+ const fail = () => {+ const error = new Error("optional log sink unavailable");+ if (failure === "throwing") throw error;+ return Promise.reject(error);+ };++ await test(`a ${failure} logger does not stop discovery or reduction`, async () => {+ const { fixture, store } = await coordinatorFixture();+ const executor = new FakeExecutor({+ discoveryCandidateId: "candidate-1",+ });+ const events: DeepScanLogEvent[] = [];+ const terminal = await runCoordinator(fixture, store, executor, {+ log(event) {+ events.push(event);+ return fail();+ },+ });+ await setImmediate();+ assert.equal(terminal?.status, "succeeded", terminal?.error);+ assert.equal(executor.discoveryCalls, 1);+ assert.equal(executor.dedupCalls, 1);+ for (const event of [+ "coordinator_started",+ "discovery_accepted",+ "dedup_committed",+ "coordinator_terminal",+ ]) {+ assert.ok(events.some((entry) => entry.event === event));+ }+ });++ await test(`a ${failure} logger does not stop cancellation or cleanup`, async () => {+ const { fixture, store } = await coordinatorFixture();+ const gate = Promise.withResolvers<void>();+ const executor = new FakeExecutor({+ discoveryGates: { "discovery-0001": gate.promise },+ });+ let workerSignal: AbortSignal | undefined;+ const events: DeepScanLogEvent[] = [];+ const coordinator = createCoordinator(+ fixture,+ store,+ {+ run(request) {+ workerSignal = request.signal;+ return executor.run(request);+ },+ },+ {+ log(event) {+ events.push(event);+ if (+ event.event === "coordinator_cancel_requested" ||+ event.event === "coordinator_cleanup_settled"+ )+ return fail();+ },+ },+ );+ coordinator.start();+ await executor.discoveryStarted.promise;+ const reason = "fixture cancellation\nwith diagnostic detail";+ try {+ assert.doesNotThrow(() => coordinator.cancel(reason));+ assert.equal(workerSignal?.aborted, true);+ assert.equal(workerSignal?.reason, reason);+ } finally {+ gate.resolve();+ await coordinator.wait(undefined, 5_000);+ }+ await setImmediate();+ assert.equal(coordinator.snapshot().status, "canceled");+ assert.equal(executor.runningDiscovery, 0);+ assert.equal(executor.runningDedup, 0);+ assert.equal(+ events.find((entry) => entry.event === "coordinator_cancel_requested")+ ?.reason,+ reason,+ );+ assert.ok(+ events.some((entry) => entry.event === "coordinator_cleanup_settled"),+ );+ });+ }+} finally {+ await temporaryDirectories.cleanup();+}