Skip to content

fix(a2a-pb): decode integral Value numbers as integers - #405

Closed
gulldan wants to merge 5 commits into
a2aproject:mainfrom
gulldan:fix/pb-integral-numbers
Closed

gulldan wants to merge 5 commits into
a2aproject:mainfrom
gulldan:fix/pb-integral-numbers

Conversation

@gulldan

@gulldan gulldan commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #406 → #405 → #407 → #411 → #395. Stacked on #406: review only the last commit.

Fixes #399.

Problem

google.protobuf.Value carries every number as a double, and proto_value_to_json_value turned each one back into a JSON float with serde_json::Number::from_f64. Every binding decodes through it, so an integer in a data part or in metadata reached the AgentExecutor — and a client's decoded responses — as 3600.0, and serde_json::from_value::<u32> refused it.

Fix

A whole number within ±2^53, where a double is exact, is given back as an integer (json_number in pbconv.rs); fractions, larger magnitudes and the non-finite case behave as before. Only the decoded serde_json::Value changes; the protojson wire form is untouched.

Tests

  • New integers_in_data_parts_stay_integers (a2a-pb/tests/protojson.rs): decodes a JSON-RPC SendMessage whose data part is {"sinceSeconds": 3600, "ratio": 0.5} and deserializes sinceSeconds into u32. On main it fails with invalid type: floating point 3600.0, expected u32.
  • test_struct_roundtrip and test_part_data_roundtrip used floats to work around this ("since proto Value stores all numbers as f64"); they now round-trip integers, a negative integer and a fraction.
  • The protojson_roundtrip fuzz target checks idempotence, which still holds: an integral double reaches its integer form on the first round and stays there.
  • CI steps on Linux, stable 1.99.1: cargo metadata --locked, cargo hack check --all-targets --each-feature, cargo fmt --check, cargo hack clippy --all-targets --each-feature -- -D warnings, cargo test --workspace --exclude itk-rust-current-agent, copyright headers — all green.
  • End to end, the reproduction from [Bug]: a2a-pb: integers in data parts and metadata are decoded as floats (3600 → 3600.0) #399 built on this branch answers executor saw {"sinceSeconds":3600}; as u32: Ok(3600); the echoed data part still prints 3600.0 on the wire, which this PR leaves alone.

Overlap with the A2A 1.1 stack

#385–#397 touch pbconv.rs but leave proto_value_to_json_value as it is; this diff applies cleanly on refs/pull/396/head.

🤖 Generated with Claude Code

The JSON-RPC transport never looked at the status of a response. An
error that something in front of the agent answers itself (an
authenticating proxy's 401, a gateway's 429 or 502) carries no
JSON-RPC envelope, so the caller got "failed to parse JSON-RPC
response" and could not tell a credential or rate-limit problem from
a broken server. A streaming call answered that way without a content
type was handed to the SSE parser and came back as an empty stream.

A body that is not a JSON-RPC envelope is now reported with its
status, as the REST transport already does ("HTTP 429 Too Many
Requests: <body>"); a JSON-RPC envelope is still decoded whatever the
status, and a non-success status is never treated as a stream.

Fixes: a2aproject#404

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@gulldan
gulldan requested a review from a team as a code owner October 31, 2026 10:21
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The streaming test matched on the result and panicked in an `Ok` arm that a
passing run never reaches, so that line stayed uncovered. Taking the error
with `.err().expect()` keeps the assertion and needs no `Debug` on the stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@muscariello

Copy link
Copy Markdown
Member

@gulldan thank you for all these fixes.
If you intend to contribute more, may I ask you to favor stacked PRs? In this way we can save build time in the queue.

Thanks again for your contribution.

@gulldan

gulldan commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, @muscariello, for the kind words, and for reviewing and merging #408 and approving #409 so quickly.

Understood about the build queue. I kept one PR per issue so each fix could be reviewed and reverted on its own, but I didn't realise each one costs a full CI run. From now on I'll send related fixes as a stack: one commit per issue, each PR on top of the previous one.

For the ones still open (#405, #406, #407, #411): would you like me to restack them into a single chain, or leave them as they are to avoid another round of builds? Happy to do whichever is easier for you.

Thanks again for maintaining a2a-rs and for the careful reviews.

@muscariello

muscariello commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Keep one issue per PR. That's perfect. Just stack them because at every merge we get a rebse.

google.protobuf.Value carries every number as a double, and
proto_value_to_json_value turned each one back into a JSON float, so
an integer in a data part or in metadata reached the executor, and a
client's decoded response, as 3600.0. serde then refuses it for an
integer type ("invalid type: floating point `3600.0`, expected u32").

A whole number within +-2^53, where a double is exact, is now given
back as an integer; other numbers stay floats. The round-trip tests
that used floats to work around this now use integers, and a new
protojson test decodes a JSON-RPC SendMessage whose data part holds an
integer and deserializes it into u32.

Fixes: a2aproject#399

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@gulldan

gulldan commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Done — restacked as #406 → #405 → #407 → #411 → #395; each PR description says which commit to review.

@muscariello

Copy link
Copy Markdown
Member

to create a Github stack you must use the PR window and stack them by clicking in the top right corner or use gh cli to do that.

@gulldan

gulldan commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @muscariello. I tried both ways before replying, and unfortunately I can't do it from my side: these PRs come from my fork, and GitHub doesn't support stacks across forks. The docs say: "Stacked pull requests require all branches to be in the same repository. Cross-fork stacks are not supported."

What I got:

  • gh stack link 406 405 407 411 395 can't retarget the PRs onto each other, because a PR here can only target a branch of this repository and my branches are in my fork:
    failed to update base branch for PR #405 to fix/client-jsonrpc-http-status: HTTP 422: Validation Failed
    PullRequest.base is invalid
    
    It then prints "Stacked PRs are not enabled for this repository". That part is misleading: gh stack prints it for any 404 from the stacks API, and stacks do work here (#398).
  • The stacks API itself (POST /repos/a2aproject/a2a-rs/stacks) returns 404 for me even with non-existent PR numbers, while the same token gets a normal validation error on my fork, so creating a stack here needs write access.
  • Write access wouldn't help either. On a test repository where I'm an admin I opened two PRs from a fork, made the branch names line up, and tried gh stack link and the API, both for a new stack and for adding to an existing one. Every attempt fails with:
    Pull requests from forks cannot be added to stacks.
    

Nothing changed on the PRs; all five still target main.

I'm not asking for write access: granting it to an outside contributor just for this wouldn't be a good idea. So the options I see:

Whichever is easier for you. If there's a way to stack PRs from a fork that I've missed, I'd be glad to learn it.

@muscariello

Copy link
Copy Markdown
Member

This is gonna take a long time to review because the CI will take much longer.

@gulldan

gulldan commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @muscariello — and sorry: after your comment I opened more PRs today (#414–#438), which made the CI load worse, not better.

Since a native stack can't be built from a fork, here is how I'd like to reduce the load, if it works for you:

  • I keep only the bottom PR of the chain open and close the others for now. Their issues stay open, and each issue keeps a link to the branch with the fix, so nothing is lost.
  • When a PR merges, I rebase the next one on main and reopen it. Each open PR is then a single commit on top of main, and CI runs once per fix.

Alternatives, if you prefer:

  • a maintainer pushes these branches into this repository and opens a native stack, and I close mine;
  • or one PR with one commit per issue (Fixes #… in each commit), if fewer CI runs matter more than one PR per issue.

If some of these fixes matter more to you than others, or overlap with the 1.1 stack you're working on, tell me which to send first or drop. I'll go in that order. I won't open anything new until we've agreed on the approach.

@muscariello

Copy link
Copy Markdown
Member

let me move all the branches into the remove myself. Hold on for one day please.

@muscariello

Copy link
Copy Markdown
Member

Superseded by #440, which carries the same commit on an in-repo branch so the stack can be reviewed one commit at a time.

@muscariello muscariello closed this Nov 1, 2026
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]: a2a-pb: integers in data parts and metadata are decoded as floats (3600 → 3600.0)

2 participants