Skip to content

fix(telemetry): resolve offset-naive datetime crashes in pruning, ingestion, and doctor CLI - #125

Open
markusbrand wants to merge 1 commit into
masterfrom
fix/telemetry-datetime-timezone-handling
Open

markusbrand wants to merge 1 commit into
masterfrom
fix/telemetry-datetime-timezone-handling

Conversation

@markusbrand

Copy link
Copy Markdown
Owner

Description

This PR fixes runtime crashes caused by comparisons between offset-naive and offset-aware datetimes in backend telemetry logging, retention pruning, and the doctor CLI, as well as fixing a time-bomb test failure in test_telemetry_api_routes.

Key Changes

  1. Telemetry Pruning & Logging (backend/app/telemetry/service.py):

    • Explicitly supply created_at=datetime.now(timezone.utc) when instantiating ServerEvent in log_server_event rather than relying solely on SQLite's server-side naive default in Python memory.
    • Configure bulk deletion queries in prune_telemetry_records with .execution_options(synchronize_session=False) to avoid evaluating SQL deletion predicates in Python memory against session entities with disparate datetime representations.
    • Normalize naive timestamps to timezone-aware UTC in ingest_telemetry_batch and upsert_client_ping.
  2. Doctor CLI Timeline Sorting (backend/app/cli/doctor.py):

    • Added _normalize_timeline_ts to safely normalize timestamps to UTC prior to comparison in show_trace and generate_llm_prompt timelines.
  3. Test Suite & OpenSpec Artifacts:

    • Updated backend/tests/test_telemetry.py to use dynamic relative UTC timestamps so test summaries are not immediately purged by 30-day retention policies.
    • Added regression test cases for log_server_event pruning, naive datetime ingestion, and mixed-timestamp timeline sorting.
    • Created OpenSpec change artifacts in openspec/changes/fix-telemetry-datetime-timezone-handling/.

Verification

  • Full QA suite passed (./scripts/run-qa.sh):
    • client-tauri: 21 passed, 0 failed.
    • web: build passed.
    • backend: 111 passed, 0 failed.
    • docs: mkdocs build passed.

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.

1 participant