Skip to content

tech-debt(knowledge): naive datetime.now() calls throughout codebase — should use timezone.utc #3613

@mrveiss

Description

@mrveiss

Problem

While fixing PR #3609 (knowledge/memory_graph/query_processor.py), naive datetime.now() calls were found and replaced with datetime.now(tz=timezone.utc). However, this pattern likely exists broadly across the codebase and will produce incorrect time-range filters on servers not running in UTC.

Impact

  • Time-range FT.SEARCH filters (@created_at:[{ts} +inf]) compute incorrect epoch timestamps when the server timezone is not UTC
  • Audit logs, TTL calculations, and stream keys using strftime may be off by hours relative to actual UTC time

Fix

Audit all datetime.now() calls and replace with datetime.now(tz=timezone.utc) (or datetime.utcnow() where only naive timestamps are needed, with a comment explaining why).

Suggested grep: grep -r "datetime\.now()" autobot-backend/ --include="*.py" -l

Acceptance Criteria

  • No bare datetime.now() calls remain in production code paths that involve timestamps stored in Redis or databases
  • from datetime import timezone imported where needed

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions