Skip to content

fix(sandbox): harden managed-children registry and workload launcher - #5209

Open
EmilienM wants to merge 1 commit into
ai-openshell:mainfrom
EmilienM:fix/5186-managed-children-launcher/EmilienM
Open

EmilienM wants to merge 1 commit into
ai-openshell:mainfrom
EmilienM:fix/5186-managed-children-launcher/EmilienM

Conversation

@EmilienM

@EmilienM EmilienM commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Three silent-failure paths in the sandbox, all found by reading the code: a managed-children registration leaks after a poisoned registry lock, the orphan reaper goes inert on kernels without CONFIG_PROC_CHILDREN because every missing children file reads as a vanished task, and a panicking job kills the workload launcher thread while is_alive() keeps reporting healthy.

Related Issue

Closes #5186

Changes

  • managed_children::unregister recovers from a poisoned registry lock like its sibling accessors, so a registration can no longer leak after a waiter panics while holding the lock
  • direct_child_pids classifies a missing children file per task (vanished task vs missing support), only concludes missing support when no task in the scan listed one, and reports it once per process with a warning and an OCSF detection finding
  • The workload launcher runs each job under catch_unwind, like the network broker's handler panics: the panic is logged, the thread leaves its job loop, and is_alive() turns false so later spawns fail fast

Release Notes

When no task under /proc/self/task exposes a children file (kernel built without CONFIG_PROC_CHILDREN, or restricted procfs), the sandbox now reports the inert orphan reaper once instead of failing silently. A panicking workload-launcher job now stops the launcher with a clear error instead of leaving it reporting healthy.

Testing

  • Checks appropriate to the affected code and behavior pass

  • Unit tests added/updated (if applicable)

  • E2E tests added/updated (if applicable)

  • cargo test -p openshell-sandbox --lib: 293 passed, including regression tests for each path (poisoned-lock unregister, children-file classification and reporting, panicking launcher job; the suite also passes with RUST_BACKTRACE=1)

  • cargo clippy --workspace --all-targets -- -D warnings, the perf-harness variant, and cargo fmt --all -- --check pass

  • No local e2e run: this host has no docker daemon and the k8s lane needs a full image build. The changed paths are failure paths not reachable on healthy kernels, and the launcher's normal spawn path is covered by tests that spawn real children through the filtered thread. CI lanes cover the rest.

  • uv-based checks (python format, license headers) skipped locally due to a host uv config break (2026-11-03 RPM update); this diff touches no manifests or Python files

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@FrostGod

FrostGod commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test 40e6725

@EmilienM
EmilienM force-pushed the fix/5186-managed-children-launcher/EmilienM branch from 40e6725 to e74a054 Compare November 4, 2026 03:26
@mrunalp mrunalp added retired:area:sandbox Retired; do not apply. See #5151 for item-specific migration to the current taxonomy. test:e2e Requires end-to-end coverage labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Label test:e2e applied, but pull-request/5209 is at 40e6725 while the PR head is e74a054. A maintainer needs to comment /ok to test e74a054bd314efece879addcef9e75cec6bff522 to refresh the mirror. Once the mirror catches up, re-run Branch E2E Checks from the Actions tab.

@mrunalp

mrunalp commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

/ok to test e74a054

Recover the managed-children registry from a poisoned lock in unregister,
like its sibling accessors already do, so a PID whose waiter panicked
while holding the lock cannot stay registered forever and be skipped by
the orphan reaper after the PID is reused.

Classify a missing /proc/self/task/<tid>/children file instead of
treating every NotFound as a vanished task. When no task in a scan
exposes the file (kernel built without CONFIG_PROC_CHILDREN, or
restricted procfs), log a warning and emit an OCSF detection finding
once per process instead of silently leaving the orphan reaper inert
while zombies accumulate.

Contain a panicking job on the workload launcher thread, the way the
network broker contains handler panics: the panic is reported, the
thread leaves its job loop, and the health flag turns false so every
later spawn fails fast instead of hanging on a launcher that still
reports healthy.

Closes ai-openshell#5186

Signed-off-by: Emilien Macchi <emacchi@redhat.com>
@EmilienM
EmilienM force-pushed the fix/5186-managed-children-launcher/EmilienM branch from e74a054 to 6c769e8 Compare November 9, 2026 21:16
@purp purp added area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export. topic:reliability High availability, recovery, retries, graceful degradation, and correctness across restarts. and removed retired:area:sandbox Retired; do not apply. See #5151 for item-specific migration to the current taxonomy. labels Nov 15, 2026

@FrostGod FrostGod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, small and well tested. A few comments inline, plus:

  • workload_launcher.rs L53–57 (nit): "dropped the spawn result" hides that the job panicked. Can the error say so?
  • Jobs are just cmd.spawn() (process.rs:445–456), so is the panic containment purely defensive?
  • This overlaps #5233 in managed_children.rs. Let's agree which merges first.

Comment on lines 253 to +254
let task = task?;
let path = task.path().join("children");
let contents = match std::fs::read_to_string(path) {
Ok(contents) => contents,
Err(error) if error.kind() == io::ErrorKind::NotFound => continue,
Err(error) => return Err(error),
};
children.extend(
match read_task_children(&task.path())? {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One unreadable task aborts the whole scan, and the error only reaches the debug! at L158, so the reaper can still stop silently. Skip the bad task, and warn once on repeated scan errors?

Comment on lines +319 to +341
openshell_ocsf::ocsf_emit!(
openshell_ocsf::DetectionFindingBuilder::new(openshell_ocsf::ctx::ctx())
.activity(openshell_ocsf::ActivityId::Open)
.severity(openshell_ocsf::SeverityId::Medium)
.confidence(openshell_ocsf::ConfidenceId::High)
.is_alert(true)
.finding_info(
openshell_ocsf::FindingInfo::new(
"proc-children-unavailable",
"Sandbox Orphan Reaper Unavailable",
)
.with_desc(
"No task under /proc/self/task exposes a children file, so \
the sandbox orphan reaper cannot discover unmanaged \
children, and exited descendants accumulate as zombies \
until the process limit. The likely causes are a kernel \
built without CONFIG_PROC_CHILDREN or restricted procfs \
(for example gVisor or a subset=pid mount).",
)
)
.message("orphan reaper unavailable: no /proc/self/task/*/children")
.build()
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md says to dual-emit findings with a domain event. Is standalone intended here?

Comment on lines +572 to +575
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let _registry = lock();
panic!("poison the managed-children registry");
}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this leaves the global lock poisoned for later tests. Add MANAGED_CHILDREN.clear_poison() at the end?

Comment on lines +101 to +103
if let Err(panic) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(job)) {
tracing::error!("workload launcher job panicked: {}", panic_message(&*panic));
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dead launcher means no new processes can start in this sandbox. Emit an OCSF event here, not just tracing::error!?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. test:e2e Requires end-to-end coverage topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export. topic:reliability High availability, recovery, retries, graceful degradation, and correctness across restarts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: managed_children and the workload launcher mishandle a poisoned lock, a missing CONFIG_PROC_CHILDREN and a panicking job

4 participants