Skip to content

Fix cold-start rate-limit dialog and suppress sign-in hint when signed in#507

Merged
rainxchzed merged 2 commits into
mainfrom
fix/cold-start-and-signin-hint-rate-limit
May 4, 2026
Merged

Fix cold-start rate-limit dialog and suppress sign-in hint when signed in#507
rainxchzed merged 2 commits into
mainfrom
fix/cold-start-and-signin-hint-rate-limit

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented May 4, 2026

Two fixes that didn't make it into #506 before merge.

1. Cold-start rate-limit dialog (the actual bug user reported)

`MainViewModel.init` runs `installedAppsRepository.checkAllForUpdates()` on every cold start. That fans out N direct GitHub calls (one per tracked app) via `fetchReleaseWindow`. With anon's 60/hr GitHub limit, users with 30+ tracked apps hit the ceiling on first launch — `RateLimitInterceptor` parses the `X-RateLimit-Remaining: 0` header and fires the global `RateLimitDialog` ("Resets in 31 minutes").

PR #505 didn't catch this because it touched feature-level repos (apps, dev-profile, starred), not the `InstalledAppsRepository` cold-start fan-out.

Fix: `fetchReleaseWindow` now goes backend-first via `backendApiClient.getReleases`, falls back to direct GitHub on backend 5xx/infra. Backend pool absorbs the cold-start burst (20k/hr aggregate via 4 PATs) instead of anon hitting 60/hr.

2. Sign-in hint shown to already-signed-in users

The retry-after toast in DetailsViewModel always appended "Sign in to GitHub for a higher quota." Pointless when user is already signed in. Now gated on `authenticationState.isCurrentlyUserLoggedIn()`.

`AuthenticationState` injected into `DetailsViewModel`; DI updated in `ViewModelsModule`.

Test plan

  • Cold-start with 50+ tracked apps, anonymous: no rate-limit dialog appears.
  • Cold-start same scenario, signed in: same — no dialog (silently uses backend pool, falls through to direct only on backend 5xx).
  • Backend rate limit hit while signed in → toast: "Rate limit hit — retry in Ns." (no sign-in hint).
  • Backend rate limit hit while signed out → toast: "Rate limit hit — retry in Ns. Sign in to GitHub for a higher quota."
  • Backend offline (5xx) → falls back to direct GitHub, behaves as before.

Summary by CodeRabbit

  • Improvements
    • Enhanced rate-limit error messages with context-aware sign-in suggestions—hint appears only when you're not logged in.
    • Release data fetching now routes through the backend API with automatic fallback for better reliability and performance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 50681a87-f14f-4f7e-9243-321df63aead8

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7e3f2 and c9737fb.

📒 Files selected for processing (4)
  • composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/di/ViewModelsModule.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/SharedModule.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Walkthrough

This PR updates dependency injection wiring to add authenticationState to DetailsViewModel and backendApiClient to InstalledAppsRepositoryImpl. The ViewModel now conditionally appends sign-in hints to rate-limit messages based on authentication state, and the repository prioritizes backend API calls for release fetching with fallback to direct GitHub requests on failure.

Changes

Authentication-Aware Rate-Limiting and Backend API Integration

Layer / File(s) Summary
Dependency Injection Setup
composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/di/ViewModelsModule.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/SharedModule.kt
DetailsViewModel now receives authenticationState = get() and InstalledAppsRepositoryImpl now receives backendApiClient = get() during Koin instantiation.
Repository Implementation
core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.kt
Constructor accepts new backendApiClient dependency. fetchReleaseWindow now attempts backend release fetching first, filtering by draft and pre-release policy; on backend failure, falls back to existing GitHub direct-fetch path (conditional rethrow behavior preserved).
ViewModel Implementation
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt
Constructor accepts new authenticationState dependency. Rate-limit error messaging now computes a base message and conditionally appends sign-in hint only when user is not logged in.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A repo needs to phone home to check the newest releases in town,
And when the API says "too fast," no need to make the user frown—
Just whisper "sign in, friend" to those who haven't logged down!
📱✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the two main bugs fixed: cold-start rate-limit dialog and suppressed sign-in hint when signed in.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cold-start-and-signin-hint-rate-limit

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@rainxchzed rainxchzed merged commit 84e18b1 into main May 4, 2026
1 check passed
@rainxchzed rainxchzed deleted the fix/cold-start-and-signin-hint-rate-limit branch May 4, 2026 13:34
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