fix(agents): emit chat event timestamps in milliseconds (#9867)#10243
Open
aniruddh909 wants to merge 1 commit into
Open
fix(agents): emit chat event timestamps in milliseconds (#9867)#10243aniruddh909 wants to merge 1 commit into
aniruddh909 wants to merge 1 commit into
Conversation
Agent chat replies rendered a broken timestamp in the web UI
("Invalid Timestamp" / "12:00 AM", identical for every reply) because
the SSE timestamp unit was inconsistent across producers.
EventBridge.PublishEvent emitted Unix nanoseconds while the local
dispatcher (dispatcher.go) already emitted Unix milliseconds, and the
React UI fed the value straight into `new Date(ts)` after dividing by
1e6. Nanoseconds also overflow JS's safe-integer range (~1.7e18).
Standardize on Unix milliseconds: switch PublishEvent to UnixMilli and
drop the /1e6 conversion in AgentChat.jsx so both SSE paths agree and
match the React UI's expectation. Add a regression test asserting the
published timestamp is in milliseconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the broken agent chat timestamps reported in #9867 — replies in the web UI render as "Invalid Timestamp", "12:00 AM", or the same time for every message.
Root cause
The agent chat SSE
json_messageevent is produced by two paths that disagreed on the timestamp unit, and the React UI assumed a third interpretation:core/services/agents/dispatcher.go(local dispatcher)UnixMilli()core/services/agents/events.goPublishEvent(NATS EventBridge)UnixNano()core/http/react-ui/src/pages/AgentChat.jsx/ 1e6(i.e. assumed nanoseconds)In the common single-node case the local dispatcher sends milliseconds, the UI divides by
1e6, and the result collapses to a near-epoch date → "12:00 AM" / "Invalid Timestamp". Nanoseconds are also the wrong thing to send over JSON, sinceUnixNano()(~1.7e18) exceeds JavaScript'sNumber.MAX_SAFE_INTEGER.Change
Standardize on Unix milliseconds — the JS-native unit for
new Date(ts)and within the safe-integer range:events.go:PublishEventnow usestime.Now().UnixMilli()(matching the local dispatcher), with a comment documenting the unit on both the call site and theAgentEvent.Timestampfield.AgentChat.jsx: consumedata.timestampdirectly instead of dividing by1e6.events_test.go: new regression test asserting the published timestamp falls within a millisecond[before, after]window (it fails against the oldUnixNanobehavior).Testing
go test ./core/services/agents/passes (40 specs); the new test fails when reverted toUnixNanoand passes withUnixMilli, confirming it guards the regression.Scope note
#9867 also mentions chat history not being included in context. That is by design — conversation history is stored client-side (browser localStorage), as documented in
events.go. This PR addresses only the timestamp defect.