Repository navigation
fix(timestamps): emit UTC with Z suffix across backend (#79) - #440
Merged
Merged
Conversation
Backend previously called datetime.utcnow().isoformat() in 41 modules, producing naive ISO strings like "2026-04-10T08:30:00.842757" (no timezone). The frontend then parsed these via new Date(str), which JS interprets as local time rather than UTC — so timestamps rendered in the server's timezone regardless of client locale (the bug reported against the Payments tab and elsewhere). Changes: - Replace datetime.utcnow().isoformat() with utc_now_iso() helper (returns ISO with trailing "Z") across 38 modules. - Replace three remaining datetime.now().isoformat() callsites in agent_service/crud.py (docker trinity.created label), db/users.py (role update), and main.py (health check). - docker_service.py reads trinity.created via parse_iso_timestamp so legacy naive labels are tagged UTC and serialized with offset. - Strip redundant `+ "Z"` suffixes left behind where the old code appended Z manually after isoformat() — helper already includes Z. Helper utc_now_iso() and parse_iso_timestamp() already existed in utils/helpers.py but were not mass-adopted. This PR completes that adoption. Going forward, new backend code should always use the helper. API now returns timestamps like "2026-04-21T10:42:24.745640Z" (or "+00:00" when round-tripped through Pydantic datetime), both of which JS new Date(str) parses as UTC and toLocaleString() renders in the client's local zone automatically. Closes #79 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
vybe
approved these changes
Apr 21, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Validated via /validate-pr — mechanical sweep is correct, security clean, no architectural impact. Follow-ups (naive datetime .isoformat() in routers/approvals, audit, executions, email_auth, and frontend parseUTC adoption) are acknowledged in the PR body and out of scope here.
6 of 7 tasks
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.
Summary
Backend emitted naive ISO timestamps from
datetime.utcnow().isoformat()in 41 modules — noZsuffix, no offset. JavaScriptnew Date(str)then parsed them as local time, so timestamps rendered in the server's timezone instead of the client's (the bug reported against the Payments tab and elsewhere).datetime.utcnow().isoformat()→utc_now_iso()helper (which appendsZ) across 38 modules.datetime.now().isoformat()callsites (agent create docker label, user role update, health check).docker_service.pyreadstrinity.createdlabel viaparse_iso_timestamp, so legacy naive labels are tagged UTC and emitted with+00:00on serialization.+ "Z"suffixes where the old code appended Z manually — helper already includes it. Without this, logs printed...ZZ.utc_now_iso()andparse_iso_timestamp()already existed inutils/helpers.py; this PR completes the mass adoption. Going forward, new backend code should use the helper.Closes #79
Verification
API now returns UTC-marked timestamps:
Both
...Zand...+00:00round-trip correctly throughnew Date(str).toLocaleString()in the browser — frontend now displays every timestamp in the viewer's local zone.Test plan
docker compose restart backend— no errors)GET /api/agentsreturnscreatedwith timezone markerGET /api/activities/timelinereturnsstarted_atwithZZ(notZZ)datetime.fromisoformat(label)paths still handle both...Z(new writes) and naive (legacy docker labels) —parse_iso_timestampcovers bothFollow-ups (out of scope for this PR)
new Date(str)will still mis-parse those as local. Options: one-off backfill migration OR frontendparseUTCadoption sweep (utility already exists atsrc/frontend/src/utils/timestamps.js). The latter is mechanical and ~30 files.(datetime.utcnow() - timedelta(...)).isoformat() + "Z"patterns indb/monitoring.pyweren't touched — they emit single Z correctly but could be standardized viato_utc_iso(datetime_obj).🤖 Generated with Claude Code