Skip to content

Conversation

dsarno
Copy link
Owner

@dsarno dsarno commented Aug 17, 2025

Summary

  • default validate level to standard for CLI parity
  • include unity:// URI in script read/update results
  • fix Roslyn gating to run for Standard+ and fail on errors
  • coalesce all paths in refresh debounce and ensure new calls schedule imports

Testing

  • pytest -q

https://chatgpt.com/codex/tasks/task_e_68a1eac13eac83279d6f077413ceabce

Copy link

coderabbitai bot commented Aug 17, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-roslyn-error-handling-logic-d0dyv0

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dsarno dsarno merged commit 7ee2191 into protocol-framing Aug 17, 2025
2 checks passed
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR makes several important improvements to the Unity MCP script management system to align with CLI standards and fix critical validation bugs. The changes focus on four main areas:

  1. Validation Level Standardization: Changes the default validation level from 'basic' to 'standard' to match CLI tool behavior, ensuring consistency across different interfaces.

  2. URI Response Enhancement: Adds unity:// URI format to script read and update responses, providing proper resource identification that external tools can use to reference Unity scripts.

  3. Roslyn Validation Fix: Corrects a critical bug in the Roslyn validation logic where syntax errors could be ignored. The fix ensures validation only runs for Standard+ levels and properly fails when compilation errors are detected.

  4. Refresh Debounce Improvement: Enhances the refresh debounce system to collect all affected paths from multiple rapid changes and ensures that new calls properly schedule asset imports, preventing missed updates during bulk operations.

These changes integrate well with the existing Unity MCP architecture, which serves as a bridge between Unity and Large Language Models via the Model Context Protocol. The script management functionality is a core component that allows AI tools to read, create, and modify Unity C# scripts, so improving its reliability and consistency is crucial for the overall system's effectiveness.

Important Files Changed

Files Modified
Filename Score Overview
UnityMcpBridge/Editor/Tools/ManageScript.cs 4/5 Fixed critical Roslyn validation logic, added URI responses, changed default validation level, and improved refresh debounce system

Confidence score: 4/5

  • This PR is safe to merge with good confidence due to targeted fixes for known issues
  • Score reflects solid bug fixes and consistency improvements, though the validation logic change affects core functionality
  • Pay close attention to the Roslyn validation changes to ensure error handling works as expected

Sequence Diagram

sequenceDiagram
    participant User
    participant MCP as "MCP Server"
    participant ManageScript as "ManageScript"
    participant ValidateScriptSyntax as "ValidateScriptSyntax"
    participant Roslyn as "Roslyn Compiler"
    participant FileSystem as "File System"
    participant AssetDatabase as "AssetDatabase"
    participant RefreshDebounce as "RefreshDebounce"

    User->>MCP: "manage_script request"
    MCP->>ManageScript: "HandleCommand(params)"
    
    alt action: create
        ManageScript->>ManageScript: "TryResolveUnderAssets(path)"
        ManageScript->>FileSystem: "Check if file exists"
        FileSystem-->>ManageScript: "File not exists"
        ManageScript->>ManageScript: "GenerateDefaultScriptContent()"
        ManageScript->>ManageScript: "GetValidationLevelFromGUI()"
        ManageScript->>ValidateScriptSyntax: "ValidateScriptSyntax(contents, level)"
        ValidateScriptSyntax->>Roslyn: "Parse and analyze syntax"
        Roslyn-->>ValidateScriptSyntax: "Diagnostics"
        ValidateScriptSyntax-->>ManageScript: "isValid, errors"
        alt validation fails
            ManageScript-->>MCP: "Error response with validation errors"
        else validation succeeds
            ManageScript->>FileSystem: "Write file atomically"
            ManageScript->>RefreshDebounce: "ScheduleScriptRefresh(relativePath)"
            ManageScript-->>MCP: "Success response with unity:// URI"
        end
    
    else action: update
        ManageScript->>FileSystem: "Check if file exists"
        FileSystem-->>ManageScript: "File exists"
        ManageScript->>ValidateScriptSyntax: "ValidateScriptSyntax(contents, level)"
        ValidateScriptSyntax->>Roslyn: "Parse and analyze syntax"
        Roslyn-->>ValidateScriptSyntax: "Diagnostics"
        ValidateScriptSyntax-->>ManageScript: "isValid, errors"
        alt validation fails
            ManageScript-->>MCP: "Error response with validation errors"
        else validation succeeds
            ManageScript->>FileSystem: "Atomic file replace"
            ManageScript->>RefreshDebounce: "ScheduleScriptRefresh(relativePath)"
            ManageScript-->>MCP: "Success response with unity:// URI"
        end
    
    else action: apply_text_edits
        ManageScript->>FileSystem: "Read original file"
        FileSystem-->>ManageScript: "File contents"
        ManageScript->>ManageScript: "Verify precondition SHA256"
        ManageScript->>ManageScript: "Apply edits in reverse order"
        ManageScript->>ManageScript: "CheckBalancedDelimiters()"
        ManageScript->>Roslyn: "Parse and validate syntax"
        Roslyn-->>ManageScript: "Syntax diagnostics"
        alt syntax errors
            ManageScript-->>MCP: "Error response with diagnostics"
        else syntax valid
            ManageScript->>FileSystem: "Atomic file write"
            ManageScript->>RefreshDebounce: "ScheduleScriptRefresh(relativePath)"
            ManageScript-->>MCP: "Success response with SHA256"
        end
    
    else action: validate
        ManageScript->>FileSystem: "Read file"
        FileSystem-->>ManageScript: "File contents"
        ManageScript->>ValidateScriptSyntax: "ValidateScriptSyntax(contents, standard)"
        ValidateScriptSyntax->>Roslyn: "Parse and analyze"
        Roslyn-->>ValidateScriptSyntax: "Diagnostics"
        ValidateScriptSyntax-->>ManageScript: "isValid, diagnostics"
        ManageScript-->>MCP: "Response with diagnostic details"
    
    else action: read
        ManageScript->>FileSystem: "Read file"
        FileSystem-->>ManageScript: "File contents"
        ManageScript-->>MCP: "Success response with unity:// URI and contents"
    
    else action: delete
        ManageScript->>AssetDatabase: "MoveAssetToTrash(relativePath)"
        AssetDatabase-->>ManageScript: "Success/failure"
        AssetDatabase->>AssetDatabase: "Refresh()"
        ManageScript-->>MCP: "Success response"
    end
    
    MCP-->>User: "Response"
    
    Note over RefreshDebounce: "Debounced refresh triggers after 200ms"
    RefreshDebounce->>AssetDatabase: "ImportAsset() for all pending paths"
    RefreshDebounce->>AssetDatabase: "RequestScriptCompilation()"
Loading

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bugbot free trial expires on August 31, 2025
Learn more in the Cursor dashboard.

string[] toImport;
lock (_lock) { toImport = _paths.ToArray(); _paths.Clear(); }
foreach (var p in toImport)
AssetDatabase.ImportAsset(p, ImportAssetOptions.ForceUpdate);
Copy link

Choose a reason for hiding this comment

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

Bug: Race Condition in RefreshDebounce Method

The RefreshDebounce.Schedule method has a race condition where the _scheduled flag is accessed and modified without proper synchronization. This allows multiple threads to simultaneously pass the scheduling check, leading to redundant EditorApplication.delayCall callbacks being scheduled unnecessarily, which creates inefficiency.

Fix in Cursor Fix in Web

@dsarno dsarno deleted the codex/fix-roslyn-error-handling-logic-d0dyv0 branch August 19, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant