Skip to content

fix: Startup no longer freezes during migration checks#1181

Merged
hatayama merged 4 commits into
v3-betafrom
feature/hatayama/fix-startup-freeze
May 21, 2026
Merged

fix: Startup no longer freezes during migration checks#1181
hatayama merged 4 commits into
v3-betafrom
feature/hatayama/fix-startup-freeze

Conversation

@hatayama
Copy link
Copy Markdown
Owner

Summary

  • Unity startup no longer runs a blocking migration scan during ordinary version checks.
  • The migration window now starts in an unchecked state and stays responsive while scans run.

User Impact

  • Projects no longer freeze at startup just because the package version check runs.
  • Upgrading from V2 to V3 can still surface the migration window, but manual checks wait until the user presses Check.
  • Long migration previews avoid repeated source-file reads and ignore stale progress updates after results are already shown.

Changes

  • Gate automatic migration scans behind the V2-to-V3 upgrade session signal.
  • Move migration preview work off the Unity main thread, throttle progress updates, and cache source-file content during preview.
  • Keep demo editor startup hooks out of normal startup and add focused EditMode coverage for setup, migration, session state, and dependency behavior.

Verification

  • Packages/src/Cli~/dist/darwin-arm64/uloop compile --project-path <PROJECT_ROOT> (0 errors, 0 warnings)
  • Focused EditMode migration/setup/session tests via the checked-in local uloop binary; wizard tests were rerun after the final progress-state fix.
  • codex-review v3-beta (no actionable findings after the stale progress issue was fixed)

hatayama added 4 commits May 21, 2026 15:48
Keep the input replay verification bridge out of normal Editor startup by requiring the Unity test define and disabling auto references on the demo editor assembly. Add a focused asmdef contract test so demo-only InitializeOnLoad hooks do not rejoin the regular startup path.
Opening the migration wizard during startup should not scan every project automatically. Store the V2-to-V3 upgrade signal in SessionState, consume it once for the auto-open path, and keep manual opens idle until Check is clicked.

- Run migration previews on a background task and marshal UI progress back to the main thread.
- Remove startup target-scan scheduling and cover the behavior with focused EditMode tests.
Manual migration opens should not imply that no migration work exists before the user checks. Use a distinct disabled label for the unchecked state and reduce preview scan cost by reusing source text and code-text masks across migration analysis phases.

- Throttle progress UI updates while preserving completion updates.
- Cache source reads and code masks during preview scans.
- Cover button state and scan cache behavior with focused tests.
Late progress continuations can arrive on the Unity main thread after the migration wizard has already rendered the final preview result. Mark the preview inactive before showing the final state so queued progress cannot put the window back into scanning mode.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements automatic third-party tool migration scanning triggered during editor startup when a major version transition to v3 is detected. It adds session-state persistence for the auto-scan flag, refactors the migration wizard window to support both manual and automatic entry points, and optimizes file I/O and regex masking during preview planning.

Changes

Third-Party Tool Migration Auto-Scan Feature

Layer / File(s) Summary
Session-State Persistence for Auto-Scan Flag
Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs, Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSessionStateRepository.cs, Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs, Assets/Tests/Editor/UnityCliLoopEditorSessionStateTestFactory.cs
New ShouldAutoScanThirdPartyToolMigration session-state flag enables transient marking across editor sessions with get/set/consume semantics, persistence on domain reload, and cleanup integration.
Setup Wizard Auto-Scan Decision & Scheduling
Packages/src/Editor/Presentation/Setup/SetupWizardWindow.cs, Assets/Tests/Editor/SetupWizardWindowTests.cs
Version-change evaluation detects pre-v3 to v3 transitions, decides auto-scan eligibility, marks session state, and schedules the migration wizard via EditorApplication.delayCall. Test setup/teardown isolates session state per test case.
Migration Wizard Window Auto-Scan UI & Preview Flow
Packages/src/Editor/Presentation/Setup/ThirdPartyToolMigrationWizardWindow.cs, Assets/Tests/Editor/ThirdPartyToolMigrationWizardWindowTests.cs
ShowWindowForAutoScan() entry point consumes session-state auto-scan flag and decides initial refresh via ShouldStartInitialRefresh(). Preview refresh runs on background task with cancellation checks; progress reporting is throttled and gated by preview-active status. UI states expanded to "not checked" and "checking" with migrated button text logic.
File & Regex Caching for Preview Performance
Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationFileService.cs, Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationRules.cs, Assets/Tests/Editor/ThirdPartyToolMigrationFileServiceTests.cs
ThirdPartyToolMigrationSourceFileCache memoizes file reads during preview planning. CodeTextMask instances are cached per source string via ConditionalWeakTable. RegexMatchesCode short-circuits before masking if no matches exist.
Presentation Startup Wiring & Assembly Validation
Packages/src/Editor/Presentation/PresentationEditorStartup.cs, Assets/Tests/Editor/OnionAssemblyDependencyTests.cs
Session-state service is passed to wizard window initializers during startup. Assembly dependency tests validate demo editor asmdef includes UNITY_INCLUDE_TESTS constraint and is manually referenced; migration wizard startup behavior is wired through presentation rather than auto-triggering target checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title clearly summarizes the main objective: preventing Unity startup from freezing during migration checks, which is the core issue addressed throughout the changeset.
Description check ✅ Passed The description accurately relates to the changeset, covering automatic migration scan gating, session signals, async work off the main thread, source file caching, and test coverage additions.
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 feature/hatayama/fix-startup-freeze

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

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationFileService.cs (1)

29-34: 💤 Low value

Redundant null validation on readAllText parameter.

Line 33 uses both Debug.Assert and a null-coalescing throw, which is redundant for precondition enforcement. Based on learnings, use Debug.Assert to document and enforce programmer preconditions without adding redundant runtime exceptions for internal contract violations.

♻️ Simplify to Debug.Assert only
         internal ThirdPartyToolMigrationSourceFileCache(Func<string, string> readAllText)
         {
             Debug.Assert(readAllText != null, "readAllText must not be null");
 
-            _readAllText = readAllText ?? throw new ArgumentNullException(nameof(readAllText));
+            _readAllText = readAllText;
         }
🤖 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/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationFileService.cs`
around lines 29 - 34, The constructor ThirdPartyToolMigrationSourceFileCache
currently uses both Debug.Assert(readAllText != null, ...) and a null-coalescing
throw when assigning _readAllText, which is redundant; remove the runtime null
check (the "?? throw new ArgumentNullException(nameof(readAllText))") and
instead assign _readAllText = readAllText after keeping the Debug.Assert to
document the internal precondition for readAllText.
🤖 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
`@Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationFileService.cs`:
- Around line 29-34: The constructor ThirdPartyToolMigrationSourceFileCache
currently uses both Debug.Assert(readAllText != null, ...) and a null-coalescing
throw when assigning _readAllText, which is redundant; remove the runtime null
check (the "?? throw new ArgumentNullException(nameof(readAllText))") and
instead assign _readAllText = readAllText after keeping the Debug.Assert to
document the internal precondition for readAllText.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 18c1eccb-3b38-40d1-a24d-862719e1b5be

📥 Commits

Reviewing files that changed from the base of the PR and between c633a8e and 9f66762.

⛔ Files ignored due to path filters (1)
  • Assets/Tests/Demo/Editor/uLoopMCP.Tests.Demo.Editor.asmdef is excluded by none and included by none
📒 Files selected for processing (13)
  • Assets/Tests/Editor/OnionAssemblyDependencyTests.cs
  • Assets/Tests/Editor/SetupWizardWindowTests.cs
  • Assets/Tests/Editor/ThirdPartyToolMigrationFileServiceTests.cs
  • Assets/Tests/Editor/ThirdPartyToolMigrationWizardWindowTests.cs
  • Assets/Tests/Editor/UnityCliLoopEditorSessionStateRepositoryTests.cs
  • Assets/Tests/Editor/UnityCliLoopEditorSessionStateTestFactory.cs
  • Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateService.cs
  • Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSessionStateRepository.cs
  • Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationFileService.cs
  • Packages/src/Editor/Infrastructure/ThirdPartyToolMigration/ThirdPartyToolMigrationRules.cs
  • Packages/src/Editor/Presentation/PresentationEditorStartup.cs
  • Packages/src/Editor/Presentation/Setup/SetupWizardWindow.cs
  • Packages/src/Editor/Presentation/Setup/ThirdPartyToolMigrationWizardWindow.cs

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 14 files

Re-trigger cubic

@hatayama hatayama merged commit 78b5b22 into v3-beta May 21, 2026
8 checks passed
@hatayama hatayama deleted the feature/hatayama/fix-startup-freeze branch May 21, 2026 15:43
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