earendil-works/pi · error · Error

State mismatch

Error message

State mismatch

What it means

The state parameter in the manually pasted authorization input does not match the state generated for this login attempt. Fires when the user pastes a callback URL/code from a different or stale login session; the code is rejected to prevent mismatched (potentially forged) callbacks.

Solutions

  1. Restart the OAuth flow; the callback state does not match the stored state.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/openai-codex.ts:485 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/9909b7fe334f5668. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/auth/oauth/openai-codex.ts:485

				placeholder: REDIRECT_URI,
				signal: manualAbort.signal,
			})
			.then((input) => {
				manualCode = input;
				server.cancelWait();
			})
			.catch((error) => {
				manualError = error instanceof Error ? error : new Error(String(error));
				server.cancelWait();
			});

		const result = await server.waitForCode();
		if (manualError) throw manualError;
		if (result?.code) {
			code = result.code;
		} else if (manualCode) {
			const parsed = parseAuthorizationInput(manualCode);
			if (parsed.state && parsed.state !== state) throw new Error("State mismatch");
			code = parsed.code;
		}

		if (!code) {
			await manualPromise;
			if (manualError) throw manualError;
			if (manualCode) {
				const parsed = parseAuthorizationInput(manualCode);
				if (parsed.state && parsed.state !== state) throw new Error("State mismatch");
				code = parsed.code;
			}
		}

		if (!code) throw new Error("Missing authorization code");
		return exchangeAuthorizationCodeForCredentials(code, verifier, REDIRECT_URI, interaction.signal);
	} finally {
		interaction.signal.removeEventListener("abort", onAbort);
		manualAbort.abort();

View on GitHub (pinned to 4af9d21d3b)