Skip to content

fix(ui): add traversal depth and result count bounds for UI hierarchy and queries (#126) - #190

Merged
Daliys merged 6 commits into
developmentfrom
daliys/issue-126-ui-traversal-limits
Aug 22, 2026
Merged

fix(ui): add traversal depth and result count bounds for UI hierarchy and queries (#126)#190
Daliys merged 6 commits into
developmentfrom
daliys/issue-126-ui-traversal-limits

Conversation

@Daliys

@Daliys Daliys commented Aug 22, 2026

Copy link
Copy Markdown
Member

Summary

Addresses #126 by adding bounds and truncation indicators to UI Toolkit VisualElement hierarchy traversal and queries.

Problem

UI Toolkit traversal for hierarchy and element query tools (ui_get_hierarchy, ui_query_elements, ui_capture_window_snapshot) recursively walked full VisualElement trees synchronously on the Unity main thread without depth or result count limits, causing visible editor stalls and oversized JSON payloads on complex windows.

Changes

  • SerializeVisualElement: added maxDepth (default: 30) and maxElements (default: 1000) caps. If limits are reached, recursion is halted, the truncated element node is marked with children_truncated: true, and the root object is marked with truncated: true.
  • UIGetHierarchy: accepts optional max_depth and max_elements / max_results parameters.
  • UIQueryElements & QueryVisualElementRecursive: accepts optional max_depth (default: 30) and max_results (default: 100). Immediately aborts recursion when maxResults or maxDepth is hit.
  • UICaptureWindowSnapshot: forwards max_depth and max_elements to hierarchy serialization.
  • MCP Bridge (routing.py, schemas.py): exposed and forwarded max_depth, max_elements, and max_results on unity_ui_automation (get_hierarchy, query, capture_window_snapshot).
  • Documentation & Specs: updated API_REFERENCE.MD, DOCUMENTATION.MD, and CHANGELOG.md.
  • Tests: added C# tests in AgentToolingTests.cs and Python tests in test_routing.py and test_schemas.py.

Closes #126

@Daliys
Daliys force-pushed the daliys/issue-126-ui-traversal-limits branch from e28374b to 5d3e43a Compare August 22, 2026 13:29
@Daliys
Daliys merged commit 6128159 into development Aug 22, 2026
13 checks passed
@Daliys
Daliys deleted the daliys/issue-126-ui-traversal-limits branch August 22, 2026 18:08
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