Skip to content

Conversation

dsarno
Copy link
Collaborator

@dsarno dsarno commented Aug 12, 2025

Summary

Short: Improves read_console severity classification (CSxxxx warnings/errors; Debug.Log stays Log) and ensures consistent results across domain reloads. No API/schema changes.

Addresses #199 & #125

What changed

  • Classify severity via stacktrace/message first (LogError/LogWarning/Exception/Assertion), with safe fallback to mode‑bit mapping
  • Correct error/warning/log filtering; Exceptions/Asserts counted as errors for filtering
  • Remove debug spam; tool now returns the current console buffer consistently
  • Scope limited to UnityMcpBridge/Editor/Tools/ReadConsole.cs (no API/schema changes)

Why

Unity’s internal LogEntry.mode bitfield can differ between versions, which caused misclassification (e.g., errors showing as warnings). Stacktrace‑first classification is stable and version‑resilient.

How to verify

  1. Generate one of each: Debug.Log, Debug.LogWarning, Debug.LogError (and optionally an exception/assert)
  2. Run the read_console tool with type filters (log, warning, error) and confirm correct classification
  3. Trigger a domain reload; read_console continues to return the current buffer accurately

Summary by CodeRabbit

  • New Features

    • Improved log severity classification using message content with a mode fallback.
    • Stack traces are now extracted and included in console entries.
  • Bug Fixes

    • More accurate filtering across all log types, preserving Exception and Assert handling.
    • Output now reports the actual inferred log type.
    • More robust entry retrieval with guaranteed cleanup and controlled error handling.
  • Chores

    • sinceTimestamp parsed but not yet applied; warning logged.
    • Removed unused calibration code and simplified comments.

dsarno added 4 commits August 10, 2025 19:45
…y versions

- Classify severity via stacktrace/message first (LogError/LogWarning/Exception/Assertion), with safe fallback to mode-bit mapping
- Fix error/warning/log mapping; treat Exception/Assert as errors for filtering
- Return the current console buffer reliably and remove debug spam
- No changes outside ReadConsole behavior
…llback when stacktrace shows Debug:Log

- Detect explicit Debug.Log in stacktrace (UnityEngine.Debug:Log)
- Do not downgrade/upgrade to Warning via mode bits for editor-originated logs
- Keeps informational setup lines (e.g., MCP registration, bridge start) as Log
…eserve Debug.Log as Log without mode fallback, add explicit Debug.Log detection helper
@dsarno dsarno added the bug Something isn't working label Aug 12, 2025
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Refactors console log classification to infer severity from message content with mode-based fallback, refines filtering and output to use inferred unityType, adds stack-trace extraction, ensures StartGettingEntries/EndGettingEntries are always paired, warns that sinceTimestamp is parsed but unimplemented, and simplifies reflection/error handling. No public APIs changed.

Changes

Cohort / File(s) Summary of Changes
Console classification and retrieval updates
UnityMcpBridge/Editor/Tools/ReadConsole.cs
Added message-based type inference (InferTypeFromMessage, IsExplicitDebugLog), refined mode-to-type mapping (GetLogTypeFromMode), introduced GetRemappedTypeForFiltering and ExtractStackTrace, changed output to emit unityType.ToString(), updated filtering to prefer inferred types (with mode fallback), ensured StartGettingEntries/EndGettingEntries are paired (finally), made static-constructor failures safe by nulling reflection members, logged warning for unimplemented sinceTimestamp, removed calibration code, and minor formatting tweaks.

Sequence Diagram(s)

sequenceDiagram
    actor Caller
    participant ReadConsole
    participant UnityConsole as Unity Console Backend

    Caller->>ReadConsole: GetConsoleEntries(sinceTimestamp, filters)
    Note over ReadConsole: Parse sinceTimestamp (warn: not implemented)
    ReadConsole->>UnityConsole: StartGettingEntries()
    loop For each raw entry
        ReadConsole->>ReadConsole: InferTypeFromMessage(message)
        alt Message not explicit debug/log
            ReadConsole->>ReadConsole: GetLogTypeFromMode(mode) (fallback)
        end
        ReadConsole->>ReadConsole: GetRemappedTypeForFiltering(unityType)
        ReadConsole->>ReadConsole: ExtractStackTrace(message)
        ReadConsole-->>Caller: Emit entry { type: unityType, stackTrace? }
    end
    ReadConsole->>UnityConsole: EndGettingEntries() (finally)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–25 minutes

Poem

I sift the logs, a burrowed sleuth,
Sniffing clues for severity truth.
With whiskered care I trace each line,
Stack trails curl like winter vine.
Bits to backstop, filters align—
Console carrots sorted fine. 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46f616d and ae87e3f.

📒 Files selected for processing (1)
  • UnityMcpBridge/Editor/Tools/ReadConsole.cs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • UnityMcpBridge/Editor/Tools/ReadConsole.cs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
UnityMcpBridge/Editor/Tools/ReadConsole.cs (4)

46-48: Remove empty lines for better code consistency.

These blank lines don't add value and create unnecessary whitespace.

                if (logEntriesType == null)
                    throw new Exception("Could not find internal type UnityEditor.LogEntries");
-                
-                
-

107-110: Remove empty calibration comment block.

This empty comment block should be removed as part of the calibration cleanup.

                if (_instanceIdField == null)
                    throw new Exception("Failed to reflect LogEntry.instanceID");
-                
-                // (Calibration removed)
-                

261-264: Inconsistent brace placement.

The opening brace should be on the same line as the if statement to match the codebase style.

-                    if (string.IsNullOrEmpty(message))
-                    {
+                    if (string.IsNullOrEmpty(message)) {
                        continue; // Skip empty messages
-                    }
+                    }

454-476: Unused method - consider removal.

The GetRemappedTypeForFiltering method is defined but never used in the codebase. This appears to be leftover from the previous implementation.

#!/bin/bash
# Description: Verify that GetRemappedTypeForFiltering is indeed unused
# Expected: Should only find the method definition

rg "GetRemappedTypeForFiltering"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0743e64 and 46f616d.

📒 Files selected for processing (1)
  • UnityMcpBridge/Editor/Tools/ReadConsole.cs (7 hunks)
🔇 Additional comments (9)
UnityMcpBridge/Editor/Tools/ReadConsole.cs (9)

19-20: LGTM!

Good cleanup - removing calibration code simplifies the codebase and reduces maintenance burden.


268-275: Excellent improvement to log classification reliability.

The hybrid approach using message content analysis with mode-based fallback is a significant improvement over pure mode-based classification. This addresses the core issue of Unity's mode bitfield variations across versions.


333-333: Output format uses reliable classification.

Good change - using unityType.ToString() instead of mode-derived types ensures consistent output formatting that matches the improved classification logic.


389-409: Simplified and clearer mode-to-type mapping.

The direct bit checking approach is much cleaner and easier to understand than the previous multi-branch logic. The comment about version variations is helpful context.


413-444: Robust message-based classification implementation.

The InferTypeFromMessage method provides excellent cross-version compatibility by analyzing actual message content. The order of checks is logical - Debug API calls first, then compiler diagnostics, then exceptions/assertions.


446-452: Good helper for explicit debug detection.

This method correctly identifies explicit Debug.Log calls, which is essential for the hybrid classification approach.


484-538: Comprehensive stack trace extraction logic.

The ExtractStackTrace method is well-implemented with multiple heuristics for detecting stack trace patterns. The performance note about TrimStart is helpful, and the logic handles various Unity stack trace formats effectively.


366-378: Proper resource cleanup with finally block.

Excellent improvement - ensuring EndGettingEntries is always called in the finally block prevents resource leaks and console corruption, especially after domain reloads.


180-186: Good warning for unimplemented feature.

The warning about unimplemented timestamp filtering is appropriate and helps manage user expectations.

…directly from unityType (Exception/Assert treated as errors)
@dsarno dsarno merged commit 642210c into CoplayDev:main Aug 12, 2025
1 check passed
@dsarno dsarno deleted the fix-read-console branch August 19, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant