Conversation
valeriy42
added this pull request to stack #3183
September 9, 2026 19:50
valeriy42
force-pushed
the
feature/sandbox2-pr-d-lifecycle
branch
from
September 9, 2026 20:01
78f29f4 to
ddf4aa1
Compare
valeriy42
force-pushed
the
feature/sandbox2-pr-d-lifecycle
branch
from
September 9, 2026 20:09
ddf4aa1 to
bed4aba
Compare
…ted lifecycle Replaces numeric-PID process control with an identity-bound spawner for sandboxed pytorch_inference children, because a sandboxed child's PID can be reused by an unrelated process while a stale monitor or a delayed terminate call is still in flight. CSandboxedProcessSpawner (new) drives every live child through an explicit state machine (Prepared -> Launched -> IdentityCaptured -> Registered -> Monitoring -> TerminationRequested -> CleanupRequired -> Reaped/Failed): - A non-throwing kill-and-reap guard is armed immediately once a sandboxed process is launched and its PID captured, before any operation that could throw (registry insertion, monitor-thread construction/detach). It holds its own owning reference to the sandbox handle so cleanup is safe regardless of the destruction order of other locals during unwinding, and disarms only after registry insertion and monitor handoff have both succeeded. - Four injectable seams (pidfd acquisition, registry allocation, monitor-thread launch, sandbox completion) allow every failure class to be exercised deterministically in tests, without waiting on real resource exhaustion. - pidfd-acquisition outcomes are classified explicitly: a kernel that lacks pidfd support (ENOSYS) is the only case that falls back to signalling the sandboxee through its owned monitor handle (SIGKILL, identity-safe, no numeric-PID lookup); every other acquisition failure (ESRCH, EMFILE, ENFILE, ...) is treated as a resource/identity error and fails registration outright rather than silently choosing a weaker termination mechanism. Numeric kill(pid, ...) does not appear anywhere in this file. - A one-shot CAS latch resolves the race between a timeout and the sandbox's own completion signal, replacing independent-boolean coordination with a single atomic decision that has exactly one winner. CSandboxedProcessSpawnerLifecycleTest_Linux.cc adds fault-injection coverage for every pidfd-acquisition outcome, allocation/resource failures during registration and monitor launch, protection against a stale monitor mutating a newer registration for a reused PID, protection against signalling the wrong process after PID reuse, the CAS race (deterministic interleavings, no wall-clock polling), descriptor-count cleanup after every case, and destructor latency with a live child still running. Reviewed through several fault-injection and use-after-free fix rounds this session; not yet compiled or executed against a real Linux/Sandbox2 toolchain.
valeriy42
force-pushed
the
feature/sandbox2-pr-d-lifecycle
branch
from
September 9, 2026 20:18
bed4aba to
fa81668
Compare
Contributor
Author
|
Devbox verification (Linux x86_64, real Sandbox2 toolchain): `ml_test_sandbox` filtered to `CSandboxedProcessSpawnerLifecycleTest_Linux` — 13/13 test cases passed, 372/372 assertions, exit code 0. This surfaced and fixed two real defects that macOS-only syntax checks couldn't catch:
Also ran clang-format via the CI's own check image and fixed several workspace-planning-doc citations that had leaked into comments/commit messages (not resolvable outside this internal effort's own tracking) — both now clean. Buildkite (macOS/Windows legs, full cross-platform CI) still pending. |
valeriy42
marked this pull request as ready for review
September 10, 2026 08:24
|
Pinging @elastic/ml-core (Team:ML) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rebuilds
CSandboxedProcessSpawneraround an explicit lifecycle state machine (Prepared -> Launched -> IdentityCaptured -> Registered -> Monitoring -> TerminationRequested -> CleanupRequired -> Reaped/Failed), stacked on #3184.ENOSYS) is the only case that falls back to signalling the sandboxee through its owned monitor handle (SIGKILL, identity-safe, no numeric-PID lookup); every other pidfd error is treated as a resource/identity failure and fails registration outright. Numerickill(pid, ...)does not appear anywhere in this file.CSandboxedProcessSpawnerLifecycleTest_Linux.cc: fault-injection coverage for every pidfd class, allocation/resource failures, stale-generation protection, PID-reuse identity binding, the CAS race, descriptor-baseline cleanup, and destructor-latency.Notes
E_Launched/E_CleanupRequiredlifecycle states are declared but intentionally left unassigned (no natural single point without broader restructuring) — not silently dropped.