Skip to content

fix(sdk): Receipt.verify() treats a naive created_at as UTC - #368

Merged
cursor[bot] merged 1 commit into
mainfrom
fix/358-receipt-verify-tz
Nov 16, 2026
Merged

cursor[bot] merged 1 commit into
mainfrom
fix/358-receipt-verify-tz

Conversation

@PetrefiedThunder

@PetrefiedThunder PetrefiedThunder commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #358

Root cause

Receipt.verify() compared the signed claim's created_at with the receipt's own created_at as plain datetime objects (sdk/python/src/b2a_sdk/models.py). The gateway signs created_at with an offset (...+00:00), but on SQLite the receipt it returns from MCP, replay and GET /v1/receipts/{id} is naive (...967141). An aware datetime never equals a naive one, so every genuine receipt returned MISMATCH and the README "Short tool call" example failed.

Fix

Both comparisons of created_at (the typed field and the raw field loop) now go through _utc_instant(), which reads a naive value as UTC. Gateway timestamps are always UTC. A different instant, or the same wall time under another offset, still returns MISMATCH.

The gateway side (serializing stored receipts without an offset on SQLite) is not changed here. It sits outside the SDK area this PR covers, and older gateways will keep returning naive values anyway, so the SDK has to cope.

Verification

  • New tests in sdk/python/tests/test_call.py: client.call(...).verify() with a naive created_at is VERIFIED for both amw and b2a_sdk, and two negative cases stay MISMATCH. The positive test fails on main and passes here.
  • Live repro against a local quickstart gateway (SQLite, trust mode, partner.notes.write), using the README snippet through import amw: on main, raw created_at: 2026-11-12T01:42:50.294923 and verify returns MISMATCH; on this branch it returns VERIFIED.
  • python -m pytest sdk/python/tests: 476 passed.
  • Ruff check and format across all detected projects: clean. uv build sdk/python: builds wheel and sdist.

No CHANGELOG entry, to avoid conflicts with the sibling SDK fix PRs for #359 to #362 (#372, #374, #378, #380), which would touch the same section.

🤖 Generated with Claude Code


Note

Low Risk
SDK-only receipt verification logic with targeted tests; no auth or gateway serialization changes.

Overview
Fixes #358 by normalizing created_at before equality checks in Receipt.verify(), so receipts returned from SQLite-backed gateways (naive ISO strings) no longer fail verification against offset-aware signed claims.

Adds _utc_instant() in models.py and routes both the typed-field and raw-field created_at comparisons through it, treating naive values as UTC while still MISMATCHing a different instant or a conflicting timezone offset.

New tests in test_call.py cover successful client.call(...).verify() with naive timestamps for b2a_sdk and amw, plus negative cases for wrong wall time and non-UTC offsets.

Reviewed by Cursor Bugbot for commit c7fb719. Bugbot is set up for automated code reviews on this repo. Configure here.

The gateway signs created_at with an explicit offset, but on SQLite the
receipt it returns from MCP, replay and GET /v1/receipts/{id} carries a
naive timestamp. Receipt.verify() compared the two datetimes directly, and
an aware datetime never equals a naive one, so every genuine receipt
returned MISMATCH and the README short tool call example failed.

Normalize both sides to an aware UTC instant before comparing. Gateway
timestamps are always UTC, so a naive value is read as UTC. A different
instant, or the same wall time under another offset, still mismatches.

Fixes #358

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: CS <cs@CSs-MacBook-Pro.local>
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-middleware-web Ready Ready Preview Nov 12, 2026 1:43am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T01:44:27.733373Z c7fb719 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cursor
cursor Bot merged commit 4bf3fd4 into main Nov 16, 2026
49 checks passed
@cursor
cursor Bot deleted the fix/358-receipt-verify-tz branch November 16, 2026 19:03
PetrefiedThunder added a commit that referenced this pull request Nov 17, 2026
* chore(sdk-python): bump amw-sdk version to 0.5.1

Update version from 0.5.0 to 0.5.1 in:
- pyproject.toml
- src/b2a_sdk/__init__.py
- src/b2a_sdk/client.py User-Agent
- src/b2a_sdk/x402.py User-Agent
- tests/test_trust_client.py version assertion

Add CHANGELOG.md entry for 0.5.1 documenting the receipt verification
timezone fix from PR #368 (commit 4bf3fd4, closes #358).

This is a version-bump-only change carrying the already-merged fix.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Christopher  <PetrefiedThunder@users.noreply.github.com>

* chore(sdk-python): update gateway SDK version references to 0.5.1

Update gateway's well-known endpoint and test comment to reflect the
SDK version bump from 0.5.0 to 0.5.1. This fixes the failing
test_wedge_honesty.py::test_agent_json_sdk_integrations_are_honest test
which verifies the gateway's advertised SDK version matches pyproject.toml.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Christopher  <PetrefiedThunder@users.noreply.github.com>

---------

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Christopher <PetrefiedThunder@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — c7fb719c Deployed Nov 12, 2026 by vercel[bot]
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.

Python SDK: Receipt.verify() returns MISMATCH for genuine receipts, so the README's short tool call example fails

2 participants