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
refactor(workbench): consolidate preview migration receipt lookups (#2357)
Michael D'Angeloda9eb005f63a
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts b/plugins/codex-security/mcp-app/tests/test_workbench_database.tsindex 8553c6e5c..e0855d715 100644--- a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts+++ b/plugins/codex-security/mcp-app/tests/test_workbench_database.ts@@ -381,35 +381,36 @@ function insertRunningWorker(database: DatabaseSync) {`);}+function legacyRetry(t: TestContext, attempt: number, thread: string | null) {+ const database = memory(t, 62);+ insertRunningWorker(database);+ database+ .prepare(+ "UPDATE deep_scan_workers SET attempt = ?, started_at = 'started', sdk_thread_id = ?",+ )+ .run(attempt, thread);+ if (thread === null) database.exec("DELETE FROM deep_scan_worker_threads");+ return database;+}+test("legacy retries can reuse a recorded thread and still verify usage", (t) => {for (const thread of ["first-thread", "retry-thread", null]) {- const database = memory(t, 62);- insertRunningWorker(database);- database- .prepare(- "UPDATE deep_scan_workers SET attempt = 3, started_at = 'started', sdk_thread_id = ?",- )- .run(thread);- if (thread === null) database.exec("DELETE FROM deep_scan_worker_threads");+ const database = legacyRetry(t, 3, thread);applyMigrations(database);assert.equal(- database.prepare("SELECT worker_usage_gap FROM deep_scan_runs").get()- ?.worker_usage_gap,+ storedValue(database, "deep_scan_runs", "worker_usage_gap"),thread === null ? 1 : 0,);}});test("the allowance preview keeps its data and receives canonical usage accounting", (t) => {- const database = memory(t, 62);- insertRunningWorker(database);+ const database = legacyRetry(t, 2, null);database.exec(`ALTER TABLE scans ADD COLUMN investigation_policy TEXT;UPDATE scans SET investigation_policy = 'saved policy';INSERT INTO schema_migrations (version, name, applied_at)VALUES (63, 'retain native investigation time allowances', 'preview');- UPDATE deep_scan_workers SET attempt = 2, started_at = 'started', sdk_thread_id = NULL;- DELETE FROM deep_scan_worker_threads;`);applyMigrations(database);assertMigrationNames(database, 63);diff --git a/plugins/codex-security/shared/workbench-history-repairs.json b/plugins/codex-security/shared/workbench-history-repairs.jsonindex aa32ff316..9f2112514 100644--- a/plugins/codex-security/shared/workbench-history-repairs.json+++ b/plugins/codex-security/shared/workbench-history-repairs.json@@ -1,33 +1,22 @@[[- "WITH input AS (SELECT :history AS history)",- "SELECT 'sql' AS operation,",- " 'UPDATE schema_migrations SET version = 60 WHERE version = ' || version AS value",- "FROM schema_migrations",- "WHERE version IN (58, 59) AND name = 'record classification rubric provenance'",- "UNION ALL",- "-- Release the allowance preview receipt so canonical 63 runs without touching its policy column.",- "SELECT 'sql', 'DELETE FROM schema_migrations WHERE version = 63'",- "FROM schema_migrations",- "WHERE version = 63 AND name = 'retain native investigation time allowances';"- ],- [- "-- Move checkpoint previews before source-scope history checks.",- "WITH input AS (SELECT :history AS history)",- "SELECT 'sql' AS operation,",- " 'UPDATE schema_migrations SET version = 57 WHERE version = ' || version AS value",- "FROM schema_migrations",- "WHERE version IN (47, 48, 50, 52, 53, 54)",- " AND name = 'freeze stopped scan checkpoint selections';"- ],- [- "-- Move source-scope previews before the shared history repairs.",- "WITH input AS (SELECT :history AS history)",- "SELECT 'sql' AS operation,",- " 'UPDATE schema_migrations SET version = 50 WHERE version = ' || version AS value",- "FROM schema_migrations",- "WHERE version IN (34, 40, 41, 42, 43, 44, 48)",- " AND name = 'persist authorized source excerpt scopes';"+ "WITH input AS (SELECT :history AS history),",+ "previews AS (",+ " SELECT version, CASE",+ " WHEN version IN (58, 59) AND name = 'record classification rubric provenance'",+ " THEN 'UPDATE schema_migrations SET version = 60'",+ " WHEN version IN (47, 48, 50, 52, 53, 54) AND name = 'freeze stopped scan checkpoint selections'",+ " THEN 'UPDATE schema_migrations SET version = 57'",+ " WHEN version IN (34, 40, 41, 42, 43, 44, 48) AND name = 'persist authorized source excerpt scopes'",+ " THEN 'UPDATE schema_migrations SET version = 50'",+ " WHEN version = 63 AND name = 'retain native investigation time allowances'",+ " THEN 'DELETE FROM schema_migrations'",+ " END AS repair FROM schema_migrations",+ ")",+ "SELECT 'sql' AS operation, repair || ' WHERE version = ' || version AS value",+ "FROM previews WHERE repair IS NOT NULL",+ "-- Vacate checkpoint preview 50 before moving a lower source-scope receipt into it.",+ "ORDER BY version DESC;"],["WITH history AS (",