Fix ChatGPT login: extract new device-code format and strip ANSI#7
Merged
Conversation
The Codex CLI (v0.139.0) emits a device code in a 4-then-5 format
(e.g. "IL70-LNADU"), but the extractor regex only matched 4-4. The
mismatch caused two user-visible bugs in the Login with ChatGPT flow:
- The capture loop waits for both a URL and a code before exiting; the
code never matched, so it always ran the full 15s ceiling -> the
verification page took ~15s to open.
- With no code extracted, the UI fell back to dumping the raw CLI stdout,
including ANSI color escapes, so the one-time code showed as garbled
"[90m...[94m..." text instead of a clean code.
Fixes:
- Widen _CODE_RE to {3,8}-{3,8} to accept the new (and future) formats.
- Add _ANSI_RE and strip escapes before matching. Critically this is also
done inside the capture loop: the CLI wraps the code in "\x1b[94m...",
whose trailing "m" defeats the \b boundary and would keep the early
exit from firing even with the widened regex.
Add tests/test_login_parse.py pinning the extraction (new + legacy code
formats, ANSI stripping, and a regression guard that the code is only
found after stripping). Per-file-ignore F401 for tests/__init__.py
re-export aggregators so the changed file lints clean.
Signed-off-by: Ahmed <ahmed@electroon.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
065b7f2 to
d12fb51
Compare
13 tasks
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.
What does this PR do?
Fixes the Login with ChatGPT device-code flow, which had two user-visible bugs caused by one root issue.
The Codex CLI (v0.139.0) now emits the one-time code in a 4-then-5 format (
IL70-LNADU), but_CODE_REonly matched 4-4. Because the capture loop exits early only once it has matched both a URL and a code:_LOGIN_CAPTURE_S = 15sceiling → the verification page took ~15s to open;[90m…[94m…text.Fix
_CODE_REto{3,8}-{3,8}(accepts the new and future formats)._ANSI_REand strip escapes before matching — including inside the capture loop. This is essential: the CLI wraps the code in\x1b[94m…, whose trailingmdefeats the\bboundary and would keep the early-exit from firing even with the widened regex.tests/test_login_parse.pypin extraction (new + legacy formats, ANSI stripping, and a regression guard that the code only matches after stripping).No auth-method change — ChatGPT device-auth only, engine references untouched. No JS/template/schema change.
Type of change
Checklist
tests/(taggedcodexoo)CHANGELOG.md(bullet under## [Unreleased])SECURITY.mdif this touches a safety-critical path (else N/A) — N/A: only the device-code/URL display parsing inres_users.pychanged; no tool endpoint, SQL guard, bridge token, or auth invariant is affected.git commit -s→ DCO)CODEX_HOME, CLI glob,codex_thread_id/codex_item_id)SECURITY.mdare preserved🤖 Generated with Claude Code