fix: follow redirects when downloading skills in GcpSkillRegistry - #6824
fix: follow redirects when downloading skills in GcpSkillRegistry#6824codebee-aoki wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@googlebot I signed it! |
The Agent Registry media download endpoint (alt=media) responds with a 302 redirect to a short-lived GCS signed URL instead of streaming the archive directly. httpx does not follow redirects by default and its raise_for_status() raises on 3xx responses, so _make_request treated the 302 as a failure and get_skill() could never download the skill archive. Following redirects is safe here: httpx drops the Authorization header on cross-origin redirects, so the OAuth token is not forwarded to the signed-URL host (GCS would reject a signed URL carrying extra credentials anyway).
d22bc84 to
0cb0ca7
Compare
|
Confirming this reproduces against a real Agent Registry catalog on google-adk 2.7.1: every |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
GcpSkillRegistry.get_skill()fails when downloading the skill archive. The Agent Registry API serves the revision media download (?alt=media) as a302redirect to a GCS signed URL. Thehttpx.AsyncClientcreated in_create_httpx_clientdoes not follow redirects (httpx default), andresponse.raise_for_status()raises on 3xx, so the request surfaces asRuntimeError: API request failed with status 302: ....Solution:
Pass
follow_redirects=Trueto bothhttpx.AsyncClientconstructions in_create_httpx_client(the plain client and the mTLS/ssl-context client).Following redirects is safe here: httpx removes the
Authorizationheader when following a redirect to a different origin, so the OAuth bearer token is not leaked to the GCS signed-URL host (GCS would reject a signed URL carrying extra credentials anyway).Testing Plan
Unit Tests:
Added a unit test (
test_create_httpx_client_follows_redirects) asserting that clients created by_create_httpx_clienthavefollow_redirects=True, for both the default branch and the mTLS/ssl-context branch. Also updated an existing assertion (test_get_skill_with_mtls) that checked the exacthttpx.AsyncClientconstructor kwargs, since it now includesfollow_redirects=True.Manual End-to-End (E2E) Tests:
Tested end-to-end by applying the identical change (monkey-patching
GCPSkillRegistry._create_httpx_clientto passfollow_redirects=True, same two-branch logic as this PR) to an agent deployed on Agent Engine runtime. Confirmed that skill downloads from the Agent Registry — which previously failed withRuntimeError: API request failed with status 302: ...— now succeed: the?alt=mediarequest's 302 redirect to the GCS signed URL is followed and the skill archive is downloaded and loaded correctly.Checklist
Additional context
None.