Skip to content

feat(daemon): opt-in per-seat task limit (TasksMax) on Linux/systemd hosts - #3332

Draft
billbenetti wants to merge 1 commit into
mvschwarz:mainfrom
billbenetti:feat/seat-tasks-max
Draft

billbenetti wants to merge 1 commit into
mvschwarz:mainfrom
billbenetti:feat/seat-tasks-max

Conversation

@billbenetti

Copy link
Copy Markdown
Contributor

Refs #3253

Draft: a first PR for the task limit only, in the shape described in #3253 (comment). Memory and CPU limits are not in it.

What it adds

A member-level option in the rig spec, unset by default:

members:
  - id: worker
    process_limits:
      tasks_max: 512
  • Opt-in for the chosen seat. Without process_limits, a seat launches with exactly today's pane command, and nothing is asked of systemd.
  • One seat's boundary under the shared tmux server. The chosen seat's pane command starts with systemd-run --user --scope --collect --slice openrig-seats.slice -p TasksMax=N -- <today's command>. systemd-run --scope puts itself in the new scope and then execs the command, so the pane's process and everything it forks are in that seat's scope. The tmux server stays in its openrig-tmux-*.scope, and the other seats, the daemon and shared pieces stay outside the cap. The seat's environment after -- is the same as today: the existing reset script plus the export file.
  • Only tasks_max. Any other key under process_limits (memory_max, cpu_quota, …) is refused by the spec validator with its name, never accepted silently.

Supported hosts, and no silent fallback

A seat with process_limits gets its scope or is not launched.

A launch is refused with code process_limits_unsupported and the reason when any of these is true:

  • the host is not Linux;
  • the daemon is not a systemd user service (the same check as the server scope);
  • the user bus does not answer (that answer is cached for 60 s);
  • systemd-run is missing or refuses a throwaway scope;
  • terminal.inherit_tmux_environment is on;
  • the limit is not actually enforced. The throwaway scope reads its own pids.max, and support counts only when that equals the requested value. This catches a user manager without the pids controller delegated, which accepts TasksMax= with no effect.

As for the server scope, --expand-environment=no and OOMPolicy=continue are dropped only when systemd's stderr says it lacks them. A refused seat leaves the other seats unaffected.

New launches, restart and resume

The limit is applied when a seat's pane process starts. Running work is never moved or stopped.

Launch What happens
first launch, rig seat launch --fresh, restore/resume from a snapshot new process in the seat's scope, with the stored value
provider switch keeping the pane, seat handover the host check runs before the running process is ended; refused, nothing is stopped
restart in place, shell-backed pane the resume is typed into the running shell, so it goes ahead only when that shell is read back as under the limit (applied); otherwise refused before anything is signalled
restart in place, bare pane refused before anything is held or signalled (that respawn carries no seat environment, so it can't re-apply the limit); use rig seat launch --fresh
daemon restart nothing is relaunched; a changed value applies at the seat's next launch, and status says requested until then
seat already running when the spec gains the option untouched; status says requested

Reporting: requested, applied, unsupported, unknown

rig seat status <seat> (and /api/seat/status/:seatRef as processLimits) reads the limit back from the seat's pane process, never from config alone:

  • applied: the process's cgroup is an openrig-seat-*.scope whose pids.max is the requested value;
  • requested: the seat has the option, but its process is not proven to run under it (not running, launched before the option, outside a seat scope, or a different pids.max), with the reason;
  • unsupported: the process is not under the limit and the host can't give a seat a user scope now (a seat already under its limit reads applied even when the daemon now runs where it can't make scopes);
  • unknown: the readback failed (no pane pid, cgroup v1, unreadable files).

Limit hits. pids.events max is the number of forks the limit refused, and the status line shows it:

Process limits: tasks_max 512: applied (pids.max 512, current 37, limit hit 2 times)

Notes

  • Moving out of the server scope. A seat with a limit leaves the terminal server's scope for openrig-seats.slice, so an aggregate limit an operator put on the server scope no longer covers it. The docs say so.
  • Escaping the cap. Processes a seat starts through systemd-run --user land in their own units, outside the seat's cap.
  • Never stop a seat's scope by hand. A stop kills every process in it, the seat included. Use rig seat stop.

Tests

All tests are synthetic: fake exec and fake /proc readers, with nothing touching the host's systemd, cgroups or tmux.

  • packages/daemon/test/tmux-seat-process-limits.test.ts:
    • the case: only the chosen seat's command is in its own scope with TasksMax, and after -- it is exactly today's command;
    • the control: no option, no systemd-run, nothing asked of systemd;
    • each unsupported host refuses with process_limits_unsupported and no new-session, while a seat without the option still launches;
    • the option drop, the probe memo, the 60 s bus back-off and a wrapped respawn;
    • the readback states and limit hits.
  • The preflight before a takeover (launch-node-subset) and before a handover (successor-session-launcher), and the restart-in-place refusals (seat-restart-in-place: a bare pane, and a shell not read back as under the limit).
  • The spec, persistence and docs tests for process_limits.
  • The CLI status line (packages/cli/test/seat.test.ts).

Not run here: the full suite and the real-tmux test files. On a real systemd host, the check to run is a seat at tasks_max: N forking past N, with pids.events max > 0 and the other seats unaffected. That host proof is listed as a follow-up for this draft.

…hosts

Refs mvschwarz#3253. A member's `process_limits: { tasks_max: N }` (unset by default)
starts that seat's pane command in a systemd user scope of its own, in
openrig-seats.slice, with TasksMax=N as its only limit. systemd-run --scope
execs the command, so the seat's processes are under the cap while the tmux
server, the daemon and the other seats stay outside it. Without the option a
seat launches exactly as before and nothing is asked of systemd.

- No silent fallback: a host that can't give the seat its scope (not Linux,
  the daemon not a user service, the user bus not answering, systemd-run
  missing or refusing a throwaway scope, inherit_tmux_environment on, or a
  throwaway scope whose own pids.max is not the requested value) refuses the
  launch with code process_limits_unsupported and the reason.
- New launches only: fresh launch, restore and resume read the stored value;
  a takeover and a handover check the host before ending the running process;
  restart in place of a bare pane is refused (its respawn carries no seat
  environment); running seats are never moved or stopped.
- Status: rig seat status reads the limit back from the seat's process
  (requested, applied, unsupported, unknown) with pids.current and the number
  of forks the limit refused (pids.events max).
- Only tasks_max: any other key under process_limits is refused by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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