fix(agents): Honor shared CLI context for base URL and auth - #582
Merged
Conversation
The `nemo agents` command group resolved its own base URL (only
`--base-url`/`NEMO_BASE_URL`, else localhost) and attached no auth token,
so it silently targeted the wrong platform and was rejected (401/403) on
any secured cluster — breaking the local-to-remote deploy flow (AIRCORE-885).
Add a shared `cli_context` module (resolve_base_url, resolve_context_headers)
that reads the same CLIContext the rest of the CLI uses:
- Base URL precedence: --base-url/NEMO_BASE_URL > `nemo config`/NMP_BASE_URL
> localhost. The resolved target is echoed to stderr ("Targeting <url>")
so mis-pointed commands are visible; stdout stays clean JSON.
- Auth: attach the `nemo auth login` bearer token to the platform httpx
calls (_api_request, gateway invoke) and to the usage-report SDK client.
Applies to the platform commands and to `nemo agents usage show` (which
builds its own SDK client). The module lives outside cli.py to avoid the
cli.py <-> usage/cli.py import cycle.
Tests: base-URL precedence + auth attachment (new
test_cli_context_resolution.py), usage SDK client build with context base
URL + auth, and stdout/stderr stream separation for JSON output.
Signed-off-by: Tyler Bray <tbray@nvidia.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds shared CLI context helpers for base URL and default headers. Platform commands and usage SDK setup now resolve these values from shared context, and tests were updated for stderr-targeting output plus JSON parsing from stdout. ChangesCLI context resolution
Sequence Diagram(s)sequenceDiagram
participant CLI as Command
participant Ctx as cli_context
participant HTTP as httpx
participant SDK as NeMoPlatform
CLI->>Ctx: resolve_base_url(base_url)
Ctx-->>CLI: resolved base URL
CLI->>Ctx: resolve_context_headers()
Ctx-->>CLI: headers or {}
CLI->>HTTP: request(..., headers)
HTTP-->>CLI: response
CLI->>SDK: NeMoPlatform(base_url, default_headers)
SDK-->>CLI: platform client
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Contributor
|
mckornfield
approved these changes
Jul 7, 2026
mckornfield
left a comment
Contributor
There was a problem hiding this comment.
yay centralized config
Address review feedback: the --base-url option (and its help text) was repeated inline across all 12 platform commands plus `usage show`. Define it once in cli_context as a reusable Annotated `BaseUrlOption` (with the help text in a `BASE_URL_HELP` constant) and reuse it everywhere. Also reformat the help as a numbered resolution-order list. No behavior change. Signed-off-by: Tyler Bray <tbray@nvidia.com>
arpitsardhana
pushed a commit
that referenced
this pull request
Jul 9, 2026
* fix(agents): Honor shared CLI context for base URL and auth
The `nemo agents` command group resolved its own base URL (only
`--base-url`/`NEMO_BASE_URL`, else localhost) and attached no auth token,
so it silently targeted the wrong platform and was rejected (401/403) on
any secured cluster — breaking the local-to-remote deploy flow (AIRCORE-885).
Add a shared `cli_context` module (resolve_base_url, resolve_context_headers)
that reads the same CLIContext the rest of the CLI uses:
- Base URL precedence: --base-url/NEMO_BASE_URL > `nemo config`/NMP_BASE_URL
> localhost. The resolved target is echoed to stderr ("Targeting <url>")
so mis-pointed commands are visible; stdout stays clean JSON.
- Auth: attach the `nemo auth login` bearer token to the platform httpx
calls (_api_request, gateway invoke) and to the usage-report SDK client.
Applies to the platform commands and to `nemo agents usage show` (which
builds its own SDK client). The module lives outside cli.py to avoid the
cli.py <-> usage/cli.py import cycle.
Tests: base-URL precedence + auth attachment (new
test_cli_context_resolution.py), usage SDK client build with context base
URL + auth, and stdout/stderr stream separation for JSON output.
Signed-off-by: Tyler Bray <tbray@nvidia.com>
* refactor(agents): Extract shared --base-url typer option
Address review feedback: the --base-url option (and its help text) was
repeated inline across all 12 platform commands plus `usage show`. Define
it once in cli_context as a reusable Annotated `BaseUrlOption` (with the
help text in a `BASE_URL_HELP` constant) and reuse it everywhere. Also
reformat the help as a numbered resolution-order list.
No behavior change.
Signed-off-by: Tyler Bray <tbray@nvidia.com>
---------
Signed-off-by: Tyler Bray <tbray@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
nemo agentscommand group resolved its own base URL (only--base-url/NEMO_BASE_URL, else localhost) and attached no auth token. On any real remote this means:nemo config set --base-urlandNMP_BASE_URL(the vars the rest of the CLI honors), sodeploy/invoke/listsilently hitlocalhost:8080— and reported success against the wrong platform.Authorizationheader, every agents call is rejected on an auth-enabled cluster, even afternemo auth login.Both gate the "build local, ship remote" flow. Reported in the local→remote test run (AIRCORE-885, follow-up to the AIRCORE-867 runbook).
What changed
plugins/nemo-agents/src/nemo_agents_plugin/cli_context.py—resolve_base_url/resolve_context_headersread the sameCLIContext(typer.Context.obj) as the rest of the CLI. It lives outsidecli.pyto avoid thecli.py↔usage/cli.pyimport cycle.--base-url/NEMO_BASE_URL→nemo config/NMP_BASE_URL→ localhost. Resolved target echoed to stderr (Targeting <url>) so a mis-point is visible; stdout stays clean JSON.nemo auth loginattached to the platformhttpxcalls (_api_request, gateway invoke) and to theusage showSDK client. Falls back to unauthenticated when no token is configured (local dev unchanged).nemo agents usage show(builds its own SDK client; resolution runs only in the fileset branch that actually contacts the platform).nemo config viewerror hint is now accurate.Not regenerated: the CLI/SDK generator only owns
packages/nemo_platform_ext/.../cli/commands/api/; the agents plugin CLI is hand-written, and no API routes/models changed.Test plan
test_cli_context_resolution.py: base-URL precedence (flag/env/config/default), stderr-only banner, auth-header attach, gateway invoke, no-auth-without-context.usage show <fileset>builds the SDK client with the context base URL +Authorization: Bearer.result.stdout(banner is on stderr).ruff check,ruff format --check,ty: clean.origin/main(same pre-existing failures).Summary by CodeRabbit
--base-urldefaulting from config/env) instead of a fixed local default.nemo agents usage shownow follows the same base-URL and context behavior when platform downloads are needed.