Skip to content

Commit 3d2badf

Browse files
committed
fix(codex): keep discovery ready when saved login reads stall
1 parent f627ced commit 3d2badf

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ const decodeCodexIdTokenClaims = Schema.decodeUnknownOption(
114114
),
115115
);
116116

117-
/**
118-
* A model provider that does not require OpenAI auth makes `account/read`
119-
* answer with no account, yet usage still comes from the saved ChatGPT login.
120-
* Its id_token is only an identity hint, so callers must match it against the
121-
* account the backend reports.
122-
*/
117+
// Proxied usage can retain a saved login while account/read hides it; match this hint to backend usage.
123118
const readCodexStoredChatGptLogin = Effect.fn("readCodexStoredChatGptLogin")(function* (
124119
codexHome: string,
125120
) {
@@ -646,7 +641,10 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
646641
const storedLogin =
647642
accountResponse.account || !config || credentialStore !== "file"
648643
? undefined
649-
: yield* readCodexStoredChatGptLogin(initialize.codexHome);
644+
: yield* withCodexDiscoveryDeadline(
645+
readCodexStoredChatGptLogin(initialize.codexHome),
646+
deadlineMs,
647+
);
650648

651649
return {
652650
account: accountResponse,

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ it.live("names a proxied login by its saved ChatGPT email only when Codex reads
368368
const scriptPath = path.join(codexHome, "script.json");
369369
const binaryPath = path.join(import.meta.dirname, "testFixtures", "codexCollabMockPeer.sh");
370370
// A model provider that skips OpenAI auth hides the account, yet usage still names one.
371-
const proxied = Effect.fn(function* (accountId: string, store: string) {
371+
const proxied = Effect.fn("test.proxiedCodexLogin")(function* (
372+
accountId: string,
373+
store: string,
374+
) {
372375
yield* fileSystem.writeFileString(
373376
scriptPath,
374377
JSON.stringify({
@@ -392,6 +395,18 @@ it.live("names a proxied login by its saved ChatGPT email only when Codex reads
392395
const otherAccount = yield* proxied("acct-2", "file");
393396
assert.strictEqual(otherAccount.auth.email, undefined);
394397
assert.strictEqual(otherAccount.auth.workspaceId, "acct-2");
398+
const stalledLogin = yield* proxied("acct-1", "file").pipe(
399+
Effect.provideService(FileSystem.FileSystem, {
400+
...fileSystem,
401+
readFileString: (file, ...options) =>
402+
file === path.join(codexHome, "auth.json")
403+
? Effect.never
404+
: fileSystem.readFileString(file, ...options),
405+
}),
406+
);
407+
assert.strictEqual(stalledLogin.status, "ready");
408+
assert.strictEqual(stalledLogin.auth.workspaceId, "acct-1");
409+
assert.strictEqual(stalledLogin.auth.email, undefined);
395410
}).pipe(
396411
Effect.scoped,
397412
Effect.provide(Layer.mergeAll(layerTestNodeServices, ServerSettingsModule.layerTest())),

0 commit comments

Comments
 (0)