From f45a7abef4df7dd8392deee68b97ad7d521cc856 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 22 Aug 2026 20:31:36 +0200 Subject: [PATCH] Pin anthropic below 1.0 and guard the SDK call contract anthropic 1.0.0 (2026-08-20) removed HUMAN_PROMPT and the temperature keyword that ai_analysis_service passes to messages.stream(). The PR Test job and the Cloud Run image both install with unpinned pip (uv.lock is dockerignored), so every new build after 2026-08-20 resolves 1.0.0: the Test job fails at collection, and a fresh production image would raise TypeError on every AI-analysis cache miss. The last production build (2026-08-19) predates 1.0.0, so production is currently unaffected. Pin anthropic>=0.97.0,<1 (pip resolves 0.99.0, which keeps both surfaces; uv.lock stays at 0.97.0) and add a contract test against the installed SDK's real Messages.stream signature, so mocked unit tests can no longer hide the next SDK break. No prompt or runtime behavior changes: the tracer prompt and the AI-analysis cache keys are untouched. The 1.x migration (drop temperature, revisit the model) is a separate change. Co-Authored-By: Claude Fable 5 --- .../anthropic-sdk-1-human-prompt.fixed.md | 1 + pyproject.toml | 2 +- .../services/test_anthropic_sdk_contract.py | 30 +++++++++++++++++++ uv.lock | 6 ++-- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 changelog.d/anthropic-sdk-1-human-prompt.fixed.md create mode 100644 tests/unit/services/test_anthropic_sdk_contract.py diff --git a/changelog.d/anthropic-sdk-1-human-prompt.fixed.md b/changelog.d/anthropic-sdk-1-human-prompt.fixed.md new file mode 100644 index 000000000..1e9499caa --- /dev/null +++ b/changelog.d/anthropic-sdk-1-human-prompt.fixed.md @@ -0,0 +1 @@ +Pin the anthropic SDK below 1.0: anthropic 1.0 (released 2026-08-20) removed HUMAN_PROMPT and the temperature keyword the AI analysis services pass to messages.stream(), and both the PR Test job and the Cloud Run image install with unpinned pip, so fresh builds would have failed at import (tests) or on AI-analysis cache misses (production). A contract test now checks the installed SDK's real stream() signature. diff --git a/pyproject.toml b/pyproject.toml index 412957b5b..fb5eeb293 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ dependencies = [ "a2wsgi>=1.10,<2", "alembic>=1.14,<2", - "anthropic", + "anthropic>=0.97.0,<1", "assertpy", "click>=8,<9", "cloud-sql-python-connector", diff --git a/tests/unit/services/test_anthropic_sdk_contract.py b/tests/unit/services/test_anthropic_sdk_contract.py new file mode 100644 index 000000000..70eec83c0 --- /dev/null +++ b/tests/unit/services/test_anthropic_sdk_contract.py @@ -0,0 +1,30 @@ +"""Guard the installed anthropic SDK against the call shape the services use. + +The AI analysis services call ``claude_client.messages.stream(...)`` with a +``temperature`` keyword. The unit suites mock the client with permissive +fakes, so an SDK whose real signature dropped that keyword (anthropic 1.x +removed ``temperature``/``top_p``/``top_k`` and ``HUMAN_PROMPT``) still +passes every mocked test while failing at runtime on a cache miss. This test +checks the real installed SDK instead. +""" + +import inspect + +import anthropic +from anthropic.resources.messages import Messages + + +def test_installed_anthropic_sdk_accepts_stream_temperature(): + parameters = inspect.signature(Messages.stream).parameters + assert "temperature" in parameters, ( + f"anthropic {anthropic.__version__} no longer accepts temperature in " + "Messages.stream(); migrate ai_analysis_service before raising the pin" + ) + + +def test_installed_anthropic_sdk_is_pre_1_0(): + major = int(anthropic.__version__.split(".")[0]) + assert major < 1, ( + f"anthropic {anthropic.__version__} installed; pyproject pins <1 until " + "the services are migrated to the 1.x call surface" + ) diff --git a/uv.lock b/uv.lock index d9d78904b..e9dacf541 100644 --- a/uv.lock +++ b/uv.lock @@ -2487,7 +2487,7 @@ name = "pexpect" version = "4.9.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "ptyprocess" }, + { name = "ptyprocess", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/42/92/cc564bf6381ff43ce1f4d06852fc19a2f11d180f23dc32d9588bee2f149d/pexpect-4.9.0.tar.gz", hash = "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f", size = 166450, upload-time = "2023-11-25T09:07:26.339Z" } wheels = [ @@ -2642,7 +2642,7 @@ models = [ [[package]] name = "policyengine-api" -version = "3.48.2" +version = "3.49.1" source = { editable = "." } dependencies = [ { name = "a2wsgi" }, @@ -2695,7 +2695,7 @@ dev = [ requires-dist = [ { name = "a2wsgi", specifier = ">=1.10,<2" }, { name = "alembic", specifier = ">=1.14,<2" }, - { name = "anthropic" }, + { name = "anthropic", specifier = ">=0.97.0,<1" }, { name = "assertpy" }, { name = "build", marker = "extra == 'dev'" }, { name = "click", specifier = ">=8,<9" },