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: preserve complete scan failure diagnostics (#1884)

Michael D'Angelo2c35052cf54a
diff --git a/plugins/codex-security/mcp-app/server.ts b/plugins/codex-security/mcp-app/server.ts
index 1a7bb1d3f..c212a1b5c 100644
--- a/plugins/codex-security/mcp-app/server.ts
+++ b/plugins/codex-security/mcp-app/server.ts
@@ -362,7 +362,7 @@ const progressSchema = {
};
const failSchema = {
...continuationMutationClaimSchema,
- message: requiredText.max(2400),
+ message: requiredText,
scanId: z.string().uuid(),
};
const completeScanSchema = {
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 d09cfbd3e..234ad798a 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
@@ -27,12 +27,11 @@ import type {
DiscoveryOutcome,
} from "./worker-runner.js";
import {
- boundedDeepScanErrorPair,
confirmedOwnershipChange,
errorNameWithCode,
abortError,
errorMessage,
- boundedDeepScanErrorMessage,
+ deepScanErrorMessage,
DeepScanNonRetryableError,
} from "./errors.js";
import type {
@@ -434,7 +433,7 @@ export class DeepScanCoordinator {
error = this.abortController.signal.reason;
}
const message = errorMessage(error);
- const persistedMessage = boundedDeepScanErrorMessage(error);
+ const persistedMessage = deepScanErrorMessage(error);
if (!this.setupComplete) {
this.log({
event: "setup_failed",
@@ -519,16 +518,10 @@ export class DeepScanCoordinator {
try {
await this.options.onStopped(current);
} catch (error) {
- const publicationFailure = boundedDeepScanErrorMessage(
- `Saved result publication failed: ${boundedDeepScanErrorMessage(error)}`,
- );
+ const publicationFailure = `Saved result publication failed: ${deepScanErrorMessage(error)}`;
const originalFailure = current.error?.trim();
const diagnostic = originalFailure
- ? boundedDeepScanErrorPair(
- publicationFailure,
- "\nOriginal Deep Scan failure:\n",
- originalFailure,
- )
+ ? `${publicationFailure}\nOriginal Deep Scan failure:\n${originalFailure}`
: publicationFailure;
const localState = {
...this.state,
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/errors.ts b/plugins/codex-security/mcp-app/src/deep-scan/errors.ts
index 3af49bfc8..57317357f 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/errors.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/errors.ts
@@ -1,8 +1,5 @@
-import { createHash } from "node:crypto";
import type { DeepScanRunState } from "./types.js";
-const MAX_PERSISTED_ERROR_LENGTH = 2_400;
-
const STALE_COORDINATOR_GENERATION_MESSAGE =
"Deep Scan coordinator lease belongs to a newer generation.";
@@ -71,51 +68,13 @@ export function confirmedOwnershipChange(
}
}
-/** Keep SQLite's bounded diagnostic useful while the manifest retains the full error. */
-export function boundedDeepScanErrorMessage(error: unknown): string {
- return boundedDeepScanErrorText(
- deepScanErrorMessage(error),
- MAX_PERSISTED_ERROR_LENGTH,
- );
-}
-
-export function boundedDeepScanErrorPair(
- primary: unknown,
- separator: string,
- secondary: unknown,
-): string {
- const primaryMessage = deepScanErrorMessage(primary);
- const secondaryMessage = deepScanErrorMessage(secondary);
- const available = MAX_PERSISTED_ERROR_LENGTH - separator.length;
- const balancedBudget = Math.floor(available / 2);
- let primaryBudget = Math.min(primaryMessage.length, balancedBudget);
- const secondaryBudget = Math.min(
- secondaryMessage.length,
- available - primaryBudget,
- );
- primaryBudget = Math.min(primaryMessage.length, available - secondaryBudget);
- return [
- boundedDeepScanErrorText(primaryMessage, primaryBudget),
- separator,
- boundedDeepScanErrorText(secondaryMessage, secondaryBudget),
- ].join("");
-}
-
-function deepScanErrorMessage(error: unknown): string {
+export function deepScanErrorMessage(error: unknown): string {
return (
(error instanceof Error ? error.message : String(error)).trim() ||
"Codex Security Deep Scan failed."
);
}
-function boundedDeepScanErrorText(message: string, maxLength: number): string {
- if (message.length <= maxLength) return message;
- const digest = createHash("sha256").update(message).digest("hex");
- const suffix = `\n...[truncated; sha256:${digest}]`;
- if (suffix.length >= maxLength) return message.slice(0, maxLength);
- return `${message.slice(0, maxLength - suffix.length)}${suffix}`;
-}
-
export function isStaleCoordinatorGenerationError(error: unknown): boolean {
for (let current = error; current instanceof Error; current = current.cause) {
if (current.message.includes(STALE_COORDINATOR_GENERATION_MESSAGE))
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/store.ts b/plugins/codex-security/mcp-app/src/deep-scan/store.ts
index 9a0d27329..72beffb37 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/store.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/store.ts
@@ -7,7 +7,7 @@ import { parseDeepScan, parseWorker } from "./response.js";
export { parseDeepScan };
import {
- boundedDeepScanErrorMessage,
+ deepScanErrorMessage,
DeepScanNonRetryableError,
DeepScanOwnershipChangedError,
isStaleCoordinatorGenerationError,
@@ -66,7 +66,7 @@ class DeepScanPersistenceError extends Error {
const operation = args[0] ?? "unknown";
const scanId = argumentValue(args, "--scan-id");
const workerId = argumentValue(args, "--worker-id");
- const diagnostic = boundedDeepScanErrorMessage(error);
+ const diagnostic = deepScanErrorMessage(error);
super(
`Deep Scan persistence operation ${operation} failed after ${attempts} attempts` +
`${scanId ? ` for scan ${scanId}` : ""}` +
@@ -478,7 +478,7 @@ export class WorkbenchDeepScanStore {
signal: failure.signal,
killed: failure.killed,
timeoutMs: failure.timeoutMs,
- error: boundedDeepScanErrorMessage(error),
+ error: deepScanErrorMessage(error),
}),
);
throw failure;
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/worker-runner.ts b/plugins/codex-security/mcp-app/src/deep-scan/worker-runner.ts
index 4a36f4572..f0c106031 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/worker-runner.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/worker-runner.ts
@@ -14,7 +14,7 @@ import { archiveDirectory, writePrivateFile } from "./artifacts.js";
import type { DeepScanArtifacts } from "./artifacts.js";
import {
abortError,
- boundedDeepScanErrorMessage,
+ deepScanErrorMessage,
classifyCodexWorkerError as asError,
DeepScanNonRetryableError,
confirmedOwnershipChange,
@@ -470,7 +470,7 @@ export class DeepScanWorkerRunner {
const persistedFailure = await this.options.store.updateWorker({
...baseMutation,
status: replaceableFailureKind ? "canceled" : "failed",
- error: boundedDeepScanErrorMessage(
+ error: deepScanErrorMessage(
replaceableFailureKind
? new Error(
`${replaceableFailureKind}: ${normalized.message}`,
@@ -493,7 +493,7 @@ export class DeepScanWorkerRunner {
}
await this.options.store.updateWorker({
...baseMutation,
- error: boundedDeepScanErrorMessage(normalized),
+ error: deepScanErrorMessage(normalized),
});
if (
validationStarted &&
@@ -694,12 +694,7 @@ async function writeValidationRetryPrompt(input: {
failedAttempt: number;
error: Error;
}): Promise<string> {
- const maximumLength = 4_000;
- const trimmed = input.error.message.trim();
- const detail =
- trimmed.length <= maximumLength
- ? trimmed
- : `${trimmed.slice(0, maximumLength)}...[truncated]`;
+ const detail = input.error.message.trim();
const basePrompt = await fs.readFile(input.basePromptPath, "utf8");
const errorData = validationErrorData(input.error, detail);
const instructions =
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts b/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
index 48736a0b7..bf2d32a98 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
@@ -17,7 +17,7 @@ import { sourceReferences } from "./support/source-references.ts";
import { createTemporaryDirectories } from "./support/temporary-directories.ts";
import { once } from "node:events";
import assert from "node:assert/strict";
-import { createHash, randomUUID } from "node:crypto";
+import { randomUUID } from "node:crypto";
import { readFile, rename, rm, writeFile } from "node:fs/promises";
import path from "node:path";
import { importModule } from "./import-module.ts";
@@ -146,13 +146,6 @@ export class FakeStore {
}
async updateWorker(update: DeepScanWorkerMutation) {
- if (update.error) {
- assert.equal(
- update.error.length <= 2_400,
- true,
- "persisted worker errors must be bounded",
- );
- }
if (
update.kind === "discovery" &&
update.status === this.blockDiscoveryUpdate
@@ -353,7 +346,7 @@ export class FakeStore {
this.publicationFailureMessages.push(message);
const original = this.run.error?.trim();
this.run.error = original
- ? boundedFixtureErrorPair(message, original)
+ ? `${message}\nOriginal Deep Scan failure:\n${original}`
: message;
return structuredClone(this.run);
}
@@ -736,26 +729,6 @@ export const immediateClock: DeepScanClock = {
},
};
-function boundedFixtureErrorPair(primary: string, secondary: string) {
- const separator = "\nOriginal Deep Scan failure:\n";
- const available = 2_400 - separator.length;
- let primaryBudget = Math.min(primary.length, Math.floor(available / 2));
- const secondaryBudget = Math.min(secondary.length, available - primaryBudget);
- primaryBudget = Math.min(primary.length, available - secondaryBudget);
- return (
- boundedFixtureErrorText(primary, primaryBudget) +
- separator +
- boundedFixtureErrorText(secondary, secondaryBudget)
- );
-}
-
-function boundedFixtureErrorText(message: string, maximum: number) {
- if (message.length <= maximum) return message;
- const digest = createHash("sha256").update(message).digest("hex");
- const suffix = `\n...[truncated; sha256:${digest}]`;
- return message.slice(0, maximum - suffix.length) + suffix;
-}
-
export function createCoordinator(
fixture: Awaited<ReturnType<typeof fixtureRun>>,
store: FakeStore,
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
index dbc36a059..c5599f781 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
@@ -1148,7 +1148,7 @@ async function testCommittedReducerIsReconciledBeforeDiscoveryFailureManifest()
assert.equal(store.run.noNewStreak, 2);
}
-async function testLongWorkerErrorIsBoundedOnlyAtPersistenceBoundary() {
+async function testLongWorkerErrorIsPreservedAtPersistenceBoundary() {
const { fixture, store } = await coordinatorFixture();
const fullError = `fixture long validator error: ${"x".repeat(5_000)}`;
const terminal = await runCoordinator(
@@ -1158,13 +1158,13 @@ async function testLongWorkerErrorIsBoundedOnlyAtPersistenceBoundary() {
{ retryDelaysMs: [1, 3, 9], random: () => 0 },
);
assert.equal(terminal?.status, "failed");
- assert.equal(store.failureMessages[0].length <= 2_400, true);
- assert.match(store.failureMessages[0], /truncated; sha256:/);
+ assert.ok(store.failureMessages[0].includes(fullError));
+ assert.equal(terminal.error, store.failureMessages[0]);
assert.equal(terminal.manifestPath, undefined);
const [worker] = [...store.workers.values()];
assert.equal(worker.status, "canceled");
assert.equal(worker.attempt, 4);
- assert.match(worker.error!, /truncated; sha256:/);
+ assert.equal(worker.error, `transient_error: ${fullError}`);
}
async function testDiscoveryPhasePersistenceFailureStopsDispatch() {
@@ -2180,7 +2180,8 @@ async function testStoppedPublicationFailurePreservesOriginalDiagnostic() {
/Saved result publication failed: fixture retained result publication failure/,
);
assert.match(terminal?.error ?? "", /Original Deep Scan failure:/);
- assert.equal((terminal?.error?.length ?? 0) <= 2_400, true);
+ assert.ok(terminal?.error?.includes("y".repeat(2_350)));
+ assert.ok(terminal?.error?.includes("x".repeat(2_350)));
assert.equal(
(await store.get(fixture.run.scanId, "checkpoint-owner")).error,
terminal?.error,
@@ -2194,7 +2195,7 @@ async function testStoppedPublicationFailurePreservesOriginalDiagnostic() {
);
}
-async function testStoppedPublicationFailureBoundsPrefixedDiagnostic() {
+async function testStoppedPublicationFailurePreservesPrefixedDiagnostic() {
const { fixture, store } = await coordinatorFixture();
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
const coordinator = createCoordinator(fixture, store, executor, {
@@ -2211,9 +2212,11 @@ async function testStoppedPublicationFailureBoundsPrefixedDiagnostic() {
const terminal = await coordinator.wait(undefined, 5_000);
assert.equal(terminal?.status, "canceled");
- assert.equal((terminal?.error?.length ?? 0) <= 2_400, true);
- assert.equal(store.publicationFailureMessages.length, 1);
- assert.equal(store.publicationFailureMessages[0].length <= 2_400, true);
+ assert.equal(
+ terminal?.error,
+ `Saved result publication failed: fixture publication failure ${"z".repeat(2_400)}`,
+ );
+ assert.deepEqual(store.publicationFailureMessages, [terminal.error]);
assert.match(
store.publicationFailureMessages[0],
/^Saved result publication failed: fixture publication failure/,
@@ -4278,7 +4281,7 @@ try {
await testFailureManifestWriteDoesNotMaskOriginalError();
await testFinishPersistenceFailureRewritesManifestAsFailure();
await testCommittedReducerIsReconciledBeforeDiscoveryFailureManifest();
- await testLongWorkerErrorIsBoundedOnlyAtPersistenceBoundary();
+ await testLongWorkerErrorIsPreservedAtPersistenceBoundary();
await testDiscoveryPhasePersistenceFailureStopsDispatch();
await testCancellationClearsRetryWait();
await testGenericDiagnosticsPreserveMissingResultRetries();
@@ -4315,7 +4318,7 @@ try {
await testCancellationDuringDiscoveryAcceptanceRejectsLateSuccess();
await testRegistryEvictionAndExternalFailure();
await testStoppedPublicationFailurePreservesOriginalDiagnostic();
- await testStoppedPublicationFailureBoundsPrefixedDiagnostic();
+ await testStoppedPublicationFailurePreservesPrefixedDiagnostic();
await testTerminalReadFailureIsNotRecordedAsPublicationFailure();
await testStaleMutationObservesReplacement();
await testStoreConfirmedReplacementSurvivesReadFailure();
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_diagnostics.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_diagnostics.ts
new file mode 100644
index 000000000..673fad95b
--- /dev/null
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_diagnostics.ts
@@ -0,0 +1,125 @@
+import assert from "node:assert/strict";
+import { randomUUID } from "node:crypto";
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import path from "node:path";
+import { test } from "node:test";
+import { importModule } from "./import-module.ts";
+import { finding } from "./scan-draft-fixture.ts";
+import {
+ coordinatorFixture,
+ temporaryDirectories,
+} from "./deep_scan_coordinator_fixture.ts";
+import type { CodexWorkerRequest } from "../src/deep-scan/types.js";
+
+const {
+ DeepScanWorkerRunner,
+ createDeepScanArtifacts,
+ reconcileDeepReduction,
+ parseDeepReduction,
+} = await importModule({
+ stdin: {
+ contents: [
+ 'export { DeepScanWorkerRunner } from "./worker-runner.ts";',
+ 'export { createDeepScanArtifacts } from "./artifacts.ts";',
+ 'export { reconcileDeepReduction, parseDeepReduction } from "./artifact-validation.ts";',
+ ].join("\n"),
+ resolveDir: path.join(import.meta.dirname, "../src/deep-scan"),
+ },
+ loader: { ".md": "text" },
+});
+
+for (const kind of ["discovery", "dedup"] as const) {
+ test(`${kind} retries retain every reference from a long validation error`, async () => {
+ try {
+ const { fixture, store } = await coordinatorFixture();
+ const scanId = fixture.run.scanId;
+ const findings = Array.from({ length: 300 }, (_, index) =>
+ finding(`source-${index}`, `src/file-${index}.ts`),
+ );
+ parseDeepReduction({ scanId, findings });
+ let validationError!: Error;
+ assert.throws(
+ () =>
+ reconcileDeepReduction(
+ {
+ scanId,
+ findings: [
+ {
+ ...findings[0],
+ provenance: { sourceFindingIds: ["discovery-0001:0"] },
+ },
+ ],
+ },
+ [{ workerId: "discovery-0001", result: { scanId, findings } }],
+ null,
+ ),
+ (error: unknown) => {
+ assert.ok(error instanceof Error);
+ validationError = error;
+ return true;
+ },
+ );
+ assert.ok(validationError.message.length > 4_000);
+ assert.ok(validationError.message.includes("discovery-0001:299"));
+ const workerRoot = path.join(
+ fixture.run.scanDir,
+ "artifacts",
+ "diagnostic-worker",
+ );
+ const artifactDir = path.join(workerRoot, "output");
+ const promptPath = path.join(workerRoot, "prompt.md");
+ await mkdir(artifactDir, { recursive: true });
+ await writeFile(promptPath, "Complete the assigned security review.\n");
+ const requests: CodexWorkerRequest[] = [];
+ const runner = new DeepScanWorkerRunner({
+ run: fixture.run,
+ store,
+ executor: {
+ run: async (request: CodexWorkerRequest) => {
+ requests.push(request);
+ return {};
+ },
+ },
+ artifacts: createDeepScanArtifacts(fixture.run.scanDir),
+ pluginRoot: fixture.pluginRoot,
+ clock: { now: Date.now, sleep: async () => {} },
+ random: () => 0,
+ log: () => {},
+ retryDelaysMs: [0],
+ signal: new AbortController().signal,
+ });
+ let validations = 0;
+ const outcome = await runner.runWorkerWithRetries({
+ workerId: randomUUID(),
+ kind,
+ promptPath,
+ promptRoot: path.join(workerRoot, "prompts"),
+ artifactDir,
+ subagents: 0,
+ validate: async () => {
+ if (validations++ === 0) throw validationError;
+ },
+ });
+ assert.equal(outcome.status, "succeeded");
+ assert.equal(requests.length, 2);
+ const retry = await readFile(requests[1].promptPath, "utf8");
+ const data = JSON.parse(
+ retry
+ .split("\n")
+ .find((line) => line.startsWith('{"validation_error":'))!,
+ );
+ assert.equal(data.validation_error.message, validationError.message);
+ assert.ok(retry.includes("discovery-0001:299"));
+ assert.equal(
+ store.workerUpdates.find((update) => update.error)?.error,
+ validationError.message,
+ );
+ assert.equal(
+ await readFile(promptPath, "utf8"),
+ "Complete the assigned security review.\n",
+ );
+ } finally {
+ await temporaryDirectories.cleanup();
+ }
+ });
+}
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.ts
index 471b6f39b..76c4bcbbf 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
@@ -3080,10 +3080,7 @@ export { recordCodexSecurityDeepReduction } from "./src/artifact-deep-reducer.ts
return message.includes(reference);
},
);
- // Truncating the long, well-formed emoji message splits a surrogate pair.
- const persistedDiagnostic = reference.includes("\0")
- ? message
- : "\ufffd\n...[truncated; sha256:";
+ const persistedDiagnostic = message;
process.env.FAKE_CODEX_ARTIFACT_EVENT = JSON.stringify({
type: "item.completed",
item: {
diff --git a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
index 19b7be05d..e32d96d24 100644
--- a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
+++ b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
@@ -3493,7 +3493,7 @@ with sqlite3.connect(sys.argv[1]) as connection:
},
});
assertNoError(rotatedProgress);
- const failureMessage = "--failure\nline";
+ const failureMessage = `--failure\n${"diagnostic ".repeat(500)}final cause`;
const rotatedFailure = await testServer.callTool(2039, {
name: "fail_codex_security_scan",
arguments: {
diff --git a/plugins/codex-security/scripts/deep_scan_workbench.py b/plugins/codex-security/scripts/deep_scan_workbench.py
index 7d12f6576..c15d48b5b 100644
--- a/plugins/codex-security/scripts/deep_scan_workbench.py
+++ b/plugins/codex-security/scripts/deep_scan_workbench.py
@@ -3,7 +3,6 @@
from __future__ import annotations
import argparse
-import hashlib
import json
import os
import shutil
@@ -35,7 +34,6 @@ DEEP_SCAN_TERMINAL_REASONS = ("saturated", "capped")
DEEP_SCAN_WORKFLOW_VERSION = "deep-security-scan/v1"
DEEP_SCAN_COORDINATOR_LEASE_SECONDS = 30
DEEP_SCAN_LEGACY_COORDINATOR_GRACE_SECONDS = 120
-DEEP_SCAN_MAX_ERROR_LENGTH = 2400
DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR = "\nOriginal Deep Scan failure:\n"
@@ -145,16 +143,6 @@ def dependencies() -> Any:
return _dependencies
-def _bounded_error_text(message: str, maximum: int) -> str:
- if len(message) <= maximum:
- return message
- digest = hashlib.sha256(message.encode()).hexdigest()
- suffix = f"\n...[truncated; sha256:{digest}]"
- if len(suffix) >= maximum:
- return message[:maximum]
- return f"{message[: maximum - len(suffix)]}{suffix}"
-
-
def deep_scan_error(run: sqlite3.Row) -> str | None:
original = run["error_message"]
publication = run["publication_error_message"]
@@ -162,15 +150,7 @@ def deep_scan_error(run: sqlite3.Row) -> str | None:
return original if isinstance(original, str) else None
if not isinstance(original, str):
return publication
- available = DEEP_SCAN_MAX_ERROR_LENGTH - len(DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR)
- publication_budget = min(len(publication), available // 2)
- original_budget = min(len(original), available - publication_budget)
- publication_budget = min(len(publication), available - original_budget)
- return (
- _bounded_error_text(publication, publication_budget)
- + DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR
- + _bounded_error_text(original, original_budget)
- )
+ return publication + DEEP_SCAN_PUBLICATION_ERROR_SEPARATOR + original
def _parse_timestamp(value: str) -> datetime:
@@ -1181,7 +1161,7 @@ def upsert_deep_scan_worker(
or args.status != "canceled"
or existing is None
or existing["status"] not in {"running", "canceled"}
- or optional_text(args.error_message, maximum=2400) is None
+ or optional_text(args.error_message) is None
):
raise SystemExit(
"A replaceable Deep Scan failure requires a running discovery worker, "
@@ -1262,7 +1242,7 @@ def upsert_deep_scan_worker(
artifact_dir,
attempt,
optional_text(args.sdk_thread_id, maximum=512),
- optional_text(args.error_message, maximum=2400),
+ optional_text(args.error_message),
timestamp,
timestamp if args.status == "running" else None,
timestamp,
@@ -1279,7 +1259,7 @@ def upsert_deep_scan_worker(
if terminal_repeat:
repeated_attempt = args.attempt if args.attempt is not None else existing["attempt"]
repeated_thread_id = optional_text(args.sdk_thread_id, maximum=512)
- repeated_error = optional_text(args.error_message, maximum=2400)
+ repeated_error = optional_text(args.error_message)
repeated_result_path = result_manifest_path or existing["result_manifest_path"]
if (
repeated_attempt != existing["attempt"]
@@ -1361,7 +1341,7 @@ def upsert_deep_scan_worker(
if args.status in {"succeeded", "failed", "canceled"}
else existing["completed_at"]
)
- error_message = optional_text(args.error_message, maximum=2400)
+ error_message = optional_text(args.error_message)
if error_message is None and args.status != "succeeded":
error_message = existing["error_message"]
started_at = existing["started_at"] or (timestamp if args.status == "running" else None)
@@ -1835,7 +1815,7 @@ def fail_deep_scan(connection: sqlite3.Connection, args: argparse.Namespace) ->
def fail_deep_scan_locked(
connection: sqlite3.Connection, args: argparse.Namespace, scan_id: str
) -> dict[str, Any]:
- message = optional_text(args.message, maximum=2400)
+ message = optional_text(args.message)
if message is None:
raise SystemExit("message is required.")
promotion: tuple[Path, Path, Path | None] | None = None
@@ -1933,7 +1913,7 @@ def record_deep_scan_publication_failure(
connection: sqlite3.Connection, args: argparse.Namespace
) -> dict[str, Any]:
scan_id = require_uuid(args.scan_id, "scan-id")
- message = optional_text(args.message, maximum=2400)
+ message = optional_text(args.message)
if message is None:
raise SystemExit("message is required.")
with dependencies().scan_completion_lock(scan_id):
diff --git a/plugins/codex-security/scripts/workbench_db.py b/plugins/codex-security/scripts/workbench_db.py
index a80f4c763..da2bf5f76 100644
--- a/plugins/codex-security/scripts/workbench_db.py
+++ b/plugins/codex-security/scripts/workbench_db.py
@@ -1250,7 +1250,7 @@ def complete_budget_exhausted_scan(
if run["manifest_path"] == str(scan_dir / "scan-manifest.json")
else budget_exhausted_candidates(scan, scan_dir)
)
- warning = optional_text(args.message, maximum=2400)
+ warning = optional_text(args.message)
if warning is None:
warning = (
f"Deep Scan reached its cost limit after an estimated "
diff --git a/plugins/codex-security/scripts/workbench_saved_results.py b/plugins/codex-security/scripts/workbench_saved_results.py
index 429967a83..825a5cf0e 100644
--- a/plugins/codex-security/scripts/workbench_saved_results.py
+++ b/plugins/codex-security/scripts/workbench_saved_results.py
@@ -3064,7 +3064,7 @@ def fail_scan_locked(db: Any, connection: Any, args: Any) -> dict[str, Any]:
args.claim_token,
error_message="Scan failure is owned by another continuation.",
)
- message = db.optional_text(args.message, maximum=2400)
+ message = db.optional_text(args.message)
updated = connection.execute(
"""
UPDATE scans
diff --git a/plugins/codex-security/tests/test_workbench_db.py b/plugins/codex-security/tests/test_workbench_db.py
index 4107a8d0e..0582c1a35 100644
--- a/plugins/codex-security/tests/test_workbench_db.py
+++ b/plugins/codex-security/tests/test_workbench_db.py
@@ -184,7 +184,9 @@ def budget_scan_fixture(
return state_dir, target, scan_dir, scan_id, ledger
-def complete_budget_scan(state_dir: Path, scan_id: str, *, check: bool = True) -> dict[str, object]:
+def complete_budget_scan(
+ state_dir: Path, scan_id: str, *, warning: str = BUDGET_WARNING, check: bool = True
+) -> dict[str, object]:
return scan_command(
state_dir,
"complete-budget-exhausted-scan",
@@ -192,7 +194,7 @@ def complete_budget_scan(state_dir: Path, scan_id: str, *, check: bool = True) -
"--cost-json",
json.dumps(BUDGET_COST),
"--message",
- BUDGET_WARNING,
+ warning,
check=check,
)
@@ -223,23 +225,36 @@ def test_cost_limit_rejects_invalid_or_nonincreasing_totals(tmp_path: Path, limi
assert scan_command(state_dir, "get-scan-recipe", scan_id)["recipe"]["maxCostUsd"] == 0.005
+ "warning",
+ [
+ BUDGET_WARNING,
+ BUDGET_WARNING
+ + "\n"
+ + "Synthetic diagnostic detail.\n" * 100
+ + "Final cost-limit diagnostic.",
+ ],
+)
def test_budget_exhaustion_preserves_unvalidated_discovery_as_deferred_work(
tmp_path: Path,
+ warning: str,
) -> None:
state_dir, target, scan_dir, scan_id, ledger = budget_scan_fixture(tmp_path)
original_ledger = ledger.read_bytes()
- completed = complete_budget_scan(state_dir, scan_id)["scan"]
+ completed = complete_budget_scan(state_dir, scan_id, warning=warning)["scan"]
assert completed["progress"]["status"] == "complete"
assert completed["findings"] == []
assert completed["cost"] == BUDGET_COST
- assert completed["warnings"] == [BUDGET_WARNING]
+ assert completed["warnings"] == [warning]
+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == [warning]
assert ledger.read_bytes() == original_ledger
manifest = json.loads((scan_dir / "scan-manifest.json").read_text())
assert manifest["scan"]["target"]["displayName"] == target.name
assert manifest["scan"]["target"]["targetId"] == stable_target_id(target)
assert manifest["scan"]["sealedAt"]
+ assert warning in manifest["scan"]["scope"]["limitations"]
coverage = json.loads((scan_dir / "coverage.json").read_text())
assert coverage["mode"] == "deep_repository"
diff --git a/plugins/codex-security/tests/test_workbench_diagnostics.py b/plugins/codex-security/tests/test_workbench_diagnostics.py
new file mode 100644
index 000000000..89d0f7af7
--- /dev/null
+++ b/plugins/codex-security/tests/test_workbench_diagnostics.py
@@ -0,0 +1,162 @@
+from __future__ import annotations
+
+import sqlite3
+import uuid
+from pathlib import Path
+
+import pytest
+from workbench_test_support import (
+ begin_deep_scan,
+ create_saved_workspace,
+ fail_scan,
+ get_deep_scan,
+ get_scan,
+ resume_deep_scan,
+ scan_command,
+ start_delivered_scan,
+ upsert_deep_worker,
+ worker_paths,
+)
+
+LONG_ERROR = "Synthetic diagnostic detail.\n" * 200 + "Final diagnostic cause."
+LEGACY_ERROR = "Saved diagnostic. " * 100 + "\n...[truncated; sha256:" + "0" * 64 + "]"
+
+
+def deep_scan(tmp_path: Path):
+ state_dir = tmp_path / "state"
+ target = tmp_path / "target"
+ target.mkdir()
+ environment = {"CODEX_HOME": str(tmp_path / "codex-home")}
+ started = begin_deep_scan(
+ state_dir,
+ "diagnostic-parent",
+ "--target-path",
+ str(target),
+ "--scan-root",
+ str(tmp_path / "scans"),
+ environment=environment,
+ )["deepScan"]
+ return state_dir, str(started["scanId"]), Path(str(started["scanDir"])), environment
+
+
[email protected]("message", [LONG_ERROR, LEGACY_ERROR])
+def test_scan_failure_keeps_complete_diagnostic_and_existing_terminal_value(
+ tmp_path: Path, message: str
+) -> None:
+ state_dir = tmp_path / "state"
+ target = tmp_path / "target"
+ target.mkdir()
+ workspace = create_saved_workspace(state_dir, target)
+ started = start_delivered_scan(
+ state_dir,
+ "--workspace-id",
+ str(workspace["id"]),
+ "--scan-root",
+ str(tmp_path / "scans"),
+ )["results"]
+ scan_id = str(started["scanId"])
+
+ failed = fail_scan(state_dir, scan_id, message)["scan"]
+ assert failed["progress"]["status"] == "failed"
+ assert failed["failureMessage"] == message
+ assert get_scan(state_dir, scan_id)["scan"]["failureMessage"] == message
+ replayed = fail_scan(state_dir, scan_id, "A different later error.")["scan"]
+ assert replayed["failureMessage"] == message
+
+
[email protected]("status", ["failed", "canceled"])
[email protected]("message", [LONG_ERROR, LEGACY_ERROR])
+def test_worker_failure_keeps_complete_diagnostic_and_exact_terminal_replay(
+ deep_scan, status: str, message: str
+) -> None:
+ state_dir, scan_id, scan_dir, environment = deep_scan
+ worker_id = str(uuid.uuid4())
+ prompt, artifact_dir, _ = worker_paths(scan_dir, "diagnostic-worker")
+ worker_args = (state_dir, scan_id, worker_id, "discovery")
+ paths = (str(prompt), str(artifact_dir))
+ upsert_deep_worker(*worker_args, "running", *paths, environment=environment)
+ failure_args = (
+ *worker_args,
+ status,
+ *paths,
+ "--error-message",
+ message,
+ *(("--replaceable-failure-kind", "transient_error") if status == "canceled" else ()),
+ )
+
+ failed = upsert_deep_worker(*failure_args, environment=environment)["deepScan"]
+ assert failed["workers"][0]["error"] == message
+ replayed = upsert_deep_worker(*failure_args, environment=environment)["deepScan"]
+ assert replayed["workers"] == failed["workers"]
+ resumed = resume_deep_scan(state_dir, scan_id, "diagnostic-parent", environment=environment)[
+ "deepScan"
+ ]
+ assert resumed["workers"][0]["error"] == message
+ rejected = upsert_deep_worker(
+ *worker_args,
+ status,
+ *paths,
+ "--error-message",
+ message + " Extra detail.",
+ environment=environment,
+ check=False,
+ )
+ assert rejected["returncode"] != 0
+ assert "terminal state is immutable" in rejected["stderr"]
+
+
[email protected]("message", [LONG_ERROR, LEGACY_ERROR])
+def test_deep_failure_keeps_complete_diagnostic_and_existing_terminal_value(
+ deep_scan, message: str
+) -> None:
+ state_dir, scan_id, _, environment = deep_scan
+ failure_args = (state_dir, "fail-deep-scan", scan_id, "--message", message)
+ failed = scan_command(*failure_args, environment=environment)["deepScan"]
+ assert failed["status"] == "failed"
+ assert failed["error"] == message
+ assert get_scan(state_dir, scan_id, environment=environment)["scan"]["failureMessage"] == (
+ message
+ )
+ replayed = scan_command(*failure_args, environment=environment)["deepScan"]
+ assert replayed == failed
+ resumed = resume_deep_scan(state_dir, scan_id, "diagnostic-parent", environment=environment)[
+ "deepScan"
+ ]
+ assert resumed["error"] == message
+ rejected = scan_command(
+ state_dir,
+ "fail-deep-scan",
+ scan_id,
+ "--message",
+ message + " Extra detail.",
+ environment=environment,
+ check=False,
+ )
+ assert rejected["returncode"] != 0
+ assert "terminal failure state is immutable" in rejected["stderr"]
+
+
+def test_publication_failure_keeps_both_complete_diagnostics(deep_scan) -> None:
+ state_dir, scan_id, _, environment = deep_scan
+ scan_command(
+ state_dir, "fail-deep-scan", scan_id, "--message", LONG_ERROR, environment=environment
+ )
+ publication = "Synthetic publication detail.\n" * 200 + "Final publication cause."
+ recorded = scan_command(
+ state_dir,
+ "record-deep-scan-publication-failure",
+ scan_id,
+ "--message",
+ publication,
+ environment=environment,
+ )["deepScan"]
+ expected = publication + "\nOriginal Deep Scan failure:\n" + LONG_ERROR
+ assert recorded["error"] == expected
+ fetched = get_deep_scan(state_dir, scan_id, "diagnostic-parent", environment=environment)
+ assert fetched["deepScan"]["error"] == expected
+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
+ assert connection.execute(
+ "SELECT error_message, publication_error_message FROM deep_scan_runs WHERE scan_id = ?",
+ (scan_id,),
+ ).fetchone() == (LONG_ERROR, publication)
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 3111f28c6..9dae0c7de 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -3038,7 +3038,7 @@ export class CodexSecurity {
activeScan.id,
"--cost-json",
JSON.stringify(snapshot?.cost ?? failure.cost),
- `--message=${failure.message.slice(0, 2400)}`,
+ `--message=${failure.message}`,
],
);
if (terminalTurnStatus !== null)
@@ -3144,7 +3144,7 @@ export class CodexSecurity {
"fail-scan",
"--scan-id",
activeScan.id,
- `--message=${errorMessage(failure).slice(0, 2400)}`,
+ `--message=${errorMessage(failure)}`,
...(snapshot?.cost
? ["--cost-json", JSON.stringify(snapshot.cost)]
: []),
@@ -4203,7 +4203,7 @@ export class CodexSecurity {
"fail-scan",
"--scan-id",
activeScan.id,
- `--message=${errorMessage(error).slice(0, 2400)}`,
+ `--message=${errorMessage(error)}`,
]).catch(() => undefined);
}
if (this.#closed) this.#requireOpen();
diff --git a/sdk/typescript/src/import-scan.ts b/sdk/typescript/src/import-scan.ts
index 8a6dad634..5a49deb59 100644
--- a/sdk/typescript/src/import-scan.ts
+++ b/sdk/typescript/src/import-scan.ts
@@ -353,7 +353,7 @@ export async function importScan(
"fail-scan",
"--scan-id",
activeScan.id,
- `--message=${errorMessage(error).slice(0, 2400)}`,
+ `--message=${errorMessage(error)}`,
]).catch(() => undefined);
}
if (signal?.aborted) {
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 8dc7fb4ec..4c4f465fe 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -124,7 +124,6 @@ const CREDENTIAL_LOCK_HEARTBEAT_MILLISECONDS = 5_000;
const CREDENTIAL_LOCK_POLL_MILLISECONDS = 25;
const INCOMPLETE_CREDENTIAL_LOCK_MILLISECONDS = 30_000;
const MAX_PROCESS_ID = 2_147_483_647;
-const MAX_WINDOWS_CREDENTIAL_ACL_STDERR = 64 * 1024;
const SANDBOX_PROBE_TIMEOUT_MILLISECONDS = 10_000;
const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
"OPENAI_API_KEY",
@@ -727,8 +726,7 @@ export async function streamWindowsCredentialAclDescriptors(
let stderr = "";
child.stderr.setEncoding("utf8");
child.stderr.on("data", (chunk: string) => {
- const remaining = MAX_WINDOWS_CREDENTIAL_ACL_STDERR - stderr.length;
- if (remaining > 0) stderr += chunk.slice(0, remaining);
+ stderr += chunk;
});
let descendantsChanged = false;
@@ -1669,9 +1667,8 @@ export async function runWorkbench(
? (options.stateDirectory ??
codexSecurityStateDirectory(options.environment))
: undefined;
- // OS argv cannot carry NUL, but workbench text fields can.
- const framedArguments =
- !native && arguments_.some((argument) => argument.includes("\0"));
+ // Workbench text fields can contain NUL or exceed OS command-line limits.
+ const framedArguments = !native;
let program = archiveHandshake ? ARCHIVE_REGISTRATION_PROGRAM : undefined;
if (framedArguments)
program =
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 672d62b69..92ccdeb8f 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -6578,9 +6578,14 @@ describe("CodexSecurity orchestration", () => {
await client.close();
});
- test.each(["", "\0literal", "\0high\ud800.low\udfff.pair😀"])(
- "preserves original failures in saved scan history (%j)",
- async (suffix) => {
+ test.each([
+ ["plain", ""],
+ ["NUL", "\0literal"],
+ ["Unicode", "\0high\ud800.low\udfff.pair😀"],
+ ["long", `${"detail ".repeat(20_000)}final cause`],
+ ])(
+ "preserves original failures in saved scan history (%s)",
+ async (_label, suffix) => {
const { root, repository, codexHome, scanDir } = await scanDirectories();
const stateDirectory = join(root, "state");
const python = Bun.which("python3") ?? Bun.which("python");
diff --git a/sdk/typescript/tests-ts/import-scan.test.ts b/sdk/typescript/tests-ts/import-scan.test.ts
index 4aee932da..601bafc34 100644
--- a/sdk/typescript/tests-ts/import-scan.test.ts
+++ b/sdk/typescript/tests-ts/import-scan.test.ts
@@ -989,9 +989,10 @@ test.each(["failure", "abort"] as const)(
async (mode) => {
const context = await fixture();
const controller = new AbortController();
+ const failureMessage = `--synthetic-import-completion-failure ${"detail ".repeat(20_000)}final cause`;
const run: typeof runWorkbench = async (options, args, input) => {
if (args[0] === "prepare-scan-completion" && mode === "failure") {
- throw new Error("--synthetic-import-completion-failure");
+ throw new Error(failureMessage);
}
const result = await runWorkbench(options, args, input);
if (args[0] === "register-cli-scan" && mode === "abort")
@@ -1007,12 +1008,17 @@ test.each(["failure", "abort"] as const)(
);
if (mode === "abort")
await expect(operation).rejects.toBeInstanceOf(ScanInterruptedError);
- else
- await expect(operation).rejects.toThrow(
- "--synthetic-import-completion-failure",
- );
+ else await expect(operation).rejects.toThrow(failureMessage);
const scans = await storedScans(context);
expect(scans).toHaveLength(1);
expect(scans[0]!.status).toBe("failed");
+ if (mode === "failure") {
+ const saved = await runWorkbench(context.workbenchOptions, [
+ "get-scan",
+ "--scan-id",
+ scans[0]!.id,
+ ]);
+ expect(saved["scan"]).toMatchObject({ failureMessage });
+ }
},
);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index b8f9b94b2..2f1cd5e98 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -4107,17 +4107,22 @@ describe("runtime directories and plugin Python boundary", () => {
},
);
- test("preserves Windows credential ACL subprocess failures while streaming", async () => {
+ test("preserves complete Windows credential ACL subprocess failures while streaming", async () => {
+ const prefixLength = 70 * 1024;
+ const failure = "\nsynthetic ACL inspection failure at end";
await expect(
streamWindowsCredentialAclDescriptors(
process.execPath,
[
"--eval",
- 'process.stderr.write("synthetic ACL inspection failure"); process.exitCode = 1',
+ `process.stderr.write("x".repeat(${prefixLength}) + ${JSON.stringify(failure)}); process.exitCode = 1`,
],
async () => {},
),
- ).rejects.toMatchObject({ stderr: "synthetic ACL inspection failure" });
+ ).rejects.toMatchObject({
+ code: 1,
+ stderr: "x".repeat(prefixLength) + failure,
+ });
});
test("accepts managed Windows ACLs with trusted system principals", () => {
@@ -5177,15 +5182,16 @@ describe("runtime directories and plugin Python boundary", () => {
[
["test-command"],
["test-command", "--message=出力\0literal\nsecond line"],
+ ["test-command", `--message=${"detail ".repeat(20_000)}final cause`],
[
"test-command",
"--message=\0high\ud800.low\udfff.pair😀",
"path-\udcff",
],
["finding-issues"],
- ].map((args) => ({ args })),
+ ].map((args, index) => ({ args, index })),
)(
- "runs custom workbench $args without output limits, credentials, or generated bytecode",
+ "runs custom workbench case $index without argument/output limits, credentials, or generated bytecode",
async ({ args }) => {
const root = await temporaryDirectory();
const pluginRoot = join(root, "plugin");