Skip to content

fix(auth): add User-Agent header to Qwen OAuth refresh (closes #7746) - #7751

Closed
ten-ltw wants to merge 1 commit into
NousResearch:mainfrom
ten-ltw:fix/qwen-oauth-refresh-user-agent
Closed

fix(auth): add User-Agent header to Qwen OAuth refresh (closes #7746)#7751
ten-ltw wants to merge 1 commit into
NousResearch:mainfrom
ten-ltw:fix/qwen-oauth-refresh-user-agent

Conversation

@ten-ltw

@ten-ltw ten-ltw commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #7746 — Qwen OAuth token refresh silently fails with invalid JSON because the refresh request is missing a User-Agent header. The Qwen OAuth server returns a non-JSON response (HTML / redirect) when the header is absent.

Root Cause

Reported by @gxmst in issue #7746:

  • qwen-code-api sends User-Agent: QwenCode/0.14.0 (linux; x64) during token refresh and works fine
  • Hermes _refresh_qwen_cli_tokens() sends no User-Agent, causing the OAuth server to return a non-JSON response
  • Hermes then calls response.json() on that response and raises a confusing invalid JSON error

Changes

hermes_cli/auth.py:

  • Added _QWEN_USER_AGENT = "HermesAgent/1.0" constant
  • Added User-Agent: HermesAgent/1.0 to the httpx.post headers in _refresh_qwen_cli_tokens()
  • Improved the qwen_refresh_invalid_json error message to include:
    • HTTP status code
    • Content-Type header
    • Response body preview (first 200 chars)

tests/hermes_cli/test_auth_qwen_provider.py:

  • test_refresh_qwen_cli_tokens_sends_user_agent_header: verifies the User-Agent header is sent with the correct value
  • test_refresh_qwen_cli_tokens_invalid_json_error_includes_diagnostics: verifies diagnostics are surfaced in the error message

How to Test

# 31/31 tests pass (29 existing + 2 new)
uv venv .venv --python 3.11 && source .venv/bin/activate
uv pip install -e ".[all,dev]"
python -m pytest tests/hermes_cli/test_auth_qwen_provider.py -v

# Manual test (requires real Qwen credentials):
hermes qwen auth qwen-oauth
hermes chat  # trigger token refresh

Related Issue

Fixes #7746

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: qwen-oauth refresh fails with invalid JSON, while the same ~/.qwen/oauth_creds.json works in qwen-code-api

1 participant