Skip to content

fix(gateway): durable execs are reported as stopped after a Gateway restart - #199085

Merged
obviyus merged 1 commit into
mainfrom
fix/durable-exec-restart-notice
Nov 14, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/durable-exec-restart-notice

Conversation

@obviyus

@obviyus obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: after a graceful Gateway restart, every conversation with a running durable: true background command was told "Background exec processes were stopped; rerun them if still needed", even though the registry had just adopted that command and would wake the conversation when it exits.

User Impact

User impact: a durable waiter now survives a restart quietly. The conversation keeps waiting and wakes once, when the command exits. The agent no longer gets a false "stopped" turn, so it neither polls the surviving command nor reruns it. Ordinary (non-durable) background commands still get the same restart notice as before.

Why This Change Was Made

The graceful-shutdown marker counted every running background process, durable ones included. It now skips durable processes. Their own owner adopts them at startup and delivers the exit or lost-process wake. Docs now state which processes the restart notice covers. They also note that a crash sends no notice for ordinary processes; that gap is tracked separately.

Evidence

Real-agent E2E on an isolated source Gateway (openai/gpt-6-astra, 6 concurrent conversations per arm, automations tool denied). Each conversation is asked to wait for a fake CI that flips green about 300 s later. The Gateway gets SIGTERM about 90 s after every conversation armed its waiter and ended its turn, then a new Gateway starts on the same state.

Arm Waiters armed, turn ended False "stopped" restart turns process poll calls after restart Waiters that exited and woke their conversation
base, durable: true waiter 6/6 6 91 6/6, collected by the poll loop inside the false turn
fix, durable: true waiter 6/6 0 0 4/4 by the exit wake (2 model-written loops never matched "all 15 checks passed" and never exited, unrelated to restart)
base, ordinary waiter 6/6 6 (correct) 0 re-armed 6/6
fix, ordinary waiter 5/6 (1 was still mid-turn) 6 (correct) 0 re-armed 5/5, finished 6/6

Shutdown log, durable arm: base marked: 6, fix marked: 0.

Public trace, durable waiter, base vs fix (trial 2, paths redacted)

Base: false restart turn, then a poll loop on the adopted process:

+ 53s   -> Command still running (session faint-otter:…). Its exit wakes this conversation …
+ 62s reply: The durable background waiter is running. …
+186s USER: The Gateway restarted while you were working. Resume your work … Background exec processes were stopped; rerun them if still needed.
+190s process {"action": "poll", "timeout": 1000}
+198s reply: The original durable waiter survived the restart and is still running, so I haven't started another. …
+198s process {"action": "poll", "timeout": 30000}
+206s   -> PR #4242: 4 checks pending, 11 passed Process still running. Automatic completion wake is unavailable after ending this turn. …
… 13 more polls until CI turned green …

Fix: no restart turn; the adopted exit wakes the conversation once:

+ 69s exec {"yieldMs": 1000, "background": true, "durable": true, "timeoutSeconds": 0} "python3 -u - <<'PY' …"
+ 69s   -> Command still running (session quick-fjord:…). Its exit wakes this conversation …
+ 76s reply: The durable background wait is running. …
+354s USER: Exec completed (quick-fj, code 0) :: … PR #4242: all 15 checks passed …
+364s reply: PR #4242 is ready—all 15 checks passed. Saved and verified in `pr-2/RESULT.md` …

Regression test: src/gateway/session-restart-resume.test.ts, "marks ordinary conversations without inheriting cron, external execution or durable processes". It fails on base (agent:main:durable-waiter: expected { queuedInputIds: [], … } to deeply equal undefined) and passes with the fix; the file passes 21/21.

Known gaps, out of scope for this PR:

  • After a crash (SIGKILL), ordinary waiters still get no notice: base 0/6 conversations resumed. Closing that needs a stored fact written when the waiter is armed, which is a separate decision.
  • After restart, process poll on an adopted durable process still says its automatic wake is unavailable, although the exit does wake the conversation. With this fix, no restart turn prompts that poll.

…start

Graceful shutdown marked every running background process as stopped, durable ones included, so each restart sent a resume turn telling the agent to rerun a process the registry had just adopted. Skip durable processes in the shutdown marker; their adopted exit still wakes the session.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 14, 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 size: XS labels Nov 14, 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. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Exclude durable background processes from graceful-restart markers that report stopped commands.

Example: A durable background CI waiter survives a graceful Gateway restart.

  • Before: The conversation receives a false stopped-process notice and starts polling the surviving waiter.
  • After: The waiter remains quiet through restart and its eventual exit wakes the conversation.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful correction supported by live restart traces and a reported base-red/head-green regression; broad exact-head CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The supplied redacted logs exercise an isolated real-agent Gateway with durable and ordinary waiters across graceful shutdown and restart, showing removal of false durable restart turns and preservation of ordinary notices.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A surviving durable command is falsely reported as stopped after restart, prompting unnecessary agent activity or repeated work.
Reason: The narrow correction restores the documented durable-process contract, and this maintainer-authored PR already establishes direction.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main false restart notice with a minimal change at the existing owner; no blocking defect was found.

Priority: P2
Reviewed head: de60207816ec14db474418a058dc1868fc4abd03

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway shutdown collects live work into persisted session-resume markers; startup turns those markers into conversation inputs, while the background-process registry independently adopts durable commands and delivers their outcomes.

flowchart TD
  A[Gateway shutdown] --> B[Live work enumeration]
  B --> C[Ordinary process restart marker]
  C --> D[Startup conversation resume]
  A --> E[Durable process continues]
  E --> F[Registry startup adoption]
  F --> G[Exit notification]
Loading

Technical review

Best possible solution:

Keep the existing durable registry responsible for surviving commands and mark only ordinary background processes as stopped.

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

Current-main source deterministically marks durable background processes as stopped, and the supplied live base trace shows the resulting false conversation input; this read-only review did not execute a reproduction.

Is this the best way to solve the issue?

The patch repairs the marker producer using the existing durable flag, preserves ordinary recovery, and adds one distinct regression case without introducing another recovery owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f7d2a1c77f5.

Provenance checked

  • Graceful-restart background-process markers changes intended behavior with a stated reason (9344233: The graceful-restart redesign used one ordinary input to continue interrupted conversations and explain that ordinary background commands had stopped.)
  • Durable-process ownership and documentation keeps the original intent (20c1a15: Durable processes remain with the background-process registry across restart and deliver fresh completion inputs; macOS support later reused that contract.)
  • Existing marker-persistence regression suite keeps the original intent (e051130: Ordinary conversations retain their own restart markers without inheriting cron or external execution ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Minimal producer-side correction: The introduced production hunk excludes process.durable from restart-marker enumeration without changing active-turn recovery, ordinary-process markers, or notification delivery. (src/gateway/session-restart-resume.ts:201, de60207816ec)
  • Current main still contains the defect: Fetched main includes every running background process in hadBackgroundExec markers, including durable processes. (src/gateway/session-restart-resume.ts:197, 3f7d2a1c77f5)
  • Existing durable recovery owner: initializeDurableProcesses restores registry sessions from retained records and settles their exits through the existing notification path; adoption does not rerun commands. (src/agents/bash-process-durable.ts:66, de60207816ec)
  • Live behavior evidence: The PR supplies redacted real-agent Gateway traces across SIGTERM and restart: durable false restart turns fall from six to zero, the shown fixed waiter completes through its exit wake, and ordinary-process notices remain present. (de60207816ec)
  • Focused regression: The existing marker-persistence test now includes a durable-only conversation and checks that it receives no marker while ordinary conversations retain hadBackgroundExec; the PR reports this assertion failing on base and passing with the fix. (src/gateway/session-restart-resume.test.ts:595, de60207816ec)
  • Original intent and feature history: The graceful-restart redesign established ordinary resume inputs; the later durable-process feature explicitly retained registry ownership, startup adoption, and fresh completion inputs. Those contracts support separating durable processes from stopped-process markers. (src/gateway/session-restart-resume.ts:202, 9344233e7a66)

PR surface

Source +1, Tests +17, Docs 0. Total +18 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 20 3 +17
Docs 2 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 24 6 +18

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:

  • add P2: False restart inputs can cause unnecessary polling or repeated work for durable background commands, with limited scope.
  • 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 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: False restart inputs can cause unnecessary polling or repeated work for durable background commands, with limited scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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 14, 2026, 1:47 PM ET / 18:47 UTC.

@obviyus
obviyus merged commit 0c1fe01 into main Nov 14, 2026
130 checks passed
@obviyus
obviyus deleted the fix/durable-exec-restart-notice branch November 14, 2026 20:56
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 0c1fe01. After a graceful Gateway restart, sessions whose only background work is a surviving durable process no longer get a false "stopped" notice. Real-agent restart test: false stopped turns 6 -> 0, polls after restart 91 -> 0.

obviyus added a commit that referenced this pull request Nov 14, 2026
…nds exit together (#199113)

## What Problem This Solves

Fixes: when several background commands exit close together, the agent gets one wake turn per command, so three exits cost three model turns and three replies.

## User Impact

User impact: completions that arrive while an earlier completion turn in the same conversation is still queued or running now reach the agent together in one turn, with each result's process ID, status, exit code and output tail. A single completion starts at once, exactly as before.

## Why This Change Was Made

Each exit enqueued its own session event and became its own turn. The session event owner already turns a set of exact queued occurrences into one ordinary turn (`occurrences`, used by session-state notices), and `combineSessionEventTargetsForHost` already checks that a set shares one destination and requester authority. This change reuses both:

- New `session-event-batch.ts` in the session event owner keeps one in-flight completion turn per conversation. A completion with nothing in flight starts at once through `enqueueSessionEventForHost`, unchanged. A completion that arrives while that turn is queued or running claims its queued occurrence and waits. One second after the turn settles, every waiting completion that shares the same exec request owners, launching run, route and combinable target starts one turn with all of their occurrences.
- `bash-tools.exec-notify.ts` only switches its enqueue import to the batched entry point. Each result keeps the wake format from #199122 (`Exec completed (<id>, code 0, 4m3s):` plus a tail of up to 2,000 chars).
- One shared turn carries at most about 8,000 characters of results. Occurrence text must stay byte-exact, so the bound limits membership, not text: results past the budget start the next turn.
- The exec completion guidance is count-neutral ("Treat each completion result above as an internal continuation…") so a batched turn no longer says "this completion" for several results.

Choices and accepted edges:

- **A 1 s settle, only for completions that already waited.** A first or lone completion still starts at once (measured base: its turn starts within about 1 s of the exit, before later exits arrive), so no delay is added to single wakes. Without a settle, exits about 1 s apart sometimes straddle the end of the turn they waited behind: on the intermediate head, 2 of 6 trials split into three turns because the last exit arrived just after the batch started. Waiting completions now start 1 s after that turn settles, so stragglers join.
- **Only one request's completions share a turn.** Stop aborts every exec request owner of a turn, so mixing requests would let one Stop retire another request's result. Completions from different requests keep separate turns.
- **Only one launching run's completions share a turn.** The completion turn's input provenance names the run that launched the command, which plugins use to correlate a completion with its run (#179816). Request owners carry over into completion turns, so commands launched by a later run can share owners with earlier ones; the batch also requires the same launching run, and each shared turn keeps a truthful `inputProvenance.runId`.
- **Cron-run completions never wait.** They check at acceptance that the originating run is still alive; holding them could turn an accepted completion into a refused one.
- Removing one member after its shared turn is queued (for example, the model polled that result) leaves the shared prompt as is; the turn is retired only when every member is removed. Before the shared turn is queued, removal drops just that member.
- A waiting completion starts after its predecessor settles, so a human message queued in `followup` or `collect` mode meanwhile can run first.
- Rebased on #199122 (wake format) and #199085. This PR touches only the import line in `bash-tools.exec-notify.ts` and the guidance wording in `agent-runner-run-params.ts`.

## Evidence

**Real-agent E2E** (isolated source Gateway via `ocx src`, real OpenAI model, 6 concurrent trial sessions per arm). Each trial asks the agent to start three background waiters with `yieldMs`, waits until the session is idle with all three running, then releases them 1 s apart. Base = current `main` (`afeadf1c4fe0`, includes #199122); fix = this PR rebased on it.

| Arm | Wake turns (6 trials) | Results acknowledged | Wake-turn tokens (total) | Wake-turn cost |
| --- | --- | --- | --- | --- |
| base, 3 exits | 18 (3 per trial) | 18/18 | 501,233 | $1.152 |
| fix, 3 exits | 12 (2 per trial) | 18/18 | 326,362 (-35%) | $0.930 |
| base, 1 exit | 6 | 6/6 | 153,377 | $0.402 |
| fix, 1 exit | 6 | 6/6 | 153,934 | $0.403 |

Single-exit wake latency (release to wake message, median of 6): base 0.85 s, fix 0.85 s. A single completion never waits for the settle. Time from release to the last reply in the 3-exit arm: base median 9.2 s, fix median 7.3 s.

Every fix trial: the first exit starts its turn at once; the two later exits arrive during it and share the next turn, each keeping its own id, exit code, duration and tail. Results from earlier runs before the rebase (same arms, older wake format) matched: 12 turns vs 18.

<details><summary>Redacted trace, trial 1 (times relative to release of the first waiter)</summary>

Base (before the rebase, old wake format):

```
  +8.8s USER: Exec completed (gentle-c, code 0) :: job 1 result: r11-1603127358
 +11.7s reply (26930 tok): job 1 result: r11-1603127358
 +19.1s USER: Exec completed (dawn-gla, code 0) :: job 2 result: r12-78193628
 +22.0s reply (27407 tok): job 2 result: r12-78193628
 +26.5s USER: Exec completed (kind-sum, code 0) :: job 3 result: r13-1811516849
 +29.2s reply (27885 tok): job 3 result: r13-1811516849
```

Fix (rebased head):

```
  +1.2s USER: Exec completed (tide-cov, code 0, 34s): job 1 result: r11-1383216
  +3.7s reply (26761 tok): job 1 result: r11-1383216
  +5.1s USER: Exec completed (tidy-com, code 0, 32s): job 2 result: r12-262323306
              Exec completed (rapid-bi, code 0, 29s): job 3 result: r13-179203848
  +7.7s reply (27281 tok): job 2 result: r12-262323306 / job 3 result: r13-179203848
```

</details>

**Regression tests:** `bash-tools.exec-background-followup.test.ts` runs three real background commands through the exec tool and the real session event owner with a held first model turn. Same launching run: base starts three completion turns (red); the fix starts two, the second carrying both later results and naming their run. Different launching runs with shared request owners: the later results keep separate turns, each naming its own run (red without the launch-run check). Five results of ~2,000 chars: the shared turn takes three and the fifth starts its own turn (size bound).

**Focused suites (`ocx test`, rebased head, 14 files):** `bash-tools.exec-background-followup`, `bash-tools.test`, `bash-tools.exec-runtime`, `bash-tools.exec-runtime.cleanup`, `bash-tools.visible-subagent-notify`, `bash-tools.exec-request-stop`, `bash-tools.exec.egress-lifecycle`, `bash-tools.notify-on-exit-ack`, `bash-tools.process.e2e`, `bash-tools.exec-notify.requester`, `bash-tools.exec-notify.queue-full`, `infra/exec-session-event`, `session-event-handoff`, `agent-runner-execution-session-events`: all pass. `exec-session-event`'s chained-completion case now waits for the second receipt, which starts after the 1 s settle.

**Full tier:** `ocx build --dts` (full profile) built `92847fc`; the self-contained source package passed its tarball integrity check, installed with npm into a scratch prefix, and the packed CLI reported `OpenClaw 2026.11.3 (92847fc)` with `gateway --help` exit 0. The later head commit only changes a test type.

**Gaps:** E2E covers exits from one request in an idle Control UI-style session; completions from different requests and channel-delivered sessions are covered by the shared owner's existing tests, not by a new live run.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…estart (openclaw#199085)

## What Problem This Solves

Fixes: after a graceful Gateway restart, every conversation with a running `durable: true` background command was told "Background exec processes were stopped; rerun them if still needed", even though the registry had just adopted that command and would wake the conversation when it exits.

## User Impact

User impact: a durable waiter now survives a restart quietly. The conversation keeps waiting and wakes once, when the command exits. The agent no longer gets a false "stopped" turn, so it neither polls the surviving command nor reruns it. Ordinary (non-durable) background commands still get the same restart notice as before.

## Why This Change Was Made

The graceful-shutdown marker counted every running background process, durable ones included. It now skips durable processes. Their own owner adopts them at startup and delivers the exit or lost-process wake. Docs now state which processes the restart notice covers. They also note that a crash sends no notice for ordinary processes; that gap is tracked separately.

## Evidence

Real-agent E2E on an isolated source Gateway (`openai/gpt-6-astra`, 6 concurrent conversations per arm, automations tool denied). Each conversation is asked to wait for a fake CI that flips green about 300 s later. The Gateway gets SIGTERM about 90 s after every conversation armed its waiter and ended its turn, then a new Gateway starts on the same state.

| Arm | Waiters armed, turn ended | False "stopped" restart turns | `process poll` calls after restart | Waiters that exited and woke their conversation |
| --- | --- | --- | --- | --- |
| base, `durable: true` waiter | 6/6 | **6** | **91** | 6/6, collected by the poll loop inside the false turn |
| fix, `durable: true` waiter | 6/6 | **0** | **0** | 4/4 by the exit wake (2 model-written loops never matched "all 15 checks passed" and never exited, unrelated to restart) |
| base, ordinary waiter | 6/6 | 6 (correct) | 0 | re-armed 6/6 |
| fix, ordinary waiter | 5/6 (1 was still mid-turn) | 6 (correct) | 0 | re-armed 5/5, finished 6/6 |

Shutdown log, durable arm: base `marked: 6`, fix `marked: 0`.

<details><summary>Public trace, durable waiter, base vs fix (trial 2, paths redacted)</summary>

Base: false restart turn, then a poll loop on the adopted process:
```
+ 53s   -> Command still running (session faint-otter:…). Its exit wakes this conversation …
+ 62s reply: The durable background waiter is running. …
+186s USER: The Gateway restarted while you were working. Resume your work … Background exec processes were stopped; rerun them if still needed.
+190s process {"action": "poll", "timeout": 1000}
+198s reply: The original durable waiter survived the restart and is still running, so I haven't started another. …
+198s process {"action": "poll", "timeout": 30000}
+206s   -> PR openclaw#4242: 4 checks pending, 11 passed Process still running. Automatic completion wake is unavailable after ending this turn. …
… 13 more polls until CI turned green …
```

Fix: no restart turn; the adopted exit wakes the conversation once:
```
+ 69s exec {"yieldMs": 1000, "background": true, "durable": true, "timeoutSeconds": 0} "python3 -u - <<'PY' …"
+ 69s   -> Command still running (session quick-fjord:…). Its exit wakes this conversation …
+ 76s reply: The durable background wait is running. …
+354s USER: Exec completed (quick-fj, code 0) :: … PR openclaw#4242: all 15 checks passed …
+364s reply: PR openclaw#4242 is ready—all 15 checks passed. Saved and verified in `pr-2/RESULT.md` …
```
</details>

Regression test: `src/gateway/session-restart-resume.test.ts`, "marks ordinary conversations without inheriting cron, external execution or durable processes". It fails on base (`agent:main:durable-waiter: expected { queuedInputIds: [], … } to deeply equal undefined`) and passes with the fix; the file passes 21/21.

Known gaps, out of scope for this PR:
- After a crash (SIGKILL), ordinary waiters still get no notice: base 0/6 conversations resumed. Closing that needs a stored fact written when the waiter is armed, which is a separate decision.
- After restart, `process poll` on an adopted durable process still says its automatic wake is unavailable, although the exit does wake the conversation. With this fix, no restart turn prompts that poll.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…nds exit together (openclaw#199113)

## What Problem This Solves

Fixes: when several background commands exit close together, the agent gets one wake turn per command, so three exits cost three model turns and three replies.

## User Impact

User impact: completions that arrive while an earlier completion turn in the same conversation is still queued or running now reach the agent together in one turn, with each result's process ID, status, exit code and output tail. A single completion starts at once, exactly as before.

## Why This Change Was Made

Each exit enqueued its own session event and became its own turn. The session event owner already turns a set of exact queued occurrences into one ordinary turn (`occurrences`, used by session-state notices), and `combineSessionEventTargetsForHost` already checks that a set shares one destination and requester authority. This change reuses both:

- New `session-event-batch.ts` in the session event owner keeps one in-flight completion turn per conversation. A completion with nothing in flight starts at once through `enqueueSessionEventForHost`, unchanged. A completion that arrives while that turn is queued or running claims its queued occurrence and waits. One second after the turn settles, every waiting completion that shares the same exec request owners, launching run, route and combinable target starts one turn with all of their occurrences.
- `bash-tools.exec-notify.ts` only switches its enqueue import to the batched entry point. Each result keeps the wake format from openclaw#199122 (`Exec completed (<id>, code 0, 4m3s):` plus a tail of up to 2,000 chars).
- One shared turn carries at most about 8,000 characters of results. Occurrence text must stay byte-exact, so the bound limits membership, not text: results past the budget start the next turn.
- The exec completion guidance is count-neutral ("Treat each completion result above as an internal continuation…") so a batched turn no longer says "this completion" for several results.

Choices and accepted edges:

- **A 1 s settle, only for completions that already waited.** A first or lone completion still starts at once (measured base: its turn starts within about 1 s of the exit, before later exits arrive), so no delay is added to single wakes. Without a settle, exits about 1 s apart sometimes straddle the end of the turn they waited behind: on the intermediate head, 2 of 6 trials split into three turns because the last exit arrived just after the batch started. Waiting completions now start 1 s after that turn settles, so stragglers join.
- **Only one request's completions share a turn.** Stop aborts every exec request owner of a turn, so mixing requests would let one Stop retire another request's result. Completions from different requests keep separate turns.
- **Only one launching run's completions share a turn.** The completion turn's input provenance names the run that launched the command, which plugins use to correlate a completion with its run (openclaw#179816). Request owners carry over into completion turns, so commands launched by a later run can share owners with earlier ones; the batch also requires the same launching run, and each shared turn keeps a truthful `inputProvenance.runId`.
- **Cron-run completions never wait.** They check at acceptance that the originating run is still alive; holding them could turn an accepted completion into a refused one.
- Removing one member after its shared turn is queued (for example, the model polled that result) leaves the shared prompt as is; the turn is retired only when every member is removed. Before the shared turn is queued, removal drops just that member.
- A waiting completion starts after its predecessor settles, so a human message queued in `followup` or `collect` mode meanwhile can run first.
- Rebased on openclaw#199122 (wake format) and openclaw#199085. This PR touches only the import line in `bash-tools.exec-notify.ts` and the guidance wording in `agent-runner-run-params.ts`.

## Evidence

**Real-agent E2E** (isolated source Gateway via `ocx src`, real OpenAI model, 6 concurrent trial sessions per arm). Each trial asks the agent to start three background waiters with `yieldMs`, waits until the session is idle with all three running, then releases them 1 s apart. Base = current `main` (`faf88178b453`, includes openclaw#199122); fix = this PR rebased on it.

| Arm | Wake turns (6 trials) | Results acknowledged | Wake-turn tokens (total) | Wake-turn cost |
| --- | --- | --- | --- | --- |
| base, 3 exits | 18 (3 per trial) | 18/18 | 501,233 | $1.152 |
| fix, 3 exits | 12 (2 per trial) | 18/18 | 326,362 (-35%) | $0.930 |
| base, 1 exit | 6 | 6/6 | 153,377 | $0.402 |
| fix, 1 exit | 6 | 6/6 | 153,934 | $0.403 |

Single-exit wake latency (release to wake message, median of 6): base 0.85 s, fix 0.85 s. A single completion never waits for the settle. Time from release to the last reply in the 3-exit arm: base median 9.2 s, fix median 7.3 s.

Every fix trial: the first exit starts its turn at once; the two later exits arrive during it and share the next turn, each keeping its own id, exit code, duration and tail. Results from earlier runs before the rebase (same arms, older wake format) matched: 12 turns vs 18.

<details><summary>Redacted trace, trial 1 (times relative to release of the first waiter)</summary>

Base (before the rebase, old wake format):

```
  +8.8s USER: Exec completed (gentle-c, code 0) :: job 1 result: r11-1603127358
 +11.7s reply (26930 tok): job 1 result: r11-1603127358
 +19.1s USER: Exec completed (dawn-gla, code 0) :: job 2 result: r12-78193628
 +22.0s reply (27407 tok): job 2 result: r12-78193628
 +26.5s USER: Exec completed (kind-sum, code 0) :: job 3 result: r13-1811516849
 +29.2s reply (27885 tok): job 3 result: r13-1811516849
```

Fix (rebased head):

```
  +1.2s USER: Exec completed (tide-cov, code 0, 34s): job 1 result: r11-1383216
  +3.7s reply (26761 tok): job 1 result: r11-1383216
  +5.1s USER: Exec completed (tidy-com, code 0, 32s): job 2 result: r12-262323306
              Exec completed (rapid-bi, code 0, 29s): job 3 result: r13-179203848
  +7.7s reply (27281 tok): job 2 result: r12-262323306 / job 3 result: r13-179203848
```

</details>

**Regression tests:** `bash-tools.exec-background-followup.test.ts` runs three real background commands through the exec tool and the real session event owner with a held first model turn. Same launching run: base starts three completion turns (red); the fix starts two, the second carrying both later results and naming their run. Different launching runs with shared request owners: the later results keep separate turns, each naming its own run (red without the launch-run check). Five results of ~2,000 chars: the shared turn takes three and the fifth starts its own turn (size bound).

**Focused suites (`ocx test`, rebased head, 14 files):** `bash-tools.exec-background-followup`, `bash-tools.test`, `bash-tools.exec-runtime`, `bash-tools.exec-runtime.cleanup`, `bash-tools.visible-subagent-notify`, `bash-tools.exec-request-stop`, `bash-tools.exec.egress-lifecycle`, `bash-tools.notify-on-exit-ack`, `bash-tools.process.e2e`, `bash-tools.exec-notify.requester`, `bash-tools.exec-notify.queue-full`, `infra/exec-session-event`, `session-event-handoff`, `agent-runner-execution-session-events`: all pass. `exec-session-event`'s chained-completion case now waits for the second receipt, which starts after the 1 s settle.

**Full tier:** `ocx build --dts` (full profile) built `92847fc`; the self-contained source package passed its tarball integrity check, installed with npm into a scratch prefix, and the packed CLI reported `OpenClaw 2026.11.3 (92847fc)` with `gateway --help` exit 0. The later head commit only changes a test type.

**Gaps:** E2E covers exits from one request in an idle Control UI-style session; completions from different requests and channel-delivered sessions are covered by the shared owner's existing tests, not by a new live run.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…estart (openclaw#199085)

## What Problem This Solves

Fixes: after a graceful Gateway restart, every conversation with a running `durable: true` background command was told "Background exec processes were stopped; rerun them if still needed", even though the registry had just adopted that command and would wake the conversation when it exits.

## User Impact

User impact: a durable waiter now survives a restart quietly. The conversation keeps waiting and wakes once, when the command exits. The agent no longer gets a false "stopped" turn, so it neither polls the surviving command nor reruns it. Ordinary (non-durable) background commands still get the same restart notice as before.

## Why This Change Was Made

The graceful-shutdown marker counted every running background process, durable ones included. It now skips durable processes. Their own owner adopts them at startup and delivers the exit or lost-process wake. Docs now state which processes the restart notice covers. They also note that a crash sends no notice for ordinary processes; that gap is tracked separately.

## Evidence

Real-agent E2E on an isolated source Gateway (`openai/gpt-6-astra`, 6 concurrent conversations per arm, automations tool denied). Each conversation is asked to wait for a fake CI that flips green about 300 s later. The Gateway gets SIGTERM about 90 s after every conversation armed its waiter and ended its turn, then a new Gateway starts on the same state.

| Arm | Waiters armed, turn ended | False "stopped" restart turns | `process poll` calls after restart | Waiters that exited and woke their conversation |
| --- | --- | --- | --- | --- |
| base, `durable: true` waiter | 6/6 | **6** | **91** | 6/6, collected by the poll loop inside the false turn |
| fix, `durable: true` waiter | 6/6 | **0** | **0** | 4/4 by the exit wake (2 model-written loops never matched "all 15 checks passed" and never exited, unrelated to restart) |
| base, ordinary waiter | 6/6 | 6 (correct) | 0 | re-armed 6/6 |
| fix, ordinary waiter | 5/6 (1 was still mid-turn) | 6 (correct) | 0 | re-armed 5/5, finished 6/6 |

Shutdown log, durable arm: base `marked: 6`, fix `marked: 0`.

<details><summary>Public trace, durable waiter, base vs fix (trial 2, paths redacted)</summary>

Base: false restart turn, then a poll loop on the adopted process:
```
+ 53s   -> Command still running (session faint-otter:…). Its exit wakes this conversation …
+ 62s reply: The durable background waiter is running. …
+186s USER: The Gateway restarted while you were working. Resume your work … Background exec processes were stopped; rerun them if still needed.
+190s process {"action": "poll", "timeout": 1000}
+198s reply: The original durable waiter survived the restart and is still running, so I haven't started another. …
+198s process {"action": "poll", "timeout": 30000}
+206s   -> PR openclaw#4242: 4 checks pending, 11 passed Process still running. Automatic completion wake is unavailable after ending this turn. …
… 13 more polls until CI turned green …
```

Fix: no restart turn; the adopted exit wakes the conversation once:
```
+ 69s exec {"yieldMs": 1000, "background": true, "durable": true, "timeoutSeconds": 0} "python3 -u - <<'PY' …"
+ 69s   -> Command still running (session quick-fjord:…). Its exit wakes this conversation …
+ 76s reply: The durable background wait is running. …
+354s USER: Exec completed (quick-fj, code 0) :: … PR openclaw#4242: all 15 checks passed …
+364s reply: PR openclaw#4242 is ready—all 15 checks passed. Saved and verified in `pr-2/RESULT.md` …
```
</details>

Regression test: `src/gateway/session-restart-resume.test.ts`, "marks ordinary conversations without inheriting cron, external execution or durable processes". It fails on base (`agent:main:durable-waiter: expected { queuedInputIds: [], … } to deeply equal undefined`) and passes with the fix; the file passes 21/21.

Known gaps, out of scope for this PR:
- After a crash (SIGKILL), ordinary waiters still get no notice: base 0/6 conversations resumed. Closing that needs a stored fact written when the waiter is armed, which is a separate decision.
- After restart, `process poll` on an adopted durable process still says its automatic wake is unavailable, although the exit does wake the conversation. With this fix, no restart turn prompts that poll.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 0c1fe01)

Release adaptation: Exclude durable processes from lost non-durable resume markers at existing owner; preserve process-registry recovery. Baseline regression failed, fixed 9 tests passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit e7171f258ec8c4ced3cfd58977e3384e61bed6f4)
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
Correct the 11.7 adaptation of openclaw#199085: this target has no durable ProcessSession lifecycle. Remove the unsupported access and synthetic fixture, restore the two prior documentation claims, and retain ordinary restart notices and cron/external-owner coverage. No durable feature is introduced.

Proof: focused compiler reproduced both TS2339 errors on the parent and passes after correction; session-restart-resume.test.ts passes 9/9; targeted lint and diff check pass. Independent fresh review found no P0-P2 issues and verified the inverse of d4178f68bd25. The commit hook additionally normalized inherited import ordering in the touched source; the final four-file format check passes.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 918399fac56a5b4781925aae0850c6267a6901ed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime 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: XS 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