Skip to content

fix(exec): count only real services against the exec service cap - #200250

Merged
obviyus merged 2 commits into
mainfrom
fix/exec-survivor-settle
Nov 16, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/exec-survivor-settle

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

#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 aa4d490a. 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).

obviyus and others added 2 commits November 17, 2026 00:41
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]>
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Helpers can occupy 16 service slots, and an overflow helper is stopped.
  • After: Helpers finish during the settle window and produce no adopted service records or capacity stops.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported repair with recorded shipped-Gateway evidence and no actionable correctness finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records an isolated macOS dist-Gateway run through chat.send and a real agent: helper adoption and stopping disappear, lasting survivors remain listed beyond capacity, declared starts are refused, and Gateway stop removes all tagged survivors; the changed real-process regression is reported red on base and green on head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Finishing helpers fill service slots, produce misleading background handles, and cause useful surviving processes to be stopped.
Reason: The reported production impact and matching source justify the repair, and maintainer authorship settles the explicit change from survivor enforcement to declared-service admission.

Regression provenance

Possible 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
Reviewed head: dc6f37eb6a70b416901201e1b88bc32147783d81

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Survivor adoption and capacity enforcement changes intended behavior with a stated reason (237111e: Preserve detached services while tracking and bounding survivors, including retained output-drain anchors.)
  • Root-exit handoff census keeps the original intent (237111e: Account for processes left by a completed command before releasing process-tree ownership.)
  • Forced cleanup and relay retirement keeps the original intent (9cd6be8: Release worker capacity only after owned descendants and lineage have settled.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -4, Tests +16, Docs 0. Total +12 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 67 71 -4
Tests 1 43 27 +16
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 112 100 +12

Preflight source

Source 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

Metric Value Why it matters
Production versus test changes Production +67/−71; tests +43/−27 Settling stays with the existing owner, overflow termination disappears, and the added regression distinguishes finishing helpers from lasting services.

Labels

Label changes:

  • add P2: The reported production failure stops useful exec descendants and creates misleading service records within affected sessions.
  • add merge-risk: 🚨 availability: Foreground survivors can now exceed 16 per session and 64 per Gateway, removing their previous resource bound; the maintainer-authored PR explicitly accepts this tradeoff to prevent capacity-based termination.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The reported production failure stops useful exec descendants and creates misleading service records within affected sessions.
  • merge-risk: 🚨 availability: Foreground survivors can now exceed 16 per session and 64 per Gateway, removing their previous resource bound; the maintainer-authored PR explicitly accepts this tradeoff to prevent capacity-based termination.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 3:41 PM ET / 20:41 UTC.

@obviyus
obviyus merged commit 344cc75 into main Nov 16, 2026
219 of 221 checks passed
@obviyus
obviyus deleted the fix/exec-survivor-settle branch November 16, 2026 21:16
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 344cc75.

  • Bug: the exec survivor census ran at root exit, so helpers that were still exiting (git, cp, tee) took service slots and were stopped as over the limit.
  • Fix: adopt only what still runs after a 2 s settle window, and never stop a survivor for capacity. The cap is checked only for declared background: true services.
  • Proof: real Gateway E2E with a real model, base vs head. 20 helper-heavy calls: 288 adopted and 431 stopped on base, 0 and 0 on head. 17 nohup services are all tracked, a 17th declared service is refused, a fork loop is tracked, and Gateway stop ends them all.

obviyus added a commit that referenced this pull request Nov 16, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant