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(dedupe): continue hosted reviews after a missing submission (#2090)
Kyle Brown0fb953b0f542
diff --git a/sdk/typescript/docs/dedupe-records.md b/sdk/typescript/docs/dedupe-records.mdindex c04778475..df890c3a9 100644--- a/sdk/typescript/docs/dedupe-records.md+++ b/sdk/typescript/docs/dedupe-records.md@@ -190,7 +190,7 @@ For failure or an inconclusive review, send an explicit error:}```-The CLI never resubmits a review, including after this error. Invalid model+A host error ends the review without another submission. Invalid modelanswers, missing decisions, and host errors make the whole batch unresolved;previous successful reviews in that run do not become persistence decisions.The existing algorithm treats a validated `DISTINCT` as a nonmatch, when@@ -203,6 +203,20 @@ severity-based representative selection are reused. No local review checkpointsare read or written in records mode. Local saved-scan execution retains itsexisting tool-submission validation and workflow checkpoints.+### Continuing a review++A `review.run` request with `supportsContinuation: true` can receive the result+`{"status":"missing_submission"}`. Send this only after verifying that the+original turn completed without a pending decision or blocker. Keep that+review session open. The CLI then sends one `review.continue` request with a+fresh JSON-RPC ID and `params: {requestId, prompt}`. The request ID in the+parameters identifies the original review. Submit the prompt in the same+session and reply on the new JSON-RPC ID. The correction omits+`supportsContinuation`, so the host releases the session after that turn. A second missing submission ends+the review as unresolved. A pending tool call uses the original turn and+requires no correction. An uncertain outcome or explicit blocker follows the+existing error path. Hosts without continuation support can ignore the field.+## Final response and persistence```jsondiff --git a/sdk/typescript/src/deduplication/codex-review.ts b/sdk/typescript/src/deduplication/codex-review.tsindex 00ddd7bc9..1857d4c47 100644--- a/sdk/typescript/src/deduplication/codex-review.ts+++ b/sdk/typescript/src/deduplication/codex-review.ts@@ -41,6 +41,7 @@ import {import {reviewErrorInstructions,reviewSubmissionInstructions,+ missingSubmissionPrompt,sourceReviewInstructions,} from "./deduplication-prompts.js";import { retryDelay, waitForRetry } from "./retry.js";@@ -657,9 +658,7 @@ export class CodexReviewRunner {);if (turns === 1) {state.attempts++;- startTurn(- `Continue the original assigned review in this conversation. No submission was accepted.${validationFailure ? ` The last submission was rejected: ${validationFailure}` : ""} ${reviewSubmissionInstructions}`,- );+ startTurn(missingSubmissionPrompt(validationFailure));continue;}if (validationFailure) {diff --git a/sdk/typescript/src/deduplication/deduplication-prompts.ts b/sdk/typescript/src/deduplication/deduplication-prompts.tsindex fba0f5a13..3c496280b 100644--- a/sdk/typescript/src/deduplication/deduplication-prompts.ts+++ b/sdk/typescript/src/deduplication/deduplication-prompts.ts@@ -79,3 +79,7 @@ export function savedSourceContext(})),})}\nThe approved checkout can establish current source only for findings associated with approvedRepositoryId. A sourceSnapshot identifies the saved occurrence's repository, recorded revision, and working-tree snapshot digest; a revision can be a baseline for uncommitted changes, so preserve the supplied snapshot evidence. Missing sourceSnapshot means its saved source could not be established, not that the current checkout is its source. Current files do not establish another repository's or an earlier revision's code. Treat disjoint repository associations as separate source contexts: similar names, paths, or snippets do not prove a shared maintained control. Establish any common originating control from supplied source provenance before deciding SAME across those contexts; missing provenance is not evidence that they are the same repository. These associations do not authorize reading another checkout. Use supplied evidence and available revisions in approved checkouts, and report a required source-access blocker when it prevents a decision.\n\n`;}++export function missingSubmissionPrompt(validationFailure?: string): string {+ return `Continue the original assigned review in this conversation. No submission was accepted.${validationFailure ? ` The last submission was rejected: ${validationFailure}` : ""} ${reviewSubmissionInstructions}`;+}diff --git a/sdk/typescript/src/deduplication/records-protocol.ts b/sdk/typescript/src/deduplication/records-protocol.tsindex 746beefa3..9d7b5ccc2 100644--- a/sdk/typescript/src/deduplication/records-protocol.ts+++ b/sdk/typescript/src/deduplication/records-protocol.ts@@ -1,7 +1,14 @@+import { randomUUID } from "node:crypto";import type { Readable } from "node:stream";+import { z } from "zod";+import { missingSubmissionPrompt } from "./deduplication-prompts.js";import { runHostProtocol } from "../host-protocol.js";import { deduplicateRecords, type DeduplicateRecordsInput } from "./records.js";+const missingSubmission = z.strictObject({+ status: z.literal("missing_submission"),+});+export async function runRecordsProtocol(input: Readable,output: Parameters<typeof runHostProtocol>[1],@@ -17,7 +24,27 @@ export async function runRecordsProtocol(deduplicateRecords(params as DeduplicateRecordsInput, {signal,reviewRunner: {- run: (request) => execute(request.requestId, request),+ async run(request) {+ const first = await execute(request.requestId, {+ ...request,+ supportsContinuation: true,+ });+ if (!missingSubmission.safeParse(first).success) return first;+ const result = await execute(+ randomUUID(),+ {+ requestId: request.requestId,+ prompt: missingSubmissionPrompt(),+ },+ undefined,+ "review.continue",+ );+ if (missingSubmission.safeParse(result).success)+ throw new Error(+ "Review ended without a terminal submission after correction.",+ );+ return result;+ },},}),},diff --git a/sdk/typescript/src/host-protocol.ts b/sdk/typescript/src/host-protocol.tsindex 7c5162481..d08ebe3a1 100644--- a/sdk/typescript/src/host-protocol.ts+++ b/sdk/typescript/src/host-protocol.ts@@ -36,6 +36,7 @@ type Execute = (id: string,request: unknown,onProgress?: (event: unknown) => void,+ method?: string,) => Promise<unknown>;/** One bidirectional run, shared with dedupe. This transport never replays. */@@ -216,7 +217,7 @@ export async function runHostProtocol(void operation.run(run.data.params,- (id, params, onProgress) => {+ (id, params, onProgress, method = operation.requestMethod) => {if (terminalCode !== undefined || controller.signal.aborted)return Promise.reject(controller.signal.reason);if (pending)@@ -226,7 +227,7 @@ export async function runHostProtocol(void send({jsonrpc: "2.0",id,- method: operation.requestMethod,+ method,params,}).catch(outputError);});diff --git a/sdk/typescript/tests-ts/dedupe-records.test.ts b/sdk/typescript/tests-ts/dedupe-records.test.tsindex de8d6b661..eeb5f0758 100644--- a/sdk/typescript/tests-ts/dedupe-records.test.ts+++ b/sdk/typescript/tests-ts/dedupe-records.test.ts@@ -418,7 +418,10 @@ function fakeHost(write(chunk, _encoding, callback) {const message = JSON.parse(chunk.toString()) as Message;messages.push(message);- if (message.method === "review.run")+ if (+ message.method === "review.run" ||+ message.method === "review.continue"+ )queueMicrotask(() => onReview(message, send, stream));callback();},@@ -427,6 +430,39 @@ function fakeHost(}const run = { jsonrpc: "2.0", id: "run-1", method: "run", params: input() };+test.each([false, true])(+ "a confirmed missing submission gets one correction (missing again: %s)",+ async (missingAgain) => {+ let original!: Message;+ const host = fakeHost((message, send) => {+ if (message.method === "review.run") original = message;+ else {+ expect(message.id).not.toBe(original.id);+ expect(message.params.requestId).toBe(original.params.requestId);+ expect(message.params.prompt).toContain(+ "review_validator.submit_decisions",+ );+ }+ const result =+ message.method === "review.run" || missingAgain+ ? { status: "missing_submission" }+ : answer(original.params);+ send({ jsonrpc: "2.0", id: message.id, result });+ });+ const done = runRecordsProtocol(host.stream, host.output);+ host.send(run);+ expect(await done).toBe(missingAgain ? 1 : 0);+ const originals = host.messages.filter((m) => m.method === "review.run");+ const corrections = host.messages.filter(+ (m) => m.method === "review.continue",+ );+ expect(originals.length).toBeGreaterThan(0);+ expect(corrections.map((m) => m.params.requestId)).toEqual(+ originals.map((m) => m.params.requestId),+ );+ },+);+test("CLI records mode uses only the fake host, bypassing saved scans, persistence, auth, and updates", async () => {const host = fakeHost((message, send) => {expect(message.jsonrpc).toBe("2.0");