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
  • clean up .bak backups, guard against symlinked edits, and run immediate refreshes on the main thread

Testing

  • pytest -q

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

@coderabbitai
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-4rl4fu

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.

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 enhances the script management system in Unity MCP Bridge by addressing several operational issues and improving robustness. The changes focus on aligning the system with CLI tooling expectations and Unity's asset management best practices.

The most significant change involves fixing the Roslyn validation logic, which was previously allowing validation errors to pass through at the Standard level - this was a known issue marked with a TODO comment that has now been formally addressed. The validation now properly gates on Standard+ level and fails operations when compilation errors are detected.

Other key improvements include: changing the default validation level from 'basic' to 'standard' to match CLI parity expectations, adding unity:// URIs to script read/update responses for better resource identification by external systems, implementing comprehensive backup file cleanup to prevent Unity from importing temporary .bak files as assets, and adding symlink guards to prevent editing of symlinked files which could cause security issues or file system confusion.

The refresh debounce system has been enhanced to handle multiple file operations more efficiently by coalescing paths and ensuring proper import scheduling. Additionally, immediate refresh operations are now moved to Unity's main thread using EditorApplication.delayCall to prevent threading violations that could cause editor instability.

Important Files Changed

Filename Score Overview
UnityMcpBridge/Editor/Tools/ManageScript.cs 4/5 Comprehensive script management improvements including validation fixes, backup cleanup, symlink guards, and thread-safe refresh operations

Confidence score: 4/5

  • This PR addresses critical bugs and improves system reliability with well-targeted fixes
  • Score reflects solid improvements to validation logic and asset management, though the extensive changes require careful testing
  • Pay close attention to the Roslyn validation changes and refresh debounce logic modifications

Sequence Diagram

sequenceDiagram
    participant User
    participant HandleCommand
    participant ValidateScriptSyntax
    participant Roslyn as Roslyn Compiler
    participant FileSystem
    participant RefreshDebounce
    participant Unity as Unity Editor

    User->>HandleCommand: "Script management request"
    HandleCommand->>HandleCommand: "Extract and validate parameters"
    
    alt create/update action
        HandleCommand->>ValidateScriptSyntax: "Validate with Standard+ level"
        ValidateScriptSyntax->>ValidateScriptSyntax: "Basic structure validation"
        alt USE_ROSLYN defined and Standard+ level
            ValidateScriptSyntax->>Roslyn: "Parse syntax tree and get diagnostics"
            Roslyn-->>ValidateScriptSyntax: "Return errors/warnings"
            alt has errors
                ValidateScriptSyntax-->>HandleCommand: "Validation failed"
                HandleCommand-->>User: "Error response with diagnostics"
            end
        end
        ValidateScriptSyntax-->>HandleCommand: "Validation passed"
        HandleCommand->>FileSystem: "Atomic write (.tmp → .bak → final)"
        FileSystem->>FileSystem: "Clean up .bak files"
        HandleCommand->>RefreshDebounce: "Schedule script refresh"
        HandleCommand-->>User: "Success with unity:// URI"
        RefreshDebounce->>Unity: "Debounced asset import and compilation"
    end
    
    alt apply_text_edits action
        HandleCommand->>FileSystem: "Read current file and compute SHA256"
        alt precondition check fails
            HandleCommand-->>User: "stale_file error with SHA mismatch"
        end
        HandleCommand->>HandleCommand: "Apply edits with overlap validation"
        alt USE_ROSLYN defined
            HandleCommand->>Roslyn: "Parse and validate result"
            alt syntax errors found
                HandleCommand-->>User: "syntax_error with diagnostics"
            end
            HandleCommand->>Roslyn: "Optional formatting"
        end
        HandleCommand->>FileSystem: "Atomic write with backup cleanup"
        HandleCommand->>RefreshDebounce: "Schedule refresh"
        HandleCommand-->>User: "Success with applied count and new SHA256"
    end
    
    alt validate action
        HandleCommand->>ValidateScriptSyntax: "Validate with specified level (default: standard)"
        ValidateScriptSyntax-->>HandleCommand: "Diagnostics array"
        HandleCommand-->>User: "Validation result with structured diagnostics"
    end
Loading

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@dsarno dsarno merged commit a53204a into protocol-framing Aug 17, 2025
2 checks passed
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.

if ((now - _last) < window) return;
if (_scheduled && (now - _last) < window) return;
_last = now;
_scheduled = true;
Copy link

Choose a reason for hiding this comment

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

Bug: Debouncing Logic Fails to Prevent Race Conditions

The RefreshDebounce.Schedule method's debouncing logic is flawed. The _scheduled flag isn't synchronized, which can lead to race conditions and duplicate scheduling. Also, the _scheduled && (now - _last) < window condition allows new refreshes to be scheduled immediately after a debounced call completes, bypassing the time window and defeating the debouncing.

Fix in Cursor Fix in Web

@dsarno dsarno deleted the codex/fix-roslyn-error-handling-logic-4rl4fu 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.

2 participants