Skip to content

Fix nous refresh token rotation failure in case where api key mint/retrieval fails#269

Merged
teknium1 merged 1 commit into
mainfrom
rewbs/fix-nous-refresh-token-rotation-on-key-mint-failure
Mar 5, 2026
Merged

Fix nous refresh token rotation failure in case where api key mint/retrieval fails#269
teknium1 merged 1 commit into
mainfrom
rewbs/fix-nous-refresh-token-rotation-on-key-mint-failure

Conversation

@rewbs

@rewbs rewbs commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

We observed that many users were hitting failures because the Nous refresh token was being re-used. Most of these users had also run out of subscription credits.

The root cause is that hermes-agent was not correctly persisting the new refresh token when the call to get a new API key failed (for example due to insufficient funds).

With this change, resolve_nous_runtime_credentials now persists auth state immediately after each successful refresh (including retry refreshes), uses the latest in-memory refresh token on mint-retry paths, and _save_auth_store now does atomic durable writes (temp file + fsync + replace). Added safe optional OAuth trace logging (HERMES_OAUTH_TRACE=1, fingerprint-only token IDs + sequence IDs) and regression tests covering refresh+402, refresh+timeout, and invalid-token retry behavior across retries/restarts.

@teknium1 teknium1 merged commit db58cfb into main Mar 5, 2026
@teknium1

teknium1 commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Reviewed and merged to main via db58cfb. Thanks @rewbs — solid fix for a real bug affecting users.

What was fixed:

  1. Refresh token now persisted immediately after each successful token refresh, before attempting the mint. Previously, if mint failed (402 insufficient credits, timeout, etc.), the rotated refresh token was lost permanently.
  2. Retry path now uses the latest rotated refresh token from state instead of the stale original captured at function entry.

Bonus improvements merged:

  • Atomic durable writes for auth.json (temp + fsync + os.replace)
  • Opt-in OAuth trace logging for debugging

All 3 regression tests pass. Clean code, no issues found.

angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
… key mint failure

Fixes a bug where the refresh token was not persisted when the API key
mint failed (e.g., 402 insufficient credits, timeout). The rotated
refresh token was lost, causing subsequent auth attempts to fail with
a stale token.

Changes:
- Persist auth state immediately after each successful token refresh,
  before attempting the mint
- Use latest in-memory refresh token on mint-retry paths (was using
  the stale original)
- Atomic durable writes for auth.json (temp file + fsync + replace)
- Opt-in OAuth trace logging (HERMES_OAUTH_TRACE=1, fingerprint-only)
- 3 regression tests covering refresh+402, refresh+timeout, and
  invalid-token retry behavior

Author: Robin Fernandes <rewbs>
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
… key mint failure

Fixes a bug where the refresh token was not persisted when the API key
mint failed (e.g., 402 insufficient credits, timeout). The rotated
refresh token was lost, causing subsequent auth attempts to fail with
a stale token.

Changes:
- Persist auth state immediately after each successful token refresh,
  before attempting the mint
- Use latest in-memory refresh token on mint-retry paths (was using
  the stale original)
- Atomic durable writes for auth.json (temp file + fsync + replace)
- Opt-in OAuth trace logging (HERMES_OAUTH_TRACE=1, fingerprint-only)
- 3 regression tests covering refresh+402, refresh+timeout, and
  invalid-token retry behavior

Author: Robin Fernandes <rewbs>
rafe-walker added a commit to rafe-walker/kora that referenced this pull request May 22, 2026
Phase 2 Feature 3 frontend. Pairs with CC#1 KR-FEAT-EMAIL (outbound-only after Option-D descope).

- Backend /api/email/recent stub (4 messages spanning inbound/outbound/filtered/attachment).
- EmailPanel.tsx — stats + filter pills + spoofing chip + HTML-metadata chip + attachment chip + 400-char body preview.
- Dashboard card #10 (Mail icon).

4-layer security contract with email-specific guards: no raw addresses (per-field + walk-payload) + message_id stub shape + plain-text rendering (with dangerouslySetInnerHTML ban) + walk-payload sweep for Purelymail-token-hints / HMAC-secret-shapes / bearer-token-shapes.

Layout: 10 cards = 3+3+3+1 wrapping to 3+3+4 in lg:grid-cols-3.

241/241 admin-panel tests pass across 21 suites; tsc --noEmit + vite build clean.

Flagged pre-existing: 4 tsc -b errors in HeartbeatPanel.tsx + DashboardPage.tsx from HeartbeatStatus enum drift (unknown added) and nullable last_check_at not propagated — confirmed on bare base, NOT introduced by this PR. Recommended cleanup alongside task NousResearch#269.
rafe-walker added a commit to rafe-walker/kora that referenced this pull request May 23, 2026
Closes BOTH task NousResearch#265 (slowapi placement) AND task NousResearch#269 (mcp_clients test failures — confirmed downstream of same import-chain issue per CC#2 investigation in PR #125).

- pyproject.toml: slowapi==0.1.9 moves from [web] optional-deps to runtime deps (next to aiosmtplib pin that set the precedent in PR #124).
- uv.lock regenerated.
- Exact-equals pin per the security policy in the dependencies-block header (2026-05-12 Mini Shai-Hulud response).

Base-install verification (uv sync --frozen --extra dev, NO --extra web): mcp_clients 19/19 pass (was 13 fail + 5 err); full admin-panel regression 271/271 across 23 suites.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
… key mint failure

Fixes a bug where the refresh token was not persisted when the API key
mint failed (e.g., 402 insufficient credits, timeout). The rotated
refresh token was lost, causing subsequent auth attempts to fail with
a stale token.

Changes:
- Persist auth state immediately after each successful token refresh,
  before attempting the mint
- Use latest in-memory refresh token on mint-retry paths (was using
  the stale original)
- Atomic durable writes for auth.json (temp file + fsync + replace)
- Opt-in OAuth trace logging (HERMES_OAUTH_TRACE=1, fingerprint-only)
- 3 regression tests covering refresh+402, refresh+timeout, and
  invalid-token retry behavior

Author: Robin Fernandes <rewbs>
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.

2 participants