Skip to content

fix(exec): count only declared services and drop the survivor settle window - #200268

Merged
obviyus merged 3 commits into
mainfrom
fix/exec-no-settle-window
Nov 16, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/exec-no-settle-window

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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. fix(exec): count only real services against the exec service cap #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 fix(exec): count only real services against the exec service cap #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).

obviyus and others added 3 commits November 17, 2026 02:53
The service cap is enforced only where a service is declared, and
adoption never stops a survivor for capacity, so a helper that is still
exiting at root exit costs nothing. The settle window and its repeated
census are not needed: adopt what the census names at root exit again.

Co-authored-by: obviyus <[email protected]>
Adopted survivors are tracked but no longer counted, so helpers that are
still exiting at root exit never block a background: true start. The cap
is enforced only for declared services, through reserveServiceSlot.

Co-authored-by: obviyus <[email protected]>
Yielded ordinary commands are backgrounded sessions too, but they are not
declared services. Count only sessions started with background: true.

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: S labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug 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 changes before merge.

What this changes

This PR counts only explicitly declared background services against service limits and removes the survivor settling window.

Example: A session has 20 adopted survivors and no declared services.

  • Before: A background: true start is refused because the survivors exceed the session limit.
  • After: The declared service starts while the survivors remain tracked.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Relevant Gateway proof supports the intended repair, but a source-confirmed durable-restoration defect blocks merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records the changed admission and survivor behavior through an isolated macOS dist Gateway with a real agent, including helper-heavy commands, declared-service refusal, reset, and shutdown.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Ordinary command survivors and yielded work can prevent an explicitly requested background service from starting.
Reason: The matching source and reported Gateway behavior establish value, and maintainer authorship settles the intended admission-policy change.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR provides a useful, focused repair, but its new filter incorrectly excludes restored durable services from capacity enforcement.

Priority: P2
Reviewed head: 7b2f72cac7278556576823c01427ad65b432b3d1

Before merge

  • Keep restored durable services in the capacity count (P2) - After starting 16 long-running commands with background: true and durable: true, restart the Gateway and request another background service. DurableProcessRecord does not persist independentService, and initializeDurableProcesses reconstructs the sessions without setting it (bash-process-durable.ts:242–252). This filter therefore counts zero restored services and admits the 17th; the Gateway-wide limit is similarly undercounted. The previous filter counted these restored background sessions. Preserve declared-service classification through durable persistence/restoration, including existing records, and add a restart admission regression while retaining the exclusion of ordinary yielded commands.

Findings

  • [P2] Keep restored durable services in the capacity count — src/agents/bash-process-adopted.ts:27-29
Agent review details

How this fits together

Exec admission reserves service capacity, the process supervisor reports surviving descendants, and the process registry exposes their handles and cleanup operations.

flowchart TD
  A[Exec request] --> B[Service admission]
  B --> C[Process supervisor]
  C --> D[Survivor census]
  D --> E[Process registry]
  F[Durable process restoration] --> E
  E --> B
  E --> G[Process tools and cleanup]
Loading

Technical review

Best possible solution:

Keep the existing admission owner and immediate census while preserving declared-service counting across durable restoration.

Do we have a high-confidence way to reproduce the issue?

Current-main source confirms that survivors and yielded commands consume service capacity; the supplied Gateway comparison exercises the reported problem, while this review used source inspection without executing target code.

Is this the best way to solve the issue?

Filtering by the existing declaration marker is appropriately small, but all producers and restorers of counted sessions must preserve that distinction.

Full review comments:

  • [P2] Keep restored durable services in the capacity count — src/agents/bash-process-adopted.ts:27-29
    After starting 16 long-running commands with background: true and durable: true, restart the Gateway and request another background service. DurableProcessRecord does not persist independentService, and initializeDurableProcesses reconstructs the sessions without setting it (bash-process-durable.ts:242–252). This filter therefore counts zero restored services and admits the 17th; the Gateway-wide limit is similarly undercounted. The previous filter counted these restored background sessions. Preserve declared-service classification through durable persistence/restoration, including existing records, and add a restart admission regression while retaining the exclusion of ordinary yielded commands.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 48cd549b1c48.

Provenance checked

  • Service capacity classification changes intended behavior with a stated reason (237111e: Preserve detached work while bounding background sessions and adopted survivors.)
  • Survivor settling and repeated census changes intended behavior with a stated reason (344cc75: Avoid classifying finishing helpers as services and reporting misleading background handles.)
  • Root-exit census and cleanup ownership keeps the original intent (237111e: Account for surviving descendants before releasing command ownership while retaining separate cancellation and shutdown cleanup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/bash-tools.exec-group-cleanup.real.test.ts src/agents/bash-process-durable.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • pnpm check:test-types
  • Verify through a real Gateway that 16 declared durable services survive restart and the next declared-service start is refused.

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 237111e adds src/agents/bash-process-adopted.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 237111eabf61; files: src/agents/bash-process-adopted.ts)

PR surface

Source -38, Tests +8, Docs 0. Total -30 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 20 58 -38
Tests 1 36 28 +8
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 58 88 -30

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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Incorrect service accounting affects exec admission within individual sessions and the Gateway-wide limit.
  • merge-risk: 🚨 availability: Restored declared services become invisible to admission counting, defeating the resource limits intended to bound independent services.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • 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, 5:21 PM ET / 22:21 UTC.

@obviyus
obviyus merged commit 744a001 into main Nov 16, 2026
144 checks passed
@obviyus
obviyus deleted the fix/exec-no-settle-window branch November 16, 2026 23:04
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 744a001.

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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant