Skip to content

fix(a2a-server): add missing return after 501 in /tasks/metadata endpoint - #21730

Closed
yashodipmore wants to merge 2 commits into
google-gemini:mainfrom
yashodipmore:fix/a2a-tasks-metadata-missing-return-v2
Closed

fix(a2a-server): add missing return after 501 in /tasks/metadata endpoint#21730
yashodipmore wants to merge 2 commits into
google-gemini:mainfrom
yashodipmore:fix/a2a-tasks-metadata-missing-return-v2

Conversation

@yashodipmore

Copy link
Copy Markdown
Contributor

Summary

Fixes #21729

Adds a missing return statement after the res.status(501).send() in the GET /tasks/metadata endpoint. Without this return, when using a non-InMemory task store (e.g., GCSTaskStore), the handler falls through into the try block and attempts to send a second response, causing ERR_HTTP_HEADERS_SENT and crashing the server.

Changes

packages/a2a-server/src/http/app.ts

  • Added return; after res.status(501).send() in the /tasks/metadata route handler
  • Consistent with the pattern used in the adjacent /tasks/:taskId/metadata endpoint and all other early-exit guards in the file

packages/a2a-server/src/http/endpoints.test.ts

  • Added @google-cloud/storage mock to support GCS task store testing
  • Added new Agent Server Endpoints (GCS Task Store) describe block
  • Added test: verifies GET /tasks/metadata returns 501 (not crash) when using GCS task store

Testing

All 26 tests pass (6 endpoints + 20 app tests):

✓ Agent Server Endpoints > should create a new task via POST /tasks
✓ Agent Server Endpoints > should get metadata for a specific task via GET /tasks/:taskId/metadata
✓ Agent Server Endpoints > should get metadata for all tasks via GET /tasks/metadata
✓ Agent Server Endpoints > should return 404 for a non-existent task
✓ Agent Server Endpoints > should return agent metadata via GET /.well-known/agent-card.json
✓ Agent Server Endpoints (GCS Task Store) > should return 501 for GET /tasks/metadata when not using InMemoryTaskStore  ← NEW

Impact

  • Before: Every GET /tasks/metadata call crashes A2A server when GCS_BUCKET_NAME is set
  • After: Returns clean 501 with descriptive error message

…oint

When using a non-InMemory task store (e.g., GCSTaskStore), the
GET /tasks/metadata handler sends a 501 response but does not
return, causing the code to fall through into the try block. This
attempts to send a second response (200, 204, or 500), which
triggers ERR_HTTP_HEADERS_SENT and crashes the server.

The fix adds a return statement after the 501 send, consistent
with the pattern used in the adjacent /tasks/:taskId/metadata
endpoint and other early-exit guards in the same file.

Added a test that verifies the 501 behavior with a GCS task store.
@yashodipmore
yashodipmore requested a review from a team as a code owner March 9, 2026 17:32
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the A2A server where the GET /tasks/metadata endpoint would crash the server if a task store other than InMemoryTaskStore (e.g., GCSTaskStore) was configured. The fix ensures that the server gracefully handles this scenario by returning a 501 status and preventing subsequent response attempts, thereby improving the server's stability and reliability.

Highlights

  • API Endpoint Fix: Added a crucial "return" statement after sending a 501 status in the GET /tasks/metadata endpoint to prevent the server from crashing when a non-InMemory task store is used.
  • Testing Enhancements: Introduced a mock for @google-cloud/storage and a new test suite to verify the correct 501 behavior of the /tasks/metadata endpoint when using a GCS task store.
Changelog
  • packages/a2a-server/src/http/app.ts
    • Added a "return;" statement after res.status(501).send() in the /tasks/metadata route handler.
  • packages/a2a-server/src/http/endpoints.test.ts
    • Added a mock for @google-cloud/storage to enable testing with GCS task stores without a real connection.
    • Introduced a new describe block for "Agent Server Endpoints (GCS Task Store)".
    • Added a test case to verify that GET /tasks/metadata returns a 501 status and does not crash when a GCS task store is in use.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 9, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly addresses a server crash in the /tasks/metadata endpoint by adding a missing return statement after sending a 501 error. This prevents the code from attempting to send a second response, which previously caused an ERR_HTTP_HEADERS_SENT error. The fix is accompanied by a well-written test case that mocks the GCS task store and verifies that the endpoint now correctly returns a 501 status without crashing. The changes are correct and effectively resolve the issue.

@gemini-cli

gemini-cli Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

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

Labels

area/core Issues related to User Interface, OS Support, Core Functionality size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: A2A server GET /tasks/metadata missing return after 501 response — causes ERR_HTTP_HEADERS_SENT crash with GCS task store

2 participants