Skip to content

fix: keep Unity responsive while building the shared Roslyn worker DLL#1764

Merged
hatayama merged 1 commit into
feature/dynamic-code-slot-recoveryfrom
fix/roslyn-worker-assembly-wait-async
Jul 13, 2026
Merged

fix: keep Unity responsive while building the shared Roslyn worker DLL#1764
hatayama merged 1 commit into
feature/dynamic-code-slot-recoveryfrom
fix/roslyn-worker-assembly-wait-async

Conversation

@hatayama

@hatayama hatayama commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • The rare first-time shared Roslyn worker DLL build no longer blocks the Unity main thread with synchronous WaitForExit.
  • Existing timeout (30s) + Kill + stream drain behavior is unchanged.

User Impact

  • Before: When the compile gate was free, EnsureWorkerReadyEnsureWorkerAssemblyBuilt could run on the calling thread before the first await, so a missing worker DLL could freeze the Editor for up to the build timeout.
  • After: That build runs on the thread pool via Task.Run; the Editor stays responsive. Timeout/kill remain as the safety net.

Design (plan A)

  • Offload boundary: entire CompileWorkerAssembly (including drain) via CompileWorkerAssemblyOffMainThreadAsync.
  • No Unity APIs inside the build path (Process + File IO only).
  • Build remains outside the session state lock.
  • Rejected plan B: WaitForExitAsync is not available on Unity’s .NET Standard 2.1 profile; rewriting Exited+TCS would add moving parts without benefit.

Call-site threading (condition 3)

  • TryCompileAsyncRunSerializedCompileAsyncTryCompileWithRetriesAsync / TryCompileOnceAsync.
  • When the async compile gate is acquired without yielding, work before the first await of EnsureWorkerReadyAsync (generation check, path sync) can still run on the caller thread — including the Unity main thread.
  • The long WaitForExit(timeout) body is the part that must leave that thread; that is what Task.Run covers.

Verification

  • uloop compile → Success
  • CompileWorkerAssemblyAsync_WhenTestHookIsInstalled_ShouldReturnHookResult → Passed

Test plan

  • Confirm test-hook async path still returns hooked messages
  • Optional: delete worker DLL under temp RoslynWorker-* and run execute-dynamic-code; Editor should stay responsive during rebuild

Made with Cursor

Review in cubic

Keep the existing WaitForExit(timeout)/Kill/drain path, but run the full
CompileWorkerAssembly body via Task.Run so an idle compile-gate acquire
cannot freeze the Editor during the rare first-time worker DLL build.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hatayama

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b9376ac4-4047-4aa4-8fca-c249b4b00e20

📥 Commits

Reviewing files that changed from the base of the PR and between d59a625 and 409a911.

📒 Files selected for processing (4)
  • Assets/Tests/Editor/DynamicCodeToolTests/SharedRoslynCompilerWorkerHostTests.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerAssemblyBuilder.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerHost.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerSession.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/roslyn-worker-assembly-wait-async

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.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hatayama
hatayama merged commit e408f69 into feature/dynamic-code-slot-recovery Jul 13, 2026
2 checks passed
@hatayama
hatayama deleted the fix/roslyn-worker-assembly-wait-async branch July 13, 2026 16:11
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