Skip to content

fix(agents): stop agents polling background waits that will wake them - #198908

Merged
obviyus merged 1 commit into
mainfrom
fix/exec-waiter-dedupe
Nov 14, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/exec-waiter-dedupe

Conversation

@obviyus

@obviyus obviyus commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: an agent that waits on a slow external result (CI, a review bot) keeps one turn alive for many minutes. It polls a background command every 30 s and starts new sleep-and-check commands while earlier ones are still running, even though the command's exit would wake the conversation.

User Impact

User impact: when a background command's exit will start the next turn, the agent is told so and ends its turn instead of polling. Hidden subagents, which get no exit wake, are no longer told that they do. Fewer model round trips while waiting, and the final answer still arrives through the exit wake.

Why This Change Was Made

Observed incident (production dashboard session, Claude Opus). One turn ran for about 20 minutes waiting for a PR's CI and review result. It started four overlapping waiters (sleep 290; gh pr checks …, sleep 280; …, sleep 240; … and a 70-iteration gh loop) and made 21 process poll calls of 30 s. Each poll returned (no new output) / Process still running.. Each exec asked for yieldMs 270000–2150000 and came back after about 121 s as a background handle. All four commands had different text, so a duplicate-command guard would have caught none of them.

Root cause (current main):

  • The system prompt said Long wait: no rapid poll. Use exec yieldMs or process(poll, timeout=<ms>). But yieldMs is silently capped at 120000 and the poll timeout at 30000, so a requested 5-minute wait returned after 2 minutes as a background handle.
  • Sessions that are not chat channels default to notifyOnExitEmptySuccess=false. There, the running result never said that the exit wakes the conversation. It said to "collect the result before ending the turn if empty success matters". Idle polls said only Process still running..
  • Waiters started earlier in the same turn do not appear in the turn-start "Active exec sessions" snapshot.
  • Hidden subagent sessions get no wake turn, yet their running results said that completion wakes them.

Fix (inside the existing exec/process owners; no new tool, state or config):

  • hasExitWake(session) beside the exec result formatter, fed by the facts the process owner records: the process owner captured a wake target (notifySessionTarget). This is the single fact behind all guidance. Hidden subagents and failed target captures have no target.
  • Running results: when the exit wakes the conversation, they say so and say to end the turn if only waiting remains, instead of polling or starting another command that waits for the same result. To wait for a condition, the agent should loop inside one command. They also list the other background commands still running in the conversation, and say when yieldMs was capped. Sessions without a wake target get the existing manual-collection guidance.
  • Idle process poll results of a waking command repeat the end-the-turn guidance. process list/poll/log mark sessions without a wake target with the manual-collection follow-up.
  • Wait guidance in the system prompt, the exec description and the yieldMs schema description now match: end the turn when the exit wakes you; yieldMs max 120000.
  • Docs: docs/tools/exec.md.

Not done: a duplicate-command guard. The observed waiters were all different commands, and judging "same intent" would be a heuristic on model output. The running result lists the other running commands instead, so the model can judge.

Evidence

Real agent, isolated Gateway from source (ocx src, pinned Bun fork), openai/gpt-6-astra on the OpenClaw runtime, direct tool surface (tools.codeMode=false). Each trial is a fresh session: "I just pushed PR #N. ci-status prints its current status. Once all checks pass, write the summary line to RESULT.md, then tell me the PR is ready." The fake CI flips to passed 240 s after the agent's first check. Base = merge base 18892937; fix = this head.

S2: automations denied, so the agent must wait with exec (the incident's mechanism):

Arm Valid trials Final answer delivered Duplicate waiters process poll calls Background waiters Turns Tokens / trial Cost / trial
base 12 12/12 0 76 (6.3 per trial) 33 21 433k $0.93
fix (previous head) 6 6/6, all via exit wake 0 0 7 13 237k $0.69
fix (this head) 6 5/6 0 0 5 10 192k $0.60
  • Base pattern, every trial: sleep 30; ci-status with yieldMs, returned as a handle, then process poll timeout=30000 until exit, then a new sleep-and-check, repeated.
  • Fix pattern: one looping waiter, end the turn, the exit wake delivers the result, then write RESULT.md and reply.
  • This head also tells the agent that, under the default notifyOnExitEmptySuccess=false, a silent success wakes nobody, so the waiter must print its result. The one undelivered trial on this head started a correct single looping waiter and ended its turn, but its own status check never matched the final all 15 checks passed text, so the loop kept running past the trial window. That is the agent's parsing bug, not a missing wake; it made 0 polls.
  • An earlier fix head without the "loop inside one command" sentence also made 0 polls in 4 trials. One trial ended its turn after each 20 s check and was woken 8 times. The loop sentence removed that pattern.

S1, all default tools (control): base and fix both chose a one-shot automation in every trial: 0 exec waiters and 0 polls in both arms, 6/6 final answers each. The automation path is unchanged.

Neither arm reproduced concurrent duplicate waiters with this model. The OpenAI agent waited for each waiter to exit before starting the next one. The duplicates came from the Claude incident above. The sibling listing in the running result is covered by the regression test below, not by the E2E.

Tests (vitest-source):

  • bash-tools.exec-background-followup.test.ts: a woken conversation gets the end-the-turn guidance, a second waiter lists the first, and an idle poll repeats the guidance. A hidden subagent gets manual collection, not a wake promise. Both are red on the merge base and green here.
  • The exec/process, system prompt and prefix-stability suites pass. The shared process fixture now models an ordinary wake-armed session.

Full tier on this head: ocx build --dts plus packed tarball install: openclaw --version and gateway --help pass.

Limits:

  • E2E used one OpenAI model on the direct tool surface. Code Mode (the default for this model) waited in-turn with awaitResults in a smoke run; I did not measure it per arm.
  • Two trials in an earlier fix batch never started: the Gateway rejected concurrent first sends with Agent creation no longer owns its originally observed target. That is a session-creation race outside this change (later batches stagger sends).
  • The process-session record shape is unchanged. Only the model-facing text and the followUp in process results for sessions without a wake target change.

@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 agents Agent runtime and tooling size: S 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. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. 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

This PR aligns background-command guidance with captured wake availability, preserves manual collection, and shows other running commands.

Example: An agent waits for 15 CI checks using a command that prints its final result.

  • Before: The agent repeatedly polls background handles while waiting.
  • After: The agent starts one looping waiter, ends its turn, and replies when the command's completion wakes the conversation.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with real Gateway evidence, resolved prior findings, and green checks on the reviewed head.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Current-head redacted logs exercise the changed exec guidance through an isolated Gateway and real agent: one waiter runs, the agent ends its turn, and an exit wake produces the final answer without polling; broader model and Code Mode coverage are explicitly limited.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agents spend unnecessary turns polling work that can resume them automatically, while hidden subagents receive misleading wake promises.
Reason: The maintainer-authored direction addresses an observed incident, preserves existing notification settings, and supplies real-agent evidence of the intended improvement.

Merge readiness

✅ Ready for maintainer review

This PR is worth merging: both prior findings are resolved, current main still needs the guidance repair, and no new actionable defect was found.

Priority: P2
Reviewed head: c60b840ec3cf666b3c6536ce0fa192b705f50926

Before merge

None.

Findings

None.

Agent review details

How this fits together

The exec owner starts commands and captures notification facts; shared output rendering turns those facts into guidance consumed through exec results, process observations, and agent instructions.

flowchart TD
  A[Agent instructions] --> B[Exec tool]
  B --> C[Process session and wake facts]
  C --> D[Shared guidance renderer]
  D --> E[Exec and process results]
  C --> F[Completion notification owner]
  F --> G[Next conversation turn]
Loading

Technical review

Best possible solution:

Use captured wake facts in the shared renderer while preserving collection for unavailable wakes and potentially silent commands when empty-success notifications are disabled.

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

Current-main source exposes the inaccurate hidden-subagent wake promise and missing idle-poll guidance, while supplied baseline traces demonstrate repeated polling; no target code was executed during this review.

Is this the best way to solve the issue?

This is a focused repair using existing process facts and the existing bounded sibling listing, with no duplicate-command heuristic or competing lifecycle owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 72f7f8e26cfe.

Provenance checked

  • Launch guidance and destination availability keeps the original intent (a7ab9fa: Avoid promising automatic continuation after destination capture fails.)
  • Manual collection in process observations keeps the original intent (d647308: Keep required-result collection guidance visible after polling, logging, or listing notification-disabled commands.)
  • Prompt and tool completion guidance keeps the original intent (6f2e804: Prefer automatic completion wakes for work started now while retaining process inspection and intervention.)
  • Request ownership and yield documentation keeps the original intent (109bd47: Keep ordinary yielded commands cancellable by their originating request while allowing normal model completion to leave them running.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 73bead1 adds src/agents/bash-tools.exec-run.ts:611 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 73bead12393e; files: src/agents/bash-tools.exec-run.ts)
  • Vincent Koc: Raw commit 7df4392 adds src/agents/bash-tools.exec-result.types.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7df4392148cc; files: src/agents/bash-tools.exec-result.types.ts)
  • Vito Cappello: Raw commit f6ee991 adds src/agents/bash-tools.exec-run.ts:588 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f6ee99166170; files: src/agents/bash-tools.exec-run.ts)

PR surface

Source +58, Tests +64, Docs +1. Total +123 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 76 18 +58
Tests 3 68 4 +64
Docs 1 4 3 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 148 25 +123

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 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.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repeated background polling wastes model turns, and inaccurate wake guidance can leave required collection unfinished; the repair has a focused 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-14T14:41:06.504Z sha f2ea6db :: needs changes before merge. :: [P2] Preserve collection guidance for commands that may finish silently | [P2] Keep registry imports out of the extracted wrapper's formatter

Reviewed November 14, 2026, 10:42 AM ET / 15:42 UTC (Revision 2).

…wake them

Agents waiting on slow external results (CI, reviews) kept one turn alive
for many minutes, polling and starting new sleep-and-check commands while
earlier ones still ran.

- The system prompt recommended exec yieldMs or process poll for long
  waits, but yieldMs is capped at 120 s and poll at 30 s, so a requested
  5-minute wait returned after 2 minutes as a background handle.
- With the default for non-chat-channel sessions
  (notifyOnExitEmptySuccess=false), the running result never said that the
  exit wakes the conversation; it asked to collect the result before
  ending the turn. Idle polls said only "Process still running."
- Waiters started earlier in the same turn are not in the turn-start
  snapshot, so the agent could not see them.
- Hidden subagent sessions get no wake turn, yet were told completion
  wakes them.

Running results and idle polls now state the exit-wake fact from the wake
target the process owner captured, and tell the agent to end the turn
when only waiting remains, with one looping command for a condition.
Running results also list the other
background commands of the conversation and say when yieldMs was capped.
Sessions without a wake target get the manual-collection guidance.

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

clawsweeper Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: applying reviewed decision.

I am applying the reviewed decision for this pull request: fix(agents): stop agents polling background waits that will wake them This is item 1/1 in the current shard. Shard 1/1.

This transient lease prevents a newer review from overlapping label, comment, or close mutations.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@obviyus
obviyus force-pushed the fix/exec-waiter-dedupe branch from f2ea6db to c60b840 Compare November 14, 2026 15:23
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Redacted real-agent traces (isolated Gateway from source, openai/gpt-6-astra, automations denied, fake CI flips to passed 240 s after the first check). Paths are replaced with <path>; tool results are clipped.

This head (c60b840), trial 3: one looping waiter, the turn ends, the exit wake delivers the result. 0 polls.

+ 17s USER: I just pushed PR #4243. CI usually takes a few minutes. `<path>` prints its current status. Once all checks pass, write the summary line to <path> th…
+ 23s exec {} 'ls -l pr-3 && file pr-3/ci-status && cat pr-3/ci-status'
+ 23s   -> total 8 -rwx------@ 1 user staff 240 Nov 14 20:26 ci-status pr-3/ci-status: Bourne-Again shell script text executable, ASCII text #!/bin/bash echo "$(date +%s) $*" >> "<path>" cat "<path>"
+ 31s exec {} './pr-3/ci-status'
+ 32s   -> PR #4243: 4 checks pending, 11 passed
+ 38s exec {"yieldMs": 1000, "timeoutSeconds": 1900} "python3 - <<'PY'\nimport subprocess, time, re\nfrom pathlib import Path\nchecker = Path('pr-3/ci-status').resolve()\nf…
+ 39s   -> Command still running (session cool-crustacean:e9779a6f3918, pid 24689). Automatic stop will be requested at 2026-11-14T15:28:39.895Z; the process may exit earlier. Its exit wakes this conversation if it prints output or fails, not after a silent success. If …
+ 46s reply: CI has 11 checks passed and 4 pending. The watcher is running; once all checks pass, it will save the summary to `pr-3/RESULT.md` and I’ll …
+281s USER: Exec completed (cool-cru, code 0) :: pending, 11 passed PR #4243: 4 checks pending, 11 passed PR #4243: 4 checks pending, 11 passed PR #4243: 4 check…
+289s reply: PR #4243 is ready—all 15 checks passed. Saved to `pr-3/RESULT.md`: > PR #4243: all 15 checks passed. Summary: build-3-1712726690 green

Base (18892937), trial 1: sleep-and-check, process poll, repeat.

+ 21s USER: I just pushed PR #4241. CI usually takes a few minutes. `<path>` prints its current status. Once all checks pass, write the summary line to <path> th…
+ 28s exec {"yieldMs": 10000} "'<path>'"
+ 28s   -> PR #4241: 4 checks pending, 11 passed
+ 37s exec {"yieldMs": 1000, "timeoutSeconds": 45} "sleep 30; '<path>'"
+ 38s   -> Command still running (session nova-bloom:cea97bd2ab9c, pid 72419). Automatic stop will be requested at 2026-11-14T13:36:26.317Z; the process may exit earlier. Use process (list/poll/log/write/send-keys/submit/paste/kill/clear/remove) for follow-up. Automatic…
+ 41s process {"action": "poll", "timeout": 30000}
+ 67s   -> PR #4241: 4 checks pending, 11 passed Process still running.
+ 71s process {"action": "poll", "timeout": 30000}
+ 71s   -> (no new output) Process exited with code 0.
+ 75s exec {"yieldMs": 1000, "timeoutSeconds": 45} "sleep 30; '<path>'"
+ 76s   -> Command still running (session keen-shell:cea97bd2ab9c, pid 73541). Automatic stop will be requested at 2026-11-14T13:37:04.271Z; the process may exit earlier. Use process (list/poll/log/write/send-keys/submit/paste/kill/clear/remove) for follow-up. Automatic…
+ 82s process {"action": "poll", "timeout": 30000}
+105s   -> PR #4241: 4 checks pending, 11 passed Process still running.
+110s process {"action": "poll", "timeout": 30000}
+110s   -> (no new output) Process exited with code 0.
+115s exec {"yieldMs": 1000, "timeoutSeconds": 600} 'while true; do sleep 30; status=$(\'<path>') || exit; printf \'%s\\n\' "$status"; if [ "$status" != \'PR #4241: 4 chec…
+116s   -> Command still running (session glow-basil:cea97bd2ab9c, pid 74776). Automatic stop will be requested at 2026-11-14T13:46:59.574Z; the process may exit earlier. Use process (list/poll/log/write/send-keys/submit/paste/kill/clear/remove) for follow-up. Automatic…
+119s reply: CI still shows 4 checks pending and 11 passed. I’ve started monitoring; I’ll write `pr-1/RESULT.md` and quote the summary once all checks p…
+296s USER: Exec completed (glow-bas, code 0) :: PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passe…
+299s process {"action": "log"}
+299s   -> PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passed PR #4241: 4 checks pending, 11 passed PR #4241: all 15 checks passed. Summary: build-1-80021063 green Proce…
+304s write workspace/pr-1/RESULT.md
+312s reply: PR #4241 is ready—all 15 checks passed. Saved and verified in `pr-1/RESULT.md`: > PR #4241: all 15 checks passed. Summary: build-1-80021063…

Both previous findings are addressed on c60b840: bash-tools.exec-output no longer imports the registry or references (callers pass the running-process list and the wake facts), and with notifyOnExitEmptySuccess=false the guidance keeps poll collection for commands that may succeed silently, including the idle-poll text.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
@obviyus
obviyus merged commit 2a8e0b3 into main Nov 14, 2026
155 checks passed
@obviyus
obviyus deleted the fix/exec-waiter-dedupe branch November 14, 2026 15:45
@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 2a8e0b3. Agents that start a background command whose exit wakes the conversation are now told to end the turn instead of polling, and the running result lists the other running commands. Real-agent E2E on this head: 0 process poll calls (base: 76 across 12 trials), with the result delivered through the exit wake.

obviyus added a commit that referenced this pull request Nov 14, 2026
## What Problem This Solves

An agent can end its turn and wait for a background command whose exit continues the chat (`tools.exec.notifyOnExit`, on by default). Nothing in the conversation says that work is pending. The only signal is a quiet ring in the sidebar, and raw completion notices are hidden from chat history, so the chat looks finished until the agent suddenly replies.

## User Impact

While the chat is idle and a background command will continue it, a card above the composer reads **Waiting on `<command>`** with its elapsed time. Selecting it opens that command's live output in **Processes**, where **Stop** already lives. Two or more waiters collapse to **Waiting on N processes**; expanding it lists each one.

The card hides while a turn runs and disappears when the command exits, as its completion starts the next turn. A requested Stop removes it at once, because a stopped command does not continue the chat. Chats with no background work load nothing new.

## Why This Change Was Made

- **Data:** `sessions.processes.list` rows gain an optional `wakesSession: true`. The existing process observation sets it for running, backgrounded commands that still have a captured chat destination and no requested Stop, matching the completion owner's guards. It reuses `hasExitWake`, the exit-wake check that #198908 added beside the exec result formatter, so the card and the agent's guidance read the same fact. The additive protocol field has no version bump; protocol outputs and validators were regenerated (no generated diff).
- **UI:** the card shares the composer stack's card rules with the goal and progress cards (selector lists in `composer-progress.css`, no new stylesheet), plus the shared session spinner, `ElapsedTime` and the scroll-state name fade. It reads the existing `ProcessesPanelData` observation, the same owner Processes and Details use, so reads, `sessions.processes.changed` refreshes and access errors behave identically. It mounts only while the session row reports `backgroundProcessCount`; session keying and run-state checks live in the lazy chunk.
- **Opening output:** selecting a command reuses the existing Details → Processes action, so **Back** returns to Details, which lists the running commands.
- **Not Labs:** like the sidebar background-work ring (#188433), this presents existing state without new cost or config.

## Evidence

Real Gateway, real agent (`gpt-5.5` through the OpenAI Responses API), isolated state and port. The agent started `sh wait-for-deploy.sh` and later `sh watch-ci.sh` itself as background exec calls, then ended its turn. Before: `main` at `18892937f802` (dist fixture). After: this branch, Gateway from source with the branch's production Control UI build. Avatars are blurred in every capture.

| Scenario | Before | After |
| --- | --- | --- |
| Idle, waiting on one command · 1440×900 · dark | ![Before: idle chat waiting on one command, desktop dark](https://github.com/user-attachments/assets/d95bae30-c24e-4334-8c52-923ff87a9f9d) | ![After: Waiting on sh wait-for-deploy.sh card above the composer, desktop dark](https://github.com/user-attachments/assets/1e6301b4-093f-44ed-922b-a0d5b3e46bbf) |
| Idle, waiting on one command · 1440×900 · light | ![Before: idle chat waiting on one command, desktop light](https://github.com/user-attachments/assets/473758cd-504d-4445-b9e0-83032c3f5067) | ![After: waiting card, desktop light](https://github.com/user-attachments/assets/e618e94d-e62c-4f83-9e5c-7f75fd5ff212) |
| Idle, waiting on one command · 390×844 · dark | ![Before: phone dark](https://github.com/user-attachments/assets/0827c741-921b-4154-b0a4-a7fbcdf567d5) | ![After: waiting card above the phone composer, dark](https://github.com/user-attachments/assets/26c9c966-3652-4f2b-a40e-9013715c6bd1) |
| Idle, waiting on one command · 390×844 · light | ![Before: phone light](https://github.com/user-attachments/assets/94c009b6-761c-40e1-9a22-a5d1cd225cda) | ![After: waiting card above the phone composer, light](https://github.com/user-attachments/assets/c67aa929-984c-4e5f-bd39-591ffcd347ff) |

New states:

| State | Screenshot |
| --- | --- |
| Card selected: live output and Stop in Processes · 1440×900 · dark | ![Processes detail opened from the waiting card, desktop dark](https://github.com/user-attachments/assets/74fde24e-740d-4a0d-aab0-19b1454cb9fa) |
| Card selected · 1440×900 · light | ![Processes detail opened from the waiting card, desktop light](https://github.com/user-attachments/assets/96e181ee-2e01-4e15-97ea-b0a183f5b6da) |
| Card selected · 390×844 · dark | ![Processes sheet opened from the waiting card, phone dark](https://github.com/user-attachments/assets/ca2f907d-fc44-43f5-ab8a-f04f46d8083d) |
| Two waiters, collapsed · 1440×900 · dark | ![Waiting on 2 processes, collapsed, desktop dark](https://github.com/user-attachments/assets/06bc227e-663c-4236-af4a-6947fc528fc7) |
| Two waiters, expanded · 1440×900 · dark | ![Waiting on 2 processes, expanded, desktop dark](https://github.com/user-attachments/assets/75b56dcf-42e4-4dcb-a94b-153a2c7e5f15) |
| Two waiters, expanded · 1440×900 · light | ![Waiting on 2 processes, expanded, desktop light](https://github.com/user-attachments/assets/5856391a-4dc8-4e30-8034-dc2f770e2f87) |
| Two waiters, expanded · 390×844 · dark | ![Waiting on 2 processes, expanded, phone dark](https://github.com/user-attachments/assets/aacc8304-6912-4689-9394-086527e9c60b) |
| Two waiters, expanded · 390×844 · light | ![Waiting on 2 processes, expanded, phone light](https://github.com/user-attachments/assets/770ce3c2-2f7b-4d72-ba7f-f34c6d1e15dc) |

The video (real time, ~98 s) starts with two waiters. The first command exits: the card hides while the woken turn runs, the agent reports the deploy, and the card returns for the remaining command. The second exit ends with no card.

https://github.com/user-attachments/assets/a1c1a505-a49b-40f8-bc37-44d22956c264

Also exercised on the same Gateway: selecting **Stop** in the opened detail removed the card within one refresh and started no turn; a fresh page load showed the card within 0.5 s.

- `ocx test`: `bash-process-observation.test.ts` 8 passed (new case: only running, destination-captured, unstopped processes are marked; exit clears it) and `chat-composer-waiters.test.tsx` 1 passed (filters non-waiters, opens the selected output, collapses two waiters and expands them).
- UI typecheck, scoped oxlint/oxfmt, stylelint, Control UI controller guard, `ui:i18n:verify` and baseline (no change), test-lines ratchet (+92 of 400) passed. `protocol:gen` and `ui:validators:gen` produced no diff.
- Control UI budgets vs the `18892937f802` base build (`ui:check-performance --base-dist`): chat boot JS +202 B gzip (the lazy gate), total CSS +114 B gzip / +871 B raw, startup and New Session +10 B. The first revision added +449 B JS and +848 B CSS gzip; sharing the composer stack rules and moving logic into the lazy chunk removed most of it. Because the base already exceeds these caps, the gate allows 64 B, so `control-ui-performance` still fails on this growth.

## CI

Rebased onto `main` after #198908 landed (head `05a3083e`); CI for this head is running. Known reds on the previous head:

- `control-ui-performance`: caused by this PR (chat boot JS +220 B gzip, total CSS +114 B gzip). `main` is already over these caps, so the gate allows 64 B. Maintainer-approved in #198891 (comment).
- `check-test-types`: inherited (`scripts/perf/state-read-worker-bench.ts`, not touched here).
- A local `ocx build --dts` of this head stops at the absolute Control UI budget check, as current `main` commits (`e741fd0d`, `d98f18ff`) do; the packed tarball integrity check, `openclaw --version` and `gateway --help` pass.

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

## What Problem This Solves

Fixes: an agent that waits on a slow external result (CI, a review bot) keeps one turn alive for many minutes. It polls a background command every 30 s and starts new sleep-and-check commands while earlier ones are still running, even though the command's exit would wake the conversation.

## User Impact

User impact: when a background command's exit will start the next turn, the agent is told so and ends its turn instead of polling. Hidden subagents, which get no exit wake, are no longer told that they do. Fewer model round trips while waiting, and the final answer still arrives through the exit wake.

## Why This Change Was Made

**Observed incident (production dashboard session, Claude Opus).** One turn ran for about 20 minutes waiting for a PR's CI and review result. It started four overlapping waiters (`sleep 290; gh pr checks …`, `sleep 280; …`, `sleep 240; …` and a 70-iteration `gh` loop) and made 21 `process poll` calls of 30 s. Each poll returned `(no new output)` / `Process still running.`. Each exec asked for `yieldMs` 270000–2150000 and came back after about 121 s as a background handle. All four commands had different text, so a duplicate-command guard would have caught none of them.

**Root cause (current `main`):**

- The system prompt said `Long wait: no rapid poll. Use exec yieldMs or process(poll, timeout=<ms>)`. But `yieldMs` is silently capped at 120000 and the poll timeout at 30000, so a requested 5-minute wait returned after 2 minutes as a background handle.
- Sessions that are not chat channels default to `notifyOnExitEmptySuccess=false`. There, the running result never said that the exit wakes the conversation. It said to "collect the result before ending the turn if empty success matters". Idle polls said only `Process still running.`.
- Waiters started earlier in the same turn do not appear in the turn-start "Active exec sessions" snapshot.
- Hidden subagent sessions get no wake turn, yet their running results said that completion wakes them.

**Fix (inside the existing exec/process owners; no new tool, state or config):**

- `hasExitWake(session)` beside the exec result formatter, fed by the facts the process owner records: the process owner captured a wake target (`notifySessionTarget`). This is the single fact behind all guidance. Hidden subagents and failed target captures have no target.
- Running results: when the exit wakes the conversation, they say so and say to end the turn if only waiting remains, instead of polling or starting another command that waits for the same result. To wait for a condition, the agent should loop inside one command. They also list the other background commands still running in the conversation, and say when `yieldMs` was capped. Sessions without a wake target get the existing manual-collection guidance.
- Idle `process poll` results of a waking command repeat the end-the-turn guidance. `process` list/poll/log mark sessions without a wake target with the manual-collection follow-up.
- Wait guidance in the system prompt, the exec description and the `yieldMs` schema description now match: end the turn when the exit wakes you; `yieldMs` max 120000.
- Docs: `docs/tools/exec.md`.

Not done: a duplicate-command guard. The observed waiters were all different commands, and judging "same intent" would be a heuristic on model output. The running result lists the other running commands instead, so the model can judge.

## Evidence

**Real agent, isolated Gateway from source** (`ocx src`, pinned Bun fork), `openai/gpt-6-astra` on the OpenClaw runtime, direct tool surface (`tools.codeMode=false`). Each trial is a fresh session: "I just pushed PR #N. `ci-status` prints its current status. Once all checks pass, write the summary line to RESULT.md, then tell me the PR is ready." The fake CI flips to passed 240 s after the agent's first check. Base = merge base `39efe6fb`; fix = this head.

S2: `automations` denied, so the agent must wait with `exec` (the incident's mechanism):

| Arm | Valid trials | Final answer delivered | Duplicate waiters | `process poll` calls | Background waiters | Turns | Tokens / trial | Cost / trial |
|---|---|---|---|---|---|---|---|---|
| base | 12 | 12/12 | 0 | **76** (6.3 per trial) | 33 | 21 | 433k | $0.93 |
| fix (previous head) | 6 | 6/6, all via exit wake | 0 | **0** | 7 | 13 | 237k | $0.69 |
| fix (this head) | 6 | 5/6 | 0 | **0** | 5 | 10 | 192k | $0.60 |

- Base pattern, every trial: `sleep 30; ci-status` with `yieldMs`, returned as a handle, then `process poll timeout=30000` until exit, then a new sleep-and-check, repeated.
- Fix pattern: one looping waiter, end the turn, the exit wake delivers the result, then write RESULT.md and reply.
- This head also tells the agent that, under the default `notifyOnExitEmptySuccess=false`, a silent success wakes nobody, so the waiter must print its result. The one undelivered trial on this head started a correct single looping waiter and ended its turn, but its own status check never matched the final `all 15 checks passed` text, so the loop kept running past the trial window. That is the agent's parsing bug, not a missing wake; it made 0 polls.
- An earlier fix head without the "loop inside one command" sentence also made 0 polls in 4 trials. One trial ended its turn after each 20 s check and was woken 8 times. The loop sentence removed that pattern.

S1, all default tools (control): base and fix both chose a one-shot automation in every trial: 0 exec waiters and 0 polls in both arms, 6/6 final answers each. The automation path is unchanged.

Neither arm reproduced *concurrent* duplicate waiters with this model. The OpenAI agent waited for each waiter to exit before starting the next one. The duplicates came from the Claude incident above. The sibling listing in the running result is covered by the regression test below, not by the E2E.

**Tests** (`vitest-source`):

- `bash-tools.exec-background-followup.test.ts`: a woken conversation gets the end-the-turn guidance, a second waiter lists the first, and an idle poll repeats the guidance. A hidden subagent gets manual collection, not a wake promise. Both are red on the merge base and green here.
- The exec/process, system prompt and prefix-stability suites pass. The shared process fixture now models an ordinary wake-armed session.

**Full tier** on this head: `ocx build --dts` plus packed tarball install: `openclaw --version` and `gateway --help` pass.

**Limits:**

- E2E used one OpenAI model on the direct tool surface. Code Mode (the default for this model) waited in-turn with `awaitResults` in a smoke run; I did not measure it per arm.
- Two trials in an earlier fix batch never started: the Gateway rejected concurrent first sends with `Agent creation no longer owns its originally observed target`. That is a session-creation race outside this change (later batches stagger sends).
- The process-session record shape is unchanged. Only the model-facing text and the `followUp` in `process` results for sessions without a wake target change.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
## What Problem This Solves

An agent can end its turn and wait for a background command whose exit continues the chat (`tools.exec.notifyOnExit`, on by default). Nothing in the conversation says that work is pending. The only signal is a quiet ring in the sidebar, and raw completion notices are hidden from chat history, so the chat looks finished until the agent suddenly replies.

## User Impact

While the chat is idle and a background command will continue it, a card above the composer reads **Waiting on `<command>`** with its elapsed time. Selecting it opens that command's live output in **Processes**, where **Stop** already lives. Two or more waiters collapse to **Waiting on N processes**; expanding it lists each one.

The card hides while a turn runs and disappears when the command exits, as its completion starts the next turn. A requested Stop removes it at once, because a stopped command does not continue the chat. Chats with no background work load nothing new.

## Why This Change Was Made

- **Data:** `sessions.processes.list` rows gain an optional `wakesSession: true`. The existing process observation sets it for running, backgrounded commands that still have a captured chat destination and no requested Stop, matching the completion owner's guards. It reuses `hasExitWake`, the exit-wake check that openclaw#198908 added beside the exec result formatter, so the card and the agent's guidance read the same fact. The additive protocol field has no version bump; protocol outputs and validators were regenerated (no generated diff).
- **UI:** the card shares the composer stack's card rules with the goal and progress cards (selector lists in `composer-progress.css`, no new stylesheet), plus the shared session spinner, `ElapsedTime` and the scroll-state name fade. It reads the existing `ProcessesPanelData` observation, the same owner Processes and Details use, so reads, `sessions.processes.changed` refreshes and access errors behave identically. It mounts only while the session row reports `backgroundProcessCount`; session keying and run-state checks live in the lazy chunk.
- **Opening output:** selecting a command reuses the existing Details → Processes action, so **Back** returns to Details, which lists the running commands.
- **Not Labs:** like the sidebar background-work ring (openclaw#188433), this presents existing state without new cost or config.

## Evidence

Real Gateway, real agent (`gpt-5.5` through the OpenAI Responses API), isolated state and port. The agent started `sh wait-for-deploy.sh` and later `sh watch-ci.sh` itself as background exec calls, then ended its turn. Before: `main` at `39efe6fb1cd8` (dist fixture). After: this branch, Gateway from source with the branch's production Control UI build. Avatars are blurred in every capture.

| Scenario | Before | After |
| --- | --- | --- |
| Idle, waiting on one command · 1440×900 · dark | ![Before: idle chat waiting on one command, desktop dark](https://github.com/user-attachments/assets/d95bae30-c24e-4334-8c52-923ff87a9f9d) | ![After: Waiting on sh wait-for-deploy.sh card above the composer, desktop dark](https://github.com/user-attachments/assets/1e6301b4-093f-44ed-922b-a0d5b3e46bbf) |
| Idle, waiting on one command · 1440×900 · light | ![Before: idle chat waiting on one command, desktop light](https://github.com/user-attachments/assets/473758cd-504d-4445-b9e0-83032c3f5067) | ![After: waiting card, desktop light](https://github.com/user-attachments/assets/e618e94d-e62c-4f83-9e5c-7f75fd5ff212) |
| Idle, waiting on one command · 390×844 · dark | ![Before: phone dark](https://github.com/user-attachments/assets/0827c741-921b-4154-b0a4-a7fbcdf567d5) | ![After: waiting card above the phone composer, dark](https://github.com/user-attachments/assets/26c9c966-3652-4f2b-a40e-9013715c6bd1) |
| Idle, waiting on one command · 390×844 · light | ![Before: phone light](https://github.com/user-attachments/assets/94c009b6-761c-40e1-9a22-a5d1cd225cda) | ![After: waiting card above the phone composer, light](https://github.com/user-attachments/assets/c67aa929-984c-4e5f-bd39-591ffcd347ff) |

New states:

| State | Screenshot |
| --- | --- |
| Card selected: live output and Stop in Processes · 1440×900 · dark | ![Processes detail opened from the waiting card, desktop dark](https://github.com/user-attachments/assets/74fde24e-740d-4a0d-aab0-19b1454cb9fa) |
| Card selected · 1440×900 · light | ![Processes detail opened from the waiting card, desktop light](https://github.com/user-attachments/assets/96e181ee-2e01-4e15-97ea-b0a183f5b6da) |
| Card selected · 390×844 · dark | ![Processes sheet opened from the waiting card, phone dark](https://github.com/user-attachments/assets/ca2f907d-fc44-43f5-ab8a-f04f46d8083d) |
| Two waiters, collapsed · 1440×900 · dark | ![Waiting on 2 processes, collapsed, desktop dark](https://github.com/user-attachments/assets/06bc227e-663c-4236-af4a-6947fc528fc7) |
| Two waiters, expanded · 1440×900 · dark | ![Waiting on 2 processes, expanded, desktop dark](https://github.com/user-attachments/assets/75b56dcf-42e4-4dcb-a94b-153a2c7e5f15) |
| Two waiters, expanded · 1440×900 · light | ![Waiting on 2 processes, expanded, desktop light](https://github.com/user-attachments/assets/5856391a-4dc8-4e30-8034-dc2f770e2f87) |
| Two waiters, expanded · 390×844 · dark | ![Waiting on 2 processes, expanded, phone dark](https://github.com/user-attachments/assets/aacc8304-6912-4689-9394-086527e9c60b) |
| Two waiters, expanded · 390×844 · light | ![Waiting on 2 processes, expanded, phone light](https://github.com/user-attachments/assets/770ce3c2-2f7b-4d72-ba7f-f34c6d1e15dc) |

The video (real time, ~98 s) starts with two waiters. The first command exits: the card hides while the woken turn runs, the agent reports the deploy, and the card returns for the remaining command. The second exit ends with no card.

https://github.com/user-attachments/assets/a1c1a505-a49b-40f8-bc37-44d22956c264

Also exercised on the same Gateway: selecting **Stop** in the opened detail removed the card within one refresh and started no turn; a fresh page load showed the card within 0.5 s.

- `ocx test`: `bash-process-observation.test.ts` 8 passed (new case: only running, destination-captured, unstopped processes are marked; exit clears it) and `chat-composer-waiters.test.tsx` 1 passed (filters non-waiters, opens the selected output, collapses two waiters and expands them).
- UI typecheck, scoped oxlint/oxfmt, stylelint, Control UI controller guard, `ui:i18n:verify` and baseline (no change), test-lines ratchet (+92 of 400) passed. `protocol:gen` and `ui:validators:gen` produced no diff.
- Control UI budgets vs the `39efe6fb1cd8` base build (`ui:check-performance --base-dist`): chat boot JS +202 B gzip (the lazy gate), total CSS +114 B gzip / +871 B raw, startup and New Session +10 B. The first revision added +449 B JS and +848 B CSS gzip; sharing the composer stack rules and moving logic into the lazy chunk removed most of it. Because the base already exceeds these caps, the gate allows 64 B, so `control-ui-performance` still fails on this growth.

## CI

Rebased onto `main` after openclaw#198908 landed (head `05a3083e`); CI for this head is running. Known reds on the previous head:

- `control-ui-performance`: caused by this PR (chat boot JS +220 B gzip, total CSS +114 B gzip). `main` is already over these caps, so the gate allows 64 B. Maintainer-approved in openclaw#198891 (comment).
- `check-test-types`: inherited (`scripts/perf/state-read-worker-bench.ts`, not touched here).
- A local `ocx build --dts` of this head stops at the absolute Control UI budget check, as current `main` commits (`b160df89`, `0212c217`) do; the packed tarball integrity check, `openclaw --version` and `gateway --help` pass.

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 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: S 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