Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

deploy push reads AMP's comparison refusal by its code (#8161)

João Mouraaa5f2acd9b48
diff --git a/lib/cli/src/crewai_cli/deploy/main.py b/lib/cli/src/crewai_cli/deploy/main.py
index 96d0912a1..882bfbc19 100644
--- a/lib/cli/src/crewai_cli/deploy/main.py
+++ b/lib/cli/src/crewai_cli/deploy/main.py
@@ -193,14 +193,21 @@ def _response_failure_reason(response: httpx.Response) -> DeployFailureReason |
def _refuse_on_running_comparison(response: httpx.Response) -> None:
"""AMP held the push back because a models comparison is running on the
deployment (a redeploy would stop it and lose its runs): say so in AMP's
- own sentence, which names `--force`, and exit 1 — nothing was deployed."""
+ own sentence, which names `--force`, and exit 1 — nothing was deployed.
+
+ AMP names the refusal in `code`; its `error` carries the sentence, which is
+ what a CLI without this function prints. An AMP from before that change
+ named it in `error` and is still recognised."""
if response.status_code != 409:
return
try:
body = response.json()
except ValueError:
return
- if not isinstance(body, dict) or body.get("error") != "comparison_running":
+ if not isinstance(body, dict) or "comparison_running" not in (
+ body.get("code"),
+ body.get("error"),
+ ):
return
# AMP's words, printed as they are: Rich markup in them (a bracketed
# word, a stray closing tag) must neither vanish nor raise.
diff --git a/lib/cli/tests/deploy/test_deploy_main.py b/lib/cli/tests/deploy/test_deploy_main.py
index 0bb846409..c3991864e 100644
--- a/lib/cli/tests/deploy/test_deploy_main.py
+++ b/lib/cli/tests/deploy/test_deploy_main.py
@@ -457,11 +457,17 @@ class TestDeployCommand(unittest.TestCase):
self.mock_client.crew_status_by_uuid.return_value = self._status_response(zip_deployment=False)
held = MagicMock()
held.status_code = 409
+ sentence = (
+ "A models comparison is running on this deployment (started 05:03 UTC): redeploying now "
+ "stops it, and the runs under way are lost. Wait for it to finish, or redeploy anyway from the "
+ "deployment's page, or with `crewai deploy push --force` (a crewAI CLI newer than 1.15.28)."
+ )
+ # AMP's 409: the sentence in `error` too, for CLIs that print only that
held.json.return_value = {
- "error": "comparison_running",
- "message": "A models comparison is running on this deployment (started 05:03 UTC): redeploying now "
- "stops it, and the runs under way are lost. Wait for it to finish, or redeploy anyway with "
- "`crewai deploy push --force`.",
+ "error": sentence,
+ "code": "comparison_running",
+ "message": sentence,
+ "evaluation": {"id": "a78a325f-9e04-4962-94b3-1280003333e3", "started_at": "2026-10-14T05:03:00Z"},
}
self.mock_client.deploy_by_uuid.return_value = held
@@ -474,6 +480,7 @@ class TestDeployCommand(unittest.TestCase):
self.assertIn("`crewai deploy push --force`", printed)
self.assertIn("Nothing was deployed.", printed)
self.assertNotIn("comparison_running", printed)
+ self.assertNotIn("Request to Enterprise API failed", printed)
mock_display.assert_not_called()
ok = MagicMock()
@@ -485,6 +492,88 @@ class TestDeployCommand(unittest.TestCase):
self.mock_client.deploy_by_uuid.assert_called_once_with("test-uuid", force=True)
mock_display.assert_called_once_with({"uuid": "test-uuid"})
+ @patch("crewai_cli.deploy.main.create_project_zip")
+ @patch("crewai_cli.deploy.main.fetch_and_json_env_file")
+ @patch("crewai_cli.deploy.main.git.Repository")
+ @patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info")
+ def test_amps_refusal_is_recognised_on_every_route_in_either_shape(
+ self, mock_display, mock_repository, mock_fetch_env, mock_create_project_zip
+ ):
+ """AMP names the refusal in `code`, its `error` carrying the sentence; an
+ AMP from before named it in `error`. Either way, deploying by id, by name
+ or through a ZIP update, the CLI says why and deploys nothing."""
+ sentence = (
+ "A models comparison is running on this deployment (started 05:03 UTC): "
+ "redeploying now stops it, and the runs under way are lost."
+ )
+ shapes = {
+ "named in code": {
+ "error": sentence,
+ "code": "comparison_running",
+ "message": sentence,
+ },
+ "named in error": {"error": "comparison_running", "message": sentence},
+ }
+ # route: (deploy kwargs, status call, zip deployment, AMP call, origin)
+ routes = {
+ "by id": (
+ {"uuid": "test-uuid"},
+ "crew_status_by_uuid",
+ False,
+ "deploy_by_uuid",
+ "https://github.com/test/repo.git",
+ ),
+ "by name": (
+ {},
+ "crew_status_by_name",
+ False,
+ "deploy_by_name",
+ "https://github.com/test/repo.git",
+ ),
+ "zip update": (
+ {"uuid": "test-uuid"},
+ "crew_status_by_uuid",
+ True,
+ "update_crew_from_zip",
+ None,
+ ),
+ }
+ mock_fetch_env.return_value = {}
+ mock_create_project_zip.return_value = Path("/tmp/test_project.zip")
+ mock_repository.return_value.create_initial_commit_if_needed.return_value = (
+ False
+ )
+ for route, (kwargs, status_call, zip_deployment, call, origin) in routes.items():
+ for shape, body in shapes.items():
+ with self.subTest(route=route, shape=shape):
+ self.mock_client.reset_mock()
+ mock_display.reset_mock()
+ mock_repository.return_value.origin_url.return_value = origin
+ getattr(
+ self.mock_client, status_call
+ ).return_value = self._status_response(
+ zip_deployment=zip_deployment
+ )
+ held = MagicMock()
+ held.status_code = 409
+ held.json.return_value = body
+ getattr(self.mock_client, call).return_value = held
+
+ with (
+ patch("sys.stdout", new=StringIO()) as out,
+ self.assertRaises(SystemExit) as stopped,
+ ):
+ self.deploy_command.deploy(skip_validate=True, **kwargs)
+
+ self.assertEqual(stopped.exception.code, 1)
+ printed = " ".join(out.getvalue().split())
+ self.assertIn(sentence, printed)
+ self.assertIn("Nothing was deployed.", printed)
+ self.assertNotIn("comparison_running", printed)
+ self.assertNotIn("Request to Enterprise API failed", printed)
+ getattr(self.mock_client, call).assert_called_once()
+ mock_display.assert_not_called()
+
@patch("crewai_cli.deploy.main.git.Repository")
@patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info")
def test_amps_hold_back_sentence_is_printed_literally_whatever_brackets_it_has(
@@ -496,7 +585,8 @@ class TestDeployCommand(unittest.TestCase):
held = MagicMock()
held.status_code = 409
held.json.return_value = {
- "error": "comparison_running",
+ "error": "A comparison [bold]running[/] on [crew] [/unmatched] — redeploy with --force.",
+ "code": "comparison_running",
"message": "A comparison [bold]running[/] on [crew] [/unmatched] — redeploy with --force.",
}
self.mock_client.deploy_by_uuid.return_value = held