Skip to content

fix(app): resolve conversation detail through the local day key, not raw UTC fields - #10979

Closed
kodjima33 wants to merge 2 commits into
mainfrom
issues-improver/10976-local-day-key-getter
Closed

kodjima33 wants to merge 2 commits into
mainfrom
issues-improver/10976-local-day-key-getter

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

What

ConversationDetailProvider.conversationOrNull validated the conversation it resolved by comparing the raw year/month/day of its effective date (startedAt ?? createdAt) against selectedDate. Server timestamps parse as UTC, so those are UTC fields — while selectedDate is the local day key that conversationLocalDayKey produced when grouping.

Both sides now go through conversationLocalDayKey, so the getter can only accept or reject the very key the grouper produced.

Why

Wherever a conversation's local calendar day differs from its UTC one — started late in the UTC day ahead of UTC, or at the start of it behind — the check failed for a conversation that is sitting in the selected day-group, and the getter returned null:

  • build paths (conversationOrNull) render a blank detail page;
  • gesture/async paths (conversation) throw StateError: No valid conversation found.

That is every user whose device is not at UTC, for any conversation near their local midnight.

Reported in #10976 as a red test on main. It is not fixture rot: the fixture was pinned at 23:30 UTC, which only diverges ahead of UTC, so the guard was green on every host behind UTC — including CI, which runs ubuntu-latest at UTC, where local and UTC calendar days can never diverge at all. That is why the defect shipped and why the test looked fine here until someone ran it from a positive offset.

Second commit

The two sibling-identity tests in the same file pinned fixtures to UTC instants two hours apart. Those straddle local midnight at far-enough offsets and split into two day groups, so groupedConversations.keys.single threw Bad state: Too many elements under TZ=Pacific/Kiritimati (+14) and Pacific/Midway (-11). Neither test is about UTC/local divergence — both just need one group — so they are anchored in local time.

What I tested

flutter test test/providers/conversation_detail_provider_selection_test.dart, run per timezone, on the parent commit and on this branch:

TZ offset parent this branch
Pacific/Midway −11 fail pass
America/Los_Angeles −7 fail pass
America/New_York −4 fail pass
UTC 0 pass¹ pass
Europe/Berlin +2 fail pass
Asia/Kathmandu +5:45 fail pass
Asia/Tokyo +9 fail pass
Australia/Sydney +10 fail pass
Pacific/Kiritimati +14 fail pass

¹ Stated plainly: at UTC the two calendar days cannot diverge, so the case under test cannot be constructed and the guard asserts only plain resolution there. CI runs at UTC, so CI will not catch a regression of this bug — the guard is real on every developer machine outside UTC, and inert on the runner. Pinning TZ for the app test lane would fix that, but it changes the CI workflow and is out of scope here.

Also run:

  • full app suite bash app/test.sh → 987 passed, 0 failed (issue reports 957 passed / 1 failed on main).
  • dart format --line-length 120 → 0 changed.
  • make preflight → passing.

Not exercised in a running app build: this is a pure provider-lookup path with no UI change, covered by the unit test above driving the real groupConversationsByDate → updateConversation → conversationOrNull sequence.

Notes

  • app/scripts/analyze_ratchet.sh is red on my machine, on main as well as here, from one deprecated_member_use_from_same_package on getDeviceImagePathByModel (lib/pages/conversations/wal_item_detail/wal_item_detail_page.dart:634). That is a local-toolchain artifact, not a repo state: the same run reports experimental_member_use 0-found against a baseline of 13, and this box is on Flutter 3.38.5 while CI takes current stable. CI's own ratchet is green on main. Nothing here touches either file.
  • Four call sites still derive the day key with raw date components instead of conversationLocalDayKey (chat/widgets/ai_message.dart, onboarding/conversation_created_widget.dart, memories/widgets/memory_item.dart, conversation_detail/page.dart fallback). Same defect class, but in widget code I cannot unit-verify, so per the repo's "only make an opportunistic fix you can verify" rule they are filed as Four conversation day-key call sites derive the key from raw UTC fields instead of conversationLocalDayKey #10980 rather than changed blind.

Failure-Class: none

fixes #10976

Auto-generated from issue feedback by the mini issues-improver — tested and merged.

`ConversationDetailProvider.conversationOrNull` validated the resolved
conversation by comparing the raw year/month/day of its effective date
(`startedAt ?? createdAt`) against `selectedDate`. Server timestamps parse as
UTC, so those are UTC fields, while `selectedDate` is the *local* day key
`conversationLocalDayKey` produced when grouping. Wherever a conversation's
local calendar day differs from its UTC one — started late in the UTC day
ahead of UTC, or at the start of it behind — the check failed for a
conversation sitting in the selected day-group, so the getter returned null:
a blank detail page on build paths, `StateError` from the non-null getter on
gesture paths.

Both sides now go through `conversationLocalDayKey`, the same function the
grouping uses, so the getter can only accept or reject the key the grouper
produced.

The regression test derived its instant from a pinned 23:30 UTC, which only
diverges ahead of UTC — it was green on every host behind it, including CI at
UTC, where local and UTC days can never diverge at all. It now derives the
instant from the host's offset at that date so the divergence is constructed
on either side of UTC.

Verified: `flutter test test/providers/conversation_detail_provider_selection_test.dart`
fails on the parent commit and passes on this one under TZ=Europe/Berlin,
Asia/Tokyo, Asia/Kathmandu, Pacific/Kiritimati, America/New_York,
America/Los_Angeles and Pacific/Midway; full suite `bash app/test.sh` is
987 passed / 0 failed (was 957/1 on main).

fixes #10976
The two sibling-identity tests in this file pinned their fixtures to UTC
instants two hours apart, which straddle local midnight at far-enough offsets
and split into two day groups — `groupedConversations.keys.single` then threw
`Bad state: Too many elements` under TZ=Pacific/Kiritimati (+14) and
Pacific/Midway (-11). Neither test is about UTC/local divergence; both need
one group. Anchoring them in local time gives that in every timezone.

Verified: the file passes under TZ=UTC, Europe/Berlin, Asia/Tokyo,
Asia/Kathmandu, Australia/Sydney, Pacific/Kiritimati, Pacific/Midway,
America/New_York and America/Los_Angeles.

@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.

2 issues found across 2 files

Confidence score: 3/5

  • In app/lib/pages/conversation_detail/conversation_detail_provider.dart, fallback/external-entry flows can misinterpret a raw UTC calendar date as a local day, so selectedDate may not match the intended conversation on non-UTC devices and resolve to null for users — normalize these paths to the same timezone/day semantics before lookup (e.g., convert to local-day or keep everything UTC consistently).
  • In app/test/providers/conversation_detail_provider_selection_test.dart, the regression test can pass on UTC hosts without actually validating the local-vs-UTC day split, which leaves this bug class underprotected in CI depending on runner timezone — make the test timezone-explicit/deterministic so it fails when day-boundary handling regresses.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/lib/pages/conversation_detail/conversation_detail_provider.dart">

<violation number="1" location="app/lib/pages/conversation_detail/conversation_detail_provider.dart:94">
P2: Conversation details opened through the fallback or external-entry paths can still resolve to null on non-UTC devices: those paths pass a raw UTC calendar date, while this line interprets `selectedDate` as a local-day key. Normalizing those remaining date arguments with `conversationLocalDayKey` (or passing the grouper's key through every entry path) would keep the validation consistent.</violation>
</file>

<file name="app/test/providers/conversation_detail_provider_selection_test.dart">

<violation number="1" location="app/test/providers/conversation_detail_provider_selection_test.dart:132">
P3: The new regression test only exercises the local-vs-UTC day divergence on non-UTC hosts: on a UTC host _instantSplittingUtcAndLocalDay() returns 23:59 UTC where the local and UTC calendar days coincide, so the getter's day-key comparison takes the trivial equality path and the test asserts plain resolution. Because CI runs at UTC, this test won't catch a future reintroduction of the raw-UTC comparison bug that caused #10976. Consider pinning the process timezone (e.g., set TZ=/var/run/... to a non-UTC zone in the test, or inject a clock/timezone) so the regression path is exercised deterministically in CI.</violation>
</file>

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

Re-trigger cubic

if (effectiveDate.year == selectedDate.year &&
effectiveDate.month == selectedDate.month &&
effectiveDate.day == selectedDate.day) {
if (conversationLocalDayKey(effectiveDate) == conversationLocalDayKey(selectedDate)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Conversation details opened through the fallback or external-entry paths can still resolve to null on non-UTC devices: those paths pass a raw UTC calendar date, while this line interprets selectedDate as a local-day key. Normalizing those remaining date arguments with conversationLocalDayKey (or passing the grouper's key through every entry path) would keep the validation consistent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/pages/conversation_detail/conversation_detail_provider.dart, line 94:

<comment>Conversation details opened through the fallback or external-entry paths can still resolve to null on non-UTC devices: those paths pass a raw UTC calendar date, while this line interprets `selectedDate` as a local-day key. Normalizing those remaining date arguments with `conversationLocalDayKey` (or passing the grouper's key through every entry path) would keep the validation consistent.</comment>

<file context>
@@ -84,15 +84,14 @@ class ConversationDetailProvider extends ChangeNotifier with MessageNotifierMixi
-      if (effectiveDate.year == selectedDate.year &&
-          effectiveDate.month == selectedDate.month &&
-          effectiveDate.day == selectedDate.day) {
+      if (conversationLocalDayKey(effectiveDate) == conversationLocalDayKey(selectedDate)) {
         return _cachedConversation = result;
       }
</file context>

/// a DST boundary between the two cannot flip which side it falls on.
DateTime _instantSplittingUtcAndLocalDay() {
final offset = DateTime.utc(2026, 7, 18, 12).toLocal().timeZoneOffset;
return offset.isNegative ? DateTime.utc(2026, 7, 18, 0, 0) : DateTime.utc(2026, 7, 18, 23, 59);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The new regression test only exercises the local-vs-UTC day divergence on non-UTC hosts: on a UTC host _instantSplittingUtcAndLocalDay() returns 23:59 UTC where the local and UTC calendar days coincide, so the getter's day-key comparison takes the trivial equality path and the test asserts plain resolution. Because CI runs at UTC, this test won't catch a future reintroduction of the raw-UTC comparison bug that caused #10976. Consider pinning the process timezone (e.g., set TZ=/var/run/... to a non-UTC zone in the test, or inject a clock/timezone) so the regression path is exercised deterministically in CI.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/test/providers/conversation_detail_provider_selection_test.dart, line 132:

<comment>The new regression test only exercises the local-vs-UTC day divergence on non-UTC hosts: on a UTC host _instantSplittingUtcAndLocalDay() returns 23:59 UTC where the local and UTC calendar days coincide, so the getter's day-key comparison takes the trivial equality path and the test asserts plain resolution. Because CI runs at UTC, this test won't catch a future reintroduction of the raw-UTC comparison bug that caused #10976. Consider pinning the process timezone (e.g., set TZ=/var/run/... to a non-UTC zone in the test, or inject a clock/timezone) so the regression path is exercised deterministically in CI.</comment>

<file context>
@@ -112,6 +122,19 @@ void main() {
+/// a DST boundary between the two cannot flip which side it falls on.
+DateTime _instantSplittingUtcAndLocalDay() {
+  final offset = DateTime.utc(2026, 7, 18, 12).toLocal().timeZoneOffset;
+  return offset.isNegative ? DateTime.utc(2026, 7, 18, 0, 0) : DateTime.utc(2026, 7, 18, 23, 59);
+}
+
</file context>

@kodjima33

Copy link
Copy Markdown
Collaborator Author

Superseded — the same fix landed in #10981 (e6db4d5e81), which is on main: ConversationDetailProvider.conversationOrNull now compares conversationLocalDayKey(startedAt ?? createdAt) against conversationLocalDayKey(selectedDate), and #10976 is closed by it. Closing so this doesn't sit open as a duplicate.

🤖 hourly watchdog

@kodjima33 kodjima33 closed this Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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.

conversation_detail_provider_selection_test fails on main — the different-days guard is red

1 participant