Skip to content

fix: Play mode control waits reliably and input overlays avoid missing script warnings#1219

Merged
hatayama merged 5 commits into
v3-betafrom
feature/hatayama/fix-playmode-overlay-warnings
May 26, 2026
Merged

fix: Play mode control waits reliably and input overlays avoid missing script warnings#1219
hatayama merged 5 commits into
v3-betafrom
feature/hatayama/fix-playmode-overlay-warnings

Conversation

@hatayama

Copy link
Copy Markdown
Owner

Summary

  • uloop control-play-mode now waits until Unity reaches the requested Play, Stop, or Pause state before returning.
  • Input simulation overlays no longer carry project-local missing script references that can pollute Console logs.

User Impact

  • A Play request no longer reports success while Unity is still entering Play Mode and IsPlaying is still false.
  • Slow projects can use --timeout-seconds to give Unity more time, and timeout failures now return an actionable CLI error.
  • Keyboard and mouse simulation checks no longer add overlay-owned missing script warnings to the same Console log stream as game warnings.

Changes

  • Move Play Mode state waiting into the native CLI so it can survive Unity domain reload disconnects after the request is dispatched.
  • Add a hidden status-only Play Mode probe and focused timeout handling for the requested state.
  • Remove the project-local script reference from the packaged mouse input overlay prefab.
  • Add focused Go and Unity EditMode regression coverage, and refresh the checked-in native CLI binaries.

Verification

  • ~/.codex/skills/codex-review/scripts/codex-review v3-beta
  • go test ./...
  • scripts/check-go-cli.sh
  • Packages/src/Cli~/dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)"
  • Packages/src/Cli~/dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex --filter-value "(ControlPlayModeUseCaseTests|InputVisualizationCanvasPrefabTests)"

hatayama added 4 commits May 26, 2026 23:23
The packaged input overlay should not reference demo-only scripts from Assets,
because installed packages do not include those project test assets and Unity
reports them as missing scripts when the overlay prefab is instantiated.
Return control-play-mode responses only after Unity reaches the requested
PlayMode state, and expose a timeout budget so slow projects can opt into a
longer wait instead of receiving a started message while still in Edit Mode.
Keep the Unity RPC from awaiting across PlayMode domain reloads, and poll a hidden status-only request from the native CLI so Play/Stop can survive bridge recovery before returning final state.
Timeouts mean the requested PlayMode state was not reached, so return a failed CLI result instead of letting automation continue as if the Editor is ready.
@coderabbitai

coderabbitai Bot commented May 26, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6d7bdfca-df7c-4df8-b45c-9c7d81506448

📥 Commits

Reviewing files that changed from the base of the PR and between 21c2a32 and ec24269.

📒 Files selected for processing (1)
  • Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs

📝 Walkthrough

Walkthrough

This PR adds configurable timeout support to the control-play-mode tool, allowing the CLI to wait for Unity play-mode state transitions within a timeout window. It introduces StatusOnly state-query capability on the editor side, comprehensive polling and retry logic on the CLI side, and adds validation tests for overlay prefab assets.

Changes

Control Play Mode Timeout and StatusOnly State Query

Layer / File(s) Summary
Configuration schema and constant definitions
Packages/src/Editor/FirstPartyTools/ControlPlayMode/ControlPlayModeSchema.cs, Packages/src/Editor/FirstPartyTools/ControlPlayMode/ControlPlayModeUseCase.cs, Packages/src/Cli~/internal/tools/default-tools.json, Assets/Tests/Editor/ControlPlayModeUseCaseTests.cs
TimeoutSeconds and StatusOnly properties added to editor schema and tool JSON definition; DefaultTimeoutSeconds constant (180 seconds) established; tests verify schema defaults and StatusOnly behavior.
Editor use case StatusOnly and response handling
Packages/src/Editor/FirstPartyTools/ControlPlayMode/ControlPlayModeUseCase.cs
ExecuteAsync now short-circuits when StatusOnly is true, returning play-mode status without executing actions; response construction centralized in CreateResponse helper.
CLI state-wait polling implementation
Packages/src/Cli~/internal/cli/control_play_mode_wait.go
Core polling logic: sends control command with transient retry, decodes initial state, optionally short-circuits if state matches, otherwise polls with configurable timeout, handles disconnects and context cancellation separately, constructs structured timeout errors with diagnostic details. Includes robust timeout-seconds parsing supporting int, int64, and float64 types.
CLI integration and error definitions
Packages/src/Cli~/internal/cli/run.go, Packages/src/Cli~/internal/cli/error_envelope.go
runTool routes control-play-mode commands through state-wait logic before standard tool execution; new errorCodeControlPlayModeWaitTimeout error code added to CLI error set.
CLI wait behavior tests
Packages/src/Cli~/internal/cli/control_play_mode_wait_test.go
Tests cover stale initial state recovery, transport-loss post-reload waiting, timeout failures with proper error codes, and float timeout-seconds parsing; includes TCP server helpers to simulate Unity JSON-RPC responses.
Feature documentation
Packages/src/Editor/FirstPartyTools/ControlPlayMode/Skill/SKILL.md
Documents --timeout-seconds parameter, adds usage example with extended timeout budget, revises notes to clarify command waits for requested state before returning.

Prefab Asset Validation Tests

Layer / File(s) Summary
Missing script detection in overlay prefabs
Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs
Added RegularExpressions import and test fixture constants listing overlay prefab paths; new tests instantiate prefabs and validate zero missing-script components per GameObject, scan prefab YAML for m_Script GUIDs to ensure they do not reference Assets/ script locations; helper method traverses child transforms and asserts missing-script MonoBehaviour counts.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the two main changes: Play mode control now waits reliably, and input overlays avoid missing script warnings.
Description check ✅ Passed The description comprehensively covers the changeset, explaining the Play Mode waiting mechanism, overlay fixes, and the split between CLI and editor changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/hatayama/fix-playmode-overlay-warnings

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
Packages/src/Editor/FirstPartyTools/ControlPlayMode/Skill/SKILL.md (1)

59-59: ⚡ Quick win

Document timeout failure behavior.

The note explains that the command waits and suggests increasing the timeout, but it doesn't explain what happens when the timeout expires. The PR objectives state that "timeout failures return actionable errors," which is important user-facing behavior that should be documented.

📝 Suggested addition to clarify timeout behavior
-- The command waits for the requested state before returning. Increase `--timeout-seconds` for projects with slow PlayMode entry.
+- The command waits for the requested state before returning. Increase `--timeout-seconds` for projects with slow PlayMode entry. The command will fail with an error if the timeout is reached before the requested state is achieved.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Packages/src/Editor/FirstPartyTools/ControlPlayMode/Skill/SKILL.md` at line
59, Update the SKILL.md note about "--timeout-seconds" so it documents what
happens when the timeout expires: state that the command returns a non-zero exit
code, prints an actionable error message explaining the timeout caused failure
(including which state was waited for), and suggests remediation (increase
--timeout-seconds or diagnose PlayMode entry delays); reference the
"--timeout-seconds" flag and the PlayMode entry/state wait behavior so readers
know the exact failure semantics and next steps.
Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs (1)

22-40: ⚡ Quick win

Consolidate duplicated prefab path lists to avoid drift.

OverlayPrefabPaths and OverlayPrefabFilePaths must be kept in sync manually. A single paired structure reduces maintenance mistakes and keeps both tests aligned.

♻️ Refactor sketch
-        private static readonly string[] OverlayPrefabPaths =
+        private static readonly (string packagePath, string sourcePath)[] OverlayPrefabs =
         {
-            "Packages/io.github.hatayama.uloopmcp/Runtime/Common/InputVisualizationCanvas.prefab",
-            "Packages/io.github.hatayama.uloopmcp/Runtime/SimulateMouseInput/SimulateMouseInputOverlay.prefab",
-            ...
+            (
+                "Packages/io.github.hatayama.uloopmcp/Runtime/Common/InputVisualizationCanvas.prefab",
+                "Packages/src/Runtime/Common/InputVisualizationCanvas.prefab"
+            ),
+            (
+                "Packages/io.github.hatayama.uloopmcp/Runtime/SimulateMouseInput/SimulateMouseInputOverlay.prefab",
+                "Packages/src/Runtime/SimulateMouseInput/SimulateMouseInputOverlay.prefab"
+            ),
+            // ...
         };

Then use .packagePath in the load/instantiate test and .sourcePath in the YAML scan test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs` around lines 22 -
40, Replace the duplicated arrays OverlayPrefabPaths and OverlayPrefabFilePaths
with a single paired structure (e.g., an array of objects with packagePath and
sourcePath properties) so the two path variants cannot drift; update the tests
to read .packagePath when performing the load/instantiate tests and .sourcePath
when performing the YAML scan tests, and replace all references to
OverlayPrefabPaths and OverlayPrefabFilePaths accordingly (look for usages in
the load/instantiate test and the YAML scan test).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs`:
- Around line 164-169: The test currently lets empty assetPath from
AssetDatabase.GUIDToAssetPath(guid) pass the Does.Not.StartWith("Assets/")
check, so change the assertion to explicitly require a non-empty, project path:
retrieve assetPath (via AssetDatabase.GUIDToAssetPath(guid)), then Assert that
assetPath is not null or empty and that it StartsWith "Assets/" for the
OverlayPrefabFilePaths[pathIndex] reference to guid; use the same variables
(assetPath, guid, OverlayPrefabFilePaths[pathIndex], pathIndex) so the failure
message still identifies the prefab and GUID.

---

Nitpick comments:
In `@Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs`:
- Around line 22-40: Replace the duplicated arrays OverlayPrefabPaths and
OverlayPrefabFilePaths with a single paired structure (e.g., an array of objects
with packagePath and sourcePath properties) so the two path variants cannot
drift; update the tests to read .packagePath when performing the
load/instantiate tests and .sourcePath when performing the YAML scan tests, and
replace all references to OverlayPrefabPaths and OverlayPrefabFilePaths
accordingly (look for usages in the load/instantiate test and the YAML scan
test).

In `@Packages/src/Editor/FirstPartyTools/ControlPlayMode/Skill/SKILL.md`:
- Line 59: Update the SKILL.md note about "--timeout-seconds" so it documents
what happens when the timeout expires: state that the command returns a non-zero
exit code, prints an actionable error message explaining the timeout caused
failure (including which state was waited for), and suggests remediation
(increase --timeout-seconds or diagnose PlayMode entry delays); reference the
"--timeout-seconds" flag and the PlayMode entry/state wait behavior so readers
know the exact failure semantics and next steps.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e4323145-cd11-4353-8fb4-0075258e2ff8

📥 Commits

Reviewing files that changed from the base of the PR and between fb4713d and 21c2a32.

⛔ Files ignored due to path filters (5)
  • Assets/Tests/Editor/ControlPlayModeUseCaseTests.cs.meta is excluded by none and included by none
  • Packages/src/Cli~/dist/darwin-amd64/uloop is excluded by !**/dist/** and included by none
  • Packages/src/Cli~/dist/darwin-arm64/uloop is excluded by !**/dist/** and included by none
  • Packages/src/Cli~/dist/windows-amd64/uloop.exe is excluded by !**/dist/**, !**/*.exe and included by none
  • Packages/src/Runtime/SimulateMouseInput/SimulateMouseInputOverlay.prefab is excluded by !**/*.prefab and included by none
📒 Files selected for processing (10)
  • Assets/Tests/Editor/ControlPlayModeUseCaseTests.cs
  • Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs
  • Packages/src/Cli~/internal/cli/control_play_mode_wait.go
  • Packages/src/Cli~/internal/cli/control_play_mode_wait_test.go
  • Packages/src/Cli~/internal/cli/error_envelope.go
  • Packages/src/Cli~/internal/cli/run.go
  • Packages/src/Cli~/internal/tools/default-tools.json
  • Packages/src/Editor/FirstPartyTools/ControlPlayMode/ControlPlayModeSchema.cs
  • Packages/src/Editor/FirstPartyTools/ControlPlayMode/ControlPlayModeUseCase.cs
  • Packages/src/Editor/FirstPartyTools/ControlPlayMode/Skill/SKILL.md

Comment thread Assets/Tests/Editor/InputVisualizationCanvasPrefabTests.cs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 15 files

Re-trigger cubic

Detect empty GUID resolution results so package overlay prefab tests catch broken m_Script references instead of passing them through the project-script check.
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