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(workbench): restore usage accounting on preview databases (#2352)

Michael D'Angelo006e8e32cc5f
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts b/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
index ffad1b5c9..8553c6e5c 100644
--- a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
+++ b/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
@@ -400,6 +400,32 @@ test("legacy retries can reuse a recorded thread and still verify usage", (t) =>
}
});
+test("the allowance preview keeps its data and receives canonical usage accounting", (t) => {
+ const database = memory(t, 62);
+ insertRunningWorker(database);
+ 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);
+ assert.equal(storedValue(database, "deep_scan_runs", "worker_usage_gap"), 1);
+ database.exec("UPDATE deep_scan_runs SET worker_usage_gap = 0");
+ database.exec("UPDATE deep_scan_workers SET attempt = 3");
+ assert.equal(storedValue(database, "deep_scan_runs", "worker_usage_gap"), 1);
+ const history = migrationHistory(database);
+ applyMigrations(database);
+ assert.deepEqual(migrationHistory(database), history);
+ assert.equal(
+ storedValue(database, "scans", "investigation_policy"),
+ "saved policy",
+ );
+});
+
test("worker thread history survives retry, replay, and worker retirement", (t) => {
const database = memory(t, 49);
insertRunningWorker(database);
diff --git a/plugins/codex-security/shared/workbench-history-repairs.json b/plugins/codex-security/shared/workbench-history-repairs.json
index 22f3a7b65..aa32ff316 100644
--- a/plugins/codex-security/shared/workbench-history-repairs.json
+++ b/plugins/codex-security/shared/workbench-history-repairs.json
@@ -4,7 +4,12 @@
"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';"
+ "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.",
diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
index 426494965..24a257fc8 100644
--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
@@ -1302,6 +1302,25 @@ def test_deep_scan_time_limit_migration_backfills_and_repairs_existing_runs(
assert migration_name_row(connection, 28)[0] == "persist deep scan discovery time limit"
+def test_allowance_preview_retains_policy_and_applies_canonical_usage_migration() -> None:
+ db, migrate = create_historical_database(63)
+ with closing(db):
+ timestamp = "2026-01-01T00:00:00Z"
+ db.execute("ALTER TABLE scans ADD COLUMN investigation_policy TEXT")
+ record_migration(db, 63, "retain native investigation time allowances", timestamp)
+ insert_historical_row(db, "workspaces", timestamp, id="legacy-workspace")
+ insert_legacy_scan(db, timestamp, investigation_policy="saved policy")
+ migrate(db)
+ query = "SELECT name, applied_at FROM schema_migrations WHERE version = 63"
+ receipt = db.execute(query).fetchone()
+ assert receipt["name"] == "retain unverified Deep Scan worker attempts"
+ assert db.execute("SELECT count(worker_usage_gap) FROM deep_scan_runs").fetchone()[0] == 0
+ migrate(db)
+ assert db.execute(query).fetchone() == receipt
+ assert db.execute("SELECT investigation_policy FROM scans").fetchone()[0] == "saved policy"
+
+
def test_workbench_reconciles_monorepo_migration_lineage() -> None:
connection, apply_migrations = create_historical_database(29)