Skip to content

feat(supervisor): record launch and exit of sandbox sessions - #5252

Merged
krishicks merged 1 commit into
mainfrom
feat/4268-session-process-events/krishicks
Dec 2, 2026
Merged

krishicks merged 1 commit into
mainfrom
feat/4268-session-process-events/krishicks

Conversation

@krishicks

@krishicks krishicks commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The entrypoint's launch reached only the sandbox container's stdout, and no process the runtime started had an exit event. The runtime now keeps a bounded log of the launches and exits of the entrypoint and each exec or SSH session, and the supervisor emits them as OCSF Process Activity.

Second of a stack of four for #4268 (#5251 has merged):

  1. feat(supervisor): identify the process behind each network event #5251 Identify the process behind each network event (merged)
  2. feat(supervisor): record launch and exit of sandbox sessions #5252 This PR: record launch and exit of sandbox sessions
  3. feat(supervisor): record each exec in the workload and its exit #5253 Record each exec in the workload and its exit
  4. feat(supervisor): record the command line of each process #5254 Record the command line of each process

Related Issue

Refs #4268

Changes

  • The runtime records the launch and exit of every process it spawns and reaps (entrypoint, exec and SSH sessions) in a bounded, sequence-numbered log.
  • New ReadProcessEvents long-poll RPC on the sandbox protocol (capability openshell.sandbox.process-events): sequence cursor, size-capped responses, and a count of events no longer retained. Reading after a sequence acknowledges it, and a read without a cursor resumes after the last acknowledged event, so a replacement supervisor doesn't replay what its predecessor read. wait: false returns at once.
  • The supervisor reads it for the life of the boundary and emits Process Activity Launch (pid, start time, parent) and Terminate (exit code; 128 + signal for signal exits; status: Failure when the code isn't 0). Before the boundary goes away it does one zero-wait read so the final exits are reported.
  • Each event keeps the runtime's observation time and a deterministic metadata.uid derived from the process instance, so the few events a replacement supervisor can report twice are ones consumers can drop.
  • The runtime's own entrypoint Launch on stdout names the same executable path as the recorded events.

Before: no Process Activity in the supervisor's OCSF output.

After:

PROC:LAUNCH    [INFO] /usr/bin/bash(78)
NET:OPEN       [INFO] ALLOWED /usr/bin/bash(82) -> example.com:443 [policy:demo engine:opa]
PROC:TERMINATE [INFO] /usr/bin/bash(78) [exit:0]
PROC:LAUNCH    [INFO] /usr/bin/bash(91)
PROC:TERMINATE [INFO] /usr/bin/bash(91) [exit:3]
PROC:LAUNCH    [INFO] /usr/bin/bash(93)
PROC:TERMINATE [INFO] /usr/bin/bash(93) [exit:137]
{"activity_name":"Terminate","message":"Process exited: pid=93 signal=9","exit_code":137,"process":{"name":"/usr/bin/bash","pid":93,"created_time":1793758508670,"parent_pid":1},"actor":{"name":"openshell-sandbox","pid":1}}

The network actor (pid 82, parent 78) joins to the session's Launch on pid + created_time.

Known limitations:

  • The runtime still writes its own entrypoint Launch to container stdout for older supervisors, so stdout collectors see two entrypoint Launches (with the same process name).
  • After a supervisor takeover, the new supervisor can repeat the one response its predecessor received but hadn't acknowledged (at most 256 events), and a read already waiting at promotion can still return events to the old supervisor. Duplicates repeat metadata.uid and the original time.
  • created_time is within about 1 s of wall-clock time (btime has whole-second resolution). It is consistent across process and network events, so it still works as a join key.
  • A lost > 0 count is only a warning log here; PR 3 turns it into a record.

Testing

  • Lockfile checks and rust:format:check pass locally; clippy is left to CI
  • Unit tests added/updated (acknowledged-cursor resume, closing the log, unencodable events, Terminate status); openshell-sandbox (366) passes in an Ubuntu 24.04 guest (kernel 6.8), openshell-sandbox-backend (120) and openshell-supervisor (318) on macOS
  • Manual end-to-end: gateway + Docker sandbox (kernel 7.0), before/after OCSF output above (run before the review fixes)

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

@krishicks
krishicks added this pull request to stack #5255 November 4, 2026 15:03
@purp purp added area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. topic:api Public APIs, gRPC/protobuf, SDK interfaces, versioning, compatibility, and API design standards. topic:documentation Architecture docs, READMEs, project website updates, and automated documentation generation. topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export. labels Nov 15, 2026
@krishicks
krishicks force-pushed the feat/4268-session-process-events/krishicks branch from c21a122 to 9d3a0d2 Compare November 20, 2026 18:04
Base automatically changed from feat/4268-network-event-process/krishicks to main November 20, 2026 21:52
@krishicks
krishicks force-pushed the feat/4268-session-process-events/krishicks branch 2 times, most recently from 4e766e9 to 2ae9ba1 Compare November 23, 2026 17:40
@krishicks
krishicks marked this pull request as ready for review November 23, 2026 17:40
Comment thread docs/observability/logging.mdx Resolved
Comment thread crates/openshell-supervisor/src/lib.rs Resolved
The entrypoint's launch reached only the sandbox container's stdout, and
no process the runtime started had an exit event: the entrypoint's exit
code reached the gateway only as sandbox state, and an exec or SSH
session's status went only to its caller.

The runtime is the parent of the entrypoint and of each exec or SSH
session process and reaps each with its exact status, so it records their
launches and exits, with the time it observed them, in a bounded log with
sequence numbers. Runtimes that advertise openshell.sandbox.process-events
serve the log through ReadProcessEvents, a long poll with a sequence
cursor that caps each response by size and reports how many events it no
longer retains. A read acknowledges the events before its cursor, and a
read without one resumes after the last acknowledged event, so a
replacement supervisor does not report again what its predecessor read.

The supervisor reads the log for the life of the boundary and emits OCSF
Process Activity: Launch with the process's pid, start time, and parent,
and Terminate with its exit code, 128 plus the signal number when a
signal ended it, and a Failure status when that code is not 0. Before the
boundary goes away it reads once more without waiting, so the final exits
are reported. Each event keeps the time the runtime observed it and a
metadata.uid derived from the process instance, so the few events a
replacement supervisor can report twice are ones consumers can drop. The
runtime's own entrypoint Launch on stdout names the same executable path.

Refs #4268

Signed-off-by: Kris Hicks <khicks@nvidia.com>
@krishicks
krishicks force-pushed the feat/4268-session-process-events/krishicks branch from 2ae9ba1 to 31207d6 Compare December 1, 2026 21:27
@krishicks
krishicks enabled stacked auto-merge December 1, 2026 23:04

@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.

LGTM

@krishicks
krishicks added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 5cac5a9 Dec 2, 2026
89 of 96 checks passed
@krishicks
krishicks deleted the feat/4268-session-process-events/krishicks branch December 2, 2026 19:22
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. topic:api Public APIs, gRPC/protobuf, SDK interfaces, versioning, compatibility, and API design standards. topic:documentation Architecture docs, READMEs, project website updates, and automated documentation generation. topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants