Skip to content

fix(backend): render screen activity search timestamps in UTC instead of host-local time (#4643) - #8588

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
ZachL111:zach/screen-activity-search-utc-timestamp
Jun 29, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
ZachL111:zach/screen-activity-search-utc-timestamp

Conversation

@ZachL111

@ZachL111 ZachL111 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

search_screen_activity_tool renders each matching screenshot's timestamp for the chat model with a naive datetime.fromtimestamp(ts). Without a tz, the epoch is interpreted in the host's local timezone, so the time shown depends on where the backend runs.

The companion chat tool conversation_tools already renders match timestamps in the user's timezone (via notification_db.get_user_time_zone(uid)). Rendering screen-activity matches in a fixed timezone would make the two surfaces disagree within a single chat answer, which is the inconsistency #4643 is about.

Fix

Render screen-activity match timestamps in the user's timezone, matching conversation_tools. A small _resolve_display_tz(uid) helper reads notification_db.get_user_time_zone(uid) and returns the corresponding ZoneInfo, falling back to UTC when the user has no timezone set or the value is not a valid IANA name.

display_tz = _resolve_display_tz(uid)
...
ts_str = datetime.fromtimestamp(ts, tz=display_tz).strftime('%Y-%m-%d %H:%M:%S') if ts else 'Unknown'

Test

tests/unit/test_screen_activity_search_utc.py (registered in test.sh) loads the tool with its heavy leaves stubbed and exercises _resolve_display_tz behaviorally: a set timezone resolves to that zone, an unset timezone falls back to UTC, and an invalid name falls back to UTC. A source-level check confirms the render uses the resolved timezone and no longer uses the naive form.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @ZachL111 — good catch on the underlying bug. Rendering an epoch via datetime.fromtimestamp(ts) without a tz makes the displayed time depend on the backend host's local timezone, which is clearly wrong. Passing tz=timezone.utc removes that host-dependence and is a real improvement.

One consistency note before this lands, though. The description says the change "matches how conversation search and the other timestamp renderings handle epoch values," but that's not quite accurate: conversation search renders match timestamps in the user's timezone via notification_db.get_user_time_zone(uid) (see conversation_tools.py, conversations_to_string(..., tz=...)), not UTC. So if this merges as-is, screen-activity matches will appear in UTC while conversation matches in the same chat answer appear in the user's local time — exactly the kind of mixed rendering #4643 is about.

I'd like a maintainer to confirm the intended direction here:

The code change itself is correct and minimal, and the structural source-level test is reasonable given the heavy import graph (though a behavioral assertion on the rendered output would be stronger if feasible later). No security/data-handling concerns on this change.

Tagging for product/maintainer review on the UTC-vs-user-timezone consistency question.

@Git-on-my-level Git-on-my-level added feature-fit-review Needs review of product/feature direction with Omi mission/vision needs-maintainer-review Needs a human maintainer to sign off before merge labels Jun 29, 2026
@ZachL111

Copy link
Copy Markdown
Contributor Author

Good point, thanks. You are right that conversation_tools renders match timestamps in the user's timezone (via notification_db.get_user_time_zone(uid)), so UTC here would have made the two surfaces disagree within the same chat answer. My description's "matches conversation search" line was about the host-dependence fix rather than the destination timezone, so it was misleading.

Updated in bd9e325 to render in the user's timezone like conversation_tools, via a small _resolve_display_tz(uid) helper that falls back to UTC when the user has no timezone set or the value is not a valid IANA name. Both surfaces now render the same way, addressing the #4643 consistency you flagged. I also corrected the PR description.

The helper is covered behaviorally (a set timezone resolves to that zone, unset and invalid both fall back to UTC), with a source-level check on the wiring.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@ZachL111

Copy link
Copy Markdown
Contributor Author

Fixed: _resolve_display_tz now wraps the whole resolution, including the notification_db.get_user_time_zone(uid) Firestore read, in the try/except so a transient lookup error falls back to UTC instead of failing the search (matching the fail-soft pattern in the other retrieval tools). Added test_resolve_display_tz_falls_back_to_utc_when_lookup_raises to cover it.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend bug fix with regression test; CI green. Approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-fit-review Needs review of product/feature direction with Omi mission/vision needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants