Repository navigation
chore: Simplify shared Roslyn worker lifecycle ownership - #1629
Conversation
Move process, temporary-directory, synchronization, and test-seam ownership from the static host into one instance session. Keep host entrypoints and orchestration stable while source guards prevent mutable state from returning to the facade.
📝 WalkthroughWalkthroughShared Roslyn compiler worker process lifecycle and I/O handling is extracted from ChangesWorker Session Extraction
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Host as SharedRoslynCompilerWorkerHost
participant Session as SharedRoslynCompilerWorkerSession
participant Process as Worker Process
Host->>Session: ExecuteLocked(TryCompileWithRetries)
Session->>Session: HasLiveProcessLocked()
alt worker not ready
Session->>Session: CompileWorkerAssemblyLocked()
Session->>Process: StartProcessLocked(startInfo)
end
Session->>Process: SendCompileRequestLocked(requestFile)
Session->>Process: GetOutputReaderLocked()
Process-->>Session: response
Session-->>Host: compile result
Host->>Session: ShutdownProcessLocked() (on cancel/retry failure)
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 2
🤖 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
`@Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerSession.cs`:
- Around line 100-127: The shutdown path in SharedRoslynCompilerWorkerSession
currently exits to the catch blocks on StandardInput failures before reaching
the Kill() fallback, which can leave the worker process orphaned after
_workerProcess is cleared. Refactor the quit/flush/wait logic in the worker
shutdown code so that any IOException, ObjectDisposedException, or
InvalidOperationException from writing
SharedRoslynCompilerWorkerProtocol.SharedCompilerWorkerQuitCommand still falls
through to the kill fallback when workerProcess.HasExited is false, and keep
LogWorkerShutdownFailure as the shared error reporting path.
- Around line 41-45: Dispose any stale cached worker before replacing it in
StartProcessLocked. When ProcessStartHelper.TryStart returns a new process,
check the existing _workerProcess and, if it is non-null and not live according
to HasLiveProcessLocked(), dispose it before assigning the new process handle.
Use the StartProcessLocked and HasLiveProcessLocked methods in
SharedRoslynCompilerWorkerSession to keep the cached process lifecycle correct.
🪄 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: c7f8c80e-ac21-432c-8b67-bf792fad4c0c
⛔ Files ignored due to path filters (1)
Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerSession.cs.metais excluded by none and included by none
📒 Files selected for processing (4)
Assets/Tests/Editor/DynamicCodeToolTests/SharedRoslynCompilerWorkerHostTests.csAssets/Tests/Editor/StaticFacadeStateGuardTests.csPackages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerHost.csPackages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/SharedRoslynCompilerWorkerSession.cs
There was a problem hiding this comment.
All reported issues were addressed across 5 files
You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Summary
User Impact
Changes
SharedRoslynCompilerWorkerSessionas the single owner of worker process and directory state, synchronization, startup, request I/O, compiler test delegation, and shutdown cleanup.SharedRoslynCompilerWorkerHostentrypoints and test facades, delegating through one privateServiceValue.ExecuteLocked<T>and assert every lock-required session operation withMonitor.IsEntered.Verification
dist/darwin-arm64/uloop compile --project-path <PROJECT_ROOT>: 0 errors, 0 warningsSharedRoslynCompilerWorkerHostTests: 15 passedExternalCompilerPathResolverTests: 15 passedExternalCompilerMessageParserTests: 1 passedStaticFacadeStateGuardTests: 20 passedOnionAssemblyDependencyTests: 83 passedSharedRoslynCompilerWorkerSessionhas no dependency onSharedRoslynCompilerWorkerHost.Refs: R2-32 in the Unity CLI Loop refactoring ToDo.