Skip to content

fix(protocol): strip trailing slashes from base_url in protocol client - #520

Open
saiyam-jain-dev wants to merge 3 commits into
scaleapi:mainfrom
saiyam-jain-dev:fix/protocol-client-trailing-slash
Open

saiyam-jain-dev wants to merge 3 commits into
scaleapi:mainfrom
saiyam-jain-dev:fix/protocol-client-trailing-slash

Conversation

@saiyam-jain-dev

@saiyam-jain-dev saiyam-jain-dev commented Nov 6, 2026 •

Copy link
Copy Markdown

What and why

In agentenv-protocol's client, _rpc, get_card, and invoke_extension concatenated endpoints directly onto base_url. When callers pass a base_url with a trailing slash (such as http://host:port/), the constructed URLs contain duplicate slashes (//agentenv, //.well-known/agent-env.json, //endpoint). This can cause 404s or redirects on strict HTTP servers and reverse proxies, and breaks prefix matching in request_headers.

While fetch_interface already stripped trailing slashes, the other request methods did not.

This change:

  • Strips trailing slashes from base_url in _rpc, get_card, and invoke_extension.
  • Ensures extension endpoints are formatted with a single leading slash.
  • Adds unit tests in test_client.py verifying that trailing slashes are stripped and canonical URLs are requested.

How it was tested

  • Ran pytest on packages/agentenv-protocol/tests/test_client.py (44 passed).
  • Ran ruff check on protocol client and tests.
  • Ran check_plugin_api.py against origin/main (no plugin surface changes).

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

Normalizes request URLs when base_url ends with slashes.

  • Protocol requests join base addresses and paths with one separator.

The earlier missing-slash test concern is addressed by test_invoke_extension_ensures_leading_slash_on_relative_endpoint. Since the previous review, only the missing-endpoint test was added. No new actionable issues were found. Tests were inspected, not run.

Reviews (3) · Last reviewed commit: "test(protocol): assert invoke_extension ..." · Reviewed by Greptile

@saiyam-jain-dev
saiyam-jain-dev requested a review from a team as a code owner November 6, 2026 22:23
@saiyam-jain-dev

Copy link
Copy Markdown
Author

Added test_invoke_extension_ensures_leading_slash_on_relative_endpoint asserting that endpoints lacking a leading slash are properly formatted with exactly one slash.

@andrewpark-scaleai andrewpark-scaleai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I ran test_client.py (45 passed), and 3 of the new tests fail against main, so they cover the bug.

Two optional follow-ups:

  • A few other places still join base_url by concatenation: env_gateway_provider.py:1674,1678, env_provider.py:125, and website/conformance.py:90. A trailing slash still produces // there. It might be worth normalizing base_url once where it enters, or noting the remaining gap in the description.
  • If a card leaves out endpoint, invoke_extension now raises AttributeError on None.startswith. Previously it built http://hostNone. A clear ValueError would be friendlier.

@saiyam-jain-dev

Copy link
Copy Markdown
Author

Added an explicit unit test verifying that invoke_extension raises ValueError when an extension card omits endpoint. Noted the other concatenation locations (env_gateway_provider.py, env_provider.py, website/conformance.py) for a separate follow-up normalization pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants