Skip to content

fix(backend): use shared timezone-aware UTC timestamps (#170) - #203

Merged
BrandDead merged 2 commits into
main-tL2525from
fix/170-timezone-aware-utc
Oct 1, 2026
Merged

BrandDead merged 2 commits into
main-tL2525from
fix/170-timezone-aware-utc

Conversation

@BrandDead

Copy link
Copy Markdown
Owner

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), new backend/python/utils/{__init__,utc}.py, new backend/python/tests/test_utc_timestamps.py, append-only docs/PROJECT_LOG.md.

Out: every frontend/** file (zero files changed — git diff --name-only origin/main-tL2525...HEAD -- frontend is empty), backend/supabase/** (no migration, RLS, or config change), backend/python/models/block.py, the standalone backend/python/backend-*.py services, secrets, scheduler deployment, gameplay balance, and API field renames.

Reserved files: all files above were reserved in the issue comment at base 04ee0e3178880147cdb8115bd182aadb012653cb before any edit.

Contracts preserved

  • Serialized timestamp compatibility. to_iso_utc emits 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-fix datetime.utcnow().isoformat() output, including the "microseconds omitted when zero" case. Moving to Z/+00:00 is left as a deliberate future contract change.
  • Field names and response shapes. No key, signature, or payload changed; only the expression producing the value did.
  • Naive values keep their meaning. A naive input is treated as already-UTC and is never shifted, which is what the removed utcnow() call sites meant. Aware inputs are converted to UTC first.
  • One authoritative path. No new state container, no duplicate writer, no second timestamp system; the shared helper is the single source.
  • Determinism/idempotency. Snapshot IDs still hash 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.utc did not exist, the live modules still constructed naive UTC, and the runtime paths emitted datetime.datetime.utcnow() is deprecated. After implementation: 12 passed.

Baseline vs after (same venv, Python 3.12.3):

Baseline After
Backend tests 95 passed 107 passed
Warnings 153 (all utcnow deprecation) 0
utcnow sites in live runtime 17 0

Full repository gate — preflight.sh exited 0:

  • frontend lint + typecheck: clean
  • Vitest: 91 files, 1033 passed, 4 skipped
  • asset audit: 112 assets, 0 errors, 0 warnings, 7.70 MB of the 20 MB budget
  • asset packages: 5 packages, 4 schemas
  • production build: 3347 modules in 27.18s
  • backend pytest (triggered because backend/python changed): 107 passed, 0 warnings

New warnings compared with base: none added; 153 removed. No # type: ignore, no as any-style escape, no warnings filter 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 revert of the single commit; no data migration is involved because no stored value is rewritten.

Integration notes

BrandDead added 2 commits October 1, 2026 18:58
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
@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
slide Ready Ready Preview Oct 1, 2026 7:04pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T19:05:07.821729Z 61f6301 PR opened
🔒 Security Review ✅ Completed 2026-10-01T19:06:40.439266Z 61f6301 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copy link
Copy Markdown
Owner Author

CI evidence on fix/170-timezone-aware-utc

All required checks pass on head 61f6301d90bd6b2a3a2792e4854bc040c3dd6891:

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.

Copy link
Copy Markdown
Owner Author

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.

@BrandDead
BrandDead merged commit 9eef5aa into main-tL2525 Oct 1, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 61f6301d Deployed Oct 1, 2026 by vercel[bot]
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.

Replace deprecated naive UTC timestamp construction

1 participant