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): parse UTC timestamps on Python 3.10 (#462)

mldangelo-oaidc350e057773
diff --git a/sdk/typescript/_bundled_plugin/.codex-plugin/plugin.json b/sdk/typescript/_bundled_plugin/.codex-plugin/plugin.json
index 04c30b9c6..4015ea149 100644
--- a/sdk/typescript/_bundled_plugin/.codex-plugin/plugin.json
+++ b/sdk/typescript/_bundled_plugin/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "codex-security",
- "version": "0.1.20",
+ "version": "0.1.21",
"description": "Codex Security workflows for security scans, analysis, and investigation.",
"author": {
"name": "OpenAI"
diff --git a/sdk/typescript/_bundled_plugin/scripts/deep_scan_workbench.py b/sdk/typescript/_bundled_plugin/scripts/deep_scan_workbench.py
index 113f7c156..f548db39e 100644
--- a/sdk/typescript/_bundled_plugin/scripts/deep_scan_workbench.py
+++ b/sdk/typescript/_bundled_plugin/scripts/deep_scan_workbench.py
@@ -160,6 +160,12 @@ def now() -> str:
return dependencies().now()
+def _parse_timestamp(value: str) -> datetime:
+ if isinstance(value, str) and value.endswith(("Z", "z")):
+ value = value[:-1] + "+00:00"
+ return datetime.fromisoformat(value)
+
+
def state_dir() -> Path:
return dependencies().state_dir()
@@ -219,7 +225,7 @@ def require_deep_scan_run(connection: sqlite3.Connection, scan_id: str) -> sqlit
def deep_scan_deadline_reached(run: sqlite3.Row) -> bool:
- elapsed = datetime.fromisoformat(now()) - datetime.fromisoformat(str(run["created_at"]))
+ elapsed = _parse_timestamp(now()) - _parse_timestamp(str(run["created_at"]))
return elapsed.total_seconds() / 3600 >= run["max_time_hours"]
@@ -880,12 +886,12 @@ def coordinator_lease_is_live(
""",
(run["scan_id"],),
).fetchone()
- return active_worker is not None and datetime.fromisoformat(
+ return active_worker is not None and _parse_timestamp(
str(run["updated_at"])
- ) > datetime.fromisoformat(timestamp) - timedelta(
+ ) > _parse_timestamp(timestamp) - timedelta(
seconds=DEEP_SCAN_LEGACY_COORDINATOR_GRACE_SECONDS
)
- heartbeat_time = datetime.fromisoformat(str(run["updated_at"]))
+ heartbeat_time = _parse_timestamp(str(run["updated_at"]))
heartbeat_path = (
Path(scan["scan_dir"])
/ "artifacts"
@@ -895,10 +901,10 @@ def coordinator_lease_is_live(
try:
heartbeat = json.loads(heartbeat_path.read_text(encoding="utf-8"))
if heartbeat["coordinatorGeneration"] == run["coordinator_generation"]:
- heartbeat_time = max(heartbeat_time, datetime.fromisoformat(heartbeat["updatedAt"]))
+ heartbeat_time = max(heartbeat_time, _parse_timestamp(heartbeat["updatedAt"]))
except (OSError, KeyError, TypeError, ValueError):
pass
- current_time = datetime.fromisoformat(timestamp)
+ current_time = _parse_timestamp(timestamp)
return heartbeat_time > current_time - timedelta(seconds=DEEP_SCAN_COORDINATOR_LEASE_SECONDS)
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_remediation.py b/sdk/typescript/_bundled_plugin/scripts/workbench_remediation.py
index afb1c6c98..5d38e0553 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_remediation.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_remediation.py
@@ -23,6 +23,8 @@ def remediation_claim_is_active(remediation: sqlite3.Row) -> bool:
if not isinstance(claimed_at, str):
return True
try:
+ if claimed_at.endswith(("Z", "z")):
+ claimed_at = claimed_at[:-1] + "+00:00"
parsed = datetime.fromisoformat(claimed_at)
if parsed.tzinfo is None:
return True
diff --git a/sdk/typescript/src/version.ts b/sdk/typescript/src/version.ts
index 01dd50067..955feef3f 100644
--- a/sdk/typescript/src/version.ts
+++ b/sdk/typescript/src/version.ts
@@ -8,7 +8,7 @@ const PACKAGE_VERSIONS = packageVersions(
export const VERSION = PACKAGE_VERSIONS.package;
export const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;
export const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;
-export const BUNDLED_PLUGIN_VERSION = "0.1.20" as const;
+export const BUNDLED_PLUGIN_VERSION = "0.1.21" as const;
const PACKAGE_NAME = "@openai/codex-security";
const VERSION_PATTERN =
diff --git a/sdk/typescript/tests-ts/deep-scan-timestamp-compat.test.ts b/sdk/typescript/tests-ts/deep-scan-timestamp-compat.test.ts
new file mode 100644
index 000000000..cc471029b
--- /dev/null
+++ b/sdk/typescript/tests-ts/deep-scan-timestamp-compat.test.ts
@@ -0,0 +1,148 @@
+import { join } from "node:path";
+import { describe, expect, test } from "bun:test";
+import { PLUGIN_ROOT } from "./plugin-root.js";
+
+const timestampProbe = `
+import json, sqlite3, sys, tempfile
+from datetime import datetime as native_datetime
+from pathlib import Path
+sys.path.insert(0, sys.argv[1])
+import deep_scan_workbench as deep_scan
+
+class Python310Datetime:
+ @staticmethod
+ def fromisoformat(value):
+ if isinstance(value, str) and value.endswith(("Z", "z")):
+ raise ValueError("Python 3.10 rejects Z-suffixed timestamps")
+ return native_datetime.fromisoformat(value)
+
+if sys.version_info >= (3, 11):
+ deep_scan.datetime = Python310Datetime
+case = json.loads(sys.argv[2])
+deep_scan.now = lambda: case["now"]
+connection = sqlite3.connect(":memory:")
+connection.execute("CREATE TABLE deep_scan_workers (scan_id TEXT, status TEXT)")
+if case.get("activeWorker"):
+ connection.execute("INSERT INTO deep_scan_workers VALUES ('scan', 'running')")
+run = {
+ "scan_id": "scan",
+ "created_at": case.get("createdAt"),
+ "updated_at": case.get("updatedAt"),
+ "max_time_hours": case.get("maxTimeHours"),
+ "coordinator_generation": case.get("generation", 1),
+}
+with tempfile.TemporaryDirectory() as scan_dir:
+ if "heartbeat" in case:
+ heartbeat_path = Path(scan_dir) / "artifacts" / "deep_discovery" / f"coordinator-heartbeat-{run['coordinator_generation']}.json"
+ heartbeat_path.parent.mkdir(parents=True)
+ heartbeat_path.write_text(json.dumps(case["heartbeat"]), encoding="utf-8")
+ if case["operation"] == "deadline":
+ result = deep_scan.deep_scan_deadline_reached(run)
+ else:
+ result = deep_scan.coordinator_lease_is_live(connection, run, {"scan_dir": scan_dir}, case["now"])
+ print(json.dumps(result))
+`;
+
+interface TimestampProbe {
+ operation: "deadline" | "coordinator";
+ now: string;
+ createdAt?: string;
+ updatedAt?: string;
+ maxTimeHours?: number;
+ generation?: number;
+ activeWorker?: boolean;
+ heartbeat?: { coordinatorGeneration: number; updatedAt: unknown };
+}
+
+function runTimestampProbe(probe: TimestampProbe): boolean {
+ const python = Bun.which("python3") ?? Bun.which("python") ?? Bun.which("py");
+ if (python === null) throw new Error("A Python interpreter is required.");
+
+ const result = Bun.spawnSync(
+ [
+ python,
+ "-I",
+ "-B",
+ "-c",
+ timestampProbe,
+ join(PLUGIN_ROOT, "scripts"),
+ JSON.stringify(probe),
+ ],
+ { stdout: "pipe", stderr: "pipe" },
+ );
+
+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);
+ return JSON.parse(new TextDecoder().decode(result.stdout)) as boolean;
+}
+
+describe("Python 3.10 Deep Scan timestamps", () => {
+ test.each([
+ [
+ "before the deadline",
+ "2026-08-15T00:00:00Z",
+ "2026-08-15T00:59:59Z",
+ false,
+ ],
+ ["at the deadline", "2026-08-15T00:00:00Z", "2026-08-15T01:00:00Z", true],
+ [
+ "with lowercase UTC suffixes",
+ "2026-08-15T00:00:00z",
+ "2026-08-15T01:00:00z",
+ true,
+ ],
+ [
+ "with explicit UTC offsets",
+ "2026-08-15T02:00:00+02:00",
+ "2026-08-15T01:00:00Z",
+ true,
+ ],
+ ] as const)("evaluates timestamps %s", (_label, createdAt, now, reached) => {
+ expect(
+ runTimestampProbe({
+ operation: "deadline",
+ createdAt,
+ maxTimeHours: 1,
+ now,
+ }),
+ ).toBe(reached);
+ });
+
+ test.each([
+ ["fresh legacy", 1, "2026-08-15T00:09:59Z", true],
+ ["expired legacy", 1, "2026-08-15T00:08:00Z", false],
+ ["fresh current", 2, "2026-08-15T00:09:59Z", true],
+ ["expired current", 2, "2026-08-15T00:09:30Z", false],
+ ] as const)(
+ "evaluates %s coordinator leases",
+ (_label, generation, updatedAt, live) => {
+ expect(
+ runTimestampProbe({
+ operation: "coordinator",
+ generation,
+ activeWorker: generation === 1,
+ updatedAt,
+ now: "2026-08-15T00:10:00Z",
+ }),
+ ).toBe(live);
+ },
+ );
+
+ test.each([
+ ["current", 2, "2026-08-15T00:09:45Z", true],
+ ["older generation", 1, "2026-08-15T00:09:45Z", false],
+ ["invalid", 2, null, false],
+ ] as const)(
+ "uses the %s coordinator heartbeat",
+ (_label, coordinatorGeneration, updatedAt, live) => {
+ expect(
+ runTimestampProbe({
+ operation: "coordinator",
+ generation: 2,
+ updatedAt: "2026-08-15T00:09:00Z",
+ now: "2026-08-15T00:10:00Z",
+ heartbeat: { coordinatorGeneration, updatedAt },
+ }),
+ ).toBe(live);
+ },
+ );
+});
diff --git a/sdk/typescript/tests-ts/workbench-remediation-timestamp.test.ts b/sdk/typescript/tests-ts/workbench-remediation-timestamp.test.ts
new file mode 100644
index 000000000..061e550c9
--- /dev/null
+++ b/sdk/typescript/tests-ts/workbench-remediation-timestamp.test.ts
@@ -0,0 +1,93 @@
+import { join } from "node:path";
+import { describe, expect, test } from "bun:test";
+import { PLUGIN_ROOT } from "./plugin-root.js";
+
+const remediationLeaseProbe = `
+import json, sys
+from datetime import datetime, timezone
+sys.path.insert(0, sys.argv[1])
+import workbench_remediation as remediation
+
+class Python310DateTime(datetime):
+ @classmethod
+ def fromisoformat(cls, value):
+ if value.endswith(("Z", "z")):
+ raise ValueError("Python 3.10 rejects Z-suffixed timestamps")
+ return datetime.fromisoformat(value)
+
+ @classmethod
+ def now(cls, tz=None):
+ return datetime(2026, 8, 15, 12, 0, tzinfo=timezone.utc)
+
+remediation.datetime = Python310DateTime
+case = json.loads(sys.argv[2])
+print(json.dumps(remediation.remediation_claim_is_active({
+ "pending_action_claim_token": case.get("token"),
+ "pending_action_delivered_at": case.get("deliveredAt"),
+ "pending_action_claimed_at": case.get("claimedAt"),
+})))
+`;
+
+interface RemediationClaim {
+ token: string | null;
+ claimedAt?: string;
+ deliveredAt?: string;
+}
+
+function isClaimActive(claim: RemediationClaim): boolean {
+ const python = Bun.which("python3") ?? Bun.which("python") ?? Bun.which("py");
+ if (python === null) throw new Error("A Python interpreter is required.");
+
+ const result = Bun.spawnSync(
+ [
+ python,
+ "-I",
+ "-B",
+ "-c",
+ remediationLeaseProbe,
+ join(PLUGIN_ROOT, "scripts"),
+ JSON.stringify(claim),
+ ],
+ { stdout: "pipe", stderr: "pipe" },
+ );
+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);
+ return JSON.parse(new TextDecoder().decode(result.stdout)) as boolean;
+}
+
+describe("workbench remediation timestamps on Python 3.10", () => {
+ test.each([
+ [
+ "expires at the claim deadline",
+ { claimedAt: "2026-08-15T11:58:00Z" },
+ false,
+ ],
+ ["accepts lowercase UTC", { claimedAt: "2026-08-15T11:58:00z" }, false],
+ [
+ "preserves explicit offsets",
+ { claimedAt: "2026-08-15T13:58:00+02:00" },
+ false,
+ ],
+ ["keeps a fresh claim", { claimedAt: "2026-08-15T11:58:01Z" }, true],
+ [
+ "expires at the delivery deadline",
+ {
+ claimedAt: "2026-08-15T11:30:00Z",
+ deliveredAt: "2026-08-15T11:45:00Z",
+ },
+ false,
+ ],
+ [
+ "keeps a fresh delivery after an older claim",
+ {
+ claimedAt: "2026-08-15T11:30:00Z",
+ deliveredAt: "2026-08-15T11:45:01Z",
+ },
+ true,
+ ],
+ ["has no claim without a token", { token: null }, false],
+ ["preserves an invalid timestamp", { claimedAt: "not-a-timestamp" }, true],
+ ["preserves a naive timestamp", { claimedAt: "2026-08-15T11:00:00" }, true],
+ ] as const)("%s", (_label, fields, active) => {
+ expect(isClaimActive({ token: "claim", ...fields })).toBe(active);
+ });
+});