Skip to content

fix: suspension and restart wait for background execs - #104172

Merged
steipete merged 2 commits into
mainfrom
codex/background-exec-suspension
Jul 11, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/background-exec-suspension

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Fixes #104079

What Problem This Solves

Fixes an issue where hosts using cooperative Gateway suspension or safe restart could receive an idle result while an approved background exec process was still running. A visible process entry could also be removed before the operating-system process had actually exited, leaving the remaining work unaccounted for.

Why This Change Was Made

The process registry now retains a count-only live background-exec marker through confirmed exit. Detached approval execution atomically hands work from Gateway root admission to that marker, while suspension and every safe-restart path account for both sides of the handoff. The protocol exposes only an aggregate background-exec blocker; commands, PIDs, output, and session identifiers remain private.

User Impact

Hosting controllers no longer freeze, snapshot, or restart the Gateway across a live background command. process remove can still hide a session immediately, but lifecycle admission remains blocked until the process owner confirms exit.

Release-note context: cooperative suspension and safe restart now wait for live background exec sessions.

Evidence

  • Blacksmith Testbox blue-prawn / run 29139283576: 207 focused test executions passed across registry, detached approval, suspension, restart, reload, and protocol suites.
  • pnpm protocol:check passed.
  • pnpm build passed.
  • pnpm check:changed -- <touched files> passed, including core/test typecheck and the full core lint fan-out.
  • pnpm docs:check-mdx, pnpm docs:check-links, pnpm docs:check-i18n-glossary, and pnpm format:docs:check passed; link audit checked 5,807 internal links with zero broken links.
  • Fresh autoreview: clean, no actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 11, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head ab0a51c712f2eb565db80cd1559eb50a5d0d0af4, but the PR head is now 9f702499334e289525c4520efed5c34605b6330f. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (2 earlier review cycles)
  • reviewed 2026-07-11T04:50:59.106Z sha 5d2160e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T05:33:20.449Z sha 8eb03efe15195b95520f2308c56522537f5ac731 :: needs real behavior proof before merge. :: [P1] Keep the blocker until fallback-killed processes actually exit

@steipete
steipete force-pushed the codex/background-exec-suspension branch from 5d2160e to 8eb03ef Compare July 11, 2026 05:24
@steipete

steipete commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper please re-review this exact head with the real behavior proof below.

Exact head: 9f702499334e289525c4520efed5c34605b6330f

Exact-head CI: run 29141777808 completed with all 68 checks green at the SHA above. The rebased fixture repair also passed check-test-types.

Fresh Testbox-through-Crabbox live proof: tbx_01kx7vhp659s306xc1p4hyzf6n

I fetched the exact commit on the fresh Testbox, asserted that the synced tracked tree had no working-tree or index delta from it, and built it. I then started the actual built Gateway against an isolated deterministic Responses endpoint. The model issued a real background exec tool call, which launched an OS child through the Gateway-hosted agent.

Observed contract:

  • While the child was live, gateway.suspend.prepare returned busy, activeCount: 1, and exactly one aggregate blocker: { kind: "background-exec", count: 1 }.
  • The response contained no command text, PID, output, cwd, session id, or scope id.
  • A safe gateway.restart.request returned deferred with the same single aggregate blocker.
  • After the child emitted its actual terminal event, the deferred in-process restart completed; the Gateway produced a second ready epoch.
  • A persistent controller connection then completed gateway.suspend.prepare (ready, zero active work) -> gateway.suspend.status (ready) -> gateway.suspend.resume (running, resumed: true) -> status (running). The persistent connection matters because a prepared Gateway intentionally rejects new WebSocket handshakes.

Sanitized terminal result:

{
  "whileChildLive": {
    "suspendPrepare": {
      "status": "busy",
      "reason": "active-work",
      "activeCount": 1,
      "blockers": [
        {
          "kind": "background-exec",
          "count": 1,
          "message": "1 active background exec session(s)"
        }
      ]
    },
    "safeRestart": {
      "status": "deferred",
      "safe": false,
      "backgroundExecSessions": 1,
      "totalActive": 1
    }
  },
  "afterActualChildExit": {
    "inProcessRestartCompleted": true,
    "gatewayReadyEpochs": 2,
    "suspendPrepare": {
      "status": "ready",
      "activeCount": 0,
      "blockerCount": 0
    },
    "suspendStatus": "ready",
    "resume": {
      "ok": true,
      "status": "running",
      "resumed": true
    },
    "postResumeStatus": "running"
  },
  "disclosureCheck": {
    "blockerIsAggregateOnly": true,
    "commandPidSessionDetailsPresent": false
  },
  "cleanup": {
    "controllerStopped": true,
    "gatewayStopped": true,
    "gatewayPortClosed": true,
    "mockClosed": true,
    "isolatedStateRemoved": true,
    "testboxStopped": true
  }
}

The fresh exact-head build passed in the same Testbox. The temporary harness was not committed and was removed; the PR worktree is clean at the SHA above. The Testbox was stopped after proof capture.

@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper assist is taking a look at your question.

I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes.

Request: please re-review this exact head with the real behavior proof below. Exact head: 8eb03efe15195b95520f2308c56522537f5ac731 Exact-head CI: run 29141176792 completed successfully at the SHA above. Testbox-through-Crabbox live proof: tbx_01kx7t9aay6vxatexcb8rcdgww I fetched the exact commit on the Testbox, asserted that the synced tracked tree had no working-tree or i...

@steipete
steipete force-pushed the codex/background-exec-suspension branch from 8eb03ef to ab0a51c Compare July 11, 2026 05:37
@clawsweeper

clawsweeper Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper assist: The proof is strong for 8eb03efe15195b95520f2308c56522537f5ac731, but it cannot establish the current PR head’s behavior because the head changed afterward to ab0a51c712f2eb565db80cd1559eb50a5d0d0af4. A full correctness re-review is needed.

Evidence:

Suggested next action: Provide equivalent exact-head CI and behavior proof for ab0a51c712f2eb565db80cd1559eb50a5d0d0af4, then request @clawsweeper review.


Source: #104172 (comment)
Assist reasoning: high.

@steipete
steipete force-pushed the codex/background-exec-suspension branch from ab0a51c to 9f70249 Compare July 11, 2026 05:47
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper assist is taking a look at your question.

I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes.

Request: please re-review this exact head with the real behavior proof below. Exact head: 9f702499334e289525c4520efed5c34605b6330f Exact-head CI: run 29141777808 completed with all 68 checks green at the SHA above. The rebased fixture repair also passed check-test-types. Fresh Testbox-through-Crabbox live proof: [tbx_01kx7vhp659s306xc1p4hyzf6n](https://gi...

@steipete
steipete merged commit 02cd9bf into main Jul 11, 2026
103 of 106 checks passed
@steipete
steipete deleted the codex/background-exec-suspension branch July 11, 2026 05:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 30, 2026
…roval admission (#161469)

The exec-approval admission catch matched a plain Error whose message was
"gateway is draining for restart". That matched the untyped refusal that
runWithGatewayIndependentRootWorkAdmission threw when the check was added in
#104172. #112989 changed that producer to GatewayDrainingError, so the
instanceof branch already covered it, and #160869 then changed the draining
copy, so the string could no longer match anything.

No path delivers a draining refusal here without class identity: the
admission call passes no AbortSignal, the wrapper and the error class come
from the same module, and the callback's spawn and authorization failures
are caught inside the admitted run.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…roval admission (openclaw#161469)

The exec-approval admission catch matched a plain Error whose message was
"gateway is draining for restart". That matched the untyped refusal that
runWithGatewayIndependentRootWorkAdmission threw when the check was added in
openclaw#104172. openclaw#112989 changed that producer to GatewayDrainingError, so the
instanceof branch already covered it, and openclaw#160869 then changed the draining
copy, so the string could no longer match anything.

No path delivers a draining refusal here without class identity: the
admission call passes no AbortSignal, the wrapper and the error class come
from the same module, and the callback's spawn and authorization failures
are caught inside the admitted run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Background exec sessions do not block Gateway suspension

1 participant