Skip to content

fix(cli): remove shadowing local json import breaking A2A setup#6345

Open
AnayGarodia wants to merge 1 commit into
google:mainfrom
AnayGarodia:fix-a2a-json-unboundlocal
Open

fix(cli): remove shadowing local json import breaking A2A setup#6345
AnayGarodia wants to merge 1 commit into
google:mainfrom
AnayGarodia:fix-a2a-json-unboundlocal

Conversation

@AnayGarodia

Copy link
Copy Markdown

Fixes #6332

Running adk api_server --a2a (or get_fast_api_app(..., a2a=True)) silently mounts no A2A routes. The gemini_enterprise_app_name block near the end of get_fast_api_app has a redundant function-local import json. Because of that local import, json is a local variable for the entire function, so the earlier json.load(f) in the A2A discovery loop raises UnboundLocalError: cannot access local variable 'json'. That exception is caught by the loop's except Exception, logged as "Failed to setup A2A agent", and swallowed, so every A2A agent silently fails to register and no /a2a/... routes are added.

json is already imported at module scope, so this removes the redundant local import. (The sibling import inspect in that block is kept: inspect is not imported at module scope.)

The existing A2A test only checks /list-apps, so it passed despite the broken route mounting. The added regression test drives get_fast_api_app(a2a=True) over a temp agent directory and asserts the A2A application is actually constructed (i.e. execution gets past the json.load call). It fails on main with the UnboundLocalError path and passes with this change; the existing A2A tests continue to pass.

@google-cla

google-cla Bot commented Jul 8, 2026

Copy link
Copy Markdown

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.

@AnayGarodia

Copy link
Copy Markdown
Author

@googlebot I signed it!

2 similar comments
@AnayGarodia

Copy link
Copy Markdown
Author

@googlebot I signed it!

@AnayGarodia

Copy link
Copy Markdown
Author

@googlebot I signed it!

@AnayGarodia AnayGarodia force-pushed the fix-a2a-json-unboundlocal branch from cbd1837 to 96765a5 Compare July 8, 2026 08:41
@rohityan rohityan self-assigned this Jul 9, 2026
@rohityan rohityan added a2a [Component] This issue is related a2a support inside ADK. needs review [Status] The PR/issue is awaiting review from the maintainer labels Jul 9, 2026
@rohityan

rohityan commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Hi @AnayGarodia , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan

rohityan commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Hi @wyf7107 , can you please review this. LGTM

@AnayGarodia AnayGarodia force-pushed the fix-a2a-json-unboundlocal branch from 4facc49 to f23b0e6 Compare July 11, 2026 04:56
@AnayGarodia

Copy link
Copy Markdown
Author

Rebased onto main to clear the conflict.

Heads-up from the rebase: the underlying UnboundLocalError is already resolved on main — commit 38587d7 (the a2a-sdk compatibility-shim refactor) removed the function-local import json as a side effect. So this PR now carries just the regression test that locks the behavior in. That fix landed without a test, and a future function-local import json would silently reintroduce the shadowing, so the guard still earns its place.

The test is skipped on the a2a-sdk v1 path (_compat.IS_A2A_V1), matching the sibling A2A tests that mock A2AStarletteApplication. Happy to retitle to test(cli): ... if you'd prefer given the fix itself is now upstream.

@adk-bot adk-bot added the web [Component] This issue will be transferred to adk-web label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a2a [Component] This issue is related a2a support inside ADK. needs review [Status] The PR/issue is awaiting review from the maintainer web [Component] This issue will be transferred to adk-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adk api_server --a2a silently mounts no A2A routes: UnboundLocalError on json in get_fast_api_app

3 participants