Skip to content

Fix region provider related bugs#983

Merged
hiroshihorie merged 5 commits intomainfrom
hiroshi/fix-region-bugs
Feb 6, 2026
Merged

Fix region provider related bugs#983
hiroshihorie merged 5 commits intomainfrom
hiroshi/fix-region-bugs

Conversation

@hiroshihorie
Copy link
Member

@hiroshihorie hiroshihorie commented Feb 6, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Fixed cache expiry behavior for region URL lookups by correcting time-unit handling and extending the short cache interval.
    • Corrected region validation during leave events so region data is properly checked before being returned.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Corrects region-related bugs: fixes cache timing by using milliseconds for expiry and updates leave-event region validation to check hasRegions() instead of hasReason().

Changes

Cohort / File(s) Summary
Changelog Entry
.changes/fix-region-bugs
Adds patch file documenting the region URL provider cache timing fix and the leave-event region validation correction.
Event Handler Fix
lib/src/internal/events.dart
SignalLeaveEvent regions getter now returns regions only when request.hasRegions() is true (replaced hasReason() check).
Cache Timing Fix
lib/src/support/region_url_provider.dart
Switched timestamp usage from microsecondsSinceEpoch to millisecondsSinceEpoch, updated lastUpdateAt assignments, and increased settingsCacheTime to 5000 (ms).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through timestamps, tiny and brisk,
Milliseconds now steady — no more risk.
I checked for regions where they truly hide,
Fixed the cache, then danced with pride. 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix region provider related bugs' accurately summarizes the main changes in the PR, which involve fixes to region URL provider cache timing and region validation logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hiroshi/fix-region-bugs

🧹 Recent nitpick comments
lib/src/support/region_url_provider.dart (1)

114-119: toHttpUrl silently converts wss:// to httpss:// for URLs with scheme wss.

replaceFirst('ws', 'http') on a URL starting with wss:// yields https:// which happens to be correct, but toHttpUrl on a plain http:// or https:// URL is a no-op since it only fires when the URL starts with ws. This works by coincidence for wss → https. Worth noting as intentional if it is, but the logic is fragile.

Similarly, toWebsocketUrl converts https://wss:// by the same string-prefix trick (httpws turns https into wss).

Consider using Uri parsing for robustness if these helpers are used more broadly.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46da211 and ca39ce3.

📒 Files selected for processing (1)
  • lib/src/support/region_url_provider.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter Web WASM
  • GitHub Check: Build for Flutter Web
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter Linux
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Dart Analyze Check
  • GitHub Check: Build for Flutter Android
🔇 Additional comments (1)
lib/src/support/region_url_provider.dart (1)

21-21: Timestamp unit consistency fix looks correct.

All reads and writes of lastUpdateAt now consistently use millisecondsSinceEpoch, and settingsCacheTime is expressed in the same unit (5000 ms). The previous cache-never-expiring bug (micro vs. milli mismatch) is resolved.

Also applies to: 39-39, 74-74, 88-88

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@lib/src/support/region_url_provider.dart`:
- Line 39: fetchRegionSettings is writing lastUpdateAt using
microsecondsSinceEpoch while the cache check (the settingsCacheTime comparison)
reads lastUpdateAt in millisecondsSinceEpoch; update the assignment in
fetchRegionSettings to use DateTime.now().millisecondsSinceEpoch (replace
microsecondsSinceEpoch) so lastUpdateAt uses the same units as the
milliseconds-based check (note setServerReportedRegions already uses
millisecondsSinceEpoch).
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be1389e and 46da211.

📒 Files selected for processing (3)
  • .changes/fix-region-bugs
  • lib/src/internal/events.dart
  • lib/src/support/region_url_provider.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Build for Flutter Web
  • GitHub Check: Build for Flutter Web WASM
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter Linux
  • GitHub Check: Build for Flutter Android
🔇 Additional comments (2)
.changes/fix-region-bugs (1)

1-1: LGTM!

Changelog entry accurately describes both bug fixes.

lib/src/internal/events.dart (1)

467-467: LGTM!

Correct fix — the regions getter now properly guards on request.hasRegions() instead of the unrelated request.hasReason().

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@hiroshihorie hiroshihorie merged commit df41188 into main Feb 6, 2026
17 checks passed
@hiroshihorie hiroshihorie deleted the hiroshi/fix-region-bugs branch February 6, 2026 08:40
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.

1 participant