Repository navigation
fix(backend): use shared timezone-aware UTC timestamps (#170) - #203
Conversation
Replace every `datetime.utcnow()` call site in the live backend runtime with a single shared helper, `utils.utc`, that returns timezone-aware UTC values. Python 3.12 deprecates `utcnow()` and schedules it for removal, and the required CI runs the full backend suite, so the warnings were visible on every run. - New `backend/python/utils/utc.py`: `utc_now()`, `to_iso_utc()`, `utc_now_iso()`. - Serialization deliberately reproduces the established external wire format (UTC ISO-8601, no offset designator) so no API consumer sees a changed string. - Session/seed identifiers now derive from the true UTC epoch instead of a host-local reinterpretation of a naive value. - 17 call sites across 9 files; no field names, signatures, or response shapes change. Refs #170
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
CI evidence on
|
| Check | Result |
|---|---|
| Backend (pytest) | pass (21s) |
| Frontend (lint + build) | pass (2m25s) |
| Vercel | pass — deployment completed |
| Vercel Preview Comments | pass |
Local preflight.sh on the same tree also exited 0 (Vitest 91 files / 1033 passed / 4 skipped; asset audit 0 errors / 0 warnings at 7.70 MB / 20 MB; production build 3347 modules in 27.18s; backend 107 passed / 0 warnings).
Leaving this PR open for the integration owner per the contributor workflow — nothing merged, nothing deployed, and #170 remains open.
|
Integration review, exact head 61f6301: independent source review found no concrete regression; Python 3.12 focused 12/12 and full backend 107/107 with 0 warnings, verified in isolated checkout. UTC contract tests also passed under America/New_York and Asia/Tokyo. Exact-head required GitHub frontend/backend and Vercel checks passed, no unresolved review threads; #175 authenticated staging proof remains open. PR #202 overlaps only docs/PROJECT_LOG.md; rebase/resolution required before its future merge. |
Outcome
Every backend API and service timestamp now comes from one shared timezone-aware UTC helper, so the Python 3.12
datetime.utcnow()deprecation no longer fires anywhere in the live runtime — while every serialized timestamp string stays byte-compatible with what consumers already receive.Scope
In:
backend/python/api/{avatar,combat,driveby,inventory,world}.py,backend/python/routes/art.py,backend/python/services/{block_state_engine,grid_generator,scheduler}.py(call-site replacement only), newbackend/python/utils/{__init__,utc}.py, newbackend/python/tests/test_utc_timestamps.py, append-onlydocs/PROJECT_LOG.md.Out: every
frontend/**file (zero files changed —git diff --name-only origin/main-tL2525...HEAD -- frontendis empty),backend/supabase/**(no migration, RLS, or config change),backend/python/models/block.py, the standalonebackend/python/backend-*.pyservices, secrets, scheduler deployment, gameplay balance, and API field renames.Reserved files: all files above were reserved in the issue comment at base
04ee0e3178880147cdb8115bd182aadb012653cbbefore any edit.Contracts preserved
to_iso_utcemits the exact established shape: UTC ISO-8601, no offset designator (2026-07-17T01:02:03.456789). A regression test pins this byte-for-byte against the pre-fixdatetime.utcnow().isoformat()output, including the "microseconds omitted when zero" case. Moving toZ/+00:00is left as a deliberate future contract change.utcnow()call sites meant. Aware inputs are converted to UTC first.block_id-version-timestamp; only the timestamp's provenance changed.Verification
Regression first.
tests/test_utc_timestamps.py(12 tests) was committed and run against the unmodified base — 12 failed, for exactly the intended reasons:utils.utcdid not exist, the live modules still constructed naive UTC, and the runtime paths emitteddatetime.datetime.utcnow() is deprecated. After implementation: 12 passed.Baseline vs after (same venv, Python 3.12.3):
utcnowdeprecation)utcnowsites in live runtimeFull repository gate —
preflight.shexited 0:backend/pythonchanged): 107 passed, 0 warningsNew warnings compared with base: none added; 153 removed. No
# type: ignore, noas any-style escape, nowarningsfilter suppression — the warnings are gone because the deprecated call is gone.Browser/player-path evidence: not applicable — this PR changes no player-facing surface, no frontend file, and no response shape. The repo's manual phone/desktop evidence requirement is therefore not claimed here rather than faked; the honest limit is that the backend change was verified by the full backend suite plus the API contract tests already in it.
Operational impact
None. No migration, RLS, secret, scheduler, tick endpoint, payment, or deployment change. Rollback is
git revertof the single commit; no data migration is involved because no stored value is rewritten.Integration notes
docs/PROJECT_LOG.mdas deliberate follow-ups: the unusedmodels/block.pySQLAlchemy model (naiveDateTimecolumns make that a persistence-semantics decision) and the standalonebackend-*.pyscripts the suite does not import.