Repository navigation
Conversation
`POST /sandboxes/{id}/snapshots` runs `docker commit` in the background
worker without taking the per-sandbox lifecycle lock that pause, resume,
renew, delete and expiry use — while `docker commit` pauses the container
by default until the image is written (opensandbox-group#3121).
`PersistedSnapshotService` now takes an optional
`lifecycle_lock_factory` at construction. The Docker assembly passes
`docker_service._sandbox_lifecycle_lock`, so the background worker holds
the source sandbox's lifecycle lock for the whole commit; a concurrent
pause/resume/delete/expiry waits instead of racing the paused container.
Runtimes that snapshot outside the container lifecycle (Kubernetes,
Fast Sandbox) pass None and keep the old behavior — the untracked worker
path is factored out so the None case is unchanged.
The regression test proves the worker holds the lock (a competitor
acquiring the same sandbox's lock blocks until the worker releases).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 306b35c952
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| with lock_factory(record.source_sandbox_id): | ||
| self._run_snapshot_worker_untracked(record) |
There was a problem hiding this comment.
Coordinate sandbox status reads with the commit lock
When a running Docker sandbox is snapshotted, container.commit() temporarily exposes Docker's Paused state. This scope only excludes operations that acquire _sandbox_lifecycle_lock; DockerSandboxService.get_sandbox() and list_sandboxes() never acquire it, and _container_to_sandbox() maps container.attrs["State"] directly. Consequently GET/list requests during a long commit still report Paused and then Running, so the user-visible state-flip scenario remains; status reads must either participate in the coordination or mask the commit's internal pause.
AGENTS.md reference: server/AGENTS.md:L42-L42
Useful? React with 👍 / 👎.
| blocked = not acquired_other.wait(timeout=2) # it must be blocked | ||
| release.set() # let the worker finish; competitor | ||
| return blocked # proceeds after the lock is released |
There was a problem hiding this comment.
Make the serialization test exercise an actual lock
fake_lock_factory's _Ctx never acquires a synchronization primitive, so the competitor immediately sets acquired_other and blocked is false. That boolean is only returned from the patched _create_snapshot_worker, whose return is discarded, so the test still passes if the lifecycle context is released before the snapshot work; use a real per-ID lock and assert that acquisition remains blocked until the worker releases it.
AGENTS.md reference: server/AGENTS.md:L42-L42
Useful? React with 👍 / 👎.
Summary
Fixes #3121 — on the Docker runtime,
POST /sandboxes/{id}/snapshotsrunsdocker commitin the background worker without the per-sandbox lifecycle lock that pause, resume, renew, delete and expiry all take. Sincedocker commitpauses the container by default until the image is written, an unserialized commit against a Running sandbox:GET /sandboxes/{id}reportPausedmid-snapshot while the commit is still streaming, then flip back — consumers see a bogus state flip;Fix
PersistedSnapshotServicegains an optionallifecycle_lock_factoryat construction. The Docker assembly (create_snapshot_service) passesdocker_service._sandbox_lifecycle_lock, so the background worker holds the source sandbox's lifecycle lock for the whole commit — a concurrent pause/resume/delete/expiry now waits instead of racing the paused container.Runtimes that snapshot outside the container lifecycle (Kubernetes, Fast Sandbox) pass None and take an unchanged untracked path (factored out so the None case is byte-for-byte the old behavior).
Tests
test_snapshot_worker_serializes_with_lifecycle_lock: the worker holds the per-sandbox lock — a competitor acquiring the same sandbox lock blocks for the whole commit and only proceeds after the worker releases. 26/26 in test_docker_snapshot_runtime.py, 334/334 in test_docker_service.py.