Skip to content

feat(a2asrv): agent card HTTP caching (ETag/304, opt-in Cache-Control) - #496

Merged
yarolegovich merged 7 commits into
a2aproject:mainfrom
dongjiang1989:add-header
Nov 5, 2026
Merged

yarolegovich merged 7 commits into
a2aproject:mainfrom
dongjiang1989:add-header

Conversation

@dongjiang1989

@dongjiang1989 dongjiang1989 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements the agent card caching guidance of the A2A specification (§8.6) in the Go SDK.

HTTP caching for the agent card endpoint

NewStaticAgentCardHandler / NewAgentCardHandler responses now carry:

  • Weak ETag — W/"<sha256>" computed over the card content. Randomized signature values are excluded (and the tag is weak) so revalidation keeps working for cards signed per request via NewSignedCardProducer: randomized algorithms like ES256 produce a different signature on every request, so a strong tag over the full body would never match. Each signature's protected header (deterministic per signing key; carries kid/alg/jku) is covered, so a key rotation changes the ETag and clients refetch the card with fresh signatures instead of being pinned to a retired key's signature by 304s.
  • If-None-Match → 304 Not Modified — weak comparison per RFC 9110 §8.2.2, including * and comma-separated candidate lists.
  • Opt-in Cache-Control — new variadic option WithCacheControl("public, max-age=3600"). No default: an appropriate max-age depends on how often the card changes, which only the deployment knows. Revalidation against the ETag works either way and costs a single 304 round trip.
  • Vary: Origin unconditionally — including on no-Origin responses that carry Access-Control-Allow-Origin: *, so a shared cache can never serve them to credentialed cross-origin requests.
  • Raw-JSON producers (AgentCardJSONProducer) are supported: the tag is computed from the raw body with the signatures member stripped and the protected headers folded in (map re-marshal normalizes member order).

The constructors gain a variadic ...AgentCardHandlerOption parameter — source-compatible for all existing call sites.

This brings Go to parity with the Python SDK (agent_card_routes.py: weak ETag, opt-in Cache-Control, 304 negotiation) and the Java SDK (AgentCardCacheMetadata: Cache-Control/ETag metadata), and goes beyond both in honoring If-None-Match on the Go side the same way Python does.

The A2A-Version discovery change that was originally part of this PR has been split out into #531 per review.

Testing

New unit and handler-level tests, including:

  • ETag emission on static and dynamic handlers; If-None-Match forms (exact weak tag, strong form of a weak tag, *, candidate lists, mismatches)
  • Cache-Control absent by default / verbatim passthrough on 200 and 304 when configured
  • Signed-card regression test: a producer that re-signs identical content on every request yields a stable ETag and 304s on revalidation
  • Key-rotation test: changing the signing key changes the ETag and turns a conditional GET into a 200
  • Raw-JSON producer path with per-request changing signatures
  • CORS table tests assert Vary: Origin on every response
  • cardETag does not mutate the input card

Verification: gofmt clean, go vet ./..., go test -race ./... (all packages pass), go build ./....

Notes

  • No behavior change for existing users beyond the additive ETag/304 support and the Vary: Origin header; Cache-Control emission is strictly opt-in.

Comment thread a2asrv/agentcard.go Resolved
@dongjiang1989

Copy link
Copy Markdown
Contributor Author

@yarolegovich PTAL, thx

Comment thread a2asrv/agentcard.go Resolved
Comment thread a2aclient/agentcard/resolver.go Outdated
// Announce the SDK's native protocol version on discovery requests,
// matching the behavior of the other A2A SDKs. A caller-provided
// A2A-Version header (via WithRequestHeader) takes precedence.
req.Header.Set(a2a.SvcParamVersion, string(a2a.Version))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's please move this to a separate PR, it's unrelated to caching. card endpoint doesn't check the version, so not sure we need it at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Move to #531

Comment thread a2asrv/agentcard_cache_test.go Resolved
Comment thread a2asrv/agentcard_test.go Resolved
Comment thread a2asrv/agentcard_cache.go Resolved
dongjiang1989 added a commit to dongjiang1989/a2a-go that referenced this pull request Nov 5, 2026
…leanup

Address review feedback on a2aproject#496:

- Set Vary: Origin unconditionally, including on responses to requests
  without an Origin, so a shared cache can never serve a stored
  ACAO:* response to a credentialed cross-origin request.
- Remove TestWithCacheControl, covered by TestAgentCardHandler_CacheControl.
- Add a get(t, url, ifNoneMatch) test helper and t.Parallel() across the
  agent card tests.
- Bump the copyright year to 2026 in the new cache files.

The A2A-Version discovery change was split out into a2aproject#531.

Signed-off-by: dongjiang1989 <[email protected]>
Serve agent card responses with a weak ETag computed over the card
content excluding signatures, honor If-None-Match with 304 responses
(RFC 9110 weak comparison), and add an opt-in WithCacheControl option,
implementing the caching guidance of the A2A specification section 8.6.

Excluding signatures from the tag keeps revalidation working for cards
signed per request via NewSignedCardProducer, whose randomized
signatures would otherwise invalidate a strong tag on every request.
Aligns with the Python (agent_card_routes) and Java
(AgentCardCacheMetadata) SDKs.

Signed-off-by: dongjiang1989 <[email protected]>
The ETag previously excluded card signatures entirely, so a key rotation
kept returning 304 and clients would hold signatures made by a retired
key indefinitely. Each signature's protected header (kid/alg/jku) is
deterministic per signing key, so it is now included in the tag: the
ETag stays stable across per-request re-signings but changes when the
signing key rotates.
…leanup

Address review feedback on a2aproject#496:

- Set Vary: Origin unconditionally, including on responses to requests
  without an Origin, so a shared cache can never serve a stored
  ACAO:* response to a credentialed cross-origin request.
- Remove TestWithCacheControl, covered by TestAgentCardHandler_CacheControl.
- Add a get(t, url, ifNoneMatch) test helper and t.Parallel() across the
  agent card tests.
- Bump the copyright year to 2026 in the new cache files.

The A2A-Version discovery change was split out into a2aproject#531.

Signed-off-by: dongjiang1989 <[email protected]>
@dongjiang1989 dongjiang1989 changed the title feat: agent card HTTP caching (ETag/304) and A2A-Version on discovery feat(a2asrv): agent card HTTP caching (ETag/304, opt-in Cache-Control) Nov 5, 2026
@dongjiang1989

Copy link
Copy Markdown
Contributor Author

cc @yarolegovich Please recheck it

@yarolegovich yarolegovich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm after the Vary fix

Comment thread a2asrv/agentcard.go Resolved
Comment thread a2asrv/agentcard_cache.go Resolved
Comment thread a2asrv/agentcard_cache.go Resolved
Comment thread a2asrv/agentcard_cache_test.go Resolved
Comment thread a2asrv/agentcard_test.go Resolved
- Use Header().Add for Vary: Origin so values contributed by outer
  middleware (e.g. gzhttp's Vary: Accept-Encoding) are preserved
- Rename WithCacheControl to WithAgentCardCacheControl so it does not
  read like a RequestHandlerOption
- Sort signature protected headers in cardETag/rawJSONETag so a resolver
  returning signers in varying order produces a stable tag
- Add t.Parallel()/t.Cleanup(srv.Close) in card handler tests; new tests
  for Vary preservation and signature-order stability
@dongjiang1989

Copy link
Copy Markdown
Contributor Author

Thanks @yarolegovich Updated

@yarolegovich
yarolegovich merged commit 313efd9 into a2aproject:main Nov 5, 2026
5 checks passed
@dongjiang1989
dongjiang1989 deleted the add-header branch November 5, 2026 14:29
yarolegovich pushed a commit that referenced this pull request Nov 6, 2026
Passes `WithAgentCardCacheControl("public, max-age=3600")` to the ITK
agent's card handler, opting it into the `Cache-Control` header added in
#496.
yarolegovich added a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


## [2.8.0](v2.7.0...v2.8.0)
(2026-11-06)


### Features

* **a2aacp:** add an A2A agent executor for Agent Client Protocol (ACP)
agents ([#491](#491),
[#492](#492),
[#493](#493),
[#494](#494),
[#530](#530),
[#545](#545),
[#548](#548),
[#552](#552),
[#562](#562))
* **a2agrpc:** add GRPCConnectionPool for gRPC client connection reuse
(fixes [#109](#109))
([#382](#382))
([a2411f7](a2411f7))
* **a2asrv:** add NewErrorSanitizer, an opt-in interceptor which logs
request errors in full and sends clients only A2A errors
([#552](#552))
([ece71bc](ece71bc))
* **a2asrv:** agent card HTTP caching (ETag/304, opt-in Cache-Control)
([#496](#496))
([313efd9](313efd9))
* implement structured input extension
([#490](#490))
([367f987](367f987))


### Bug Fixes

* **a2aclient:** honor API key security scheme Location
([#497](#497))
([c59beb5](c59beb5))
* **a2aclient:** honor configured HTTP authentication schemes
([#502](#502))
([413de0c](413de0c))
* **a2aclient:** normalize service param keys set by the client and
AuthInterceptor
([#479](#479))
([96f4df0](96f4df0))
* **a2aclient:** return JSON-RPC errors from non-200 responses
([#559](#559))
([97f1fac](97f1fac))
* **a2acrypto:** reject malformed Unicode before signing
([#450](#450))
([ec6cb14](ec6cb14))
* **a2aevent:** preserve input-required history order
([#501](#501))
([72f94a3](72f94a3))
* **a2aevent:** recover the whole artifact when it changes in place
([#485](#485))
([4d61739](4d61739))
* **a2a:** round-trip null data and nil raw parts through JSON
([#513](#513))
([186decc](186decc))
* **a2asrv:** make ServiceParams.With nil-safe
([#544](#544))
([c6042b8](c6042b8))
* **a2asrv:** preserve escaped tenant REST paths
([#514](#514),
[#562](#562))
([f86cf6c](f86cf6c))
* **a2asrv:** preserve numeric precision in raw card ETags
([#546](#546))
([18c2e72](18c2e72))
* **a2asrv:** reject HEAD before creating task subscriptions
([#481](#481))
([e641e3c](e641e3c))
* **a2asrv:** split comma-separated A2A-Extensions values
([#519](#519))
([db83820](db83820)),
closes [#516](#516)
* **a2av0:** keep security schemes and v0.3 interface in extended agent
cards ([#558](#558))
([196d4bb](196d4bb)),
closes [#556](#556)
* **client:** accept cached status and artifact stream events
([#508](#508))
([ea78132](ea78132))
* **client:** honor streaming interceptor error recovery
([#507](#507))
([737b626](737b626))
* **client:** keep propagated tenants local to each call
([#495](#495))
([0eaf017](0eaf017))
* **client:** preserve escaped REST path segments
([#488](#488))
([8880d8f](8880d8f))
* compare and send A2A-Version as Major.Minor
([#555](#555))
([b5ea753](b5ea753))
* don't fail CancelTask when the canceled execution ends first
([#521](#521))
([1613ae6](1613ae6)),
closes [#518](#518)
* don't move a task to FAILED when cancelation retries run out
([#522](#522))
([247933b](247933b))
* **jsonrpc:** return empty result for successful push config deletion
([#525](#525))
([42d0738](42d0738))
* pass CancelTask metadata over REST
([#520](#520))
([a104b2e](a104b2e)),
closes [#517](#517)
* **pbconv:** preserve JSON data part values
([#503](#503))
([7c040e0](7c040e0))
* **pbconv:** send pkceRequired for authorization code flows
([#542](#542))
([cb2c30b](cb2c30b))
* **push:** cap push notification configs per task
([#405](#405))
([6bb5a68](6bb5a68))
* report executions or cancelations in progress, and messages to
terminal tasks in cluster mode, as UnsupportedOperation
([#552](#552))
([ece71bc](ece71bc))
* **sse:** ignore a leading UTF-8 byte order mark
([#511](#511))
([248f628](248f628))
* **taskexec:** keep the error when broadcasting an event fails
([#536](#536))
([636fa9f](636fa9f))
* **taskexec:** report canceler panics during concurrent cancelation
([#535](#535))
([7ffc680](7ffc680))
* **taskexec:** skip heartbeats for non-positive intervals
([#543](#543))
([c4158ae](c4158ae))
* **taskexec:** wait for the cancelation result of input-required tasks
([#560](#560))
([3194abe](3194abe))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Yaroslav Shevchuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants