Skip to content

Conversation

@dsarno
Copy link
Collaborator

@dsarno dsarno commented Jan 15, 2026

Summary

  • skip QueuePlayerLoopUpdate nudge when refresh_unity also requested compilation
  • keep wait_for_ready polling behavior unchanged otherwise

Testing

  • Unity EditMode tests (UnityMCPTests) — pass
  • Unity PlayMode tests (UnityMCPTests) — pass
  • Server pytest suite — pass

Summary by Sourcery

Enhancements:

  • Add an allow-nudge guard to Unity readiness polling to avoid QueuePlayerLoopUpdate when a compilation is in progress.

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved Unity refresh responsiveness by making the refresh nudge conditional based on compilation status. The refresh mechanism now adapts its behavior depending on whether a compilation was requested, optimizing the readiness check process.

✏️ Tip: You can customize this high-level summary in your review settings.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 15, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the Unity readiness wait helper to optionally skip the EditorApplication.QueuePlayerLoopUpdate 'nudge' when a compile has been requested, while preserving the existing polling behavior otherwise.

Sequence diagram for conditional Unity nudge during refresh wait

sequenceDiagram
    actor Developer
    participant RefreshUnity
    participant WaitHelper as WaitForUnityReadyAsync
    participant EditorApplication

    Developer->>RefreshUnity: HandleCommand(params)
    activate RefreshUnity
    note right of RefreshUnity: compileRequested is computed

    RefreshUnity->>WaitHelper: WaitForUnityReadyAsync(timeout, allowNudge = !compileRequested)
    activate WaitHelper

    WaitHelper->>EditorApplication: subscribe Tick to update
    activate EditorApplication

    alt allowNudge is true (no compile requested)
        WaitHelper->>EditorApplication: QueuePlayerLoopUpdate()
    else allowNudge is false (compile requested)
        note right of WaitHelper: Skip QueuePlayerLoopUpdate
    end

    loop until Unity ready or timeout
        EditorApplication-->>WaitHelper: Tick invoked on update
        WaitHelper-->>WaitHelper: Check readiness and timeout
    end

    WaitHelper-->>RefreshUnity: Task completes or throws TimeoutException
    deactivate WaitHelper

    RefreshUnity-->>Developer: HandleCommand result
    deactivate RefreshUnity
    deactivate EditorApplication
Loading

Updated class diagram for RefreshUnity wait helper behavior

classDiagram
    class RefreshUnity {
        +Task~object~ HandleCommand(JObject params)
        -static Task WaitForUnityReadyAsync(TimeSpan timeout, bool allowNudge)
    }

    class WaitForUnityReadyAsyncWorker {
        -TaskCompletionSource~bool~ tcs
        -DateTime start
        -void Tick()
    }

    class EditorApplication {
        +static event Action update
        +static void QueuePlayerLoopUpdate()
    }

    RefreshUnity --> WaitForUnityReadyAsyncWorker : uses
    WaitForUnityReadyAsyncWorker --> EditorApplication : subscribes update
    WaitForUnityReadyAsyncWorker --> EditorApplication : calls QueuePlayerLoopUpdate when allowNudge == true
Loading

File-Level Changes

Change Details Files
Add an allowNudge parameter to the Unity readiness wait helper and conditionally issue QueuePlayerLoopUpdate.
  • Extend WaitForUnityReadyAsync to accept a boolean allowNudge flag alongside the timeout.
  • Update the HandleCommand call site to pass allowNudge as the negation of compileRequested, so nudging is disabled during compile-triggered refreshes.
  • Wrap the EditorApplication.QueuePlayerLoopUpdate call in a conditional check on allowNudge, preserving previous behavior when nudging is allowed.
MCPForUnity/Editor/Tools/RefreshUnity.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

A boolean parameter allowNudge is added to WaitForUnityReadyAsync(), controlling whether the Unity nudge operation executes during readiness checks. The HandleCommand call path passes !compileRequested as the value, conditionally gating the nudge behavior.

Changes

Cohort / File(s) Summary
Unity Readiness Check Parameter Addition
MCPForUnity/Editor/Tools/RefreshUnity.cs
Added bool allowNudge parameter to WaitForUnityReadyAsync() method signature. Implemented conditional logic to skip QueuePlayerLoopUpdate call when allowNudge is false. Updated call site in HandleCommand path to pass !compileRequested as argument.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A nudge here, a nudge there—or sometimes not at all!
The rabbit hops through Unity's readiness, answering the call.
With allowNudge now guiding the way,
Control flows smoother through each day! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Guard refresh wait nudge during compile' accurately captures the main change: conditionally gating the Unity nudge (QueuePlayerLoopUpdate) based on whether compilation was requested.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f08ac0 and 3c706ed.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Tools/RefreshUnity.cs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-29T15:23:11.613Z
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 491
File: MCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.cs:78-115
Timestamp: 2025-12-29T15:23:11.613Z
Learning: In MCPForUnity, prefer relying on the established testing process to catch UI initialization issues instead of adding defensive null checks for UI elements in editor windows. This means during reviews, verify that tests cover UI initialization paths and that code avoids repetitive null-check boilerplate in Editor Windows. If a UI element can be null, ensure there is a well-tested fallback or that its initialization is guaranteed by design, rather than sprinkling null checks throughout editor code.

Applied to files:

  • MCPForUnity/Editor/Tools/RefreshUnity.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (2)
MCPForUnity/Editor/Tools/RefreshUnity.cs (2)

97-99: LGTM!

The logic correctly disables the nudge when compilation is requested, since Unity will already be actively processing the compilation pipeline. The named parameter improves readability.


131-131: LGTM!

The conditional nudge implementation is clean. The empty catch block is acceptable here since QueuePlayerLoopUpdate() is a best-effort operation and failures shouldn't interrupt the wait logic. The comment adequately explains the intent.

Also applies to: 170-174

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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
Contributor

@sourcery-ai sourcery-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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dsarno dsarno merged commit b6fa293 into CoplayDev:main Jan 15, 2026
2 checks passed
dsarno added a commit to dsarno/unity-mcp that referenced this pull request Jan 15, 2026
The allowNudge parameter was attempting to fix Unity 6 compilation loops
by skipping QueuePlayerLoopUpdate, but this was not the root cause.

The actual issue (fixed by CoplayDev#559's Unity 6+ preprocessor guard) is that
EditorApplication.update callbacks don't survive domain reloads properly
in Unity 6+.

Since CoplayDev#559 skips WaitForUnityReadyAsync entirely on Unity 6+ when compile
is requested, the allowNudge guard is redundant and can be removed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
dsarno added a commit that referenced this pull request Jan 15, 2026
The allowNudge parameter was attempting to fix Unity 6 compilation loops
by skipping QueuePlayerLoopUpdate, but this was not the root cause.

The actual issue (fixed by #559's Unity 6+ preprocessor guard) is that
EditorApplication.update callbacks don't survive domain reloads properly
in Unity 6+.

Since #559 skips WaitForUnityReadyAsync entirely on Unity 6+ when compile
is requested, the allowNudge guard is redundant and can be removed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dsarno dsarno deleted the fix/refresh-unity-loop branch January 15, 2026 16:04
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