Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(deep-scan): recheck empty targets before a resumed scan's first dispatch (#2346)

Hafiar93ec970f165a
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
index 8591439c0..93a3a71d6 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
@@ -1175,8 +1175,8 @@ function cloneState(state: DeepScanRunState): DeepScanRunState {
}
function isFreshRun(state: DeepScanRunState): boolean {
+ // A coordinator can persist the discovery phase before dispatching its first worker.
return (
- !state.discoveryStarted &&
state.dispatchedCount === 0 &&
!state.persistedWorkers?.some((worker) => worker.kind !== "setup") &&
(state.persistedDedupInputs?.length ?? 0) === 0
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_store_integration.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_store_integration.ts
index 3e491a909..62fabce4c 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_store_integration.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_store_integration.ts
@@ -51,8 +51,9 @@ export { recordCodexSecurityScanDraftViaWorkbench, saveScanDraftCheckpoint } fro
});
await testCanonicalParentCheckpointsSurviveSuccessiveWrites();
-await testJoiningCallerAdmission(false);
-await testJoiningCallerAdmission(true);
+await testJoiningCallerAdmission("fresh-empty");
+await testJoiningCallerAdmission("resumed-empty");
+await testJoiningCallerAdmission("resumed-with-source");
await testFreeformFailureMessagesAgainstRealWorkbench();
await testWorkerRetryThreadsRemainInScanUsage();
await testReducerCommitAndFinishAgainstRealWorkbench();
@@ -74,7 +75,9 @@ await testCoordinatorCommitResponseRecovery();
await testCoordinatorCommitResponseRecovery("record-deep-scan-iteration");
await testCoordinatorCommitResponseRecovery("finish-deep-scan");
-async function testJoiningCallerAdmission(afterDiscoveryProgress: boolean) {
+async function testJoiningCallerAdmission(
+ scenario: "fresh-empty" | "resumed-empty" | "resumed-with-source",
+) {
const { fixtureRoot, targetPath, environment } = await createWorkbenchFixture(
"deep-scan-joining-caller-",
);
@@ -91,24 +94,25 @@ async function testJoiningCallerAdmission(afterDiscoveryProgress: boolean) {
try {
const created = await owner.begin({ targetPath, threadId, scanRoot });
const lease = { scanId: created.scanId, threadId };
- // The joining caller sees the run before its owner starts discovery.
- // Admission must use the state returned by the later claim.
+ // Admission uses the later claim, even if the owner entered discovery before it expired.
+ const discoveryProgress = {
+ scanId: created.scanId,
+ phase: "discovery",
+ } as const;
const joined = await joiner.begin({ ...lease, scanRoot });
assert.equal(joined.discoveryStarted, false);
- if (afterDiscoveryProgress) {
+ if (scenario !== "fresh-empty") {
const claimed = await owner.claimCoordinator(lease);
assert.equal(claimed.acquired, true);
- await owner.updateProgress({
- scanId: created.scanId,
- phase: "discovery",
- });
+ await owner.updateProgress(discoveryProgress);
const observer = await joiner.claimCoordinator(lease);
assert.equal(observer.acquired, false);
assert.equal(observer.run.discoveryStarted, true);
assert.equal(observer.run.dispatchedCount, 0);
await expireLease(environment, created.scanId);
}
- await rm(path.join(targetPath, "fixture.py"));
+ if (scenario !== "resumed-with-source")
+ await rm(path.join(targetPath, "fixture.py"));
const { coordinator } = await startDeepScanEngine({
run: joined,
store: joiner,
@@ -120,32 +124,27 @@ async function testJoiningCallerAdmission(afterDiscoveryProgress: boolean) {
threadId,
});
try {
- if (afterDiscoveryProgress) {
- await Promise.race([
- executor.discoveryStarted.promise,
- coordinator
- .wait(undefined, 30_000)
- .then((run: { error?: string } | undefined) =>
- assert.fail(
- run?.error ?? "Adopted coordinator did not dispatch a worker",
- ),
- ),
- ]);
- const recovered = await joiner.get(created.scanId, threadId);
- assert.equal(recovered.coordinatorGeneration, 3);
- assert.ok(recovered.dispatchedCount > 0);
+ const terminal = await Promise.race([
+ executor.discoveryStarted.promise,
+ coordinator.wait(undefined, 30_000),
+ ]);
+ const persisted = await joiner.get(created.scanId, threadId);
+ if (scenario !== "fresh-empty")
+ assert.equal(persisted.coordinatorGeneration, 3);
+ if (scenario === "resumed-with-source") {
+ assert.ok(executor.discoveryCalls > 0, terminal?.error);
+ assert.ok(persisted.dispatchedCount > 0);
await assert.rejects(
- owner.updateProgress({ scanId: created.scanId, phase: "discovery" }),
+ owner.updateProgress(discoveryProgress),
/newer generation/,
);
} else {
- const terminal = await coordinator.wait(undefined, 30_000);
assert.equal(terminal?.status, "failed");
assert.match(terminal.error, /target is empty.*no security audit/iu);
assert.equal(executor.discoveryCalls, 0);
- const persisted = await owner.get(created.scanId, threadId);
assert.equal(persisted.status, "failed");
assert.deepEqual(persisted.persistedWorkers, []);
+ assert.equal(persisted.dispatchedCount, 0);
}
} finally {
coordinator.cancel("fixture cleanup");