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(bulk-scan): recover expired locks with null owners (#98)

Gautam Sharma7a07c33bd46b
diff --git a/sdk/typescript/src/multiscan.ts b/sdk/typescript/src/multiscan.ts
index a93988a1a..80813884c 100644
--- a/sdk/typescript/src/multiscan.ts
+++ b/sdk/typescript/src/multiscan.ts
@@ -919,7 +919,7 @@ async function inspectLock(
processStartedAt?: number;
};
try {
- identity = JSON.parse(owner) as typeof identity;
+ identity = (JSON.parse(owner) ?? {}) as typeof identity;
} catch {
return { owner, stale: Date.now() - modifiedAt > LOCK_LEASE_MS };
}
diff --git a/sdk/typescript/tests-ts/multiscan-checkout.test.ts b/sdk/typescript/tests-ts/multiscan-checkout.test.ts
index 88f43ff72..89701e71a 100644
--- a/sdk/typescript/tests-ts/multiscan-checkout.test.ts
+++ b/sdk/typescript/tests-ts/multiscan-checkout.test.ts
@@ -786,6 +786,28 @@ describe("multiscan", () => {
expect((await lstat(lock)).isDirectory()).toBe(true);
});
+ test("preserves a null lock owner until its lease expires", async () => {
+ const { paths } = await repositoryFixture("null-owner");
+ const lock = join(paths.output, ".lock");
+ const ownerPath = join(lock, "owner.json");
+ await mkdir(lock, { recursive: true, mode: 0o700 });
+ await writeFile(ownerPath, "null", { mode: 0o600 });
+ const configured = options(paths, client(completeRun));
+
+ await expect(runMultiscan(configured)).rejects.toThrow(
+ "A multiscan supervisor is already running.",
+ );
+ expect(await readFile(ownerPath, "utf8")).toBe("null");
+
+ const expired = new Date(Date.now() - 120_000);
+ await utimes(ownerPath, expired, expired);
+ expect(await runMultiscan(configured)).toMatchObject({
+ completed: 1,
+ failed: 0,
+ });
+ await expect(access(lock)).rejects.toThrow();
+ });
+
test("recovers an interrupted stale-lock recovery claim", async () => {
const { paths } = await repositoryFixture(
"interrupted-recovery",