fix: Prevent stale server recovery after Editor restarts#1166
Conversation
Store reload and recovery flags in Unity SessionState so stale runtime state does not survive Editor restarts. Keep UserSettings JSON focused on persistent preferences, strip legacy transient keys, and preserve the first reload that crosses the migration.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR migrates transient runtime state (server running, after-compile, domain reload, reconnecting, and UI-display flags) from persisted editor settings to per-editor-session storage. A new ChangesSession State Refactoring: Move Transient Runtime Flags to Per-Editor-Session Storage
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs (1)
96-109: ⚡ Quick winMake
MarkDomainReloadStarted(false)explicitly normalize recovery/UI flags.Line 99 returns early, so previous
isAfterCompile/isReconnecting/UI flags remain untouched. That can preserve stale recovery intent across cycles in the same Editor session. Consider clearing those flags in the!serverIsRunningpath to make transition outcomes deterministic.♻️ Proposed adjustment
public void MarkDomainReloadStarted(bool serverIsRunning) { SetIsDomainReloadInProgress(true); if (!serverIsRunning) { + SetIsAfterCompile(false); + SetIsReconnecting(false); + SetShowReconnectingUI(false); + SetShowPostCompileReconnectingUI(false); return; } SetIsServerRunning(true); SetIsAfterCompile(true);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs` around lines 96 - 109, MarkDomainReloadStarted currently returns early when serverIsRunning is false which leaves previous recovery/UI flags stale; update the !serverIsRunning branch in MarkDomainReloadStarted to explicitly normalize state by calling SetIsServerRunning(false), SetIsAfterCompile(false), SetIsReconnecting(false), SetShowReconnectingUI(false) and SetShowPostCompileReconnectingUI(false) before returning so the editor session flags are deterministic.Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs (1)
42-57: ⚡ Quick winAdd a regression test for
MarkDomainReloadStarted(serverIsRunning: false).Current coverage only exercises the
truebranch. A false-branch test that pre-seeds reconnect/recovery flags helps catch stale-flag regressions early.🧪 Suggested test case
[Test] public void GetFlags_WhenServiceAndRepositoryAreRecreated_ReadsExistingSessionValues() { @@ } + +[Test] +public void MarkDomainReloadStarted_WhenServerIsNotRunning_DoesNotLeaveRecoveryFlagsEnabled() +{ + _sessionStateService.SetIsAfterCompile(true); + _sessionStateService.SetIsReconnecting(true); + _sessionStateService.SetShowReconnectingUI(true); + _sessionStateService.SetShowPostCompileReconnectingUI(true); + + _sessionStateService.MarkDomainReloadStarted(serverIsRunning: false); + + Assert.That(_sessionStateService.GetIsDomainReloadInProgress(), Is.True); + Assert.That(_sessionStateService.GetIsAfterCompile(), Is.False); + Assert.That(_sessionStateService.GetIsReconnecting(), Is.False); + Assert.That(_sessionStateService.GetShowReconnectingUI(), Is.False); + Assert.That(_sessionStateService.GetShowPostCompileReconnectingUI(), Is.False); +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs` around lines 42 - 57, Add a new unit test alongside GetFlags_WhenServiceAndRepositoryAreRecreated_ReadsExistingSessionValues that calls _sessionStateService.MarkDomainReloadStarted(serverIsRunning: false) (instead of true), pre-seeds any reconnect/recovery flags to true via the existing test factory/state setup, recreates the service with UnityCliLoopEditorSessionStateTestFactory.CreateService(), and asserts the recreated UnityCliLoopEditorSessionStateService returns the expected false values from GetIsServerRunning(), GetIsAfterCompile(), GetIsDomainReloadInProgress(), GetIsReconnecting(), GetShowReconnectingUI(), and GetShowPostCompileReconnectingUI() so the false branch and stale-flag regressions are covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs`:
- Around line 42-57: Add a new unit test alongside
GetFlags_WhenServiceAndRepositoryAreRecreated_ReadsExistingSessionValues that
calls _sessionStateService.MarkDomainReloadStarted(serverIsRunning: false)
(instead of true), pre-seeds any reconnect/recovery flags to true via the
existing test factory/state setup, recreates the service with
UnityCliLoopEditorSessionStateTestFactory.CreateService(), and asserts the
recreated UnityCliLoopEditorSessionStateService returns the expected false
values from GetIsServerRunning(), GetIsAfterCompile(),
GetIsDomainReloadInProgress(), GetIsReconnecting(), GetShowReconnectingUI(), and
GetShowPostCompileReconnectingUI() so the false branch and stale-flag
regressions are covered.
In `@Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs`:
- Around line 96-109: MarkDomainReloadStarted currently returns early when
serverIsRunning is false which leaves previous recovery/UI flags stale; update
the !serverIsRunning branch in MarkDomainReloadStarted to explicitly normalize
state by calling SetIsServerRunning(false), SetIsAfterCompile(false),
SetIsReconnecting(false), SetShowReconnectingUI(false) and
SetShowPostCompileReconnectingUI(false) before returning so the editor session
flags are deterministic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ffea0240-d1f6-473b-b2bc-840e0425a0cf
⛔ Files ignored due to path filters (5)
Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs.metais excluded by none and included by noneAssets/Tests/Editor/UnityCliLoopEditorSessionStateTestFactory.cs.metais excluded by none and included by nonePackages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs.metais excluded by none and included by nonePackages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorLegacySessionStateReader.cs.metais excluded by none and included by nonePackages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSessionStateRepository.cs.metais excluded by none and included by none
📒 Files selected for processing (25)
Assets/Tests/Editor/DomainReloadDetectionServiceTests.csAssets/Tests/Editor/DomainReloadRecoveryUseCaseTests.csAssets/Tests/Editor/StaticFacadeStateGuardTests.csAssets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.csAssets/Tests/Editor/UnityCliLoopEditorSessionStateTestFactory.csAssets/Tests/Editor/UnityCliLoopEditorSettingsRecoveryTests.csAssets/Tests/Editor/UnityCliLoopPackageRemovalSettingsResetterTests.csAssets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.csAssets/Tests/Editor/UnityCliLoopServerStartupProtectionTests.csPackages/src/Editor/Application/SessionRecoveryService.csPackages/src/Editor/Application/UnityCliLoopServerStartupService.csPackages/src/Editor/Application/UseCases/DomainReloadRecoveryUseCase.csPackages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.csPackages/src/Editor/CompositionRoot/UnityCliLoopEditorBootstrapper.csPackages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.csPackages/src/Editor/Domain/UnityCliLoopEditorSettingsData.csPackages/src/Editor/Domain/UnityCliLoopEditorSettingsService.csPackages/src/Editor/Infrastructure/Server/DomainReloadDetectionFileService.csPackages/src/Editor/Infrastructure/Server/UnityCliLoopServerController.csPackages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorLegacySessionStateReader.csPackages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSessionStateRepository.csPackages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsRepository.csPackages/src/Editor/Infrastructure/UnityCliLoopBridgeServer.csPackages/src/Editor/Presentation/PresentationEditorStartup.csPackages/src/Editor/Presentation/UnityCliLoopSettingsWindow.cs
💤 Files with no reviewable changes (2)
- Packages/src/Editor/Domain/UnityCliLoopEditorSettingsService.cs
- Packages/src/Editor/Domain/UnityCliLoopEditorSettingsData.cs
There was a problem hiding this comment.
2 issues found across 30 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Remove legacy JSON recovery flags immediately after applying them to SessionState so upgrade migration cannot reapply stale reload state on later domain reloads. Also align the newly added settings-window session registration with the existing Debug.Assert contract.
Summary
User Impact
Changes
Verification