-
Notifications
You must be signed in to change notification settings - Fork 8
chore: release main #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stainless-app
wants to merge
2
commits into
main
Choose a base branch
from
release-please--branches--main--changes--next
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
chore: release main #411
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| ".": "0.13.1", | ||
| ".": "0.14.0", | ||
| "adk": "0.13.1" | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
|
||
| __title__ = "agentex" | ||
| __version__ = "0.13.1" # x-release-please-version | ||
| __version__ = "0.14.0" # x-release-please-version |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| """Runtime SDK ↔ backend contract-version guard. | ||
|
|
||
| Complements the *build-time* cross-version compatibility tests (``tests/compat``): | ||
|
|
||
| - **Build-time** (CI): is this *client* compatible with the window of supported server | ||
| contracts (``min-supported``..``current``)? | ||
| - **Runtime** (this module): is the *server* the SDK is pointed at within that window? | ||
|
|
||
| It runs once at ACP/worker startup, reads the backend's contract version (the version | ||
| the server already reports via ``/openapi.json`` ``info.version``), and **fails fast with | ||
| an actionable error** if the backend is older than this SDK supports — instead of the | ||
| mismatch surfacing later as opaque 500s / missing-field errors deep in a request. | ||
|
|
||
| ``MIN_BACKEND_CONTRACT`` is the same source of truth as the ``min-supported`` server | ||
| contract in ``tests/compat/server_specs/manifest.json``: the oldest agentex backend this | ||
| SDK version supports. Bump both together when a breaking change raises the floor. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
| import httpx | ||
|
|
||
| from agentex.lib.utils.logging import make_logger | ||
|
|
||
| logger = make_logger(__name__) | ||
|
|
||
| # Oldest agentex backend contract this SDK is compatible with. | ||
| # Keep in sync with the `min-supported` spec in tests/compat (#407); the version axis | ||
| # itself comes from scale-agentex release tags (#321). Bump on a breaking SDK change. | ||
| MIN_BACKEND_CONTRACT = "0.1.0" | ||
|
|
||
| SKIP_ENV = "AGENTEX_SKIP_VERSION_CHECK" | ||
|
|
||
| # Full-string SemVer. Accepts: `1.2.3`, leading `v`, surrounding whitespace, `-prerelease` | ||
| # (captured), `+build` (ignored). Anchored at both ends so a malformed tail (`0.1.0rc1`, | ||
| # `0.1.0.1`) is rejected → None → "unknown, proceed", not silently coerced to stable `0.1.0`. | ||
| _VERSION_RE = re.compile( | ||
| r"^\s*v?(\d+)\.(\d+)\.(\d+)" # major.minor.patch | ||
| r"(?:-([0-9A-Za-z.-]+))?" # optional -prerelease (captured) | ||
| r"(?:\+[0-9A-Za-z.-]+)?" # optional +build metadata (ignored) | ||
| r"\s*$" | ||
| ) | ||
|
|
||
|
|
||
| class IncompatibleBackendError(RuntimeError): | ||
| """Raised when the agentex backend is older than this SDK's minimum supported contract.""" | ||
|
|
||
|
|
||
| def _parse(version: str | None) -> tuple[int, int, int, str | None] | None: | ||
| """Parse ``major.minor.patch[-prerelease]`` → ``(major, minor, patch, prerelease)``. | ||
|
|
||
| ``prerelease`` is the raw dot-separated identifier string (e.g. ``"rc.1"``), or None for | ||
| a stable release. Build metadata (after ``+``) is ignored. Returns None if unparseable. | ||
| """ | ||
| m = _VERSION_RE.match(version or "") | ||
| if not m: | ||
| return None | ||
| return (int(m.group(1)), int(m.group(2)), int(m.group(3)), m.group(4) or None) | ||
|
|
||
|
|
||
| # Comparable SemVer precedence key. The 4th element keeps a uniform shape across stable and | ||
| # prerelease so the whole tuple is orderable: (rank, identifiers), where stable rank 1 > prerelease | ||
| # rank 0 (and the identifier list is only ever compared when both sides are prereleases, rank 0). | ||
| _PreKey = tuple[int, int, int, tuple[int, list[tuple[int, int, str]]]] | ||
|
|
||
|
|
||
| def _precedence_key(parsed: tuple[int, int, int, str | None]) -> _PreKey: | ||
| """SemVer §11 precedence key (directly comparable with ``<``). | ||
|
|
||
| A stable release outranks any prerelease of the same triplet (``0.1.0-rc.1 < 0.1.0``); | ||
| among prereleases, numeric identifiers rank below alphanumeric and compare field-by-field, | ||
| with a longer identifier list outranking a shorter prefix-equal one. | ||
| """ | ||
| major, minor, patch, prerelease = parsed | ||
| if prerelease is None: | ||
| return (major, minor, patch, (1, [])) # stable sorts above every prerelease | ||
| identifiers: list[tuple[int, int, str]] = [] | ||
| for ident in prerelease.split("."): | ||
| if ident.isdigit(): | ||
| identifiers.append((0, int(ident), "")) # numeric: lowest class, numeric order | ||
| else: | ||
| identifiers.append((1, 0, ident)) # alphanumeric: higher class, lexical order | ||
| return (major, minor, patch, (0, identifiers)) | ||
|
|
||
|
|
||
| def _truthy(name: str) -> bool: | ||
| return os.environ.get(name, "").strip().lower() in ("1", "true", "yes", "on") | ||
|
|
||
|
|
||
| async def fetch_backend_version(base_url: str, *, timeout: float = 5.0) -> str | None: | ||
| """Return the backend's reported contract version (``/openapi.json`` ``info.version``), or None.""" | ||
| url = base_url.rstrip("/") + "/openapi.json" | ||
| try: | ||
| async with httpx.AsyncClient(timeout=timeout) as client: | ||
| resp = await client.get(url) | ||
| resp.raise_for_status() | ||
| return (resp.json().get("info") or {}).get("version") | ||
| except Exception as exc: # noqa: BLE001 - any failure → unknown, handled by caller | ||
| logger.warning("backend version guard: could not fetch %s (%s)", url, exc) | ||
| return None | ||
|
|
||
|
|
||
| async def assert_backend_compatible( | ||
| base_url: str | None, | ||
| *, | ||
| min_version: str = MIN_BACKEND_CONTRACT, | ||
| sdk_version: str | None = None, | ||
| ) -> None: | ||
| """Fail fast at startup if the backend is older than ``min_version``. | ||
|
|
||
| No-op (warns, does not raise) when: | ||
| - ``AGENTEX_SKIP_VERSION_CHECK`` is set (explicit bypass), | ||
| - ``base_url`` is unset, | ||
| - the backend version can't be determined (unreachable / unparseable) — a transient | ||
| blip or a contract-less server shouldn't crash startup. | ||
|
|
||
| Raises ``IncompatibleBackendError`` only when the backend version is *known* and older | ||
| than ``min_version``. | ||
| """ | ||
| if _truthy(SKIP_ENV): | ||
| logger.warning("%s set — skipping backend version guard", SKIP_ENV) | ||
| return | ||
| if not base_url: | ||
| return | ||
|
|
||
| if sdk_version is None: | ||
| from agentex._version import __version__ as sdk_version # local import to avoid cycles | ||
|
|
||
| backend_version = await fetch_backend_version(base_url) | ||
| if backend_version is None: | ||
| logger.warning( | ||
| "backend version guard: could not determine backend version at %s; proceeding " | ||
| "(set %s=1 to silence).", | ||
| base_url, | ||
| SKIP_ENV, | ||
| ) | ||
| return | ||
|
|
||
| backend, minimum = _parse(backend_version), _parse(min_version) | ||
| if backend is None or minimum is None: | ||
| logger.warning( | ||
| "backend version guard: unparseable version(s) backend=%r min=%r; proceeding.", | ||
| backend_version, | ||
| min_version, | ||
| ) | ||
| return | ||
|
|
||
| if _precedence_key(backend) < _precedence_key(minimum): | ||
| raise IncompatibleBackendError( | ||
| f"agentex-sdk {sdk_version} requires agentex backend >= {min_version}, " | ||
| f"but {base_url} reports {backend_version}. " | ||
| f"Upgrade the backend, or pin agentex-sdk to a version compatible with backend " | ||
| f"{backend_version}. (Set {SKIP_ENV}=1 to bypass at your own risk.)" | ||
| ) | ||
|
|
||
| logger.info( | ||
| "backend version guard OK: sdk=%s backend=%s (min=%s)", | ||
| sdk_version, | ||
| backend_version, | ||
| min_version, | ||
| ) |
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
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
Empty file.
Empty file.
70 changes: 70 additions & 0 deletions
70
tests/lib/core/temporal/workers/test_worker_version_guard.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """AgentexWorker wires the backend version guard into worker startup. | ||
|
|
||
| A Temporal worker runs as its own process and never goes through the ACP server | ||
| lifespan, so the guard must run inside `_register_agent` — before `register_agent`, | ||
| and only when `AGENTEX_BASE_URL` is set. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import Mock, AsyncMock | ||
|
|
||
| import pytest | ||
|
|
||
| from agentex.lib.core.temporal.workers import worker as worker_mod | ||
| from agentex.lib.core.compat.version_guard import IncompatibleBackendError | ||
|
|
||
|
|
||
| def _worker(): | ||
| # explicit health_check_port so __init__ doesn't read EnvironmentVariables | ||
| return worker_mod.AgentexWorker(task_queue="test-queue", health_check_port=8080) | ||
|
|
||
|
|
||
| def _patch_env(monkeypatch, base_url): | ||
| env = Mock() | ||
| env.AGENTEX_BASE_URL = base_url | ||
| fake_cls = Mock() | ||
| fake_cls.refresh.return_value = env | ||
| monkeypatch.setattr(worker_mod, "EnvironmentVariables", fake_cls) | ||
| return env | ||
|
|
||
|
|
||
| async def test_guard_runs_before_register_agent(monkeypatch): | ||
| env = _patch_env(monkeypatch, "http://backend") | ||
| order: list[str] = [] | ||
| guard = AsyncMock(side_effect=lambda *a, **k: order.append("guard")) | ||
| register = AsyncMock(side_effect=lambda *a, **k: order.append("register")) | ||
| monkeypatch.setattr(worker_mod, "assert_backend_compatible", guard) | ||
| monkeypatch.setattr(worker_mod, "register_agent", register) | ||
|
|
||
| await _worker()._register_agent() | ||
|
|
||
| guard.assert_awaited_once_with("http://backend") | ||
| register.assert_awaited_once_with(env) | ||
| assert order == ["guard", "register"] # guard must precede registration | ||
|
|
||
|
|
||
| async def test_incompatible_backend_blocks_registration(monkeypatch): | ||
| _patch_env(monkeypatch, "http://backend") | ||
| guard = AsyncMock(side_effect=IncompatibleBackendError("backend too old")) | ||
| register = AsyncMock() | ||
| monkeypatch.setattr(worker_mod, "assert_backend_compatible", guard) | ||
| monkeypatch.setattr(worker_mod, "register_agent", register) | ||
|
|
||
| with pytest.raises(IncompatibleBackendError): | ||
| await _worker()._register_agent() | ||
|
|
||
| register.assert_not_awaited() # fail fast — never register against an unsupported backend | ||
|
|
||
|
|
||
| async def test_no_base_url_skips_guard_and_registration(monkeypatch): | ||
| _patch_env(monkeypatch, None) | ||
| guard = AsyncMock() | ||
| register = AsyncMock() | ||
| monkeypatch.setattr(worker_mod, "assert_backend_compatible", guard) | ||
| monkeypatch.setattr(worker_mod, "register_agent", register) | ||
|
|
||
| await _worker()._register_agent() | ||
|
|
||
| guard.assert_not_awaited() | ||
| register.assert_not_awaited() |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new runtime guard is implemented under
src/agentex/lib, but the rootagentex-clientwheel excludessrc/agentex/lib/**; those files ship from theagentex-sdk/ADK package instead. This manifest bumps only the root client package while leavingadkat0.13.1, and the ADK package metadata still points atagentex-sdk0.13.1, so publishing this release can advertise the startup version guard without publishing the package that containsBaseACPServer,AgentexWorker, orcompat.version_guard. Users upgrading the ADK package would still run without the guard. Please release/bump the ADK package for this change as well, and keep its client dependency aligned if it depends on the co-released client version.Prompt To Fix With AI