Skip to content

fix(core): Fix backwards pagination not working if channel was never opened - #2812

Merged
VelikovPetar merged 2 commits into
v9from
port/master-to-v9/FLU-563_fix-pagination-never-opened-channel
Jul 14, 2026
Merged

fix(core): Fix backwards pagination not working if channel was never opened#2812
VelikovPetar merged 2 commits into
v9from
port/master-to-v9/FLU-563_fix-pagination-never-opened-channel

Conversation

@VelikovPetar

Copy link
Copy Markdown
Contributor

Submit a pull request

Linear: FLU-563

Github Issue: #

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Backport of masterv9 of commit 1a90e921105fa9edad3985828868fadc22f39d2d (PR #2789, Fixes FLU-563).

The bug

When a user enters a channel with unread_count > 0 but the server-side read state is the "never explicitly read" sentinel (last_read_message_id = null and last_read = 0001-01-01T00:00:00Z — Go's time.Time{} zero value), StreamChannelState._maybeInitChannel unconditionally called loadChannelAtTimestamp(currentUserRead.lastRead).

The backend silently ignores the zero-time created_at_around (via IsZero()) and returns the channel tail. The client then mis-infers boundaries via _inferBoundariesFromAnchorTimestamp: because year-1 precedes every loaded message, it concludes endOfPrependReached: true, sets _topPaginationEnded = true, and backwards pagination is permanently dead on the channel.

The fix

Guard the timestamp branch on currentUserRead.lastRead.isAfter(_minValidLastRead) (DateTime.utc(1970)). When it's the zero sentinel, the code falls through to the existing catch-all — stay on the cached latest window if up-to-date, otherwise reload the latest page.

Adds a _maybeInitChannel test group with four regression guards: idAround for lastReadMessageId, createdAtAround for real timestamps, no query for the Go zero-time case when up-to-date, and a latest-page reload for the Go zero-time case when stale.

Backport notes

  • Manual port, not a clean cherry-pick. The _maybeInitChannel logic on v9 was byte-for-byte identical to master's pre-fix state, but v9 and master diverge in analysis_options.yaml: v9 drops the page_width: 120 formatter block (reverting to the 80-col default) and enables the avoid_redundant_argument_values lint. A raw cherry-pick would have imported master's formatting/lint style.
  • v9-specific adaptation: master's DateTime.utc(1970, 1, 1) / DateTime.utc(1, 1, 1) are written as DateTime.utc(1970) / DateTime.utc(1) here (semantically identical) to satisfy v9's enabled avoid_redundant_argument_values lint.
  • Verified test-first: confirmed the two Go-zero-time tests fail on v9 before the fix, then pass after. dart format, dart analyze --fatal-infos, and all 30 tests in stream_channel_test.dart are green.

Screenshots / Videos

No UI changes. (See the before/after videos on the original master PR #2789.)

…opened

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4fb095e-5927-41ef-aff2-c4ab25177d6b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch port/master-to-v9/FLU-563_fix-pagination-never-opened-channel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@VelikovPetar
VelikovPetar marked this pull request as ready for review July 14, 2026 08:14
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v9@f3ceb35). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff          @@
##             v9    #2812   +/-   ##
=====================================
  Coverage      ?   66.86%           
=====================================
  Files         ?      429           
  Lines         ?    27102           
  Branches      ?        0           
=====================================
  Hits          ?    18121           
  Misses        ?     8981           
  Partials      ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@VelikovPetar
VelikovPetar merged commit ec65119 into v9 Jul 14, 2026
24 checks passed
@VelikovPetar
VelikovPetar deleted the port/master-to-v9/FLU-563_fix-pagination-never-opened-channel branch July 14, 2026 09:50
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.

2 participants