Skip to content

fix(read_console): stop the Console window's filters from hiding entries - #1342

Open
KamilDev wants to merge 1 commit into
CoplayDev:betafrom
KamilDev:fix/read-console-ui-filter-leak
Open

fix(read_console): stop the Console window's filters from hiding entries#1342
KamilDev wants to merge 1 commit into
CoplayDev:betafrom
KamilDev:fix/read-console-ui-filter-leak

Conversation

@KamilDev

@KamilDev KamilDev commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Description

read_console inherits the Console window's UI filters, so entries the user has hidden in the Editor are invisible to the agent — and the tool still reports success: true, so "Retrieved 0 log entries" is indistinguishable from a clean console. Worst case is right after a compile, where an agent proceeds on broken state.

LogEntries filtering state is global and shared with the Console window. StartGettingEntries() honors both:

  • the toolbar's Log / Warning / Error severity toggles — ConsoleFlags.LogLevelLog|Warning|Error, bits 1<<7, 1<<8, 1<<9
  • the toolbar's search box — LogEntries.SetFilteringText

The tool's own filterText argument is applied client-side afterwards, so it cannot compensate for entries the native call never returned.

GetConsoleEntries now snapshots both, neutralizes them for the duration of the read, and restores them in the finally block once the iteration session is closed — so the user's Console view is left exactly as they had it. The tool's own types and filterText arguments still do the filtering, which is what the caller actually asked for.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

MCPForUnity/Editor/Tools/ReadConsole.cs

  • Reflect LogEntries.consoleFlags, SetFilteringText and GetFilteringText.
  • TryForceLogLevelFlags / RestoreConsoleFlags — OR the three severity bits on for the read, restore afterwards. Idempotent: when the bits are already set the property is not written at all.
  • TryClearFilteringText / RestoreFilteringText — blank the search query for the read, restore afterwards.
  • Restoration happens after EndGettingEntries, so it never runs inside an open iteration session, and it runs even if the iteration throws.

TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ReadConsoleTests.cs

  • HandleCommand_Get_IgnoresConsoleSearchFilter — logs a probe, sets a non-matching search query, asserts the probe is still returned and that the query is left as the user set it.
  • HandleCommand_Get_IgnoresConsoleSeverityToggles — logs a probe, switches the Log/Warning bits off, asserts the probe is still returned and that the flags are restored.

Notes on the approach

  • The three severity bits only, not the whole mask. Collapse (1<<0) also changes what StartGettingEntries returns, but forcing it off would flood a page with duplicates of a spammed message and push distinct entries past the count/pageSize limit — that hides output rather than revealing it. Left alone deliberately.
  • The search query is only cleared when GetFilteringText is also available, so a user's search is never discarded without a way to put it back.
  • All four reflected members exist in 2021.3, 2022.3, 6000.0 and 6000.3 (checked against UnityCsReference at each tag), so this is not a version-gated path in practice. They are still reflected optionally: if a future Unity renames one, console reads degrade to the current behavior instead of failing outright. The HandleCommand reflection guard is deliberately unchanged — these members are not required for a console read to work at all, and clear does not depend on them.

Compatibility / Package Source

  • Unity version(s) tested: compile-verified against 2022.3.27f1 and 6000.3.14f1 for win, osx and linux each; behavior verified at runtime in a live 6000.3.14f1 Editor
  • Package source used: local file: checkout
  • Resolved commit hash from Packages/packages-lock.json: n/a (file: source)

Testing/Screenshots/Recordings

  • Python tests (cd Server && uv run pytest tests/ -v)
  • Unity EditMode tests
  • Unity PlayMode tests
  • Package import/compile check
  • Not applicable (explain why in Additional Notes)

Compile

tools/compile-check.sh run against local Hub installs of 2022.3.27f1 and 6000.3.14f1 — MCPForUnity.Runtime and MCPForUnity.Editor compile clean on win, osx and linux for both. The EditMode test assembly was compiled the same way (same reference set plus the built package DLLs) to confirm the two new tests build; the only diagnostics are pre-existing CS0618/CS0649 warnings from unrelated test files.

Runtime, in a live 6000.3.14f1 Editor

Verified against a project consuming this branch through a file: package reference, confirming first that the loaded MCPForUnity.Editor assembly actually contained the new methods.

The bug, reproduced: with the Log and Warning toggles switched off, a raw LogEntries.StartGettingEntries() returns 0 — with a freshly logged entry sitting in the console. That is the tool's old view.

The fix, against that same state: read_console returns the probe entry, and consoleFlags is left byte-identical afterwards.

Search-box case (the reported one): with the search box set to a query matching nothing, read_console returns the probe, and GetFilteringText() afterwards still returns the user's query unchanged.

Idempotence confirmed incidentally: in that project the three severity bits were already on, so TryForceLogLevelFlags correctly declined to write the property at all and consoleFlags never changed.

On the two new tests

They have not been run as an NUnit fixture. TestProjects/UnityMCPTests is pinned to 2021.3.45f2 and I have no 2021 Editor installed; opening it in a newer one would silently upgrade the tracked ProjectVersion.txt. Note that the Test in editmode check on this PR passes in ~5s without a license, so it has not run them either — they need a licensed Editor run.

What I could do instead: execute both test bodies verbatim — same NUnit Assert calls, same setup and teardown — against the live Editor. Both pass. That exercises the assertion logic, but not the fixture plumbing ([Test] discovery, test-runner domain state), so a maintainer's licensed run is still the real gate.

Python tests were not run — this change touches no Python.

Manual repro, for anyone verifying by hand

  1. Type anything into the Console window's search box (or switch the Log/Warning toggles off).
  2. Debug.Log("PROBE").
  3. read_console with action: "get", types: ["log"].
  4. Before: {"success": true, "message": "Retrieved 0 log entries"}. After: the probe is returned, and the search box / toggles are left untouched.

Documentation Updates

  • I have added/removed/modified tools or resources

No tool or resource signature changed — the response shape and every argument are identical, so website/docs/reference/ is unaffected.

Related Issues

Fixes #1239

Additional Notes

Supersedes #1252, which fixed the same issue and was closed unmerged by its author. Differences from that patch, all of them the review points it collected:

  • The search query is saved and restored rather than cleared permanently — fix(read_console): force console severity flags ON to bypass UI filter (silent 0 entries) #1252 noted it cleared the box "without saving because GetFilteringText is not guaranteed to exist", but it does exist on every version this package supports, and losing a user's search on every console read is avoidable.
  • Both mutations sit inside the same try/finally as the iteration, so a throw restores both.
  • The HandleCommand reflection guard is left alone, so clear stays available regardless of these optional members.

Credit for the original diagnosis goes to @beast-ofcourse in #1239.

Summary by CodeRabbit

  • Bug Fixes
    • Console reads now include messages hidden by active search filters or disabled severity toggles.
    • The Console’s existing filters and severity settings are preserved and restored after reading.
    • Added graceful handling when Console settings cannot be accessed or restored.

LogEntries filtering state is global and shared with the Console window.
StartGettingEntries() honors both the toolbar's Log/Warning/Error severity
toggles (ConsoleFlags bits 1<<7..1<<9) and the search box (SetFilteringText),
so a toggle switched off or a leftover search query silently starves
read_console of entries. The tool still reports success, so an agent reads
"Retrieved 0 log entries" as a clean console -- worst case right after a
compile, where it proceeds on broken state.

Snapshot both, neutralize them for the duration of the read, and restore them
in the finally block once the iteration session is closed, so the user's view
is left exactly as they had it. The tool applies its own types and filterText
arguments, which is what callers actually asked for.

The search query is only cleared when GetFilteringText is also available, so a
user's search is never discarded without a way to put it back. All four
reflected members exist in 2021.3, 2022.3, 6000.0 and 6000.3, but they are
reflected optionally: if a future Unity renames them, console reads degrade to
the previous behavior instead of failing outright.

Fixes CoplayDev#1239
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf68c7b9-af81-42b8-82be-a4a9d770de5f

📥 Commits

Reviewing files that changed from the base of the PR and between c21bf49 and 17495d4.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/ReadConsole.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ReadConsoleTests.cs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

read_console now ignores active Unity Console severity and search filters during entry retrieval. It restores the original filter state after reading. Edit-mode tests verify entry retrieval and state restoration.

Changes

Console filter handling

Layer / File(s) Summary
Console filter reflection and lifecycle
MCPForUnity/Editor/Tools/ReadConsole.cs
ReadConsole discovers Unity Console filter members through reflection, enables all severity flags, clears search text during reads, and restores both states afterward. Reflection failures produce warnings and do not prevent normal operation.
Filter behavior validation
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ReadConsoleTests.cs
Tests verify that read_console returns entries despite an active search filter or disabled log and warning flags. The tests also verify that the original Console state is restored.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 17495

The change isolates console reads from the window’s severity and search filters while restoring the user’s settings afterward; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ReadConsole
  participant UnityConsole
  participant LogEntries
  ReadConsole->>UnityConsole: Save filter state
  ReadConsole->>UnityConsole: Enable severity flags and clear search text
  ReadConsole->>LogEntries: Iterate console entries
  LogEntries-->>ReadConsole: Return entries
  ReadConsole->>UnityConsole: Restore saved filter state
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #1239 by neutralizing severity and search filters during retrieval and restoring the Console state afterward.
Out of Scope Changes check ✅ Passed The implementation and EditMode tests are directly related to fixing Console filter inheritance in read_console.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing Console window filters from hiding entries returned by read_console.
Description check ✅ Passed The description follows the template, explains the implementation and compatibility, documents testing limits, and links the related issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

[Bug] read_console silently returns 0 entries when Console window severity toggles are off (filter inheritance)

1 participant