Skip to content

cleanup: deferred Nous review refinements#61

Merged
jramos merged 1 commit into
mainfrom
cleanup/nous-followup-refinements
May 15, 2026
Merged

cleanup: deferred Nous review refinements#61
jramos merged 1 commit into
mainfrom
cleanup/nous-followup-refinements

Conversation

@jramos
Copy link
Copy Markdown
Owner

@jramos jramos commented May 15, 2026

Summary

Follow-up to PR #60. Five small refinements deferred from that PR's review pass — none change correctness; all sharpen clarity, error messages, or save a round-trip on a rare path.

Change Why
_force_remint pre-checks OAuth expiry When inference 401s and OAuth is also expiring, refresh first instead of mint→401→refresh→mint. Saves one round-trip on the rare double-stale path. The mint's own 401 retry still backstops portal-side OAuth revocation.
_parse_error_body falls back to body-text snippet on JSON parse failure A CDN HTML error page or portal outage returning text previously degraded to "unknown: status N" with no diagnostic. Now includes up to 512 chars of raw body so an operator can correlate the failure.
_format_oauth_error matches "reused" against the code field, not the free-form detail Previously a substring search on detail could false-positive on unrelated portal messages like "this is not a reusable connection". Regression test added.
_maybe_resolve_nous_lm docstring trimmed The 20-line protocol re-explanation collapsed to a 6-line summary pointing at nous_lm.py for the canonical model. Three places were documenting the two-stage credential model independently; trimming two reduces the drift surface.
_oauth_needs_refresh_agent_key_needs_mint cross-reference The two methods make opposite choices on unknown-expiry (OAuth: don't refresh; agent_key: do re-mint). Each now acknowledges the other's asymmetric reasoning.
Tighten _sync_from_shared_state + _absorb_mint_response + initial-mint comments Strip what-the-code-does docstrings; add a why-this-shape docstring on the state-mutating method that didn't have one.

Test plan

  • 4 new tests added: _force_remint with stale OAuth (proves refresh-first ordering + Bearer carries refreshed token), _parse_error_body fallback to body text, regression guard against the "reusable connection" false-positive, empty-body fallback to status-only.
  • Full suite: 954 tests pass (was 950 + 4 new).
  • Manual smoke (tests/manual/nous_smoke.py) still passes all 5 scenarios.
  • CI green on Python 3.10/3.11/3.12/3.13.

Out of scope

The third place documenting the two-stage model — docs/model_resolution.md's Nous Portal section — stays detailed because that's the user-facing entrypoint. The trimming above only consolidates the internal documentation to one canonical location (nous_lm.py).

Follow-up to the review pass on the Nous OAuth + agent_key work. Five
small refinements that improve clarity or reduce a rare extra hop, none
of which change correctness:

_force_remint pre-checks OAuth expiry. When inference 401s and we
force a re-mint, an OAuth that's also expiring is now refreshed first
instead of being discovered via mint-401-triggers-refresh-retry. Saves
one round-trip on the rare double-stale path (mint+refresh+mint = 2
hops vs the previous mint+401+refresh+mint = 3). The mint's own 401
retry still backstops portal-side OAuth revocation that wasn't visible
through the skew check.

_parse_error_body falls back to a body-text snippet when the response
isn't JSON. A CDN HTML error page or a portal outage that returns
text/plain previously degraded to a generic "unknown: status N" with
no diagnostic. Now the error message includes up to 512 chars of the
raw body so an operator can correlate the failure with what came back.

_format_oauth_error tightens the "reuse" check to match the explicit
code field, not the free-form detail string. Previously a substring
search on detail could false-positive on unrelated portal messages
like "this is not a reusable connection". Test added as a regression
guard.

Comment cleanup. _maybe_resolve_nous_lm docstring trimmed from a
~20-line protocol re-explanation to a 6-line summary that points at
nous_lm.py for the canonical model. Three places previously documented
the two-stage credential model independently; trimming two reduces the
drift surface. _sync_from_shared_state lost its restate-the-body
docstring. _absorb_mint_response gained a docstring documenting the
api_key/agent_key field-name fallback and the expires_at-vs-expires_in
precedence. _oauth_needs_refresh and _agent_key_needs_mint now cross-
reference each other where they intentionally diverge on the unknown-
expiry default (OAuth: don't refresh, mint backstops; agent_key: do
re-mint, no equivalent backstop).

Initial-mint comment trimmed to the cost-shape rationale only — the
"missing or already expiring" half restated _ensure_credentials's
already-clear name.
@jramos jramos merged commit 08a5422 into main May 15, 2026
4 checks passed
@jramos jramos deleted the cleanup/nous-followup-refinements branch May 15, 2026 18:46
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.

1 participant