Skip to content

Commit 65ea6a0

Browse files
authored
fix(auth): clarify Codex OAuth region failures (#71501)
1 parent c6770d3 commit 65ea6a0

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Docs: https://docs.openclaw.ai
1919
- Google Chat: preserve reply text when a typing indicator message is deleted or can no longer be updated, so media captions and first text chunks are resent instead of silently disappearing. (#71498) Thanks @colin-lgtm.
2020
- Heartbeat: clamp oversized scheduler delays through the shared safe timer helper, preventing `every` values over Node's timeout cap from becoming a 1 ms crash loop. Fixes #71414. (#71478) Thanks @hclsys.
2121
- Control UI/chat: collapse assistant token/model context details behind an explicit Context disclosure and show full dates in message footers, making historical transcript timing clear without noisy default metadata. (#71337) Thanks @BunsDev.
22+
- OpenAI/Codex OAuth: explain `unsupported_country_region_territory` token-exchange failures with a proxy/region hint instead of surfacing a generic OAuth error. Fixes #51175.
2223
- Telegram: remove the startup persisted-offset `getUpdates` preflight so polling restarts do not self-conflict before the runner starts. Fixes #69304. (#69779) Thanks @chinar-amrutkar.
2324
- Telegram: keep the polling stall watchdog active even when grammY reports the runner as not running while its task is still pending, so a rebuilt transport cannot leave `getUpdates` silent until a manual gateway restart. Fixes #69064. Thanks @LDLoeb.
2425
- Browser/Playwright: ignore benign already-handled route races during guarded navigation so browser-page tasks no longer fail when Playwright tears down a route mid-flight. (#68708) Thanks @Steady-ai.

src/plugins/provider-openai-codex-oauth.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ describe("loginOpenAICodexOAuth", () => {
181181
);
182182
});
183183

184+
it("explains OpenAI unsupported region token exchange failures", async () => {
185+
mocks.loginOpenAICodex.mockRejectedValue(new Error("403 unsupported_country_region_territory"));
186+
187+
const { prompter, spin } = createPrompter();
188+
const runtime = createRuntime();
189+
await expect(
190+
loginOpenAICodexOAuth({
191+
prompter,
192+
runtime,
193+
isRemote: false,
194+
openUrl: async () => {},
195+
}),
196+
).rejects.toThrow(/unsupported_region/i);
197+
198+
expect(spin.stop).toHaveBeenCalledWith("OpenAI OAuth failed");
199+
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("HTTPS_PROXY"));
200+
expect(prompter.note).toHaveBeenCalledWith(
201+
"Trouble with OAuth? See https://docs.openclaw.ai/start/faq",
202+
"OAuth help",
203+
);
204+
});
205+
184206
it("passes manual code input hook for remote oauth flows", async () => {
185207
const creds = createCodexCredentials();
186208
mocks.loginOpenAICodex.mockImplementation(async (opts: CodexLoginOptions) => {

src/plugins/provider-openai-codex-oauth.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const openAICodexOAuthOriginator = "openclaw";
1515
const localManualFallbackDelayMs = 15_000;
1616
const localManualFallbackGraceMs = 1_000;
1717

18-
type OpenAICodexOAuthFailureCode = "callback_timeout" | "callback_validation_failed";
18+
type OpenAICodexOAuthFailureCode =
19+
| "callback_timeout"
20+
| "callback_validation_failed"
21+
| "unsupported_region";
1922

2023
function waitForDelayOrLoginSettle(params: {
2124
delayMs: number;
@@ -54,6 +57,16 @@ function createOpenAICodexOAuthError(
5457

5558
function rewriteOpenAICodexOAuthError(error: unknown): Error {
5659
const message = formatErrorMessage(error);
60+
if (/unsupported_country_region_territory/i.test(message)) {
61+
return createOpenAICodexOAuthError(
62+
"unsupported_region",
63+
[
64+
"OpenAI rejected the token exchange for this country, region, or network route.",
65+
"If you normally use a proxy, verify HTTPS_PROXY, HTTP_PROXY, or ALL_PROXY is set for the OpenClaw process and then retry `openclaw models auth login --provider openai-codex`.",
66+
].join(" "),
67+
error,
68+
);
69+
}
5770
if (/state mismatch|missing authorization code/i.test(message)) {
5871
return createOpenAICodexOAuthError("callback_validation_failed", message, error);
5972
}

0 commit comments

Comments
 (0)