Skip to content

fix(cli): exit cleanly with a re-login hint on an expired/invalid token (#3231)#3240

Open
abhay-codes07 wants to merge 1 commit into
omnigent-ai:mainfrom
abhay-codes07:fix/3231-credential-rejection-clean-exit
Open

fix(cli): exit cleanly with a re-login hint on an expired/invalid token (#3231)#3240
abhay-codes07 wants to merge 1 commit into
omnigent-ai:mainfrom
abhay-codes07:fix/3231-credential-rejection-clean-exit

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

Related issue

Closes #3231

Summary

An expired or invalid access token crashed the CLI. On the daemon-chat path sdk.sessions.create raised an uncaught OmnigentError (the auto-reported crash was {'error_code': 403, 'message': 'Invalid access token. [ReqId: ...]'}). It propagated to main's catch-all except Exception, which handed it to the friendly crash handler — so the user got the calm crash screen and a prompt to file a GitHub issue for what is really just their own lapsed credentials, and the crash handler auto-reported it.

A 401/403 from the server against our own credentials is user-actionable (sign in again), not a bug to report. main now recognizes that case, prints a re-login hint pointing at omnigent login, and exits 1 — without the crash screen or the bug-filing prompt. Every other error still routes to the crash handler unchanged.

Detection is a small pure helper, credential_rejection_hint, keyed on the error's HTTP status (the client SDK's OmnigentError sets status_code; server-side errors set http_status) rather than substring-matching a message. That helper fully captures the routing decision; the glue in main is three lines that print the hint and exit when it returns non-None.

Test Plan

tests/cli/test_credential_rejection_hint.py (new):

OMNIGENT_SKIP_WEB_UI=true uv run pytest tests/cli/test_credential_rejection_hint.py -q
# 10 passed

Without the change the suite errors at import (the helper does not exist); with it, all 10 pass. ruff check + ruff format --check clean.

Demo

N/A. CLI error-handling change with no visual surface of its own. Before: an expired token renders the crash screen and prompts the user to file a GitHub issue (and auto-reports it). After: Authentication failed: the server rejected your credentials (HTTP 403). Your login may have expired — run \omnigent login ` to sign in again.` and a clean exit 1.

Type of change

  • Bug fix
  • Feature
  • UI / frontend change
  • Refactor / chore
  • Docs
  • Test / CI
  • Breaking change

Test coverage

  • Unit tests added / updated
  • Integration tests added / updated
  • E2E tests added / updated
  • Manual verification completed
  • Existing tests cover this change
  • Not applicable

Coverage notes

The helper is pure and covers the full routing decision (which statuses are treated as credential rejections vs. handed to the crash handler), including the real-world #3231 body shape reconstructed via the SDK. The three-line glue in main (print hint + SystemExit(1) when the helper returns a message) is verified by reading; a full main() invocation is intentionally not driven since it installs the crash handler, migrates state, and sets up logging.

Changelog

An expired or invalid login now exits with a clear "run omnigent login" hint instead of showing the crash screen and prompting to file a bug report.

…en (omnigent-ai#3231)

An expired or invalid access token surfaced as an uncaught
OmnigentError (e.g. `{'error_code': 403, 'message': 'Invalid access
token...'}`) from `sdk.sessions.create` on the daemon-chat path. It
propagated to `main`'s catch-all, which handed it to the friendly crash
handler -- so the user got the calm crash screen and a prompt to FILE A
GITHUB ISSUE for what is really just their own lapsed credentials. It was
also auto-reported by the crash handler.

A 401/403 from the server against our own credentials is user-actionable
(sign in again), not a bug to report. `main` now recognizes that case and
prints a re-login hint pointing at `omnigent login`, then exits 1 without
the crash screen or the bug-filing prompt. Every other error still routes
to the crash handler unchanged.

Detection is a small pure helper `credential_rejection_hint` keyed on the
error's HTTP status (the client SDK sets `status_code`; server-side
errors set `http_status`), so it does not rely on substring matching a
message. The real omnigent-ai#3231 body shape -- a proxy 403 that is not the
`{"error": {...}}` envelope, which makes the SDK stringify the whole body
as the message -- is covered by reconstructing it through the SDK's own
`raise_for_status`.

Signed-off-by: abhay-codes07 <abhaysingh0293@gmail.com>
Copilot AI review requested due to automatic review settings July 24, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions
github-actions Bot requested a review from PattaraS July 24, 2026 14:36
@github-actions github-actions Bot added the size/M Pull request size: M label Jul 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@abhay-codes07 This PR is a Bug fix, Feature, or UI / frontend change but the Demo section is missing or only contains a placeholder.

These change types require a screenshot or screen recording so reviewers can see the new behaviour without checking out the branch. Please update the Demo section with:

  • A screenshot or screen recording of the change, or
  • A link to a hosted video or GIF showing the new behaviour.

Use N/A only when the change has no user-visible effect whatsoever (e.g. a pure refactor or test-only change). If that's the case, uncheck the relevant type box and check Refactor / chore or Test / CI instead.

@github-actions github-actions Bot added the needs-demo PR needs a demo screenshot or recording label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-demo PR needs a demo screenshot or recording size/M Pull request size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Crash] OmnigentError: {'error_code': 403, 'message': 'Invalid access token. [ReqId: 145ae51b-da74-40a7-ac56-0ad190834faf]'}

3 participants