Skip to content

fix(cli): accept backend flags only on commands that honour them - #4310

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/cli-agent-backend-parent
Sep 26, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:claude/cli-agent-backend-parent

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

gaia prompt "hi" --use-claude and --base-url http://remote… still answered from local Lemonade, so users thought they had a Claude or remote answer when they didn't. Twenty subcommands also accepted eight backend flags they never read (e.g. gaia kill --use-claude --stream). Now prompt honours --base-url, --use-claude and --claude-model. Every command accepts only the flags its handler reads.

Behaviour change: a flag that used to be accepted and silently ignored is now a usage error (exit 2). For example, gaia kill --use-claude, gaia prompt --max-steps 3 and gaia llm --use-claude now fail with "unrecognized arguments". No in-tree script, CI workflow or doc used any of these combinations.

Test plan

  • pytest tests/unit/cli/test_cli_backend_flags.py: 102 failed on main, 128 passed + 1 skipped with the fix. Covers non-agent commands rejecting the flags with exit 2, each command keeping the flags it reads, and prompt --base-url reaching create_client(base_url=…) through main().
  • Neighbouring CLI/daemon/installer/config/llm unit tests, run with isolated GAIA_HOME/GAIA_DAEMON_HOME: 861 passed, 2 skipped
  • black, isort and pylint pass on the changed files; util/check_doc_links.py passes
  • gaia kill --use-claude exits 2; gaia prompt hi --list-tools is rejected
  • gaia prompt "say ok" --base-url http://127.0.0.1:9/api/v1 --no-lemonade-check now tries the given URL instead of localhost
  • gaia prompt "hi" --use-claude against the real Claude API (the local venv lacks anthropic and a key)

Fixes #4217

`gaia prompt --use-claude` and `--base-url` were accepted and then ignored, so the answer came from local Lemonade while the user believed it came from Claude or a remote server. Twenty subcommands inherited eight agent-backend flags from one shared parent parser, and most of them never read those flags.

- Split the shared parent into logging/common flags for every command plus
  model, base-url, Claude, trace, and agent-loop parents. Each command now
  gets only the flags its handler reads. An unread flag is a usage error
  (exit 2) instead of a silent no-op.
- `gaia prompt` now passes --base-url to the Lemonade client, and
  --use-claude/--claude-model build a Claude client.
- `gaia email` keeps --trace for the in-flight daemon-relay trace fix.

Fixes amd#4217
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This makes gaia prompt actually honour --use-claude and --base-url instead of quietly answering from local Lemonade, and stops ~20 subcommands from accepting eight backend flags they never read. The split into per-capability parent parsers is clean, and I traced every place the CLI reads these flags — nothing left behind reads a flag its command no longer defines, so the behaviour change should be limited to the intended "unrecognized arguments" errors.

One thing worth fixing before merge: gaia talk keeps four of these flags but still ignores three of them. --model, --use-claude and --claude-model never reach the voice session — the model you pass is dropped and the answer still comes from local Lemonade. That's the exact bug this PR fixes for prompt. The PR description explains talk is waiting on #3616, which is reasonable, but the new flag table added here tells users talk honours them today, and an existing docs example already shows gaia talk --model …. Either pass the model through (a one-line change) or footnote the table so the docs don't promise something that doesn't happen yet. The same applies more mildly to gaia email --trace, which is accepted and unread pending #3346.

Real-world evidence

No evidence-bundle.md was produced for this run, so I'm relaying what the PR description itself shows. The changed surface is the CLI, and the description carries matching CLI evidence: gaia kill --use-claude exits 2, gaia prompt hi --list-tools is rejected, and gaia prompt "say ok" --base-url http://127.0.0.1:9/api/v1 --no-lemonade-check now targets the given URL instead of localhost. That covers the rejection behaviour and the --base-url fix.

The one gap the author already calls out: gaia prompt "hi" --use-claude has not been run against the real Claude API (no anthropic package or key locally). The unit test for that path mocks create_client, so it proves the right client is requested, not that the request succeeds. Worth one real run before this is considered proven end to end. No test environment was available to me here (pytest is not installed in this checkout), so the rest of my verdict rests on static review.

🔍 Technical details

🟡 talk keeps backend flags its handler never reads (src/gaia/cli.py:1315, 770)

talk_parser takes *llm_backend_parents, but the talk branch of async_main builds TalkConfig(...) without ever passing kwargs["model"], and TalkConfig has no base_url/Claude fields at all. So:

  • --model — silently dropped; TalkConfig.model stays at its DEFAULT_MODEL_NAME default. docs/reference/features.mdx:149 documents gaia talk --model Qwen3-0.6B-GGUF …, which is a no-op today.
  • --use-claude / --claude-model — read only by initialize_lemonade_for_agent to skip the Lemonade pre-check; TalkSDK then builds a Lemonade-backed session anyway.
  • --base-url does take effect, via LemonadeManager.ensure_ready(base_url=…) at src/gaia/cli.py:167.

This contradicts the rule stated in the new comment at src/gaia/cli.py:105 ("an unread flag is a usage error, not a silent no-op") and the table at docs/reference/cli.mdx:3293. The model pass-through is one line:

        config = TalkConfig(
            model=kwargs.get("model") or DEFAULT_MODEL_NAME,
            whisper_model_size=kwargs.get("whisper_model_size", "base"),

If the Claude wiring must wait for #3616, a footnote on the --use-claude row ("accepted by talk; wiring lands in #3616") keeps the table honest. Same treatment for the --trace row and email, which is accepted at src/gaia/cli.py:1368 but read nowhere in-tree.

🟢 --use-chatgpt loses its migration message outside chat/prompt/talk

main() still checks getattr(args, "use_chatgpt", False) and calls parser.error(REMOVED_PROVIDER_MESSAGE) (src/gaia/cli.py:3453), but the hidden flag now lives only on claude_parser. gaia llm --use-chatgpt used to print the "configure your model in Lemonade / see the gateway-migration doc" guidance and now prints a bare unrecognized arguments. Low impact — the flag is argparse.SUPPRESS'd — but it's a small loss of actionable-error quality against the CLAUDE.md fail-loudly guidance.

🟢 GaiaCliClient(use_claude=True) with no claude_model sets self.model = None

At src/gaia/cli.py:342, self.model = claude_model overwrites the constructor default with None when a programmatic caller omits claude_model (the CLI always supplies claude-sonnet-4-20250514, so this can't fire from argv). ClaudeProvider recovers via its own default (src/gaia/llm/providers/claude.py:184), but self.model stays None in the debug log and in generate(model=self.model). Mirroring the parser default closes it:

            self.model = claude_model or "claude-sonnet-4-20250514"

🟢 test_non_agent_commands_reject_backend_flags only asserts exit code 2

The comment at tests/unit/cli/test_cli_backend_flags.py:331 is honest about why, and the baseline test does most of the work. Still, on the subcommand-bearing entries (eval, mcp, api) a future refactor could start rejecting the argv for an unrelated reason and the test would stay green. Asserting "unrecognized arguments" in stderr for the flat commands would tighten it without much cost.

Verified clean

I audited every read of model / base_url / use_claude / claude_model / trace / max_steps / stream / list_tools off the parsed namespace to check for AttributeError on commands that lost a flag:

  • All reads in src/gaia/cli.py outside chat/prompt/talk/llm/email/api/stats/mcp-start use getattr(args, …, default).
  • The direct args.model reads at src/gaia/cli.py:3243, 4251, 4461 belong to eval tasks run / eval agent / eval benchmark, which define their own --model (2395, 2109, 2237).
  • args.base_url at 7689/7789/7801 is mcp start, which now gets base_url_parser.
  • agent configure --model (src/gaia/cli_agent.py:210) and the eval/tool_cost.py / eval/pdf_document_generator.py __main__ parsers are self-contained.
  • No error/remedy string in src/ or hub/ emits a gaia <cmd> --<backend-flag> combination that would now fail tests/unit/test_remedy_commands_are_runnable.py.
  • No duplicate option registrations — --base-url, --use-claude, --trace, --max-steps, --stream, --list-tools are each defined exactly once (plus the independent top-level --base-url at 1084).
  • No in-tree workflow, script or doc uses a now-rejected combination; the --use-claude hits in util/launch-tui-*.ps1 and docs/reference/eval.mdx:587 are the Go gaia-drive binary, not this parser.

Strengths

  • The per-capability parent parsers (model_parser, base_url_parser, claude_parser, trace_parser, agent_loop_parser) are the right shape — composable, and the llm_backend_parents bundle keeps the call sites readable.
  • The test file is genuinely good: a baseline test proving each argv parses without the flag is what makes the exit-2 assertions meaningful, and test_prompt_passes_base_url_to_client drives real main() rather than stopping at the parser.
  • The behaviour change is called out explicitly in the PR description with the reasoning for each command, and the docs table at docs/reference/cli.mdx:3289 gives users one place to look when a flag stops being accepted.

…mand

`gaia llm --use-chatgpt` printed a bare "unrecognized arguments" instead of
the migration message explaining where the provider went, so a user following
an old doc or script got no hint about what to do next. Same for `gaia email`.

Splitting the backend flags into per-capability parents put the hidden
`--use-chatgpt` on the Claude parent, which only chat, prompt and talk take.
But `--use-chatgpt` is not a backend capability — it names a REMOVED provider
and exists only so main() can answer with the migration guidance. It now has
its own parent, attached to every command that picks an LLM backend: chat,
prompt, talk, llm and email.

Commands that never pick a provider (kill, stats, api …) still reject it as a
plain usage error, which is the behaviour this PR intends.

Caught by CI on Linux py3.10/py3.12 and the macOS smoke job via
tests/unit/test_removed_llm_providers.py. Parametrized the new coverage across
all five commands so a later parser change can't drop the message from one of
them unnoticed.
# Conflicts:
#	docs/reference/cli.mdx
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Fixed the CI regression, and main is merged in.

gaia llm --use-chatgpt answered with a bare "unrecognized arguments" instead of the migration guidance explaining where the provider went — so anyone following an old doc or script got no hint about what to do next. gaia email had the same gap. Both now print the actionable message again, while commands that never pick a provider (kill, stats, api …) keep rejecting the flag outright, which is what this PR intends.

🔍 Technical details

Root cause. Splitting the backend flags into per-capability parents put the hidden --use-chatgpt on claude_parser, which only chat, prompt and talk take. But --use-chatgpt is not a backend capability — it names a removed provider and is parsed solely so main() can reach parser.error(REMOVED_PROVIDER_MESSAGE). On llm and email argparse rejected it before main() ever saw it.

Fix. It now has its own removed_provider_parser, added to llm_backend_parents and attached to llm and email — every command that picks an LLM backend. claude_parser keeps only the flags that really are Claude-specific.

Verified on the real CLI

Run against this checkout (PYTHONPATH pinned — the ambient editable install resolves to a different worktree):

gaia llm --use-chatgpt hello    exit=2  cli.py: error: The openai/litellm providers ... were removed because they disca…
gaia prompt --use-chatgpt hi    exit=2  (same)
gaia chat --use-chatgpt         exit=2  (same)
gaia talk --use-chatgpt         exit=2  (same)
gaia email --use-chatgpt        exit=2  (same)
gaia kill --use-chatgpt         exit=2  cli.py: error: unrecognized arguments: --use-chatgpt

The last line is the intended behaviour, not a miss — kill selects no provider.

Tests

tests/unit/test_removed_llm_providers.py::test_real_cli_returns_actionable_migration_error (the job that caught this on Linux py3.10/py3.12 and macOS smoke) reproduced locally and now passes.

Added to tests/unit/cli/test_cli_backend_flags.py, parametrized so a later parser change cannot silently drop the message from one command:

  • test_removed_provider_flag_gets_migration_guidance across all five LLM-backend commands — drives real main() and asserts the guidance text and that "unrecognized arguments" is absent, which is what the old test could not distinguish.
  • test_removed_provider_flag_stays_a_usage_error_elsewhere pins kill / stats / api to the plain usage error, so the fix cannot drift into re-accepting the flag everywhere.

Without the fix: 3 fail (llm, email, and the CI subprocess test). With it: 148 passed, 1 skipped.

Merge

origin/main merged. One real conflict in docs/reference/cli.mdx: main added a paragraph about an agent running out of steps, this PR narrowed --max-steps from "any agent command" to gaia chat. Resolved by keeping both — main's new paragraph plus this PR's narrowing, which matches agent_loop_parser being chat-only. Verified no conflict markers repo-wide and AST-parsed both changed .py files.

Full sweep tests/unit/cli tests/unit/test_removed_llm_providers.py tests/unit/test_email_cli.py tests/unit/test_inference_location.py: 470 passed, 11 failed — all 11 are test_cli_smoke.py console-script checks asserting shutil.which("gaia-cli"/"gaia-mcp"/…) is not None. They need pip install -e . shims on PATH, which this sandbox lacks; they never import the parser. python util/lint.py --black --isort --fix clean.

Still open from the review

The 🟡 talk item is untouched: --model, --use-claude and --claude-model are still accepted there but never reach the voice session, pending #3616. The flag table added in this PR still implies otherwise, so it needs either the one-line model pass-through or a footnote before merge.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit c1cee09 Sep 26, 2026
33 of 35 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/cli-agent-backend-parent branch September 26, 2026 04:09
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
…g another (amd#4334)

`gaia email --base-url <url>` used to health-check the given Lemonade
server and then triage on a different one: whatever the daemon's email
sidecar was already using. So users pointing email at another server got
a passing check and requests to the wrong place. The flag now fails with
exit 2 and says what works: restart the daemon with `LEMONADE_BASE_URL`
set. The email agent already honours that variable.

Rejecting the flag was one of the two options in the issue. Wiring it
through would mean adding a per-request server field to the frozen
sidecar query contract, and letting any daemon client repoint the email
agent's inference. That's a design decision, so this PR doesn't make it.

Overlaps:
- amd#4310 lists `email` as accepting `--base-url`. With this PR it's still
accepted at parse time and then rejected in the handler, so that table
needs a note if both merge.
- amd#3346 adds a row to the same `gaia email` options table. Expect a
trivial doc conflict there.

## Test plan
- [x] `python -m pytest tests/unit/test_email_cli.py -q`: the new test
fails on `main` (1 failed, 3 passed) and passes on this branch (4
passed)
- [x] `python -m pytest tests/unit/cli tests/unit/test_email_cli.py
tests/unit/test_email_autonomy_cli.py tests/unit/test_amd_gaia_urls.py
tests/unit/test_email_sidecar_relay.py -q`: 348 passed, 7 skipped
- [x] `gaia email --base-url http://x:1/api/v1 -q hi` exits 2 with the
guidance, and no daemon or Lemonade call is made
- [x] black, isort, pylint (repo config) on `src/gaia/cli.py`; `python
util/check_doc_links.py --internal-only`

Fixes amd#4312

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI changes documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): backend flags are accepted and silently ignored on 19 subcommands

2 participants