fix(xai-oauth): add --paste-code flag for WSL2 firewall workaround#27523
Closed
levi951 wants to merge 1 commit into
Closed
fix(xai-oauth): add --paste-code flag for WSL2 firewall workaround#27523levi951 wants to merge 1 commit into
levi951 wants to merge 1 commit into
Conversation
WSL2 ships with Hyper-V Firewall DefaultInboundAction=Block (Microsoft's current default with mirrored networking). xAI's OAuth redirect to http://127.0.0.1:56121/callback is silently dropped before reaching the WSL VM. xAI then renders its "Could not establish connection" fallback page showing the auth code as text — but stock Hermes has no way to accept that code, so the listener times out and the code is orphaned. This adds a stdin-paste path to `hermes auth add xai-oauth`: - New `--paste-code` flag (auto-enabled when `--no-browser` is set) - `_xai_wait_for_callback` spins up a daemon thread that reads one line from stdin and feeds the pasted code into the same callback handler via internal HTTP (127.0.0.1:<port>/callback?code=...&state=...) - First-write-wins: whichever channel (browser redirect or stdin paste) delivers a code first short-circuits the wait loop Works on any platform with the loopback callback blocked: WSL2 + Hyper-V Firewall, GCP Cloud Shell, GitHub Codespaces, AWS Instance Connect, restrictive corporate proxies, etc. Refs: PR #27305 (community wrapper writeup), issue #27385 (loopback callback edge cases), issue #26923 (remote console OAuth fallback).
Contributor
|
Closing in favor of #26929 (submitted first, same gap). #26929 covers the same use case with broader scope:
Your stdin-thread first-write-wins pattern is clever; we may revisit it as a future enhancement to allow the listener and stdin path to race when both are available. Thanks for surfacing the WSL2 firewall workaround. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WSL2 ships with the Hyper-V Firewall
DefaultInboundAction=Block(Microsoft's current default with mirrored networking). xAI's OAuth redirect tohttp://127.0.0.1:56121/callbackis silently dropped before reaching the WSL VM. xAI then renders its "Could not establish connection" fallback page showing the auth code as text — but stock Hermes has no way to accept that code, so the listener times out and the code is orphaned.This PR adds the
--code-flag-equivalent that PR #27305 mentioned was needed but not yet shipped.Changes
--paste-codeflag onhermes auth add(auto-enabled when--no-browseris set, so the existing remote-session UX gets the fix for free)_xai_wait_for_callbackspins up a daemon thread that reads one line from stdin and feeds the pasted code into the same callback handler via internal HTTP (127.0.0.1:<port>/callback?code=...&state=...)UX
Why it works
The stdin reader doesn't bypass any OAuth security — the pasted code still flows through the same
_make_xai_callback_handlerthat the browser redirect would hit, which validatesstateand exchanges the code via PKCE. We just route the code over loopback inside the same kernel that's running the listener, avoiding the Windows-side firewall entirely.Affected platforms
ssh -Ltunnel option (parallel solution to OAuth loopback login broken for remote/browser-based consoles (GCP, Codespaces, etc.) #26923)Refs
--code. This is that PR.Test plan
hermes auth add xai-oauth --type oauth --no-browser --paste-codeon Beelink WSL2 — paste-from-fallback-page completes auth,auth.jsonpopulatedhermes auth add --helpshows the new--paste-codeflaghermes auth add xai-oauth --type oauthwithout--paste-codebehaves identically to before🤖 Generated with Claude Code