Skip to content

test(cli): hold every gaia command to a contract, from the parser - #7342

Merged
kovtcharov-amd merged 18 commits into
amd:mainfrom
kovtcharov:kalin/ci-cli-contract
Nov 12, 2026
Merged

kovtcharov-amd merged 18 commits into
amd:mainfrom
kovtcharov:kalin/ci-cli-contract

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

rc18 shipped four CLI bugs that one table could have caught: gaia download --list exited 0 with the model server down and listed every model as "not downloaded", gaia prompt printed its answer twice, and gaia talk --index and gaia api start sent requests to the default server instead of the one --base-url named. This adds that table. It reads every command from the CLI's own parser and runs each one for real, so a command or a --base-url flag added tomorrow is covered with no edit.

What every command is held to:

  • No traceback, for all commands the parser registers, run with the model server down.
  • For every command that takes --base-url, plus a short list of flag variants the walk cannot reach (download --list, prompt, llm, -p):
    • with --base-url X, every request goes to X and none to the server the environment names;
    • the model's answer is printed once;
    • with the server down, a command that uses it exits non-zero and says why.

What its first run found (155 cases, under three minutes in the new workflow):

Command What happens Issue
gaia api start, model server down prints the error, exits 0 new: #7344
gaia chat --base-url X, gaia -p ... --base-url X embedder, health and hardware calls still go to the default server new: #7345
schedule show / remove / pause / resume / run <unknown> traceback #7333
connectors connect <unknown> traceback #7334
mcp engineering, mcp code-index refusal shown as a traceback #7335
gateway auth with no terminal traceback #7336

All twelve are strict expected failures naming the issue, so each fix has to delete its line.

Stacked on #7331 (it uses that PR's tests/fixtures/fake_lemonade.py); the commits before "test(cli): ..." are that PR.

Test plan

  • The new CLI Contract workflow on this PR passes
  • python -m pytest tests/integration/test_cli_contract.py -k "download or prompt" -q passes locally
  • Delete a KNOWN_BUGS line and the workflow fails with that command's own output in the message
🔍 Technical details
  • Each command runs as python -m gaia.cli ... in a throwaway home with stdin closed and a 25 s limit; one still running then (a server, a prompt) is ended with its children. A daemon a command starts in that home is stopped after the run.
  • Nine command groups are never started (kill, uninstall, init, daemon, lemonade embedded, eval, test, telegram, slack), each with the reason in NEVER_STARTED; a test fails if that table names a command that no longer exists.
  • gaia gateway install is outside the --base-url rule: its flag is the gateway's address, not the model server's.
  • It has its own workflow instead of joining the unit job: about 150 subprocess runs, on Linux only, and only when src/gaia changes.

In rc18 a cloud-only user had a 5 GB local model downloaded and loaded behind
their back by the start-up warm-up, by Memory > Run Inference and by a
scheduled run. Each bug fired only from one starting state, and every test had
been written from a PC that was already set up.

tests/fixtures/fake_lemonade.py is a model server that answers like Lemonade
over real HTTP and writes down every request. The matrix crosses five starting
states with three entry points and asserts what reached the server: no local
chat model touched on a cloud setup, nothing downloaded unasked, and the local
default used where that is right.

Three cells fail on the open fixes for amd#7217 and amd#7218. Two fail on a bug the
matrix found: a scheduled run ignores a cloud model picked in the app (amd#7329).
All five are strict expected failures.
The unit job does not install the flagship package, so the start-up warm-up
cells failed there with ModuleNotFoundError. They now skip when the package
is absent, and test_gaia_agent.yml, the lane that installs it, runs the
matrix so the column is still enforced.
installer/headless/fake_model_server.py already answers like Lemonade and
logs every request, so the fixture now starts that server and reads its log
instead of carrying a second one. It plays a PC whose only downloaded models
are the ones a state names, and refuses a model that is not downloaded, so a
request for one is counted as the download it would be on a user's PC.
rc18 shipped CLI bugs a table could have caught: `gaia download --list`
exited 0 with the model server down and listed every model as missing,
`gaia prompt` printed its answer twice, and `gaia talk --index` and
`gaia api start` sent requests to the default server instead of the one
--base-url named.

The test reads every command from the CLI's own parser and runs each as a
subprocess: none may end in a traceback; a command that takes --base-url (or
is one of a few listed invocations) is also run against two recording
servers and then with none, and must send every request to the named server,
print the answer once, and exit non-zero with a reason when the server is
down. A new command, or a new --base-url flag, is covered with no edit.

It runs in its own workflow, CLI Contract, on changes to src/gaia.
The matrix's fixture starts installer/headless/fake_model_server.py, so a
change to that file has to run the lane that runs the matrix.
…ssue

The table's first run in CI (155 cases, under three minutes) found 13
failures. Nine are the tracebacks the frozen walk also found (amd#7333, amd#7334,
amd#7335, amd#7336). Three are new: `gaia api start` exits 0 after failing to reach
the model server (amd#7344), and `gaia chat` and `gaia -p` send their embedder,
health and hardware calls to the default server despite --base-url (amd#7345).

Each is a strict expected failure. `gaia gateway install` is taken out of the
--base-url rule: its flag is the gateway's address, not the model server's.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This is a solid harness. It reads every command from the CLI's own parser, runs each one for real against a fake model server that records its requests, and lists each known failure as a strict xfail that names its issue, so a fix can't land quietly. It changes only tests and CI. I found no bugs, and everything it references exists on this branch: the fake server's flags and ANSWER, build_parser, the daemon-stop helpers, the sidecar warm-up hook, and the allow_network marker. Only the new CLI Contract workflow collects the new integration file, so nothing runs it twice.

Two small, optional suggestions:

  • 🟢 The fake server can stall in a long test. It logs one line to stderr for every request, but the fixture pipes stderr and only reads it if the server fails to start. Once roughly 700 requests fill the pipe buffer, the server blocks and the test hangs until its client times out. Today's tests send a handful of requests, so nothing fails yet. Sending stderr to a file in the temp folder fixes it.
  • 🟢 A comment promises something CI doesn't do. The comment says a daemon a command starts "must die with this test run", but the setting it relies on is only passed through if it is already set, and the new workflow never sets it. The instance.json cleanup after each run is what actually stops those daemons, so either set the variable in the workflow or reword the comment.
🔍 Technical details
  • tests/fixtures/fake_lemonade.py:214-219: stderr=subprocess.PIPE is only read in the start-failure branch. fake_model_server.py:386 log_message writes [fake-lemonade] … per request, so the pipe fills after roughly 64 KB. Suggested: stderr=open(folder / "stderr.txt", "wb"), read that file for the error message, and close it in __exit__. This file comes from test: cover every starting state against a recording model server #7331, so the fix can go in either PR.
  • tests/integration/test_cli_contract.py:518-520: GAIA_DAEMON_EXIT_WITH_PID is only forwarded when the parent already has it, and test_cli_contract.yml doesn't export it. _stop_daemon (gated on instance.json) is what actually cleans up. Detached daemons are outside _end_tree's child walk, so that gate is the only cleanup they get.
  • Rubric sections checked: Sibling paths and Documentation drift don't apply (no behaviour change; tests and CI only). Release/CI ordering: the matrix test is collected by test_gaia_agent.yml with the flagship installed, and by the unit lane, where importorskip skips the warm-up cells.

kovtcharov and others added 9 commits November 11, 2026 23:57
Both fixes are on main now, so the memory-inference and warm-up cells pass
and their expected-failure lines go, as the strict marker requires. The two
scheduled-run cells (amd#7329) are the ones left.
…bug cells

The fake server logs a stderr line per request into a pipe nobody read, so it
stalled once the pipe filled: after 77 requests on Windows, ~700 on Linux. It
now logs to a file in its own folder, and a test drives 200 KB of log through
it.

A known-bug cell now only passes as expected on an assertion failure, so a
broken import or a renamed entry point fails loudly instead of reading as the
bug. The scheduled run's refused load is the request the cell judges, so that
refusal no longer ends the run before the assertion. The server is registered
for teardown as soon as it starts.
…whole tree

A daemon a command starts now gets GAIA_DAEMON_EXIT_WITH_PID set to the test
process, so it exits with the run even where the instance.json cleanup misses
it; before, the variable was only forwarded if CI happened to set it, which it
did not.

A child that exited between the listing and the kill raised and skipped the
rest of the tree, leaving the parent running past the wait. Each process is
now killed on its own.
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
…d#7346)

`gaia api start` printed that it couldn't reach the model server and
then exited 0, so a script or service manager starting it read the
failure as success. It now exits 1 after the same error message,
matching the other commands that run this check.

Closes amd#7344

## Test plan

- [x] `python -m pytest tests/unit/api tests/unit/cli` passes (652
passed, 2 skipped)
- [ ] `python -m pytest tests/unit/ -x` passes in CI. The runner was
missing the `responses` test dependency, so the full suite could not be
collected here.
- [ ] `python util/lint.py --all` passes in CI. Here, Import Validation
and Tool Descriptions fail the same way on clean `main`, and every other
check passes.
- [ ] With no model server running: `gaia api start --port 8099
--base-url http://127.0.0.1:1/api/v1; echo $?` prints the error and then
`1`

<details>
<summary>🔍 Technical details</summary>

- `handle_api_command` in `src/gaia/cli.py` ran `return` when
`initialize_lemonade_for_agent` failed. It now calls `sys.exit(1)`, as
the other callers of that helper already do.
- New test
`test_start_exits_nonzero_when_the_model_server_is_unreachable` in
`tests/unit/api/test_api_frozen.py` stubs the helper to fail. It asserts
exit code 1 and checks that uvicorn never starts.
- Once this lands, the strict expected failure for `api start` in the
CLI contract table (amd#7342) can be removed. That table isn't on `main`
yet.
</details>

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

This turns red as soon as it meets current main: gaia api start now exits non-zero with the model server down (#7344 was fixed by #7346, merged 10:10 UTC, after this branch's last CI run), so its strict expected-failure cell passes unexpectedly. Delete the ("model server", "api start") line from KNOWN_BUGS, merge main again, and re-run.

While there, please keep a timeout from flipping a known-bug cell: a command that is killed at the 25 s limit produces no traceback and no stray request, so its strict xfail reports an unexpected pass and fails the run, on a job that runs for every merge-queue group.

🔍 Technical details

# Conflicts:
#	.github/workflows/test_gaia_agent.yml
… as a fix

gaia api start now exits non-zero with the model server down (amd#7346), so
its strict known-bug cell would pass unexpectedly and fail the run.

A command stopped at the time limit prints no traceback and sends no
stray request, so a known-bug cell that timed out used to count as fixed.
It now fails, naming the issue it never reached, and the xfail is pinned
to AssertionError so that failure cannot be absorbed as the bug itself.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Done in a60dde4: the fixed gaia api start entry is gone, main is merged in, and a known-bug cell that hits the 25 s limit now fails instead of passing as fixed.

Locally (-n 4) every other known bug still reproduces, so the rest of the list stays.

🔍 Technical details

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 12, 2026
Merged via the queue into amd:main with commit 8e678b6 Nov 12, 2026
28 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/ci-cli-contract branch November 12, 2026 13:15
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
…7542)

The CLI contract test from amd#7342 misses the rc18 bug it was written to
catch. With the health check removed again, `gaia download --list`
retries each model against the dead server, is stopped at the 25 s
limit, and the test skips the exit-code check and passes. Now a command
that finishes with the server up must also finish with it down. Servers
that are still running at the limit in both runs stay exempt.

## Test plan
- [x] Removed the health check from `download --list`:
`test_model_server_contract[download --list]` fails with this change and
passed without it
- [x] Clean main: `pytest tests/integration/test_cli_contract.py -n 4`
gives 150 passed, 10 xfailed. The 2 local failures (`agent status`,
`agent health`) come from stale editable installs on the test PC, as
noted on amd#7342
- [x] Probe of all 12 model-server commands: every one that exits with
the server up also exits with it down, so no existing cell turns red
- [ ] CLI Contract workflow green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps/infrastructure changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants