Skip to content

fix: Compile handles externally changed open Scenes without blocking - #1261

Merged
hatayama merged 2 commits into
v3-betafrom
feature/hatayama/detect-scene-reload-dialog
Jun 2, 2026
Merged

hatayama merged 2 commits into
v3-betafrom
feature/hatayama/detect-scene-reload-dialog

Conversation

@hatayama

@hatayama hatayama commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Compile now resolves clean externally changed open Scenes before Unity refreshes assets, avoiding the modal dialog that can block autonomous CLI runs.
  • Callers can use --stop-on-external-scene-changes to fail fast instead of automatic reload, while dirty external conflicts now stop with clear diagnostics instead of overwriting files.

User Impact

  • Before this change, a compile request could hang behind the Unity external Scene change dialog after a Scene file changed on disk.
  • After this change, default compile runs continue automatically for clean external Scene changes, and unsafe dirty conflicts return actionable errors.

Changes

  • Track open Scene file fingerprints and resolve external changes before compile refresh.
  • Add CLI parsing/help/completion support for --stop-on-external-scene-changes.
  • Preserve external Scene preflight details during force compile and bump the native CLI contract/minimum version.

Verification

  • git diff --check origin/v3-beta
  • cli/dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)"
  • cli/dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex --filter-value "ExternalSceneChangeResolverTests|CompileSessionResultServiceTests|FirstPartySchemaProperties_WhenLoaded_ShouldNotExposeDescriptionAttributes|CliSetupApplicationServiceTests"
  • scripts/check-go-cli.sh
  • ~/.codex/skills/codex-review/scripts/codex-review v3-beta

hatayama added 2 commits June 2, 2026 01:54
Reload or save open Scene files that changed on disk before AssetDatabase.Refresh so autonomous compile runs do not block on Unity's external-change dialog. Add --stop-on-external-scene-changes for callers that want compile to stop instead of resolving the Scene state automatically.
Keep actionable external Scene preflight diagnostics during force compile, bump the native CLI contract for the new compile flag, and avoid auto-saving Scenes that are both dirty in Unity and changed on disk.
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces external scene change detection for the compile workflow. It detects when Unity scene files are externally modified, optionally reloads or stops compilation based on a configurable policy, and wires this preflight check into the compile controller before compilation starts. Changes span both C# editor code and Go CLI option parsing.

Changes

External Scene Change Detection for Compile Workflow

Layer / File(s) Summary
Configuration and type contracts
Packages/src/Editor/FirstPartyTools/Compile/CompileSchema.cs, Packages/src/Editor/FirstPartyTools/Compile/UnityCliLoopCompileTypes.cs, Packages/src/Editor/Domain/CliConstants.cs, cli/contract.json, cli/internal/tools/default-tools.json
New ReloadExternalSceneChanges: bool = true property added to CompileSchema and UnityCliLoopCompileRequest; minimum CLI version bumped to 3.0.0-beta.24 in constants and JSON contract files.
External scene resolver implementation
Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs, Assets/Tests/Editor/ExternalSceneChangeResolverTests.cs
ExternalSceneChangeTracker snapshots scene file fingerprints via editor callbacks; ExternalSceneChangeResolver detects external changes, coordinates preflight save/reload workflows, and returns success only when safe to proceed or policy allows stopping before compilation.
CLI option name mapping and help text
cli/internal/cli/tools.go, cli/internal/cli/command_help.go
Maps ReloadExternalSceneChanges property to --stop-on-external-scene-changes CLI option for compile command; generates custom help text with "default: auto-reload enabled" notation and "Stop before execution" phrasing.
Compile controller policy and error handling
Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs
Adds SetExternalSceneChangePolicy() setter, calls resolver before compilation, aborts early with compiler-style error messages from unresolved scene paths; new PreserveDetailsWhenForceRecompile flag on CompileResult preserves detailed preflight errors instead of generic force-recompile summaries.
Request construction and result detail preservation
Packages/src/Editor/FirstPartyTools/Compile/CompileTool.cs, Packages/src/Editor/FirstPartyTools/Compile/CompilationExecutionService.cs, Packages/src/Editor/FirstPartyTools/Compile/CompileSessionResultService.cs, Packages/src/Editor/FirstPartyTools/Compile/CompileUseCase.cs, Assets/Tests/Editor/CompileSessionResultServiceTests.cs
CompileTool converts schema properties into request fields; CompilationExecutionService applies the policy from request; CompileSessionResultService preserves detailed results when flag is true; CompileUseCase includes reload policy in logs; new test validates detail preservation for force-recompile failures.
Editor startup initialization
Packages/src/Editor/FirstPartyTools/FirstPartyToolsEditorStartup.cs
ExternalSceneChangeTracker.Initialize() called during editor startup to begin monitoring scene file fingerprints.
User documentation and CLI test coverage
.agents/skills/uloop-compile/SKILL.md, .claude/skills/uloop-compile/SKILL.md, Packages/src/Editor/FirstPartyTools/Compile/Skill/SKILL.md, cli/internal/cli/completion_test.go, cli/internal/cli/help_test.go, Assets/Tests/Editor/CliSetupApplicationServiceTests.cs
SKILL.md files document --stop-on-external-scene-changes flag and behavior; CLI completion and help tests updated to expect new option; minimum CLI version test renamed and updated to 3.0.0-beta.24.
CLI flag parsing unit tests
cli/internal/cli/tools_test.go
Verifies --stop-on-external-scene-changes sets property to false and compile-specific flag aliases do not apply to unrelated tools.

Sequence Diagram

sequenceDiagram
    participant CompileTool as CompileTool
    participant CompilationExecutionService as CompilationExecutionService
    participant CompileController as CompileController
    participant ExternalSceneChangeResolver as ExternalSceneChangeResolver
    participant EditorSceneManager as EditorSceneManager
    
    CompileTool->>CompileTool: ToRequest(schema)<br/>set ReloadExternalSceneChanges
    CompilationExecutionService->>CompileController: SetExternalSceneChangePolicy(request.ReloadExternalSceneChanges)
    CompileController->>CompileController: TryCompileAsync
    CompileController->>ExternalSceneChangeResolver: ResolveExternalSceneChanges(reloadPolicy)
    alt external changes detected
        ExternalSceneChangeResolver->>EditorSceneManager: check if safe to reload/save
        alt dirty scenes cannot be saved or reload fails
            ExternalSceneChangeResolver-->>CompileController: CanProceed=false, ScenePaths[]
        else reload succeeds
            ExternalSceneChangeResolver-->>CompileController: CanProceed=true
        end
    else policy disallows reload
        ExternalSceneChangeResolver-->>CompileController: CanProceed=false, Message
    else no changes
        ExternalSceneChangeResolver-->>CompileController: CanProceed=true
    end
    alt CanProceed=false
        CompileController->>CompileController: BuildUnresolvedScenesFailure<br/>PreserveDetailsWhenForceRecompile=true
        CompileController-->>CompilationExecutionService: CompileResult(failure)
    else CanProceed=true
        CompileController->>EditorSceneManager: Unity compile
        CompileController-->>CompilationExecutionService: CompileResult(success/compiler-error)
    end
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes


Possibly Related PRs

  • hatayama/unity-cli-loop#1246: Both PRs bump the minimum CLI version and update CliSetupApplicationServiceTests around version requirement enforcement, though this PR ties it to the external-scene compile flag feature.

  • hatayama/unity-cli-loop#1248: Both PRs modify CompileSessionResultService.CreateCompileResult behavior and result payload shaping to handle detailed vs. summary information based on the compilation scenario.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% 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 clearly and concisely describes the main change: compile now handles externally changed open Scenes without blocking, which is the core functionality addition in this changeset.
Description check ✅ Passed The description is directly related to the changeset, providing clear context on the problem solved (modal dialogs blocking CLI runs), the solution (auto-resolving clean changes), and new user-facing options (--stop-on-external-scene-changes flag).
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/detect-scene-reload-dialog

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.

🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs (1)

133-154: 💤 Low value

Confirm that auto-saving every dirty open Scene (not just externally changed ones) is intended.

When any clean Scene was changed externally, shouldReloadSceneSetup becomes true and the reload path (Line 281) calls this method, which saves all dirty open Scenes via EditorSceneManager.SaveScene — including Scenes that have unsaved in-Editor edits but no external disk change. Because RestoreSceneManagerSetup reloads the whole setup, this is necessary to avoid discarding those edits, but it also silently writes the user's in-progress Scenes to disk during a compile.

This is defensible (it preserves work rather than losing it), but it's an implicit disk write that callers may not expect from a compile. Please confirm this is the intended behavior, or consider scoping the reload to only the externally changed Scenes (e.g., reopening just those paths) so unrelated dirty Scenes are left untouched.

🤖 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/Compile/ExternalSceneChangeResolver.cs`
around lines 133 - 154, SaveDirtyOpenScenesBeforeReload currently auto-saves
every dirty open Scene (via EditorSceneManager.SaveScene) when a reload is
needed, which causes unexpected disk writes; change the logic so only scenes
that were externally changed are auto-saved before reload (or make the behavior
explicit/configurable). Specifically, update the reload call site that checks
shouldReloadSceneSetup to pass the list of externally changed scene paths into
SaveDirtyOpenScenesBeforeReload (or add a new
SaveDirtyScenes(IEnumerable<string> pathsToSave) helper) and modify
SaveDirtyOpenScenesBeforeReload to accept that list and only call
EditorSceneManager.SaveScene for scenes whose scene.path appears in that list
(preserving the existing GetSceneDisplayPath and RecordSceneSnapshot usage for
saved scenes); alternatively expose an opt-in flag so callers can choose the
current global-save behavior.
🤖 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.

Nitpick comments:
In `@Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs`:
- Around line 133-154: SaveDirtyOpenScenesBeforeReload currently auto-saves
every dirty open Scene (via EditorSceneManager.SaveScene) when a reload is
needed, which causes unexpected disk writes; change the logic so only scenes
that were externally changed are auto-saved before reload (or make the behavior
explicit/configurable). Specifically, update the reload call site that checks
shouldReloadSceneSetup to pass the list of externally changed scene paths into
SaveDirtyOpenScenesBeforeReload (or add a new
SaveDirtyScenes(IEnumerable<string> pathsToSave) helper) and modify
SaveDirtyOpenScenesBeforeReload to accept that list and only call
EditorSceneManager.SaveScene for scenes whose scene.path appears in that list
(preserving the existing GetSceneDisplayPath and RecordSceneSnapshot usage for
saved scenes); alternatively expose an opt-in flag so callers can choose the
current global-save behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5bcce741-df1e-4962-bf94-0e6a9376f7f4

📥 Commits

Reviewing files that changed from the base of the PR and between f84c16b and 2696548.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/ExternalSceneChangeResolverTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs.meta is excluded by none and included by none
📒 Files selected for processing (23)
  • .agents/skills/uloop-compile/SKILL.md
  • .claude/skills/uloop-compile/SKILL.md
  • Assets/Tests/Editor/CliSetupApplicationServiceTests.cs
  • Assets/Tests/Editor/CompileSessionResultServiceTests.cs
  • Assets/Tests/Editor/ExternalSceneChangeResolverTests.cs
  • Packages/src/Editor/Domain/CliConstants.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompilationExecutionService.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileController.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileSchema.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileSessionResultService.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileTool.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileUseCase.cs
  • Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs
  • Packages/src/Editor/FirstPartyTools/Compile/Skill/SKILL.md
  • Packages/src/Editor/FirstPartyTools/Compile/UnityCliLoopCompileTypes.cs
  • Packages/src/Editor/FirstPartyTools/FirstPartyToolsEditorStartup.cs
  • cli/contract.json
  • cli/internal/cli/command_help.go
  • cli/internal/cli/completion_test.go
  • cli/internal/cli/help_test.go
  • cli/internal/cli/tools.go
  • cli/internal/cli/tools_test.go
  • cli/internal/tools/default-tools.json

@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 25 files

Re-trigger cubic

@hatayama
hatayama merged commit 8d6ed1b into v3-beta Jun 2, 2026
8 checks passed
@hatayama
hatayama deleted the feature/hatayama/detect-scene-reload-dialog branch June 2, 2026 00:49
@github-actions github-actions Bot mentioned this pull request Jun 2, 2026
RyanXie123 pushed a commit to RyanXie123/unity-cli-loop that referenced this pull request Sep 22, 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