fix(cli): exit cleanly when no ChatGPT token is present - #33
fix(cli): exit cleanly when no ChatGPT token is present#33robotlearning123 wants to merge 1 commit into
Conversation
The most common first-run state is "installed + registered with the MCP client, but `codex login` / `gpt2agent setup` not run yet" — no token exists. Spawning `gpt2agent run [--stdio]` in that state raised a bare RuntimeError out of BackendClient() inside build_server(), dumping a backend.py traceback into the MCP client's server logs. The unauthenticated-HTTP-bind refusal already exits cleanly via SystemExit; the far more common missing-token path did not. Make them consistent: introduce TokenNotFoundError (a RuntimeError subclass, so existing `except RuntimeError` handlers and tests keep working) and catch it in main() to exit 1 with the actionable one-line message instead of a traceback. Verified: `HOME=<empty> gpt2agent run --stdio` now prints "No ChatGPT token found — run `codex login` or `gpt2agent setup` (...)" and exits 1 with no traceback; server still boots normally when a token is present. Adds regression tests; full suite green (325 passed), ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013CXqaBdbZMKH99Tv78AhGX
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The most common first-run state for a new user is installed + registered with the MCP client, but
codex login/gpt2agent setupnot run yet — so no token exists. Theinstallflow does not require a token (it prints "No auth.json yet, run codex login"), so this state is normal after a one-line install + client restart.In that state, the MCP client spawns
gpt2agent run --stdio, which raised a bareRuntimeErrorout ofBackendClient()insidebuild_server()and dumped abackend.pytraceback into the client's MCP server logs:The unauthenticated-HTTP-bind refusal path right below it already exits cleanly via
SystemExit; the far more common missing-token path did not. This is a launch-quality inconsistency.Fix
TokenNotFoundError(RuntimeError)inbackend.pyand raise it (instead of bareRuntimeError) from_load_token_with_source(). It's aRuntimeErrorsubclass, so every existingexcept RuntimeErrorhandler andpytest.raises(RuntimeError, ...)assertion keeps working unchanged.server.main()and exit1with the actionable one-line message viaSystemExit— matching the HTTP-bind refusal path — instead of a traceback.Before / after (real output)
Server still boots normally when a token is present (verified: exit 0 on stdin close).
Tests
Adds
tests/test_audit_2026_07_13_startup.py:TokenNotFoundErroris aRuntimeErrorsubclass and is raised on missing token.main()withrun --stdioand no token raisesSystemExitcarrying the actionable message (no traceback).Full suite: 325 passed, 9 skipped;
ruff checkclean.🤖 Generated with Claude Code