Fix retro reuse existing analysis#2859
Merged
veloce merged 2 commits intoMar 31, 2026
Merged
Conversation
veloce
reviewed
Mar 31, 2026
| // of analyses is reached. | ||
| if (e.statusCode == 400) { | ||
| debugPrint('Analysis already requested for game $id'); | ||
| _currentAnalysis.value = id.gameId; |
Contributor
There was a problem hiding this comment.
Does not look useful: we already assign it in line 96.
This was referenced Apr 9, 2026
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
tom-anders
added a commit
to tom-anders/lichess-mobile
that referenced
this pull request
Apr 27, 2026
Previous fix was in lichess-org#2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
veloce
pushed a commit
that referenced
this pull request
Apr 28, 2026
Previous fix was in #2859, but this PR fixes the root cause instead of adding a workaround. The root cause of this problem was that we check `_game.serverAnalysis == null` to check if the RetroController needs to trigger server analysis in case it isn't already running. When the server analysis was already triggered by the `AnalysisController`, the problem was that `archivedGameProvider` is not invalidated and still returns `null` for the server analysis field. By using the `GameRepository` directly instead, we get a fresh response from the server which correctly has a non-null `serverAnalysis`. An alternative fix would be to add `red.invalidate(archivedGameProvider(gameId))` when a server analysis request is triggered in the analysis screen, however this leads to the analysis screen being rebuilt when triggering server analysis, which causes a short flicker of the screen during the reload. To verify that everything still works, I successfully tested the following scenarios: 1) Trigger server analysis in analysis screen and immediately open "Learn From Your Mistakes" -> The loading bar correctly displays server analysis progress, once analysis is finished Learn from your mistakes is available. 2) Trigger server analysis in analysis screen, wait for it to finish and only then open "Learn From Your Mistakes" -> Learn from your mistakes is available immediately without any loading bar. 3) Trigger server analysis, wait for it to finish and then close the analysis screen. Open analysis again for the same game and open "Learn from your Mistakes". -> Learn from your mistakes is available immediately without any loading bar.
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.
Related to #2564 and #2750
What this changes
This PR tries to fix the case where Learn from your mistakes can get stuck / keep loading after a computer analysis was already requested first.
The issue seems to come from the retro flow attaching too late to analysis progress and potentially trying to request / restart analysis again for the same game.
Changes
400 already requestedWhy
This should help with the cases described in:
Learn from your misstake "something went wrong""Learn from your mistakes" sometimes remains stuck loading