Repository navigation
fix(exec): count only real services against the exec service cap - #200250
Conversation
A command's helpers that are still exiting at root exit (git, cp, tee) were adopted as services, filled the 16-per-session cap and were stopped as over the limit. The process owner now takes its survivor census again until the group is empty or 2 s pass; only what still runs then is adopted and counted. Each census keeps earlier survivors, so none escapes by outliving its parent, and a still-running root is handed off at once. Co-authored-by: obviyus <[email protected]>
The service cap belongs where a service is declared (reserveServiceSlot). Adoption now tracks every survivor and never stops one as over the limit, so the overflow kill and killReleasedProcess are deleted. A background: true start is still refused at the limit, and survivors still count. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR waits briefly before adopting surviving exec processes and tracks survivors beyond service capacity instead of stopping them. Example: A foreground command leaves 17 helpers running sleep 0.5.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; reproduction). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this PR repairs source-confirmed helper misclassification and unintended process termination on current main. The maintainer-authored direction is explicit, supplied Gateway evidence exercises the changed behavior, and no blocking correctness defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe exec supervisor owns command descendants, reports surviving processes to the agent process registry, and retains existing process-tool and shutdown cleanup. flowchart TD
A[Host exec command] --> B[Process group owner]
B --> C[Survivor settle census]
C --> D[Adopted process registry]
E[Declared background start] --> F[Service admission cap]
F --> B
D --> G[Process tool and shutdown cleanup]
Technical reviewBest possible solution: Use the existing process owner to settle helpers, retain custody of lasting survivors, and enforce capacity when admitting declared services. Do we have a high-confidence way to reproduce the issue? Current-main source exposes immediate census and overflow termination, and the PR supplies a matching failing-base/passing-head Gateway comparison and real-process regression. Is this the best way to solve the issue? The patch is a focused repair using existing ownership, admission, registry, and cleanup boundaries; the documented latency and capacity changes are explicitly chosen by its maintainer author. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2435c1faa791. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -4, Tests +16, Docs 0. Total +12 across 7 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 16, 2026, 3:41 PM ET / 20:41 UTC. |
|
Landed in 344cc75.
|
…window (#200268) ## Problem #200250 added a 2 s settle window before survivor adoption, so that helpers still exiting at root exit (`git`, `cp`, `tee`) would not take service slots. That is a heuristic on top of the real defect: the service cap counted processes that were never declared as services. Survivors and yielded ordinary commands were counted against the 16-per-session limit, so they could block a `background: true` start. ## Fix The cap now belongs to declared services only. - `serviceCapacityError` counts only sessions with `independentService` (started with `background: true`) plus reservations. It does not count adopted survivors or yielded ordinary commands. - The settle window and its repeated census are deleted. The process owner again reports what runs at root exit, and adoption tracks all of it. #200250 already removed the overflow kill, so no survivor is stopped for capacity. Production code: +20 / −58. Together with #200250, compared with the code before it: +18 / −60. ## User impact - A helper that a command leaves behind never blocks a declared service and is never stopped. Its session drops out within one 5 s reap interval after it exits. - Commands that leave processes running return without the 2 s delay that #200250 added. - Tool results name every survivor again, including short-lived helpers. - At 16 declared services, the 17th `background: true` start is still refused. - Survivors are still tracked, listed, and stopped on session reset and Gateway stop. ## Proof **Real Gateway E2E** (dist build, macOS, scratch state, service-managed exec path, real model `claude-opus-5-5`). Base is the code before #200250 (`aa4d490a`), from the #200250 run. | Journey | Base (`aa4d490a`) | Head | |---|---|---| | 20 calls of `for i in $(seq 18); do (git status --short; sleep 0.5) & done; …; cp a.txt b.txt` | "16 of 16" on every call; 431 helpers stopped | 720 adopted, 0 stopped | | `nohup python3 -m http.server &`, then 16 × `nohup sleep &` | 16 adopted, 17th stopped | 17 adopted, 0 stopped | | 17 × `background: true` in a new session | — | 16 start; the 17th is refused with "16 of 16 allowed services" | | busy fork loop `while :; do sleep 0.05; done &` | adopted | adopted | | `/reset` of the servers session | — | `nohup` server and 16 survivors: all stopped (17 → 0) | | Gateway stop | 0 left | 0 left | **Tests** (`bash-tools.exec-group-cleanup.real.test.ts`, vitest-source, real processes, macOS): - New: three calls each leave 17 `sleep 0.5` helpers, then a `background: true` start succeeds at once, then a fork loop is tracked. Fails on `aa4d490a` ("Stopped 1 process … 16 of 16 allowed services") and passes on head. - The cap tests now fill 15 declared services plus a survivor, then show that exactly one of two concurrent starts wins and the next is refused. - Whole file on head: 10 passed, 3 skipped (Linux only). Gates: `tsgo:core`, `check:test-types`, oxlint and oxfmt on changed files, `ocx build --dts` and a packed install smoke (`openclaw --version`). Co-authored-by: Ayaan Zaidi <[email protected]>
…nclaw#200250) ## Problem openclaw#199079 adopts every process a completed host `exec` command leaves running as a service, up to 16 per session and 64 per Gateway. Over that limit it stops the new survivors. The census runs at the instant the root command exits. Helpers that are still exiting at that instant (`git`, `cp`, `tee`, `tail`, a short `sleep`) are counted as services. Two bad results follow: - Helpers fill the 16 slots and push out real work. In one evening of a production Gateway, 5 sessions hit "16 of 16 allowed services" while the Gateway held only 18 to 36 of 64. OpenClaw stopped 2 to 14 processes in each: test-harness `nohup` loops, a test `gateway run`, the `git` processes of a worktree switch. - Each helper is reported to the model as a background session that "keeps running", although it exits a moment later. Agents then spent calls killing leftovers or restarting stopped work. ## Fix Two changes to the existing owners. No new state. 1. **Adopt after a settle window** (`service-child-group-ownership.ts`). After the root exits, the process owner repeats its survivor census every 100 ms until nothing is left or 2 s pass. Only what still runs at the end is reported and adopted. Each census keeps the earlier survivors that still run the same command, so a process cannot escape custody by outliving the parent that tied it to the command. A root that still runs (a one-shot hand-off of a `background: true` service) is handed off at once. A cancellation during the window owns the tree, as before. No command names are special-cased. 2. **Never stop a survivor for capacity** (`bash-process-adopted.ts`). The cap is checked only where a service is declared (`reserveServiceSlot`, `background: true`). Adoption now tracks every survivor and never stops one as over the limit. The overflow kill and `killReleasedProcess` are deleted. Survivors still count, so a `background: true` start is still refused at the limit. Production code: +67 / −71 lines. ## User impact - Short-lived helpers no longer take service slots, are not reported as services, and are never stopped. - A real service a command leaves running (`nohup server &`, a fork loop) is still tracked, listed by `process list`, stopped by `process kill`, session reset and Gateway stop. - Commands that leave a real process running now return up to 2 s later. Commands that leave nothing running are not delayed. - At the limit, a declared `background: true` service is refused. A survivor over the limit is tracked instead of stopped. ## Proof **Real Gateway E2E** (dist build, macOS, scratch state, service-managed exec path, real model `claude-opus-5-5`). Base is the merge base `ed37fd25`. Each arm is one Gateway with three sessions driven through `chat.send`. | Journey | Base | Head | |---|---|---| | 20 calls of `for i in $(seq 18); do (git status --short; sleep 0.5) & done; git status --short; cp a.txt b.txt` | every call at "16 of 16": 288 helpers adopted as services, 431 stopped as over the limit | 0 adopted, 0 stopped, 20 of 20 clean results | | `nohup python3 -m http.server &`, then 16 × `nohup sleep &` | 16 adopted, the 17th stopped | 17 adopted and listed; no process stopped | | then a 17th declared service (`background: true`) | (not run on base) | refused: "This session runs 17 of 16 allowed services" | | busy fork loop `while :; do sleep 0.05; done &` | adopted, listed | adopted, listed | | Gateway stop | all tagged processes gone | all tagged processes gone (17 → 0) | **Regression test** (`bash-tools.exec-group-cleanup.real.test.ts`, vitest-source, real processes, macOS): one call leaves 17 helpers of `sleep 0.5`, 20 times, then a fork loop. - Base: fails, "Stopped 1 process the command left running, over the service limit … 16 of 16 allowed services". - Head: passes; no helper is adopted or stopped, and the loop is adopted. The cap tests now assert that every survivor stays tracked past the limit and that `background: true` is still refused. Whole file on head: 10 passed, 3 skipped (Linux only). Gates: `tsgo:core`, `check:test-types`, oxlint and oxfmt on changed files, `ocx build --dts` and a packed install smoke (`openclaw --version`). Co-authored-by: Ayaan Zaidi <[email protected]>
…window (openclaw#200268) ## Problem openclaw#200250 added a 2 s settle window before survivor adoption, so that helpers still exiting at root exit (`git`, `cp`, `tee`) would not take service slots. That is a heuristic on top of the real defect: the service cap counted processes that were never declared as services. Survivors and yielded ordinary commands were counted against the 16-per-session limit, so they could block a `background: true` start. ## Fix The cap now belongs to declared services only. - `serviceCapacityError` counts only sessions with `independentService` (started with `background: true`) plus reservations. It does not count adopted survivors or yielded ordinary commands. - The settle window and its repeated census are deleted. The process owner again reports what runs at root exit, and adoption tracks all of it. openclaw#200250 already removed the overflow kill, so no survivor is stopped for capacity. Production code: +20 / −58. Together with openclaw#200250, compared with the code before it: +18 / −60. ## User impact - A helper that a command leaves behind never blocks a declared service and is never stopped. Its session drops out within one 5 s reap interval after it exits. - Commands that leave processes running return without the 2 s delay that openclaw#200250 added. - Tool results name every survivor again, including short-lived helpers. - At 16 declared services, the 17th `background: true` start is still refused. - Survivors are still tracked, listed, and stopped on session reset and Gateway stop. ## Proof **Real Gateway E2E** (dist build, macOS, scratch state, service-managed exec path, real model `claude-opus-5-5`). Base is the code before openclaw#200250 (`ed37fd25`), from the openclaw#200250 run. | Journey | Base (`ed37fd25`) | Head | |---|---|---| | 20 calls of `for i in $(seq 18); do (git status --short; sleep 0.5) & done; …; cp a.txt b.txt` | "16 of 16" on every call; 431 helpers stopped | 720 adopted, 0 stopped | | `nohup python3 -m http.server &`, then 16 × `nohup sleep &` | 16 adopted, 17th stopped | 17 adopted, 0 stopped | | 17 × `background: true` in a new session | — | 16 start; the 17th is refused with "16 of 16 allowed services" | | busy fork loop `while :; do sleep 0.05; done &` | adopted | adopted | | `/reset` of the servers session | — | `nohup` server and 16 survivors: all stopped (17 → 0) | | Gateway stop | 0 left | 0 left | **Tests** (`bash-tools.exec-group-cleanup.real.test.ts`, vitest-source, real processes, macOS): - New: three calls each leave 17 `sleep 0.5` helpers, then a `background: true` start succeeds at once, then a fork loop is tracked. Fails on `ed37fd25` ("Stopped 1 process … 16 of 16 allowed services") and passes on head. - The cap tests now fill 15 declared services plus a survivor, then show that exactly one of two concurrent starts wins and the next is refused. - Whole file on head: 10 passed, 3 skipped (Linux only). Gates: `tsgo:core`, `check:test-types`, oxlint and oxfmt on changed files, `ocx build --dts` and a packed install smoke (`openclaw --version`). Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
#199079 adopts every process a completed host
execcommand leaves running as a service, up to 16 per session and 64 per Gateway. Over that limit it stops the new survivors.The census runs at the instant the root command exits. Helpers that are still exiting at that instant (
git,cp,tee,tail, a shortsleep) are counted as services. Two bad results follow:nohuploops, a testgateway run, thegitprocesses of a worktree switch.Agents then spent calls killing leftovers or restarting stopped work.
Fix
Two changes to the existing owners. No new state.
service-child-group-ownership.ts). After the root exits, the process owner repeats its survivor census every 100 ms until nothing is left or 2 s pass. Only what still runs at the end is reported and adopted. Each census keeps the earlier survivors that still run the same command, so a process cannot escape custody by outliving the parent that tied it to the command. A root that still runs (a one-shot hand-off of abackground: trueservice) is handed off at once. A cancellation during the window owns the tree, as before. No command names are special-cased.bash-process-adopted.ts). The cap is checked only where a service is declared (reserveServiceSlot,background: true). Adoption now tracks every survivor and never stops one as over the limit. The overflow kill andkillReleasedProcessare deleted. Survivors still count, so abackground: truestart is still refused at the limit.Production code: +67 / −71 lines.
User impact
nohup server &, a fork loop) is still tracked, listed byprocess list, stopped byprocess kill, session reset and Gateway stop.background: trueservice is refused. A survivor over the limit is tracked instead of stopped.Proof
Real Gateway E2E (dist build, macOS, scratch state, service-managed exec path, real model
claude-opus-5-5). Base is the merge baseaa4d490a. Each arm is one Gateway with three sessions driven throughchat.send.for i in $(seq 18); do (git status --short; sleep 0.5) & done; git status --short; cp a.txt b.txtnohup python3 -m http.server &, then 16 ×nohup sleep &background: true)while :; do sleep 0.05; done &Regression test (
bash-tools.exec-group-cleanup.real.test.ts, vitest-source, real processes, macOS): one call leaves 17 helpers ofsleep 0.5, 20 times, then a fork loop.The cap tests now assert that every survivor stays tracked past the limit and that
background: trueis still refused. Whole file on head: 10 passed, 3 skipped (Linux only).Gates:
tsgo:core,check:test-types, oxlint and oxfmt on changed files,ocx build --dtsand a packed install smoke (openclaw --version).