Skip to content

fix(a2a): serialize task status timestamps in UTC - #452

Merged
nahapetyan-serob merged 3 commits into
a2aproject:mainfrom
vbcherepanov:fix/status-timestamp-utc
Oct 14, 2026
Merged

nahapetyan-serob merged 3 commits into
a2aproject:mainfrom
vbcherepanov:fix/status-timestamp-utc

Conversation

@vbcherepanov

@vbcherepanov vbcherepanov commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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 for YYYY-MM-DDTHH:mm:ss.sssZ: UTC, millisecond precision.

Changes:

  • TaskStatus.Timestamp and ListTasksRequest.StatusTimestampAfter are written in UTC with exactly three fractional digits, e.g. 2026-10-01T08:30:00.000Z. The caller's value is not modified.
  • Reading is unchanged: Z with 0, 3, 6 or 9 fractional digits is accepted.
  • The REST client sends statusTimestampAfter in the same form.
  • NewStatusUpdateEvent uses time.Now().UTC() truncated to milliseconds, so an event reads back equal to the one that was created.

Tests in a2a/timestamp_test.go and a2aclient/rest_test.go: the event timestamp is UTC with millisecond precision and survives a round trip; a value, a pointer and a whole Task with a UTC+2 timestamp give ...Z with three digits for whole seconds, milliseconds and nanoseconds; nil is omitted; a year outside 0 to 9999 is an error; reading accepts 0, 3, 6 and 9 digits; ListTasksRequest and the REST query use the same format. The format tests fail without the fix.

go test -race -shuffle=on ./... passes, also with TZ=Europe/Belgrade. golangci-lint v2.11.4: 0 issues.

@nahapetyan-serob

Copy link
Copy Markdown
Contributor

Thanks, the switch to UTC is right. The spec is more specific, though:

  • Write timestamps as YYYY-MM-DDTHH:mm:ss.sssZ, always with three fractional digits (e.g. 2026-10-01T08:30:00.000Z).
  • When reading, keep accepting timestamps without the fraction or with other precisions. SDKs using protobuf JSON send 0, 3, 6 or 9 digits.

This change still uses Go's default encoding, so the number of digits varies: NewStatusUpdateEvent gives e.g. 2026-10-01T06:10:55.114002345Z, and a whole second gives 2026-10-01T08:30:00Z, which is what the new test asserts. ListTasksRequest.StatusTimestampAfter needs the same format.

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.
@vbcherepanov

Copy link
Copy Markdown
Contributor Author

Thanks, you're right. Done:

  • TaskStatus.Timestamp and ListTasksRequest.StatusTimestampAfter are written as YYYY-MM-DDTHH:mm:ss.sssZ, always three digits: a whole second gives 2026-10-01T08:30:00.000Z, nanoseconds are cut to .114Z. Non-UTC times are converted, the caller's value is not changed.
  • Reading is left to time.Time, so Z with 0, 3, 6 or 9 digits is accepted. There is a test for each.
  • The REST client sends statusTimestampAfter in the same form (it used time.RFC3339 before, which also dropped the fraction).
  • NewStatusUpdateEvent truncates to milliseconds, so the event a client receives is equal to the one the executor created. Without this TestJSONRPC_Streaming failed after the format change.

go test -race -shuffle=on ./... passes, also with TZ=Europe/Belgrade, and golangci-lint v2.11.4 reports 0 issues.

Comment thread a2a/core.go Outdated
}{wire: wire(s), Timestamp: newJSONTimestamp(s.Timestamp)})
}

// jsonTimestampLayout is the timestamp pattern of the spec, YYYY-MM-DDTHH:mm:ss.sssZ.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can remove the comment here

Comment thread a2a/core.go Outdated
// 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can be changed to

jsonTimestamp writes a time as ISO 8601 formtted strings in UTC timezone with Millisecond precision

Comment thread a2a/core.go Resolved
Comment thread a2a/core.go Outdated
Comment on lines +423 to +429
func newJSONTimestamp(t *time.Time) *jsonTimestamp {
if t == nil {
return nil
}
ts := jsonTimestamp(*t)
return &ts
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this helper is needed. Since jsonTimestamp is time.Time (*jsonTimestamp)(s.Timestamp) converts directly, and nil stay nil

Comment thread a2a/timestamp_test.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread internal/rest/rest.go Outdated

// 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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@vbcherepanov

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all done in the last push:

  • Removed the comment and used your doc text for jsonTimestamp.
  • MarshalJSON is now your one-liner, the year check is gone.
  • Dropped newJSONTimestamp, the conversion is direct now.
  • Moved the tests into json_test.go as two table tests, one for writing and one for reading.
  • timestampLayout in internal/rest is unexported.

go test -race ./... passes and golangci-lint reports 0 issues.

@nahapetyan-serob
nahapetyan-serob merged commit b657f33 into a2aproject:main Oct 14, 2026
5 checks passed
nahapetyan-serob pushed a commit that referenced this pull request Oct 21, 2026
🤖 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).
polchernikova-w added a commit that referenced this pull request Nov 29, 2026
…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.
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]: task status timestamps are serialized with the local offset instead of UTC

2 participants