feat(sessions): enhance session patching with sandbox state management
Merged
AH
5mo ago+163+163+012345678901234567890123456789-0-0-0123456789
- Added logic to handle archiving and unarchiving of sessions, ensuring proper sandbox state checks.
- Introduced
stopSandboxOnArchivefunction to manage sandbox teardown for archived sessions. - Updated
patchSessionByIdHandlerto include conditions for unarchiving sessions based on sandbox state. - Implemented CORS headers in response for error handling during sandbox operations.
Summary by cubic
Enhances session archive/unarchive with stricter sandbox checks and background teardown. Preserves snapshots until the sandbox stop succeeds to avoid bad restores.
-
New Features
- Added
stopSandboxOnArchive: runs viaafter(); re-reads the row; on success clearssandbox_stateand nullssnapshot_url/snapshot_created_at; on stop failure logs, setslifecycle_error, and only clears runtime state when there’s nosnapshot_url. - Hardened
patchSessionByIdHandler: on archive applies lifecycle patch and schedules background stop; on unarchive returns 409 if pausing with nosnapshot_url(ignores"hibernated"/"archived"), and clears lifecycle state/error; adds CORS headers on errors. - Extracted
isSandboxPausingandisUnarchiveConflicthelpers.
- Added
-
Refactors
- Replaced inline lifecycle updates with
ARCHIVE_LIFECYCLE_PATCHandUNARCHIVE_LIFECYCLE_PATCH; streamlined related imports.
- Replaced inline lifecycle updates with
Summary by CodeRabbit
-
Bug Fixes
- Rejects unsafe unarchive attempts while a session's sandbox runtime is pausing/paused.
- Archiving now clears sandbox/lifecycle/snapshot metadata and defers sandbox shutdown to background.
- Unarchiving clears lifecycle error/state so sessions restore cleanly; snapshot/pausing conditions are respected.
-
New Features
- Introduces sandbox path utilities and updates file/grep/glob/edit/write/read tools to use them for consistent POSIX sandbox paths.
-
Chores
- Switched event IDs to UUIDs and added a background helper to stop sandboxes on archive.