Skip to content

fix(package): Reject PlayMode test runs while the Editor is paused#1687

Merged
hatayama merged 2 commits into
v3-betafrom
fix/pause-mid-command-compile-run-tests
Jul 11, 2026
Merged

fix(package): Reject PlayMode test runs while the Editor is paused#1687
hatayama merged 2 commits into
v3-betafrom
fix/pause-mid-command-compile-run-tests

Conversation

@hatayama

@hatayama hatayama commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject PlayMode test execution when Play Mode is paused, preventing tool hangs from
    UnitySynchronizationContext continuations that are never drained during pause
  • Document why compile's WaitForPlayModeExitAsync is immune to this class of hang

Closes #1686

Measurement data (Phase A)

Scenario Before fix After fix
compile during pause 5.089s, self-resolving (StopPlayMode clears isPaused first) No change needed
run-tests --test-mode EditMode during pause 0.07s, existing validation rejects No change needed
run-tests --test-mode PlayMode during pause Would reach plain awaits (potential hang) 0.162s, preflight error

Changes

  • TestExecutionStateValidationService: Add IsPaused virtual property and PlayMode+paused guard
  • RunTestsUseCase: Add why-comment on plain awaits (mid-test pause point hit is out of scope)
  • CompileUseCase: Add why-comment on WaitForPlayModeExitAsync documenting self-resolution
  • Tests: 3 new validation tests (paused rejection, EditMode precedence, not-paused passthrough)

Test plan

  • uloop compile 0 errors / 0 warnings
  • TestExecutionStateValidationServiceTests 11/11 green
  • PlayModeToolPreflightServiceTests 8/8 green
  • Real repro: pause + PlayMode run-tests → 0.162s preflight error
  • Real repro: pause + compile → 5.089s self-resolution

Review in cubic

hatayama added 2 commits July 11, 2026 20:23
Add an isPaused preflight check to TestExecutionStateValidationService
so that PlayMode test requests are rejected immediately when Play Mode
is paused, instead of reaching plain awaits whose continuations would
hang forever in the UnitySynchronizationContext queue (see #1686).

The remaining plain awaits in RunTestsUseCase are documented with a
why-comment: the only path where they could still hang is a pause
point firing mid-test, which stalls the Test Runner itself and is
out of scope for the tool layer.
StopPlayMode() clears isPaused before setting isPlaying=false, so the
poll loop's TimerDelay continuation always finds the SynchronizationContext
queue draining normally. Measured: compile during pause self-resolved
in ~5s with no hang.
@coderabbitai

coderabbitai Bot commented Jul 11, 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: 67597003-86c5-4d94-a8da-44e5fdb1fb53

📥 Commits

Reviewing files that changed from the base of the PR and between 442f9bf and 35e5917.

📒 Files selected for processing (5)
  • Assets/Tests/Editor/PlayModeToolPreflightServiceTests.cs
  • Assets/Tests/Editor/TestExecutionStateValidationServiceTests.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileUseCase.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/RunTestsUseCase.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/TestExecutionStateValidationService.cs

📝 Walkthrough

Walkthrough

The PR adds paused-state validation for PlayMode test execution, extends unit-test stubs and coverage, and documents synchronization-context considerations around compile and test execution awaits.

Changes

Paused PlayMode validation

Layer / File(s) Summary
Paused-state validation and coverage
Packages/src/Editor/FirstPartyTools/RunTests/TestExecutionStateValidationService.cs, Assets/Tests/Editor/TestExecutionStateValidationServiceTests.cs, Assets/Tests/Editor/PlayModeToolPreflightServiceTests.cs
PlayMode validation now fails while paused; tests cover paused PlayMode, EditMode precedence, active PlayMode success, and the supporting stub state.
Await behavior documentation
Packages/src/Editor/FirstPartyTools/Compile/CompileUseCase.cs, Packages/src/Editor/FirstPartyTools/RunTests/RunTestsUseCase.cs
Comments document synchronization-context behavior around compile and test execution awaits.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestValidation
  participant ValidationService
  participant UnityEditor
  TestValidation->>ValidationService: Validate PlayMode request
  ValidationService->>UnityEditor: Read isPaused
  UnityEditor-->>ValidationService: Paused state
  ValidationService-->>TestValidation: Failure or success result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR only adds a paused-state preflight guard and comments; it does not address the mid-command await hang described in #1686. Add a safe fix for the hanging awaits themselves, such as explicit main-thread switching around the affected awaits, and verify the mid-command pause repro.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: rejecting PlayMode test runs while the Editor is paused.
Description check ✅ Passed The description is directly related to the changes and matches the implemented pause-rejection fix and documentation updates.
Out of Scope Changes check ✅ Passed All code changes support the pause-rejection fix, related tests, or explanatory comments; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 fix/pause-mid-command-compile-run-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.

@hatayama hatayama merged commit 998ce19 into v3-beta Jul 11, 2026
10 checks passed
@hatayama hatayama deleted the fix/pause-mid-command-compile-run-tests branch July 11, 2026 11:32
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
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