You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(reliability): SR-187 — ban datetime.utcnow(), enforce UTC-aware datetimes
* fix(reliability): SR-187 — ban datetime.utcnow(), enforce UTC-aware datetimes (closes#186)
Python 3.12 deprecated datetime.utcnow() (DeprecationWarning) and will
remove it in 3.14. More importantly for our domain: naive datetimes are
ambiguous when compared against UTC-aware DB timestamps — silent
off-by-tz bugs are possible today.
Changes
-------
- scripts/check_banned_patterns.py: add regex \bdatetime\.utcnow\s*\(
with rationale comment. Strings/comments are masked by the tokeniser
so the rule does not flag its own documentation (per SR-60 contract).
- scripts/tests/test_check_banned_patterns.py: 5 new tests in
UtcnowBanTests covering POS (real call + chained call) and NEG
(docstring / comment / unrelated 'xutcnow' name). All 14 tests pass.
- survey-cli/commands/answer_survey.py:870
registry timestamp. Keeps historical 'Z' suffix for
command_registry.json wire-format stability.
- survey-cli/survey/captcha/fallback_chain.py:189,197
captcha-failures-YYYYMMDD.jsonl. Keeps 'Z' suffix for log-consumer
compatibility (historical contract documented in module docstring).
Computes 'now_utc' once instead of calling twice — small race fix.
- survey-cli/survey/daemon/answer_engine.py:1005
answer_history.created_at. Now emits '+00:00' suffix; downstream DB
comparisons against UTC-aware columns now match correctly.
- survey-cli/survey/daemon/survey_agent_graph.py:173,235,449
LangGraph state started_at / completed_at. Three sites, not two —
the issue said 'two in survey_agent_graph.py' but a third was added
later at line 447 (now 449).
Acceptance criteria from #186
-----------------------------
- [x] check_banned_patterns.py extended with regex for datetime.utcnow()
- [x] All 6 instances refactored (issue said 5; found one more in
commands/answer_survey.py:870 and a third in survey_agent_graph.py
that wasn't in the issue's line-list).
- [x] CI enforces: any new datetime.utcnow() fails path-guard
- [x] Tests confirm UTC-aware behaviour (UtcnowBanTests).
- [ ] Docs: AGENTS.md 'datetime hygiene' section — deferred to a docs-
only follow-up (AGENTS.md lives outside survey-cli root and the
master file was not in this PR's scope; left for owner).
Verification
------------
$ python3 scripts/check_banned_patterns.py
No banned patterns found.
$ python3 -m unittest scripts.tests.test_check_banned_patterns
Ran 14 tests in 0.007s — OK
Author note (v0 agent / Delqhi handoff)
---------------------------------------
SR-167 (Phase 1 Verifier) is already in flight via PR #175, so this PR
takes the orthogonal SR-187 lane. No file overlap with #175. Token from
the handoff prompt should be rotated regardless of merge status.
* chore: restore +x on scripts/check_banned_patterns.py
Edit tool stripped the executable bit on the previous commit. Restored
so the file remains directly runnable (it's invoked from CI without
'python3' on some hooks).
---------
Co-authored-by: v0 agent (Delqhi) <agent@v0.app>
0 commit comments