Repository navigation
Conversation
Wrap loadHomeRows row async jobs in coroutineScope and rethrow CancellationException while retaining viewModelScope for fetchDataForRow. Assisted-by: agy:gemini-3.8-flash-high
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
In
HomeViewModel, when a user switches profiles or changes Home settings while rows are loading,dataLoadingJob?.cancel()cancels the top-level loading job. However, individual row fetches were launched onviewModelScope.async(WholphinDispatchers.IO)without being attached to thedataLoadingJobcoroutine hierarchy. As a result, cancellingdataLoadingJobstopped awaiting the rows, but left the underlying HTTP requests and row fetches continuing to execute in the background onviewModelScope. In addition,loadHomeRowscaught generalExceptioninside each row'sasyncblock, causing anyCancellationExceptionto be swallowed and mapped intoHomeRowLoadingState.Errorinstead of propagating cancellation.This PR wraps the row fetch launches and collection in
coroutineScope { ... }, launches row fetches withasync(WholphinDispatchers.IO)so they are bound to that scope, and explicitly rethrowsCancellationException. WhendataLoadingJobis cancelled, all in-flight row fetches are cancelled immediately. Thescopeparameter passed tofetchDataForRowremainsviewModelScopeso downstream pagers (ApiRequestPager) and image lookups remain active after initial loading completes.Related issues
I searched existing issues and pull requests on
damontecres/WholphinforHomeViewModel,loadHomeRows,dataLoadingJob,CancellationException, andHome rowcancellation and did not find an existing issue or pull request for this behavior.Steps to reproduce:
Testing
TestHomeRowJobs:cancellingLoadCancelsInFlightRowRequests: verifies that cancelling a runningloadHomeRowsjob cancels in-flightfetchDataForRowcalls before they complete.cancellationExceptionIsNotMappedToRowError: verifies that whenfetchDataForRowthrowsCancellationException, cancellation propagates cleanly instead of mapping the row toHomeRowLoadingState.Error.rowScopeRemainsViewModelScopeAfterLoadCompletes: verifies that afterloadHomeRowscompletes normally, theCoroutineScopepassed tofetchDataForRowisviewModelScopeand remains active.TestHomeRowJobsfails on unfixed base code (v1.1.1/159edc87) and passes cleanly with this change.TestHomeRowSamplesalongsideTestHomeRowJobsto confirm zero regressions in existing Home row behaviors.Screenshots
None (no UI change).
AI or LLM usage
I used AI tools for this change: OpenAI Codex identified the issue in an earlier larger Home change, and Google Gemini through drafted this fix, unit tests, and review. This covers the changes in
HomeViewModel.ktandTestHomeRowJobs.kt.I tested the change with the unit tests above and ktlint. I have reviewed and understand the changes in this pull request and take responsibility for them.