Repository navigation
fix(agents): stop agents polling background waits that will wake them - #198908
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +58, Tests +64, Docs +1. Total +123 across 10 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
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 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. |
f2ea6db to
c60b840
Compare
|
Redacted real-agent traces (isolated Gateway from source, This head ( Base ( Both previous findings are addressed on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
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 |
## 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 |  |  | | Idle, waiting on one command · 1440×900 · light |  |  | | Idle, waiting on one command · 390×844 · dark |  |  | | Idle, waiting on one command · 390×844 · light |  |  | New states: | State | Screenshot | | --- | --- | | Card selected: live output and Stop in Processes · 1440×900 · dark |  | | Card selected · 1440×900 · light |  | | Card selected · 390×844 · dark |  | | Two waiters, collapsed · 1440×900 · dark |  | | Two waiters, expanded · 1440×900 · dark |  | | Two waiters, expanded · 1440×900 · light |  | | Two waiters, expanded · 390×844 · dark |  | | Two waiters, expanded · 390×844 · light |  | 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]>
…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]>
## 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 |  |  | | Idle, waiting on one command · 1440×900 · light |  |  | | Idle, waiting on one command · 390×844 · dark |  |  | | Idle, waiting on one command · 390×844 · light |  |  | New states: | State | Screenshot | | --- | --- | | Card selected: live output and Stop in Processes · 1440×900 · dark |  | | Card selected · 1440×900 · light |  | | Card selected · 390×844 · dark |  | | Two waiters, collapsed · 1440×900 · dark |  | | Two waiters, expanded · 1440×900 · dark |  | | Two waiters, expanded · 1440×900 · light |  | | Two waiters, expanded · 390×844 · dark |  | | Two waiters, expanded · 390×844 · light |  | 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]>
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-iterationghloop) and made 21process pollcalls of 30 s. Each poll returned(no new output)/Process still running.. Each exec asked foryieldMs270000–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):Long wait: no rapid poll. Use exec yieldMs or process(poll, timeout=<ms>). ButyieldMsis silently capped at 120000 and the poll timeout at 30000, so a requested 5-minute wait returned after 2 minutes as a background handle.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 onlyProcess still running..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.yieldMswas capped. Sessions without a wake target get the existing manual-collection guidance.process pollresults of a waking command repeat the end-the-turn guidance.processlist/poll/log mark sessions without a wake target with the manual-collection follow-up.yieldMsschema description now match: end the turn when the exit wakes you;yieldMsmax 120000.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-astraon the OpenClaw runtime, direct tool surface (tools.codeMode=false). Each trial is a fresh session: "I just pushed PR #N.ci-statusprints 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 base18892937; fix = this head.S2:
automationsdenied, so the agent must wait withexec(the incident's mechanism):process pollcallssleep 30; ci-statuswithyieldMs, returned as a handle, thenprocess poll timeout=30000until exit, then a new sleep-and-check, repeated.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 finalall 15 checks passedtext, so the loop kept running past the trial window. That is the agent's parsing bug, not a missing wake; it made 0 polls.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.Full tier on this head:
ocx build --dtsplus packed tarball install:openclaw --versionandgateway --helppass.Limits:
awaitResultsin a smoke run; I did not measure it per arm.Agent creation no longer owns its originally observed target. That is a session-creation race outside this change (later batches stagger sends).followUpinprocessresults for sessions without a wake target change.