Skip to content

refactor(auth): Disable Nous Portal legacy session key inference fallback — JWT-only - #34508

Merged
kshitijk4poor merged 5 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/nous-jwt-only-33759
May 29, 2026
Merged

refactor(auth): Disable Nous Portal legacy session key inference fallback — JWT-only#34508
kshitijk4poor merged 5 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/nous-jwt-only-33759

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented May 29, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

Salvage of #33759 by @rewbs onto current main, plus two follow-up cleanup commits.

Removes the Nous Portal legacy opaque session-key inference fallback. Nous inference now accepts only inference:invoke JWTs:

  • Existing usable invoke JWTs are reused (no network refresh).
  • Stale or non-JWT OAuth access tokens are refreshed once via the OAuth refresh endpoint.
  • The refreshed JWT is mirrored into the existing agent_key compatibility field, so older local config layouts (opaque agent_key + valid refresh token) migrate cleanly.
  • When no refresh material is available, the resolver returns a clear relogin_required error (run: hermes auth add nous) rather than silently minting a legacy key.

Deleted machinery: _mint_agent_key, _choose_nous_inference_auth_path, NOUS_INFERENCE_AUTH_MODE_LEGACY, legacy scope constants, device-code scope fallback, HERMES_AGENT_USE_LEGACY_SESSION_KEYS handling, and the proxy retry-with-legacy-session-key path.

Commits / attribution

  • refactor(auth): Disable Nous legacy session key fallback@rewbs
  • fix(auth): address Nous JWT fallback review@rewbs
  • test(auth): update nous jwt-only expectations@rewbs
  • refactor(auth): drop weak JWT-shape fallback in auxiliary _nous_api_key — follow-up (this salvage)
  • refactor(auth): remove vestigial Nous min_key_ttl/inference_auth_mode params — follow-up (this salvage)

Follow-up 1 — _nous_api_key fallback

Removed the import-failure fallback in agent/auxiliary_client._nous_api_key that returned any 3-segment token without scope/expiry validation — a divergent reimplementation of the canonical _nous_invoke_jwt_is_usable. Since that import comes from the same module that provides resolve_nous_runtime_credentials, an import failure means the whole auxiliary Nous path is unavailable anyway; it now returns "" so the caller falls through to the clear re-auth guidance.

Follow-up 2 — dead-code removal

After the legacy path was removed, two parameters became dead surface on the Nous runtime-resolution chain:

  • min_key_ttl_secondsdel'd inside refresh_nous_oauth_pure, pass-through / telemetry-only everywhere else. It controlled the now-deleted agent-key mint TTL.
  • inference_auth_mode — with the legacy mode gone, AUTO and FRESH are behaviorally identical; it only fed validation + trace output, never a branch.

Removing them orphaned the supporting cluster (NOUS_INFERENCE_AUTH_MODE_AUTO/FRESH, NOUS_INFERENCE_AUTH_MODES, _normalize_nous_inference_auth_mode, DEFAULT_AGENT_KEY_MIN_TTL_SECONDS) — all deleted. Every caller updated; two tests exercising the removed surface deleted. No behavior change; net −134 LOC of dead code. Confirmed zero remaining references to all removed symbols across the codebase.

Test plan

scripts/run_tests.sh tests/hermes_cli/test_auth_nous_provider.py \
  tests/hermes_cli/test_web_oauth_dispatch.py tests/hermes_cli/test_proxy.py \
  tests/agent/test_auxiliary_client.py tests/agent/test_credential_pool.py \
  tests/run_agent/test_run_agent.py tests/hermes_cli/test_nous_inference_url_validation.py \
  tests/run_agent/test_provider_parity.py tests/hermes_cli/test_auth_commands.py \
  tests/hermes_cli/test_runtime_provider_resolution.py tests/cli/test_cli_provider_resolution.py \
  tests/hermes_cli/test_auth_profile_fallback.py

1032 passed, 0 failed. ruff clean on changed files; git diff --check clean.

Closes #33759

rewbs and others added 5 commits May 29, 2026 14:16
The import-failure fallback returned any 3-segment token without scope/
expiry validation, a divergent reimplementation of the canonical
_nous_invoke_jwt_is_usable check. The import is from the same module that
provides resolve_nous_runtime_credentials, so a failure means the whole
auxiliary Nous path is unavailable anyway; return "" instead so the caller
falls through to the clear 'run: hermes auth add nous' guidance rather than
handing back an unvalidated token.
… params

After the legacy session-key path was removed, two parameters became dead
surface on the Nous runtime-resolution chain:

- min_key_ttl_seconds: del'd inside refresh_nous_oauth_pure and pass-through /
  telemetry-only in refresh_nous_oauth_from_state, _try_import_shared_nous_state,
  _nous_device_code_login, and resolve_nous_runtime_credentials. It controlled the
  now-deleted agent-key mint TTL and drives no behavior.
- inference_auth_mode: with the legacy mode gone, AUTO and FRESH are behaviorally
  identical; the value only fed _normalize_nous_inference_auth_mode validation and
  oauth trace output, never a branch.

Removing inference_auth_mode orphaned its whole supporting cluster
(NOUS_INFERENCE_AUTH_MODE_AUTO/FRESH, NOUS_INFERENCE_AUTH_MODES,
_normalize_nous_inference_auth_mode), and dropping min_key_ttl_seconds orphaned
DEFAULT_AGENT_KEY_MIN_TTL_SECONDS — all deleted here.

Updated every caller (run_agent, auxiliary_client, credential_pool, proxy adapter,
runtime_provider, web_server, main, auth_commands, setup) and pruned the matching
test kwargs. Deleted two tests that exercised the removed surface
(test_legacy_auth_mode_is_rejected, test_try_refresh_..._accepts_explicit_auth_mode).

No behavior change: net -134 LOC of dead code.
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools provider/nous Nous Research API (OAuth) labels May 29, 2026
@kshitijk4poor
kshitijk4poor merged commit a22c250 into NousResearch:main May 29, 2026
19 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/nous-jwt-only-33759 branch August 5, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/nous Nous Research API (OAuth) type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants