Repository navigation
fix: Compile handles externally changed open Scenes without blocking - #1261
Conversation
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.
📝 WalkthroughWalkthroughThis 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. ChangesExternal Scene Change Detection for Compile Workflow
Sequence DiagramsequenceDiagram
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
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs (1)
133-154: 💤 Low valueConfirm that auto-saving every dirty open Scene (not just externally changed ones) is intended.
When any clean Scene was changed externally,
shouldReloadSceneSetupbecomestrueand the reload path (Line 281) calls this method, which saves all dirty open Scenes viaEditorSceneManager.SaveScene— including Scenes that have unsaved in-Editor edits but no external disk change. BecauseRestoreSceneManagerSetupreloads 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
⛔ Files ignored due to path filters (2)
Assets/Tests/Editor/ExternalSceneChangeResolverTests.cs.metais excluded by none and included by nonePackages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.cs.metais excluded by none and included by none
📒 Files selected for processing (23)
.agents/skills/uloop-compile/SKILL.md.claude/skills/uloop-compile/SKILL.mdAssets/Tests/Editor/CliSetupApplicationServiceTests.csAssets/Tests/Editor/CompileSessionResultServiceTests.csAssets/Tests/Editor/ExternalSceneChangeResolverTests.csPackages/src/Editor/Domain/CliConstants.csPackages/src/Editor/FirstPartyTools/Compile/CompilationExecutionService.csPackages/src/Editor/FirstPartyTools/Compile/CompileController.csPackages/src/Editor/FirstPartyTools/Compile/CompileSchema.csPackages/src/Editor/FirstPartyTools/Compile/CompileSessionResultService.csPackages/src/Editor/FirstPartyTools/Compile/CompileTool.csPackages/src/Editor/FirstPartyTools/Compile/CompileUseCase.csPackages/src/Editor/FirstPartyTools/Compile/ExternalSceneChangeResolver.csPackages/src/Editor/FirstPartyTools/Compile/Skill/SKILL.mdPackages/src/Editor/FirstPartyTools/Compile/UnityCliLoopCompileTypes.csPackages/src/Editor/FirstPartyTools/FirstPartyToolsEditorStartup.cscli/contract.jsoncli/internal/cli/command_help.gocli/internal/cli/completion_test.gocli/internal/cli/help_test.gocli/internal/cli/tools.gocli/internal/cli/tools_test.gocli/internal/tools/default-tools.json
Summary
--stop-on-external-scene-changesto fail fast instead of automatic reload, while dirty external conflicts now stop with clear diagnostics instead of overwriting files.User Impact
Changes
--stop-on-external-scene-changes.Verification
git diff --check origin/v3-betacli/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