Repository navigation
Conversation
AgentaSingleton.init() derived self.host from AGENTA_API_URL /
AGENTA_API_INTERNAL_URL using the unanchored `_api_url.rsplit("/api", 1)[0]`.
This matched the literal substring "/api" anywhere in the URL, including
inside the host itself. For an internal base URL whose host is literally
"api" (e.g. "http://api:8000"), this corrupted the host - dropping the port -
and broke the OTLP trace endpoint built from it.
Add strip_api_suffix() in sdk/utils/helpers.py, which uses
urllib.parse.urlsplit/urlunsplit to only ever trim a trailing "/api"
segment from the URL's path component, leaving scheme/host/port untouched
regardless of what the host is named. init.py now calls this helper instead
of the raw string split.
Add regression tests covering a host literally named "api", a host
containing "api" as a substring with and without a trailing /api segment,
a host with a port, and existing normal cases (with/without trailing /api).
Fixes Agenta-AI#6787
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Member
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.
Fixes #6787.
Root cause:
sdks/python/agenta/sdk/utils/init.pydid_api_url.rsplit("/api", 1)[0]on the raw URL string, unanchored to a path segment. For a host literally namedapi(e.g.http://api:8000), the substring/apimatches insidehttp://api:8000itself (the//+api), splitting it intohttp:/+:8000— losing the port and corrupting the host. The trace endpoint becamehttp://api/otlp/v1/tracesinstead ofhttp://api:8000/api/otlp/v1/traces.Fix: new
strip_api_suffix(url)helper inutils/helpers.pyusingurllib.parse.urlsplit/urlunsplit— only strips a trailing/apisegment from the path component (checked viapath.endswith("/api"), naturally segment-anchored), leaving scheme/host/port untouched.init.pynow calls this instead of the rawrsplit.Added regression tests in
sdks/python/oss/tests/pytest/unit/test_trace_endpoint_url.py: 9 parametrized cases onstrip_api_suffixdirectly (including the exacthttp://api:8000repro, host+suffix combos, and a non-anchored/myapicase that must NOT be stripped), plus 4 cases reproducing the full host→trace-endpoint derivation frominit.py.Verified: 17/17 tests pass (
uv run pytest).ruff format/ruff checkclean on all three changed files.