Skip to content

fix(core): preserve legitimate falsy values in _clean_empty#713

Merged
sokoliva merged 7 commits intoa2aproject:mainfrom
cchinchilla-dev:fix/core-clean-empty-drops-falsy-values-691
Feb 20, 2026
Merged

fix(core): preserve legitimate falsy values in _clean_empty#713
sokoliva merged 7 commits intoa2aproject:mainfrom
cchinchilla-dev:fix/core-clean-empty-drops-falsy-values-691

Conversation

@cchinchilla-dev
Copy link
Contributor

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #692 🦕

Problem

_clean_empty uses a truthiness check (if v) that drops legitimate falsy values like 0, False, and 0.0 alongside the intended empties ('', [], {}).

This affects canonicalize_agent_card() — the only caller — which produces canonical JSON for signature verification (RFC 8785). An AgentCard with e.g. AgentCapabilities(streaming=False) would have the field silently stripped, losing the distinction between "explicitly disabled" and "unspecified".

Fix

Restructured _clean_empty so that only empty strings are converted to None at the leaf level, and empty containers collapse naturally via or None after their children are cleaned. The filter becomes if v is not None, which only catches values the function itself converted — 0, False, and 0.0 never go through any conversion and flow through unchanged.

Alternatives considered

If maintainers prefer a different style, happy to switch to either:

  • Inline sentinel: if v not in (None, '', [], {}) directly in the comprehensions, keeping the original structure with a fixed filter.
  • Helper predicate: extract an _is_empty(v) function and use if not _is_empty(v) as the filter in both dict and list comprehensions.

Tests

Parametrized tests covering empty removal, falsy value preservation, mixed cases, non-mutation, and a regression test confirming streaming=False survives in canonicalize_agent_card output. Happy to trim test cases if seen as excessive.

@cchinchilla-dev cchinchilla-dev requested a review from a team as a code owner February 19, 2026 23:40
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @cchinchilla-dev, 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 bug in the _clean_empty utility function that caused legitimate falsy values to be removed alongside empty containers. The updated logic ensures that critical data, such as boolean False or integer 0, is preserved during data cleaning, particularly impacting the canonicalize_agent_card function which relies on this for accurate JSON representation.

Highlights

  • _clean_empty function logic: The _clean_empty utility function has been refactored to correctly distinguish between truly empty values (empty strings, lists, dicts) and legitimate falsy values (like 0, False, 0.0), ensuring only the former are removed.
  • Preservation of falsy values: This change ensures that important falsy values, such as streaming=False in AgentCapabilities, are no longer inadvertently stripped during JSON canonicalization, maintaining data integrity.
  • Comprehensive testing: Extensive new parameterized tests have been added to cover various scenarios, including empty removal, falsy value preservation, mixed cases, and non-mutation of input, along with a specific regression test for the canonicalize_agent_card function.
Changelog
  • src/a2a/utils/helpers.py
    • Refactored the _clean_empty function to correctly handle falsy values.
    • Modified the filtering logic to convert only empty strings to None and then filter None values.
  • tests/utils/test_helpers.py
    • Imported the _clean_empty function for testing.
    • Added a regression test for canonicalize_agent_card to confirm False values are preserved.
    • Introduced parameterized tests for _clean_empty to verify removal of empty values.
    • Added a test to ensure a top-level empty list becomes None.
    • Included parameterized tests for _clean_empty to confirm preservation of legitimate falsy values (0, False, 0.0).
    • Added parameterized tests for _clean_empty to handle mixed empty and falsy values.
    • Added a test to ensure _clean_empty does not mutate its input.
Activity
  • The pull request was created to fix an issue where _clean_empty removed legitimate falsy values.
  • The author provided a detailed description of the problem, the proposed fix, and alternatives considered.
  • Comprehensive tests were developed to validate the new behavior and prevent regressions.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request correctly addresses the issue where falsy but legitimate values (such as 0, False, and 0.0) were being stripped during the cleaning process for agent card canonicalization. The implementation of _clean_empty has been improved to explicitly check for None and handle empty strings at the leaf level, ensuring that other falsy values are preserved. The added tests are comprehensive and include a regression test for the reported issue. The review follows PEP 8 for Python code style.

@cchinchilla-dev
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 fixes an issue in _clean_empty where legitimate falsy values (like 0 or False) were being removed along with empty strings and collections. The new implementation properly distinguishes between these cases. The accompanying tests are very thorough and cover a wide range of scenarios, including a regression test for the original bug. I've kept all the minor suggestions to improve code efficiency and clarity. Overall, this is a high-quality contribution.

cchinchilla-dev and others added 4 commits February 20, 2026 00:54
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@sokoliva sokoliva self-assigned this Feb 20, 2026
@sokoliva
Copy link
Contributor

Thanks a lot for pointing this bug out and for opening a PR request!

Regarding alternatives considered: I prefer your short-circuit evaluation over the former inline sentinel and currently don't see the need for adding _is_empty helper function.

@sokoliva sokoliva merged commit 7632f55 into a2aproject:main Feb 20, 2026
8 checks passed
sokoliva pushed a commit that referenced this pull request Feb 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.24](v0.3.23...v0.3.24)
(2026-02-20)


### Bug Fixes

* **core:** preserve legitimate falsy values in _clean_empty
([#713](#713))
([7632f55](7632f55))
* **deps:** `DeprecationWarning` on `HTTP_413_REQUEST_ENTITY_TOO_LARGE`
([#693](#693))
([9968f9c](9968f9c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

[Bug]: _clean_empty silently drops legitimate falsy values (0, False, 0.0)

2 participants