Skip to content

fix(app): derive conversation day keys from the local-day authority (#10980) - #10987

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10980-local-day-key-call-sites
Aug 1, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10980-local-day-key-call-sites

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #10980.

The bug

Conversations are bucketed by conversationLocalDayKey(startedAt ?? createdAt) — the viewer's local calendar day (app/lib/providers/conversation_provider.dart, used by _buildGroupedByDate). Four call sites re-derived the key from the timestamp's raw UTC year/month/day. Server timestamps parse as UTC, so for every viewer off UTC the two keys disagree near local midnight and a conversation that is in the group reads as absent:

  • app/lib/pages/chat/widgets/ai_message.dart — tapping a conversation link in chat resolved idx == -1, so the tap silently did nothing.
  • app/lib/pages/memories/widgets/memory_item.dart — inserted the conversation under one key and selected another, opening the detail page on a day nothing was grouped under.
  • app/lib/pages/onboarding/conversation_created_widget.dart — the onboarding hand-off selected a day with no group.
  • app/lib/pages/conversation_detail/page.dart — the getConversationDateAndIndex fallback set selectedDate from raw components.

Same defect as #10976 (conversationOrNull), split out by that PR because these are widget paths with no test seam.

The fix

The two id-based lookups now go through the provider, which owns the derivation, so there is one authority instead of four copies:

  • getConversationDateAndIndexById(id) — resolves the loaded conversation, then reuses getConversationDateAndIndex (chat link tap). This also fixes a second miss: the chat message only carries createdAt, while grouping keys on startedAt ?? createdAt.
  • ensureConversationInGroup(conversation) — files the conversation under its local-day key and returns that key, replacing the widget-local grouping copy in memory_item.dart so the insert and the selection can no longer disagree.

The two remaining sites call conversationLocalDayKey directly. That is the test seam the issue asked for.

Verification

  • Reproduced pre-fix. A scratch test replaying the old raw-UTC derivation against the real group key missed 5–6 of 24 hours under TZ=Asia/Kolkata, America/New_York and Pacific/Auckland — e.g. 18:30Z → old key 2026-07-18 vs group key 2026-07-19 (Kolkata).
  • New regression test app/test/providers/conversation_day_key_call_sites_test.dart sweeps all 24 hours (a single pinned hour stays green at some UTC offsets): green under TZ=UTC, Asia/Kolkata, America/New_York, Pacific/Auckland, Pacific/Kiritimati, Pacific/Midway.
  • app/test.sh — 990 tests passed.
  • flutter analyze on the five changed files + the test — no new issues; dart format --line-length 120 clean.
  • make preflight — all manifest checks pass.

Product invariants affected

  • INV-MEM-1

memory_item.dart is matched by the invariant's path globs. This change only alters which day key the memory→conversation tap selects; memory tier behavior, storage, and rendering are untouched.

Failure class

A derived day-bucket key has exactly one authority; a consumer that re-derives it from raw UTC fields disagrees with that authority. Guard surface added in this PR: the two provider methods (so widgets can no longer re-derive) plus the whole-day-sweep behavioral test.

Failure-Class: FC-day-bucket-key-recomputed

🤖 automated by hourly watchdog — tested and merged

Review in cubic

…10980)

Conversations are bucketed by `conversationLocalDayKey(startedAt ?? createdAt)`
— the viewer's local calendar day. Four call sites re-derived the key from the
timestamp's raw UTC `year/month/day`, so for any viewer off UTC the key missed
the group near local midnight:

- `ai_message.dart` — tapping a conversation link in chat resolved `idx == -1`
  and silently did nothing.
- `memory_item.dart` — inserted the conversation under one key and selected
  another, opening the detail page on a day with no group.
- `conversation_created_widget.dart` — the onboarding hand-off selected a day
  that has no group.
- `conversation_detail/page.dart` — the `getConversationDateAndIndex` fallback
  set `selectedDate` from raw components.

Both id-based lookups now go through the provider, which owns the derivation:
`getConversationDateAndIndexById` (chat link) and `ensureConversationInGroup`
(memory tap, replacing the widget-local grouping copy). The two remaining sites
call `conversationLocalDayKey` directly.

## Verification

- Reproduced pre-fix: a scratch test replaying the old raw-UTC derivation
  against the real group key missed 5-6 of 24 hours under TZ=Asia/Kolkata,
  America/New_York and Pacific/Auckland (e.g. 18:30Z → old key 2026-07-18 vs
  group key 2026-07-19).
- New `app/test/providers/conversation_day_key_call_sites_test.dart` sweeps all
  24 hours; green under TZ=UTC, Asia/Kolkata, America/New_York, Pacific/Auckland,
  Pacific/Kiritimati, Pacific/Midway.
- `app/test.sh` — 990 tests passed.
- `flutter analyze` on the five changed files + the test: no new issues.

Failure-Class: FC-day-bucket-key-recomputed

@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 6 files

Confidence score: 3/5

  • In app/lib/pages/onboarding/conversation_created_widget.dart, ConversationListItem still gets a UTC-truncated createdAt while the detail provider uses local-day alignment, so tapping into detail can call updateConversation with a mismatched date and shift the conversation into the wrong day/group — pass the same local-day-normalized timestamp through this widget path.
  • In app/lib/providers/conversation_provider.dart, the helper that should preserve grouping drops memory-linked conversations fetched outside conversations when detail initializes, which can make items disappear from their expected group and undermine list consistency — ensure the canonical conversation is inserted/used in conversations before group mutations.
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/onboarding/conversation_created_widget.dart">

<violation number="1" location="app/lib/pages/onboarding/conversation_created_widget.dart:19">
P2: The detail-provider date was aligned to the local-day authority, but the ConversationListItem in this same widget still receives the old UTC-truncated createdAt date. Tapping it calls updateConversation with that UTC key (conversation_list_item.dart:127), which won't match the local-day group key, so the onboarding detail lookup can again fail/blank for any viewer whose local calendar day differs from UTC (startedAt != createdAt also widens it). Derive this date with the same conversationLocalDayKey(provider.conversation!.startedAt ?? provider.conversation!.createdAt) so insertion and selection share one authority.</violation>
</file>

<file name="app/lib/providers/conversation_provider.dart">

<violation number="1" location="app/lib/providers/conversation_provider.dart:1092">
P2: A memory-linked conversation fetched outside `conversations` is removed from its group as soon as the detail page initializes, so this helper does not maintain the group it claims to ensure. Keep the canonical conversation list and grouped map in sync (or avoid rebuilding away this temporary entry) before navigating.</violation>
</file>

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

Re-trigger cubic

if (!context.mounted) return;
context.read<ConversationProvider>().addConversation(conversation);
var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day);
var date = conversationLocalDayKey(conversation.startedAt ?? conversation.createdAt);

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: The detail-provider date was aligned to the local-day authority, but the ConversationListItem in this same widget still receives the old UTC-truncated createdAt date. Tapping it calls updateConversation with that UTC key (conversation_list_item.dart:127), which won't match the local-day group key, so the onboarding detail lookup can again fail/blank for any viewer whose local calendar day differs from UTC (startedAt != createdAt also widens it). Derive this date with the same conversationLocalDayKey(provider.conversation!.startedAt ?? provider.conversation!.createdAt) so insertion and selection share one authority.

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

<comment>The detail-provider date was aligned to the local-day authority, but the ConversationListItem in this same widget still receives the old UTC-truncated createdAt date. Tapping it calls updateConversation with that UTC key (conversation_list_item.dart:127), which won't match the local-day group key, so the onboarding detail lookup can again fail/blank for any viewer whose local calendar day differs from UTC (startedAt != createdAt also widens it). Derive this date with the same conversationLocalDayKey(provider.conversation!.startedAt ?? provider.conversation!.createdAt) so insertion and selection share one authority.</comment>

<file context>
@@ -16,7 +16,7 @@ Future updateConvoDetailProvider(BuildContext context, ServerConversation conver
     if (!context.mounted) return;
     context.read<ConversationProvider>().addConversation(conversation);
-    var date = DateTime(conversation.createdAt.year, conversation.createdAt.month, conversation.createdAt.day);
+    var date = conversationLocalDayKey(conversation.startedAt ?? conversation.createdAt);
     context.read<ConversationDetailProvider>().updateConversation(conversation.id, date);
   });
</file context>

final date = conversationLocalDayKey(conversation.startedAt ?? conversation.createdAt);
final group = groupedConversations.putIfAbsent(date, () => []);
if (!group.any((c) => c.id == conversation.id)) {
group.insert(0, conversation);

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: A memory-linked conversation fetched outside conversations is removed from its group as soon as the detail page initializes, so this helper does not maintain the group it claims to ensure. Keep the canonical conversation list and grouped map in sync (or avoid rebuilding away this temporary entry) before navigating.

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

<comment>A memory-linked conversation fetched outside `conversations` is removed from its group as soon as the detail page initializes, so this helper does not maintain the group it claims to ensure. Keep the canonical conversation list and grouped map in sync (or avoid rebuilding away this temporary entry) before navigating.</comment>

<file context>
@@ -1072,6 +1072,28 @@ class ConversationProvider extends ChangeNotifier {
+    final date = conversationLocalDayKey(conversation.startedAt ?? conversation.createdAt);
+    final group = groupedConversations.putIfAbsent(date, () => []);
+    if (!group.any((c) => c.id == conversation.id)) {
+      group.insert(0, conversation);
+    }
+    return date;
</file context>

@kodjima33
kodjima33 merged commit 131c295 into main Aug 1, 2026
31 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-10980-local-day-key-call-sites branch August 1, 2026 19:14
kodjima33 added a commit that referenced this pull request Aug 1, 2026
… (#10994)

`ConversationSyncUtils._createPointer` built the pointer's `key` from
`createdAt`'s raw year/month/day. Server timestamps parse as UTC, so those are
UTC fields, while the conversation list groups by `conversationLocalDayKey`
over `startedAt ?? createdAt` — the local day. The pointer's key is handed
straight to `ConversationDetailProvider.updateConversation` when a row on the
Processed Conversations page is tapped, so whenever the two disagree (any
viewer off UTC near local midnight, or a conversation whose `startedAt` and
`createdAt` land on different days) the lookup found no group, the selection
silently no-opped, and the detail page rendered against whatever conversation
was still cached until the page's post-frame callback re-resolved the day.

Fourth instance of FC-day-bucket-key-recomputed, and the last call site in the
conversation-grouping family that still re-derived the key: it now calls the
one authority, like #10981, #10987 and #10988.

Tested: added the case to the class's existing guard file
`app/test/providers/conversation_day_key_call_sites_test.dart`, which sweeps
all 24 hours. `flutter test test/providers/conversation_day_key_call_sites_test.dart`
passes in TZ=UTC, Asia/Kolkata, Europe/Berlin, America/Los_Angeles,
Pacific/Kiritimati and Pacific/Midway, and fails (+3 -1) in every one of those
zones with the lib change reverted. Full `flutter test` suite: 996 passed, 0
failed.

Failure-Class: FC-day-bucket-key-recomputed
@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Four conversation day-key call sites derive the key from raw UTC fields instead of conversationLocalDayKey

2 participants