Skip to content

Commit 4a4f52b

Browse files
vincentkocsteipete
authored andcommitted
fix(auth): restore codex oauth error and resume handling
1 parent a018257 commit 4a4f52b

4 files changed

Lines changed: 233 additions & 119 deletions

File tree

extensions/codex/src/app-server/run-attempt.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1111
import type { CodexServerNotification } from "./protocol.js";
1212
import { runCodexAppServerAttempt, __testing } from "./run-attempt.js";
1313
import { writeCodexAppServerBinding } from "./session-binding.js";
14-
import { buildThreadResumeParams, buildTurnStartParams } from "./thread-lifecycle.js";
14+
import {
15+
buildThreadResumeParams,
16+
buildTurnStartParams,
17+
startOrResumeThread,
18+
} from "./thread-lifecycle.js";
1519

1620
let tempDir: string;
1721

@@ -512,4 +516,46 @@ describe("runCodexAppServerAttempt", () => {
512516
}),
513517
);
514518
});
519+
520+
it("preserves the bound auth profile when resume params omit authProfileId", async () => {
521+
const sessionFile = path.join(tempDir, "session.jsonl");
522+
const workspaceDir = path.join(tempDir, "workspace");
523+
await writeCodexAppServerBinding(sessionFile, {
524+
threadId: "thread-existing",
525+
cwd: workspaceDir,
526+
authProfileId: "openai-codex:bound",
527+
model: "gpt-5.4-codex",
528+
modelProvider: "openai",
529+
});
530+
const params = createParams(sessionFile, workspaceDir);
531+
delete params.authProfileId;
532+
533+
const binding = await startOrResumeThread({
534+
client: {
535+
request: async (method) => {
536+
if (method === "thread/resume") {
537+
return { thread: { id: "thread-existing" }, modelProvider: "openai" };
538+
}
539+
throw new Error(`unexpected method: ${method}`);
540+
},
541+
} as never,
542+
params,
543+
cwd: workspaceDir,
544+
dynamicTools: [],
545+
appServer: {
546+
start: {
547+
transport: "stdio",
548+
command: "codex",
549+
args: ["app-server"],
550+
headers: {},
551+
},
552+
requestTimeoutMs: 60_000,
553+
approvalPolicy: "never",
554+
approvalsReviewer: "user",
555+
sandbox: "workspace-write",
556+
},
557+
});
558+
559+
expect(binding.authProfileId).toBe("openai-codex:bound");
560+
});
515561
});

extensions/codex/src/app-server/thread-lifecycle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ export async function startOrResumeThread(params: {
5050
appServer: params.appServer,
5151
}),
5252
);
53+
const boundAuthProfileId = params.params.authProfileId ?? binding.authProfileId;
5354
await writeCodexAppServerBinding(params.params.sessionFile, {
5455
threadId: response.thread.id,
5556
cwd: params.cwd,
56-
authProfileId: params.params.authProfileId,
57+
authProfileId: boundAuthProfileId,
5758
model: params.params.modelId,
5859
modelProvider: response.modelProvider ?? normalizeModelProvider(params.params.provider),
5960
dynamicToolsFingerprint,
@@ -63,7 +64,7 @@ export async function startOrResumeThread(params: {
6364
...binding,
6465
threadId: response.thread.id,
6566
cwd: params.cwd,
66-
authProfileId: params.params.authProfileId,
67+
authProfileId: boundAuthProfileId,
6768
model: params.params.modelId,
6869
modelProvider: response.modelProvider ?? normalizeModelProvider(params.params.provider),
6970
dynamicToolsFingerprint,

0 commit comments

Comments
 (0)