Repository navigation
fix(a2a): serialize task status timestamps in UTC - #452
Conversation
|
Thanks, the switch to UTC is right. The spec is more specific, though:
This change still uses Go's default encoding, so the number of digits varies: |
The spec (5.6.1) asks for UTC with millisecond precision. Go's default encoding writes 0 to 9 fractional digits. TaskStatus.Timestamp and ListTasksRequest.StatusTimestampAfter are now written with exactly three, and the REST client sends statusTimestampAfter in the same form. Reading still accepts any precision. NewStatusUpdateEvent truncates its timestamp to milliseconds, so an event reads back equal to the one that was created.
|
Thanks, you're right. Done:
|
| }{wire: wire(s), Timestamp: newJSONTimestamp(s.Timestamp)}) | ||
| } | ||
|
|
||
| // jsonTimestampLayout is the timestamp pattern of the spec, YYYY-MM-DDTHH:mm:ss.sssZ. |
There was a problem hiding this comment.
I think we can remove the comment here
| // jsonTimestampLayout is the timestamp pattern of the spec, YYYY-MM-DDTHH:mm:ss.sssZ. | ||
| const jsonTimestampLayout = "2006-01-02T15:04:05.000Z" | ||
|
|
||
| // jsonTimestamp writes a time as the spec requires for JSON timestamps: in UTC, |
There was a problem hiding this comment.
nit: can be changed to
jsonTimestamp writes a time as ISO 8601 formtted strings in UTC timezone with Millisecond precision
| func newJSONTimestamp(t *time.Time) *jsonTimestamp { | ||
| if t == nil { | ||
| return nil | ||
| } | ||
| ts := jsonTimestamp(*t) | ||
| return &ts | ||
| } |
There was a problem hiding this comment.
I don't think this helper is needed. Since jsonTimestamp is time.Time (*jsonTimestamp)(s.Timestamp) converts directly, and nil stay nil
There was a problem hiding this comment.
I think these tests can go into existing a2a/json_test.go. That's where the current core types JSON tests are. While moving them, the separate functions can become a couple of table driven tests, one for writing, one for reading. The year range check with the test, is not worth keeping.
|
|
||
| // TimestampLayout is the timestamp pattern of the spec, YYYY-MM-DDTHH:mm:ss.sssZ. | ||
| // It is the same pattern a2a uses for JSON timestamps. | ||
| const TimestampLayout = "2006-01-02T15:04:05.000Z" |
There was a problem hiding this comment.
it is only used by FormatTimestamp, so can be unexported
Drop the newJSONTimestamp helper and the year range check, marshal the formatted string with json.Marshal, and unexport the REST timestamp layout. Move the timestamp tests into json_test.go as two table tests.
|
Thanks for the review, all done in the last push:
go test -race ./... passes and golangci-lint reports 0 issues. |
🤖 I have created a release *beep* *boop* --- ## [2.7.0](v2.6.0...v2.7.0) (2026-10-21) ### Features * add input mode validation ([#456](#456)) ([8c814be](8c814be)) * extension point for snapshot materialization logic ([#449](#449)) ([4899045](4899045)) * reject requests with unsupported A2A-Version ([#457](#457)) ([4226e74](4226e74)) * use application/a2a+json with Accept-based negotiation ([#465](#465)) ([a8caf47](a8caf47)) ### Bug Fixes * **a2a:** serialize task status timestamps in UTC ([#452](#452)) ([b657f33](b657f33)) * decode application/a2a+json error responses in the REST client ([#448](#448)) ([3e1aa7f](3e1aa7f)) * **errordetails:** handle nil Value in Typed.MarshalJSON ([#474](#474)) ([73c49ac](73c49ac)) * **grpc:** forward next_page_token in push config list responses ([#455](#455)) ([7210014](7210014)) * **grpc:** keep caller metadata when attaching service params ([#476](#476)) ([f01e895](f01e895)) * honor a2a+json Content Type when Accept is */* or missing ([#468](#468)) ([2169266](2169266)) * reject trailing data after the JSON body ([#453](#453)) ([e85760e](e85760e)) * **rest:** map non-A2A HTTP error responses by status code ([#471](#471)) ([4baba5f](4baba5f)) * return plain error when streaming fails before the first event ([#463](#463)) ([cf62533](cf62533)) * **taskstate:** reject unknown task state values on unmarshal and REST status param ([#404](#404)) ([534a60f](534a60f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…re types (#642) Target: `release/v1.1` Part of the A2A v1.1 work see the implementation breakdowns for [generation + timeline](#612) and [bidi live](#619). This PR contains core types only, no behavior changes. This PR addresses the following from the [v1.1 spec](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md): - [§3.2.7 Task Generation Semantics](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#327-task-generation-semantics): `Task.Generation`, and `Generation` on `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent`. - [§3.2.8 Task Timeline Semantics](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#328-task-timeline-semantics), [§4.1.8 TimelineEntry](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#418-timelineentry), [§4.1.7 Artifact](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#417-artifact): `Task.Timeline`, `TimelineEntry` (entries of unknown kinds are kept with only their generation), `Artifact.StartGeneration` / `EndGeneration`. - [§3.2.8 Task Timeline Semantics, Timestamps](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#328-task-timeline-semantics) ([A2A#2426](a2aproject/A2A#2426)): `Task.CreatedAt` / `UpdatedAt` ([§4.1.1 Task](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#411-task)), `Artifact.UpdatedAt` ([§4.1.7 Artifact](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#417-artifact)), `TimelineEntry.Timestamp` ([§4.1.8 TimelineEntry](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#418-timelineentry)), `Timestamp` on `TaskStatusUpdateEvent` ([§4.2.1](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#421-taskstatusupdateevent)) and `TaskMessageUpdateEvent` ([§4.2.3](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#423-taskmessageupdateevent)). `TaskStatus.Timestamp` ([§4.1.2 TaskStatus](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#412-taskstatus)) and `ListTasksRequest.StatusTimestampAfter` ([§3.1.4 List Tasks](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#314-list-tasks)) are marked `Deprecated`. - [§4.2.3 TaskMessageUpdateEvent](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#423-taskmessageupdateevent): `TaskMessageUpdateEvent`, `NewMessageUpdateEvent`, and the `messageUpdate` case of `StreamResponse`. - [§3.2.2 SendMessageConfiguration](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#322-sendmessageconfiguration): `SendMessageConfig.IfGenerationMatch`. - [§3.1.3 Get Task](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#313-get-task): `GetTaskRequest.CurrentGeneration`. - [§3.1.6 Subscribe to Task](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#316-subscribe-to-task): `SubscribeToTaskRequest.LastSeenGeneration`. - [§3.3.2 Error Handling](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#332-error-handling): `ErrTaskGenerationMismatch` (`TASK_GENERATION_MISMATCH`). - [§3.2.4 History Length Semantics](https://github.com/a2aproject/A2A/blob/dev-1.1/docs/specification.md#324-history-length-semantics): `Task.History` and `HistoryLength` on all requests are marked `Deprecated`. - Task View from [A2A#2399](a2aproject/A2A#2399) (not merged yet): `TaskView` (`TASK_VIEW_FULL`, `TASK_VIEW_SUMMARY`), `View` on `GetTaskRequest` and `ListTasksRequest`, `TaskView` on `SendMessageConfig`. `ListTasksRequest.IncludeArtifacts` is marked `Deprecated`, and the `HistoryLength` deprecation notes point to `View` / `TaskView`. Generation fields use the new `TaskGeneration` type. It encodes as a ProtoJSON `int64` (a decimal string) and decodes from both strings and numbers. The encoding sits on the field type, not on the structs, so integrator structs that embed SDK types keep encoding their own fields. The 6 new timestamp fields use the new `Timestamp` type (`struct{ time.Time }`) the same way. Embedding keeps all `time.Time` methods, and `Equal(Timestamp)` makes `cmp` work. Two existing timestamps keep the old way: `TaskStatus.Timestamp` and `ListTasksRequest.StatusTimestampAfter` stay `*time.Time` with their per-struct `MarshalJSON` from #452, because changing their type would break users. Both are deprecated in v1.1 and removed in 2.0, so after that `Timestamp` is the only timestamp type. On the wire all timestamps look the same. Backward compatibility: only new fields, types and an error are added. All new fields are optional and omitted when empty, so requests and responses are unchanged.
Fixes #451
JSON timestamps were written with the local offset (
+02:00) and with a varying number of fractional digits. The spec (5.6.1) asks forYYYY-MM-DDTHH:mm:ss.sssZ: UTC, millisecond precision.Changes:
TaskStatus.TimestampandListTasksRequest.StatusTimestampAfterare written in UTC with exactly three fractional digits, e.g.2026-10-01T08:30:00.000Z. The caller's value is not modified.Zwith 0, 3, 6 or 9 fractional digits is accepted.statusTimestampAfterin the same form.NewStatusUpdateEventusestime.Now().UTC()truncated to milliseconds, so an event reads back equal to the one that was created.Tests in
a2a/timestamp_test.goanda2aclient/rest_test.go: the event timestamp is UTC with millisecond precision and survives a round trip; a value, a pointer and a wholeTaskwith aUTC+2timestamp give...Zwith three digits for whole seconds, milliseconds and nanoseconds;nilis omitted; a year outside 0 to 9999 is an error; reading accepts 0, 3, 6 and 9 digits;ListTasksRequestand the REST query use the same format. The format tests fail without the fix.go test -race -shuffle=on ./...passes, also withTZ=Europe/Belgrade. golangci-lint v2.11.4: 0 issues.