Fix: exit non-zero when an adk deploy subcommand fails - #212
Open
AmaadMartin wants to merge 3 commits into
Open
Conversation
added 3 commits
August 10, 2026 16:44
All three `adk deploy` subcommands printed `Deploy failed: <reason>` and then returned normally, so the process exited 0. A shell chain such as `adk deploy cloud_run ... && echo deployed` therefore continued past a deploy that never happened, and a CI stage gated on `$?` passed. Each handler now calls `ctx.exit(1)` after the existing message. `agent_engine` and `gke` take the click context through `@click.pass_context`; `cloud_run` already had it. The message text, its colour, and the `--help` output do not change.
`cli_deploy_agent_engine` and `cli_deploy_gke` now take the click context, which click injects and never declares as an option. The cloud_run check already ignored `ctx` for the same reason. Every real option still has to match a function parameter.
…ntext `ctx.exit(1)` obliged `cli_deploy_agent_engine` and `cli_deploy_gke` to take a click context they had no other use for, and that injected `ctx` parameter in turn forced an exemption into the option/parameter parity tests. `sys.exit(1)` needs neither. It already follows a red `secho` this way in `cli_test`, and it keeps the message and colour unchanged. This also reverts the parity-test exemption, so those tests match main again.
7 tasks
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Link to an existing issue (if applicable):
Or, if no issue exists, describe the change:
Problem: All three
adk deploysubcommands printDeploy failed: <reason>in red and then return normally, so the process exits 0.adk deploy cloud_run ... && echo deployedprintsdeployedafter a deploy that never happened, and a CI stage gated on$?passes. The broadexcept Exceptionalso swallows thegcloudCalledProcessError, the gcloud argument-conflictClickException, and theagent_enginemutually-exclusive-flagUsageError.Solution: Each handler adds one line,
sys.exit(1), after the existing message.cli_tools_click.py:1053-1059already pairs a redsechowithsys.exit(1)in a callback that holds no click context, so this needs no@click.pass_contextplumbing and keeps the message text and colour byte-for-byte. No traceback is printed, and--helpoutput is unchanged for all three subcommands.This is an intentional behaviour change. A pipeline that continued past a failed deploy now stops there.
cli_migrate_sessionhas the same defect. It is deliberately out of scope:adk migrate sessionis a different command, and its behaviour change deserves its own review and its own test. I filed it as separate work.Collision check: I listed all 211 open pull requests on the fork and read the diff of every one that touches
cli_tools_click.pyorcli_deploy.py(#183, #194, #17, #158, #62, #64, #91, #109, #124, #120, #72, #70, #197). None changes the deploy exception handlers, so this PR is branched frommain.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
pytest tests/unittests/cli -q-> 775 passed, 5 skipped, 4 xfailed.I wrote the tests first and ran them against the unfixed code. All six assertions failed with
assert 0 != 0. I then deleted eachsys.exit(1)one at a time and confirmed only the matching tests fail:sys.exit(1)incli_deploy_cloud_run..._cloud_run_failure,..._cloud_run_gcloud_failure_exits_non_zero,..._cloud_run_gcloud_arg_conflictsys.exit(1)incli_deploy_agent_engine..._agent_engine_failure,..._agent_engine_conflicting_import_flags_exit_non_zero,..._agent_engine_failure_exit_status_of_real_processsys.exit(1)incli_deploy_gke..._gke_failureCoverage of the new code is 100%: a
coveragerun over the deploy tests marks all threesys.exit(1)lines as executed, and the success tests cover the non-exception branch.One existing test changes:
test_cli_deploy_cloud_run_failureassertedexit_code == 0. That assertion encoded the bug, so it is now!= 0.Manual End-to-End (E2E) Tests:
test_cli_deploy_agent_engine_failure_exit_status_of_real_processruns the real CLI as a subprocess, becauseCliRunneronly reports a simulated exit code. It skips where the interpreter cannot be spawned. The same commands by hand, with no cloud project and no mocks:deployedis printed before this change and is not printed after it. No traceback appears.adk deploy cloud_run --help,adk deploy agent_engine --helpandadk deploy gke --helpstill exit 0, and I diffed their output againstmain: it is identical.CI on this branch: Unit Tests, Mypy Check and A2A v0.3 Tests pass on Python 3.10 through 3.14. The Pre-commit Linter job fails on its
update-constraintshook, which regenerates theconstraints-3.*.txtsnapshot date. That failure is unrelated to this change and reproduces on every open pull request here, including #209, #210 and #211. Every other hook,ruff,isortandpyinkincluded, passes.Locally I also ran
mypyoncli_tools_click.pybefore and after: 93 errors both times, the same set, no new error.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.