fix(auth): recover stale codex auth from CLI session#3279
Conversation
|
Nice fix direction. This addresses the real stale-Codex-auth failure mode. I tested a similar recovery path locally and found a few follow-up changes that would make this safer before merge:
The current recovery path appears to persist imported Codex tokens into Safer pattern:
I?d keep the trigger narrow:
I?d avoid using broader backend failure classes as recovery triggers. Temporary auth-service outages or malformed backend responses are not evidence that Hermes should replace its local auth from another store.
A few auth messages still point users toward
Suggested regression tests:
I prototyped this locally and verified the following behavior:
I?m not planning to open a competing PR here, but wanted to leave the safety delta in one place in case it?s useful before merge. |
0657e45 to
e7a89bd
Compare
|
Thanks for the submission @lsaether. Closing as superseded — relied on the CLI auth-sync path removed by #12360. Hermes's Codex auth design was reworked in #12360 ("Hermes owns its own Codex auth; stop touching The valid adjacent fixes from this batch (error parsing, fallback chain on auth failure, reauth UX) landed together in #15104. |
Title
fix(auth): recover stale codex auth from CLI session
Summary
~/.codex/auth.jsonalready contains a newer valid CLI sessionrelogin_requiredWhy
Hermes keeps its own Codex auth store in
~/.hermes/auth.jsonto avoid refresh-token rotation conflicts with Codex CLI. In practice, the two stores can drift:Before this change, Hermes would try to refresh its stale session, fail, and force a manual re-login even though a valid Codex CLI session already existed on the machine.
What changed
_refresh_codex_auth_tokens(), raw HTTP 401 responses now setrelogin_required=Trueresolve_codex_runtime_credentials(), Hermes only attempts CLI-session recovery when the refresh failure actually indicates the Hermes session is invalid and requires re-authentication~/.codex/auth.jsoninto Hermes's auth store without writing back to the Codex CLI storeHow to test
~/.hermes/auth.json~/.codex/auth.jsonresolve_codex_runtime_credentials()Test plan
python3 -m py_compile hermes_cli/auth.py tests/test_auth_codex_provider.pyuv run --with pytest --with pytest-xdist python -m pytest -q tests/test_auth_codex_provider.pyPlatforms tested
Notes
~/.codex/auth.json