Skip to content

Add PID namespaces and jobs to the broker core - #1818

Draft
Weidong Cui (wdcui) wants to merge 8 commits into
uliteboxfrom
wdcui/ulitebox/pid-namespaces
Draft

Weidong Cui (wdcui) wants to merge 8 commits into
uliteboxfrom
wdcui/ulitebox/pid-namespaces

Conversation

@wdcui

@wdcui Weidong Cui (wdcui) commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

This PR adds PID namespaces and jobs to the broker core, the second step toward running every container of a pod in one broker. BrokerCore becomes a once-per-process kernel holding broker-wide state. Each root process is created explicitly in a ProcessContext (PID namespace, file service, Job); children inherit it, and setup_connection only attaches an existing process. Namespaces number processes from 1 and confine lookups, signals, groups, sessions and kill(-1). Jobs drain and terminate independently, and Tasks counts the job's threads. Single-container behavior is unchanged.

@wdcui
Weidong Cui (wdcui) force-pushed the wdcui/ulitebox/pid-namespaces branch from 4820676 to cfb493f Compare November 7, 2026 03:49
@wdcui Weidong Cui (wdcui) changed the title Add PID namespaces to the broker Add PID namespaces and containers to the broker core Nov 8, 2026
Weidong Cui (wdcui) and others added 7 commits November 7, 2026 19:12
A `PidNamespace` owns the ID allocator, process and thread registries and
controlling-terminal table that `BrokerCore` used to hold, so each namespace
numbers its processes from 1 and confines lookups, signals, process groups,
sessions and `kill(-1)` to itself. `BrokerCore::with_pid_namespace` returns
a view whose root processes, and so their descendants, are in a given
namespace; several views can share one, as with `shareProcessNamespace`.

- `max_processes` is enforced broker-wide through a `live_processes` count.
- `SignalTarget::All` spares the caller and the namespace's init (its first
  process created with its initial thread, by `ProcessKey`) instead of every
  process without a creator.
- Terminals belong to one namespace: `TerminalEndpoint::owner_namespace`
  (PTY owners set by `Devices::with_owner_namespace`, otherwise the broker's
  first namespace), and `associate` refuses a terminal another namespace
  owns. A new namespace view starts without the broker's terminal.

Nothing in production creates a second namespace yet.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Replace `BrokerCore::with_terminal` and `with_pid_namespace` with
`with_container(pid_namespace, terminal)`, which creates a container
with its own terminal slot, and add `pid_namespace()`. A terminal now
belongs to the first PID namespace whose session acquires it, through
`TerminalEndpoint::claim`, instead of to an owner set on its devices or
to the broker's first namespace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
BrokerKernel now holds the broker-wide state and enforces one kernel per
process; BrokerCore is a container handle with its own PID namespace, file
service, and terminal slot, created only by BrokerCore::new. Root processes
in a PID namespace are created one at a time, so the first root registered
is the first started and becomes init.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Each container handle now shares a `Container` with its terminal, its
process and thread counts, and a terminating flag. `has_processes` reads
the container's process count, so containers sharing a PID namespace
drain independently. `terminate_container` refuses new processes in the
container and requests an expected shutdown of each of its runners.
`ResourceKind::Tasks` counts the threads of the creator's container,
while `max_threads` still bounds the whole broker. A child is in its
parent's container, whichever handle creates it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
The `dev_tests` ratchets limit `pub use` and global statics in
`litebox_broker_core`. `pid_namespace` is now a public module, like
`terminal`, instead of being re-exported, and the next namespace ID is
a `BrokerKernel` counter instead of a global, so `PidNamespace::new`
takes the kernel.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
@wdcui
Weidong Cui (wdcui) force-pushed the wdcui/ulitebox/pid-namespaces branch from eacadde to ad783d9 Compare November 8, 2026 03:14
BrokerCore is now the once-per-process kernel, independent of any PID
namespace, file service or job. A public Job replaces the per-container
handle as the lifecycle and accounting scope, and ProcessContext
(namespace, file service, job) says where a root runs; children inherit
their parent's. Hosts create each root explicitly with
BrokerCore::create_process, and setup_connection only attaches it,
checking the peer's credential. Whoever creates a process retires it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
@wdcui Weidong Cui (wdcui) changed the title Add PID namespaces and containers to the broker core Add PID namespaces and jobs to the broker core Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure derive_trait_impl_removed: built-in derived trait no longer implemented ---

Description:
A public type has stopped deriving one or more traits. This can break downstream code that depends on those types implementing those traits.
        ref: https://doc.rust-lang.org/reference/attributes/derive.html#derive
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/derive_trait_impl_removed.ron

Failed in:
  type BrokerCore no longer derives Clone, in /home/runner/work/litebox/litebox/litebox_broker_core/src/lib.rs:308

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/inherent_method_missing.ron

Failed in:
  BrokerCore::new_with_limits, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/lib.rs:401
  BrokerCore::with_terminal, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/lib.rs:450
  BrokerCore::with_process_lifecycle_sink, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/lib.rs:457
  BrokerCore::has_processes, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/lib.rs:484

--- failure method_parameter_count_changed: pub method parameter count changed ---

Description:
A publicly-visible method now takes a different number of parameters, not counting the receiver (self) parameter.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/method_parameter_count_changed.ron

Failed in:
  litebox_broker_core::BrokerCore::create_process takes 2 parameters in /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/lib.rs:584, but now takes 3 parameters in /home/runner/work/litebox/litebox/litebox_broker_core/src/lib.rs:439

--- failure method_receiver_type_changed: method receiver changed type ---

Description:
A method's receiver changed to a different type.
        ref: https://doc.rust-lang.org/reference/items/associated-items.html#methods
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/method_receiver_type_changed.ron

Failed in:
  litebox_broker_core::BrokerCore::create_process now takes &Arc<Self>, not &Self, in /home/runner/work/litebox/litebox/litebox_broker_core/src/lib.rs:439

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/struct_missing.ron

Failed in:
  struct litebox_broker_core::test_support::TestBrokerCoreBuilder, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_core/src/test_support.rs:42

--- failure function_parameter_count_changed: pub fn parameter count changed ---

Description:
A publicly-visible function now takes a different number of parameters.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/function_parameter_count_changed.ron

Failed in:
  litebox_broker_host::setup_connection now takes 6 parameters instead of 8, in /home/runner/work/litebox/litebox/litebox_broker_host/src/lib.rs:255

--- failure function_parameter_count_changed: pub fn parameter count changed ---

Description:
A publicly-visible function now takes a different number of parameters.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/function_parameter_count_changed.ron

Failed in:
  litebox_broker_userland::runner::run_to_completion now takes 5 parameters instead of 2, in /home/runner/work/litebox/litebox/litebox_broker_userland/src/runner.rs:529

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.51.0/src/lints/inherent_method_missing.ron

Failed in:
  BrokerCoreBuilder::with_file_service, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_userland/src/builder.rs:110
  BrokerCoreBuilder::with_terminal, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-ulitebox/cb3a51d5542ec798815718d8b1658d50f162e11b/litebox_broker_userland/src/builder.rs:118

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant