-
Notifications
You must be signed in to change notification settings - Fork 29
refactor(control-plane): extract SandboxLifecycleManager from SessionDO #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Extract sandbox lifecycle logic (~400 lines) from SessionDO into dedicated modules with pure decision functions and a provider abstraction: - Add SandboxProvider interface for pluggable sandbox providers - Add ModalSandboxProvider wrapping existing ModalClient - Add pure decision functions (circuit breaker, spawn, inactivity, heartbeat) - Add SandboxLifecycleManager orchestrating lifecycle operations - Add 66 unit tests for decision functions and manager - Update SessionDO to delegate lifecycle methods to manager This refactoring enables: - Unit testing via dependency injection and pure functions - Future sandbox providers (Fly.io, Docker, etc.) - Clear separation between decision logic and side effects
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Greptile OverviewGreptile SummaryExtracted ~400 lines of sandbox lifecycle logic from Key improvements
Critical issue foundThe refactoring leaves duplicate Architecture validation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 2 comments
Additional Comments (2)
The When the sandbox connects via WebSocket, the DO sets its flag to false, but the manager's flag remains unchanged. This could cause the manager to believe a spawn is still in progress when it's not, blocking future spawn attempts. Remove the Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/control-plane/src/session/durable-object.ts
Line: 398:398
Comment:
`isSpawningSandbox` flag mismatch between SessionDO and SandboxLifecycleManager
The `isSpawningSandbox` flag is now owned by `SandboxLifecycleManager` (packages/control-plane/src/sandbox/lifecycle/manager.ts:156), but SessionDO still maintains its own copy and sets it to `false` here. This creates two separate flags that can get out of sync.
When the sandbox connects via WebSocket, the DO sets its flag to false, but the manager's flag remains unchanged. This could cause the manager to believe a spawn is still in progress when it's not, blocking future spawn attempts.
Remove the `isSpawningSandbox` field from SessionDO entirely since the manager now handles this state.
How can I resolve this? If you propose a fix, please make it concise.
This check uses the DO's local Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/control-plane/src/session/durable-object.ts
Line: 881:881
Comment:
uses SessionDO's `isSpawningSandbox` flag instead of delegating to manager
This check uses the DO's local `isSpawningSandbox` flag, but the manager has its own copy. The DO should delegate the `warmSandbox()` call to the manager without checking the flag, since `warmSandbox()` in the manager already checks `isSpawningInMemory`.
How can I resolve this? If you propose a fix, please make it concise. |
- Remove duplicate isSpawningSandbox flag from SessionDO - Add isSpawning() and onSandboxConnected() methods to manager - Add tests for isSpawningSandbox reset after restore failure - Add 24 unit tests for ModalSandboxProvider error classification The refactoring previously left duplicate flags in both SessionDO and SandboxLifecycleManager. When sandbox connected via WebSocket, the DO set its flag to false but the manager's flag remained unchanged, breaking spawn coordination. Test coverage increased from 66 to 92 tests.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
- Fix restore not storing modal_object_id for future snapshots - Add HTTP response.ok validation in modal-provider - Fix falsy timestamp checks in decisions.ts (use == null) Test coverage: 97 tests passing.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Summary
Extract sandbox lifecycle logic (~400 lines) from
SessionDOinto dedicated modules with pure decision functions and a provider abstraction.Changes
SandboxProviderinterface for pluggable sandbox providers with error classification (transient vs permanent for circuit breaker)ModalSandboxProviderwrapping existingModalClientSandboxLifecycleManagerorchestrating lifecycle operations with dependency injectionSessionDOto delegate lifecycle methods to managerArchitecture Benefits
Files
src/sandbox/provider.tssrc/sandbox/providers/modal-provider.tssrc/sandbox/lifecycle/decisions.tssrc/sandbox/lifecycle/decisions.test.tssrc/sandbox/lifecycle/manager.tssrc/sandbox/lifecycle/manager.test.tssrc/sandbox/index.tssrc/session/durable-object.tsTest plan