diff --git a/libs/cli/langgraph_cli/deploy.py b/libs/cli/langgraph_cli/deploy.py index dd4e7e051..525f9d5de 100644 --- a/libs/cli/langgraph_cli/deploy.py +++ b/libs/cli/langgraph_cli/deploy.py @@ -512,6 +512,12 @@ def find_deployment_by_name( for resource in listed: if resource.get("name") == name and resource.get("id"): return ExistingDeployment(str(resource["id"]), _source_of(resource)) + if len(listed) >= MAX_PAGE_SIZE: + raise click.ClickException( + "This workspace has more deployments than the CLI can search, so it " + f"cannot tell whether '{name}' already exists. Pass --deployment-id to " + "update an existing deployment." + ) return None diff --git a/libs/cli/tests/unit_tests/test_deploy_helpers.py b/libs/cli/tests/unit_tests/test_deploy_helpers.py index 292aff97e..3ea3931a9 100644 --- a/libs/cli/tests/unit_tests/test_deploy_helpers.py +++ b/libs/cli/tests/unit_tests/test_deploy_helpers.py @@ -1149,3 +1149,33 @@ def test_finding_a_deployment_by_name_returns_none_when_the_server_has_no_match( ) assert find_deployment_by_name(client, "agent") is None + + +def test_a_full_page_without_a_match_refuses_to_claim_the_name_is_free(): + page = [ + {"id": f"dep-{index}", "name": f"other-agent-{index}"} for index in range(100) + ] + client = HostBackendClient( + "https://api.example.com", + "key", + transport=httpx.MockTransport( + lambda req: httpx.Response(200, json={"resources": page}) + ), + ) + + with pytest.raises(click.ClickException, match="--deployment-id"): + find_deployment_by_name(client, "brand-new-agent") + + +def test_a_partial_page_without_a_match_means_the_name_is_free(): + client = HostBackendClient( + "https://api.example.com", + "key", + transport=httpx.MockTransport( + lambda req: httpx.Response( + 200, json={"resources": [{"id": "dep-1", "name": "other"}]} + ) + ), + ) + + assert find_deployment_by_name(client, "brand-new-agent") is None