feat(predict): refresh eligibility on app focus #22500
Merged
+812
−40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Description
This PR implements automatic eligibility refresh for the Predict feature when the app comes to foreground. Previously, eligibility was only checked on initial load or manual refresh. Now, when a user backgrounds the app and then returns to it, the eligibility status is automatically refreshed.
What is the reason for the change?
Users may change their network configuration (e.g., switching between different network connections) while the app is backgrounded. When they return to the app, the Predict feature should automatically check eligibility again to reflect any potential changes in their connection status.
What is the improvement/solution?
AppStatelistener to theusePredictEligibilityhook that detects when the app transitions frombackground/inactivetoactivestateChangelog
CHANGELOG entry: null
Related issues
Fixes: N/A
Manual testing steps
Screenshots/Recordings
N/A - This is an internal behavior change with no visual UI impact.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduce a singleton-managed AppState listener to auto-refresh Predict eligibility on app foreground with 1-minute debounce, logging, and race-condition prevention, plus comprehensive tests.
usePredictEligibility.ts):EligibilityRefreshManager):AppStatechangelistener across hook instances.Engine.context.PredictController.refreshEligibility()on transition toactive.refreshEligibilitybypasses debounce.DevLoggerlogs and error handling.usePredictEligibility.test.ts):Written by Cursor Bugbot for commit 8c94340. This will update automatically on new commits. Configure here.