Skip to content

Commit a9ad8a9

Browse files
committed
fix: preserve Codex binding metadata during stale recovery
1 parent 9e2acf1 commit a9ad8a9

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

extensions/codex/src/app-server/compact.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ function maybeCompactCodexAppServerSession(
3636
);
3737
}
3838

39-
async function writeTestBinding(options: { authProfileId?: string } = {}): Promise<string> {
39+
async function writeTestBinding(
40+
options: Partial<Parameters<typeof writeCodexAppServerBinding>[1]> = {},
41+
): Promise<string> {
4042
const sessionFile = path.join(tempDir, "session.jsonl");
4143
await writeCodexAppServerBinding(sessionFile, {
4244
threadId: "thread-1",
@@ -336,18 +338,30 @@ describe("maybeCompactCodexAppServerSession", () => {
336338
expect(result.result).toBeUndefined();
337339
});
338340

339-
it("clears stale thread bindings and reports failed native compaction", async () => {
341+
it("preserves stale thread binding metadata for recovery and reports failed native compaction", async () => {
340342
const fake = createFakeCodexClient();
341343
fake.request.mockRejectedValueOnce(new Error("thread not found: thread-1"));
342344
setCodexAppServerClientFactoryForTest(async () => fake.client);
343-
const sessionFile = await writeTestBinding();
345+
const sessionFile = await writeTestBinding({
346+
authProfileId: "openai-codex:work",
347+
model: "gpt-5.4-mini",
348+
approvalPolicy: "on-request",
349+
sandbox: "workspace-write",
350+
serviceTier: "priority",
351+
});
344352

345353
const result = requireCompactResult(
346354
await startCompaction(sessionFile, { currentTokenCount: 456 }),
347355
);
348356

349357
expect(fake.request).toHaveBeenCalledWith("thread/compact/start", { threadId: "thread-1" });
350-
expect(await readCodexAppServerBinding(sessionFile)).toBeUndefined();
358+
const preservedBinding = await readCodexAppServerBinding(sessionFile);
359+
expect(preservedBinding?.threadId).toBe("thread-1");
360+
expect(preservedBinding?.authProfileId).toBe("openai-codex:work");
361+
expect(preservedBinding?.model).toBe("gpt-5.4-mini");
362+
expect(preservedBinding?.approvalPolicy).toBe("on-request");
363+
expect(preservedBinding?.sandbox).toBe("workspace-write");
364+
expect(preservedBinding?.serviceTier).toBe("priority");
351365
expect(result.ok).toBe(false);
352366
expect(result.compacted).toBe(false);
353367
expect(result.reason).toBe("thread not found: thread-1");

extensions/codex/src/app-server/compact.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ async function compactCodexNativeThread(
386386
} catch (error) {
387387
waiter.cancel();
388388
if (isCodexThreadNotFoundError(error)) {
389-
await clearCodexAppServerBinding(params.sessionFile, { config: params.config });
390389
return failedCodexThreadBindingCompactionResult(params, {
391390
threadId: binding.threadId,
392391
reason: formatCompactionError(error),

0 commit comments

Comments
 (0)