Skip to content

fix(app): label import-history rows from the viewer's local day (#10984) - #10988

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10984-import-history-local-day
Aug 1, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10984-import-history-local-day

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

#10984 — every row in Settings → Import History labels the wrong day and shows the wrong clock time for any viewer whose local day differs from the UTC day.

Root cause

_buildJobCard mixed two clocks in one comparison (app/lib/pages/settings/import_history_page.dart):

final now = DateTime.now();                                   // local
final today = DateTime(now.year, now.month, now.day);         // local day
final jobDate = DateTime(job.createdAt!.year, ...);           // UTC day

job.createdAt is a server timestamp (datetime.now(timezone.utc).isoformat(), backend/models/import_job.py:28) and parses UTC-flagged, so jobDate is its UTC day while today is the local day. The row therefore flips between the today / yesterday / absolute-date branches at the wrong boundary, and each branch independently renders raw UTC hour/minute.

Second, latent defect on the same lines: the yesterday key used today.subtract(const Duration(days: 1)), which on a DST transition day lands at 23:00 or 01:00 rather than midnight and never equals a day key.

Fix

The formatting moves into a top-level formatImportJobTimestamp(l10n, createdAt, {now}): it projects with toLocal() before reading any component, so both sides of the comparison and the rendered time come from the viewer's local calendar; and it derives the yesterday key with calendar arithmetic (day - 1). now is injectable so the branch behavior is testable.

Not routed through conversationLocalDayKey: that key is owned by ConversationProvider and scoped to conversation grouping — importing the provider into a settings page to reuse three lines would be worse coupling than the duplication. If a shared local-day util lands, this is a caller to migrate.

What I tested

New app/test/unit/import_job_timestamp_test.dart (4 cases: today sweep over all 24 local hours, yesterday sweep over all 24 local hours, yesterday across all 366 calendar days, absolute-date branch, plus a widget case that renders the page's own context.l10n expression from an ImportJobResponse.fromJson decode).

  • New test green under TZ=UTC, America/New_York, Asia/Kolkata, Pacific/Auckland, Pacific/Kiritimati, Pacific/Midway.
  • It fails on the pre-fix code, which is the point. Running the old derivation against the same expectations:
    • TZ=America/New_York: 24/24 hours wrong — e.g. local 20:30 rendered 2/8/2026 at 00:30 (tomorrow's date), local 00:30 rendered Today at 04:30.
    • TZ=Asia/Kolkata: 24/24 wrong — local 00:30 rendered Yesterday at 19:00.
    • TZ=Pacific/Auckland: 24/24 wrong — local 00:30 rendered Yesterday at 12:30.
  • DST half isolated separately (correct toLocal(), old Duration(days: 1) key): 2/366 days wrong in America/New_York (2026-03-08, 2026-11-01), 2/366 in Pacific/Auckland (2026-04-05, 2026-09-27) — each degraded the yesterday row to the absolute date.
  • app/test.sh: 995 tests passed.
  • flutter analyze on both changed files: no issues. dart format --line-length 120: clean.

Not exercised in a running build: reaching this page needs a signed-in account with a real Limitless import job. The widget case drives the exact production expression (formatImportJobTimestamp(context.l10n, job.createdAt!)) through a localized BuildContext instead.

Product invariants affected

none (scripts/pr-preflight --suggest)

Failure class

A derived day-bucket key has exactly one authority; a consumer that re-derives it from raw UTC calendar fields disagrees with that authority for every off-UTC viewer. Same class as #10980 / PR #10987, which fixed the conversation-grouping instance and filed this one.

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

🤖 automated by hourly watchdog — tested and merged

Review in cubic

`_buildJobCard` compared an import job's raw UTC `year/month/day` against a
`today` built from local `DateTime.now()`, and rendered the raw UTC
`hour`/`minute`. Both sides of a day comparison must come from the same
authority: for any viewer off UTC the two disagree, so a row flips between the
today / yesterday / absolute-date branches at the wrong boundary and prints the
wrong clock time — an import started at 21:00 in New York rendered as "01:00"
and on the following day.

The formatting moves into `formatImportJobTimestamp`, which projects the
timestamp with `toLocal()` before reading any component and takes the reference
clock as a parameter so the behavior is testable. The yesterday key now uses
calendar arithmetic (`day - 1`) instead of `today - Duration(days: 1)`, which
lands at 23:00/01:00 on a DST transition day and never equals a midnight key.

Fixes #10984

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.

No issues found across 2 files

Confidence score: 5/5

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

Re-trigger cubic

@kodjima33
kodjima33 merged commit 0d3dfd6 into main Aug 1, 2026
31 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-10984-import-history-local-day branch August 1, 2026 21:51
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.

2 participants