Skip to content

Commit 09e1751

Browse files
fix(server): Codex sign-in hint names the instance's CODEX_HOME (pingdotgg#35004)
1 parent 9f4b42e commit 09e1751

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,12 @@ const makePendingCodexProvider = Effect.fn("CodexProvider.makePendingCodexProvid
760760
});
761761
});
762762

763-
function accountProbeStatus({ account, rateLimits }: CodexAppServerProviderSnapshot): {
763+
const quotePath = Schema.encodeSync(Schema.fromJsonString(Schema.String));
764+
765+
function accountProbeStatus(
766+
{ account, rateLimits }: CodexAppServerProviderSnapshot,
767+
codexHome: string | undefined,
768+
): {
764769
readonly status: Exclude<ServerProviderState, "disabled">;
765770
readonly auth: ServerProvider["auth"];
766771
readonly message?: string;
@@ -788,7 +793,9 @@ function accountProbeStatus({ account, rateLimits }: CodexAppServerProviderSnaps
788793
return {
789794
status: "error",
790795
auth: { status: "unauthenticated" },
791-
message: "Codex CLI is not authenticated. Run `codex login` and try again.",
796+
message: codexHome
797+
? `Codex CLI is not authenticated. Run \`codex login\` with CODEX_HOME set to ${quotePath(codexHome)} and try again.`
798+
: "Codex CLI is not authenticated. Run `codex login` and try again.",
792799
};
793800
}
794801

@@ -903,7 +910,12 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
903910
const snapshot = probeResult.success.value;
904911
const accountStatus = managedAuth
905912
? { status: "ready" as const, auth: managedAuth, message: undefined }
906-
: accountProbeStatus(snapshot);
913+
: accountProbeStatus(
914+
snapshot,
915+
codexSettings.homePath
916+
? expandHomePath(codexSettings.homePath, yield* HostProcess.HomeDirectory)
917+
: undefined,
918+
);
907919
// Sign-in guidance still applies when Codex itself says it needs an OpenAI login.
908920
const usageLimits =
909921
!snapshot.nativeUsage && !accountStatus.message

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,25 @@ it.layer(
466466
}),
467467
);
468468

469+
it.effect("names the instance's CODEX_HOME in the sign-in hint for a custom home", () =>
470+
Effect.gen(function* () {
471+
const homePath = "/srv/codex-work-home";
472+
const status = yield* checkCodexProviderStatus(
473+
decodeCodexSettings({ binaryPath: "codex", homePath }),
474+
() =>
475+
Effect.succeed(
476+
makeCodexProbeSnapshot({
477+
account: { account: null, requiresOpenaiAuth: true },
478+
}),
479+
),
480+
);
481+
482+
assert.strictEqual(status.auth.status, "unauthenticated");
483+
assert.include(status.message ?? "", "CODEX_HOME");
484+
assert.include(status.message ?? "", homePath);
485+
}),
486+
);
487+
469488
it.effect("returns ready with unknown auth when app-server does not require OpenAI auth", () =>
470489
Effect.gen(function* () {
471490
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>

0 commit comments

Comments
 (0)