Skip to content

fix(agents): sessions_yield awaits wake-armed background commands in one-shot runs - #199283

Merged
obviyus merged 2 commits into
mainfrom
fix/sessions-yield-exec-wake
Nov 15, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/sessions-yield-exec-wake

Conversation

@obviyus

@obviyus obviyus commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: one-shot runs cannot wait for a background command without polling. A hidden subagent or an isolated cron agent turn ends with its final reply, so "end the turn and let the exit wake you" does not work there:

  • A hidden subagent gets the exit only as a passive system event in its next turn, which never comes. Its running result therefore says "Automatic completion wake is unavailable … use poll with a timeout", and the agent calls process poll every 10–30 s for the whole wait.
  • An isolated cron run gets the same manual-collection guidance. When the run ends first, a queued exit still arrives later as an extra follow-up turn, which answers NO_REPLY.
  • sessions_yield only awaited child sessions. With a running command and no child, it said "No pending child completion … did not pause the turn". In a hidden subagent it refused outright ("Use process to poll and collect it before yielding").

User Impact

User impact: a subagent or automation that waits for CI, a deploy or any long command starts one background command and calls sessions_yield. The command's exit resumes the same run with the exit result, and the run reports normally. No poll loop, fewer model round trips and tokens, and no spurious NO_REPLY turns after a cron run. Ordinary chat sessions are unchanged: their exit still wakes the conversation when the turn ends.

Why This Change Was Made

Owners extended (no new tool, parameter, state or stored row):

  • Exec wake target capture (prepareExecExitNotification): hidden subagent and cron-run commands now capture their own session as the wake target and record exitWakeAfterYield, but only when sessions_yield is callable in that run. The exec tool reads this from the run's final callable tool set, the same way it reads process availability. Collectors (which never get sessions_yield) and tool policies that remove it keep the previous manual-collection guidance. hasExitWake stays the single fact that the running result, idle process poll text and the Control UI waiting card read. For a one-shot run it also requires a deadline, so a wait is always bounded by the command's timeoutSeconds. A timeout already ends the command, and that exit resumes the run. timeoutSeconds: 0 keeps manual-collection guidance.
  • Running result text (describeExitWake): one-shot runs read "This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it or start another command for the same result." Ordinary sessions keep the step 2 text.
  • Yield claim (createRequesterYieldCallback): a wake-armed running command that the current run started (originRunId) is a completion claim, like a pending child. An accepted yield marks those commands (resumesYieldedRun). The step 2 refusal of a hidden-subagent yield with uncollected background work stays for commands whose exit cannot resume the run.
  • Hidden subagent resume (maybeNotifyOnExit + prepareReplySubagentContinuation): the exit of an awaited command is sent as the ordinary exec wake turn (same content as step 2: exit code, duration, 2,000-char tail) instead of a passive event. It carries the starting run as sourceRunId. Reply admission treats an exec wake exactly like a tool handoff result: it continues the paused task only when that run is the yielded one, so the subagent's final reply still goes to its requester through the registry. A hidden subagent that did not yield still gets only the passive notice.
  • Cron run resume (executeCronRun): the cron executor opens a per-run resume slot. A yield on the run's own commands returns { resumesInPlace: true }; the embedded runner ends the turn but keeps the reply operation open, and the executor runs the next turn in the same operation with the exit text as the prompt. The resumed turn's reply is the run's result. A cron yield for children keeps the existing scheduler-owned behavior. A requested Stop or kill releases the wait without a turn.
  • Text and docs: sessions_yield and exec descriptions, the cron unattended preamble (the "will not resume after sessions_yield" sentence now applies only to child yields), docs/tools/exec.md, docs/gateway/background-process.md, docs/tools/subagents/tool-reference.md, docs/concepts/subagent-yield-handoff.md. Prompt snapshots regenerated.

Accepted edge cases (named, no code): a command that exits in the instant between an accepted subagent yield and the pause being published runs as a separate follow-up turn instead of continuing the paused task (same window as the existing tool-handoff resume). The Control UI waiting card in a hidden subagent session now shows for wake-armed commands, because the exit can resume the run. An interactive session that calls sessions_yield on a wake-armed command gets yielded, which ends the turn exactly as ending it normally would.

Production delta: +199/−49 lines in src (excluding tests).

Evidence

Real agent, isolated source Gateway (ocx src, pinned Bun fork, own state/port/HOME, env -i). Claude Opus through the shared Claude proxy, OpenClaw runtime, direct tool surface, automations denied. A fake CI flips to passed 240 s after the first status check. Fresh session per trial, 6 trials per arm, measured from the Gateway's own transcript store. base = 10159aefda9c (main at branch time), fix = bfd56dc84d66 (first head). The second head (d51e737ba7da, manual collection kept where sessions_yield is not callable) reran 3 hidden-subagent and 3 cron trials: 6/6 delivered, 0 polls, 5/5 background waiters resumed by their exit (1 cron trial waited in turn).

Scenario Arm Final result delivered process poll calls Exit resumed the run Spurious NO_REPLY turns Tokens / trial
(a) parent spawns a hidden subagent that waits for CI, parent reports base 6/6 76 (all in the subagent) 0/6 0 594k
fix 6/6 0 5/5 waiters (1 trial waited in turn) 0 314k
(b) isolated cron agent turn waits for CI base 6/6 61 (12 idle) 0/6 (2 exits arrived after the run) 3 477k
fix 6/6 0 5/5 waiters (1 trial waited in turn) 0 156k
(c) ordinary dashboard session, S2 (ci-status) base 6/6 12 6/6 0 296k
fix 6/6 0 6/6 0 198k

(a) parent: in every fix trial the parent yielded for the child and received the child's final summary through the existing subagent completion; in 5/6 the child's reply came from the exec-resumed turn. (b) base: the run polled until CI passed, answered, and the queued exit then started an extra follow-up turn in 3 trials. (c): the ordinary session's running-result text is unchanged. Claude calls sessions_yield after starting the waiter in 4/6 trials on base and 4/6 on this head. On base that returns nothing_pending and the agent then polls in 3 of those trials (12 polls); here the yield is accepted, the turn ends and the exit wakes the conversation. Two fix trials ran in a supplemental 2-trial arm, because a concurrent packaging step briefly rewrote package.json and broke two trial sends in the first arm.

Redacted trace, hidden subagent, fix (P = parent, S = subagent):

P +13s sessions_spawn → accepted
P +17s sessions_yield → {"status":"yielded"}
S +22s exec {"yieldMs":120000,"timeoutSeconds":1500} 'cd pr-1 && …loop until ci-status passes…'
S +142s  -> Command still running (session delta-sage:…, pid …), times out in 23m. This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it …
S +145s sessions_yield → {"status":"yielded"}
S +263s USER: Exec completed (delta-sa, code 0, 4m1s): … PR #4241: all 15 checks passed. Summary: build-1-… green
S +266s write pr-1/RESULT.md
S +269s reply: All 15 CI checks on PR #4241 have passed. … PR #4241: all 15 checks passed. Summary: build-1-… green
P +270s USER: [Subagent Context] Every subagent in this batch has now settled …
P +279s reply: The subagent says CI on PR #4241 passed. Its summary line is: PR #4241: all 15 checks passed …

Same scenario, base: the subagent's running result says "Automatic completion wake is unavailable after ending this turn … use poll with a timeout", then 14 process poll timeout=30000 calls each return PR #4241: 4 checks pending, 11 passed … Process still running. until it exits.

Cron, fix: exec → running result with the sessions_yield text → sessions_yield → {"status":"yielded"} → Exec completed (tender-c, code 0, 4m1s): … as the next turn of the same run → ci-status > RESULT.md → final reply PR #4241: all 15 checks passed …, recorded as the run summary.

Tests (vitest from source):

  • bash-tools.exec-background-followup.test.ts: a hidden subagent's command resumes it only after sessions_yield awaits it (passive notice otherwise; wake turn with source: "exec", sourceRunId and the step 2 content when yielded); a yielded cron run resumes in place with the exit text and sends no session event; cron running results carry the sessions_yield text.
  • bash-tools.exec-background-followup.test.ts also keeps the main behavior where sessions_yield is not callable: a hidden subagent gets manual-collection guidance and no wake promise, and a cron run is told to collect before ending the turn.
  • openclaw-tools.requester-yield.test.ts: a wake-armed command the run started is a yield claim only when it has a deadline; only an accepted yield arms the resume.
  • The two new tests fail on main, where the resume path does not exist; the updated cron assertions also fail there. The exec/process, descriptions, sessions_yield tool, requester yield, embedded runner yield orchestration, cron run lifecycle, model-switch retry and prompt-snapshot suites pass. tsgo:core passes.

Full tier: ocx build --dts on the rebased head (cace873cdf6c), then a packed tarball install: tarball integrity, openclaw --version (2026.11.3 (cace873)) and gateway --help pass; the packed bash-tools.exec-output chunk carries the new guidance.

Limits:

  • Claude only, direct tool surface; OpenAI and Code Mode were not measured for this step.
  • In one trial per fix arm (a) and (b), the agent waited in turn with a capped yieldMs block instead of backgrounding; it made no polls.
  • The cron harness has no chat channel, so every run (base and fix) records completionStatus: failed for delivery; the run summary is the agent's final reply in both arms.
  • Gateway restart mid-wait is out of scope (step 5).

CI: rebased onto main 92016ce978f0 (picks up #199113, which only changed the exec-completion enqueue import; no conflict in the yield/wake path). Focused yield, exec, cron and embedded-runner suites and tsgo:core pass on the rebased head. If checks-ui-e2e (1/2) fails in ui/src/e2e/chat-cli-history-redaction.e2e.test.ts ("preserves tool source in Activity while bounding the visible preview", waiting for .activity-empty), that failure is on main: #199168 removed the Activity element, but this test still waits for it. Locally, pnpm test:ui:e2e ui/src/e2e/chat-cli-history-redaction.e2e.test.ts fails the same way on main 92016ce978f0 and on this head (1 failed, 1 passed in both). This PR touches no ui/ file. Other PRs pass that shard because their changed files select only 6 UI test files that do not include this one; this PR's change set selects 19.

@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 agents Agent runtime and tooling size: M labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 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 lets sessions_yield await background commands and resume hidden subagents or isolated cron runs with their exit results.

Example: A hidden subagent starts a CI waiter with timeoutSeconds: 1500 that exits after 240 seconds.

  • Before: The subagent repeatedly calls process poll to collect the result.
  • After: The subagent calls sessions_yield, resumes with the exit result, and returns its summary to the parent.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful continuation support with real Gateway evidence, focused regressions, and no actionable code findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Supplied real-agent isolated Gateway traces exercise the changed exec owner through hidden-subagent task resumption and parent delivery, plus cron resumption with the final answer recorded as the originating run summary; supplemental trials cover callable-tool gating, and the rebase is supported by focused checks without claiming a new live rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Hidden subagents and isolated automations spend repeated model turns polling long commands because their final reply ends the work instead of waiting for its exit.
Reason: The maintainer-authored direction adds a useful continuation capability to a previously documented manual workflow, with measured reductions in polling and preserved collector behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides useful bounded waiting for one-shot runs, resolves the earlier callable-tool finding, and introduces no actionable defect found in this review; required CI remains blocked by an inherited Activity test failure.

Priority: P2
Reviewed head: cace873cdf6cda1201f38451cd4e9fbf1ac2ad8e

Before merge

None.

Findings

None.

Agent review details

How this fits together

The exec notification owner converts process exits into continuation input, while requester-yield admission, subagent task adoption, and the cron executor preserve the originating work's completion ownership.

flowchart TD
  A[Agent starts background command] --> B[Exec captures callable continuation]
  B --> C[sessions_yield awaits command]
  C --> D[Command exits]
  D --> E[Subagent task resumes]
  D --> F[Cron operation resumes]
  E --> G[Final result delivered]
  F --> G
Loading

Technical review

Best possible solution:

Use the existing exec, yield, task-adoption, and cron owners to resume bounded command waits while preserving manual collection wherever yield is unavailable.

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

Current-main source establishes the missing one-shot continuation capability, and the supplied base/fix Gateway traces demonstrate its polling consequence; this read-only review executed no target code.

Is this the best way to solve the issue?

The change extends the existing completion owners without a new tool or setting, and its small runtime resume slot handles the distinct cron lifetime rather than creating a competing scheduler.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exec completion routing and result content keeps the original intent (753a7a5: Immediate notifications moved into ordinary session execution while preserving captured destinations, requester ownership, cancellation, and queueing.)
  • Cron manual-collection guidance changes intended behavior with a stated reason (d867f17: A cron completion could not promise a wake once its originating run ended; this PR explicitly keeps yielded exec waits inside that run.)
  • Scheduler-owned child yields keeps the original intent (71e2f57: Automation child yields should end normally while the scheduler delivers child output under the job policy.)
  • Collector yield withholding keeps the original intent (610f6dc: Collectors require explicit result collection, and parking them can strand their waiter.)
  • Paused-task continuation identity changes intended behavior with a stated reason (8ea3ef8: Tool-handoff input continues only its own paused task; the PR deliberately extends that originating-run match to exec wakes.)
  • Callable authority versus stable tool declarations keeps the original intent (b45c967: Tool declarations follow the session catalog while actual continuation capability follows callable authority.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 00636f0 adds src/agents/bash-tools.exec-notify.ts:137 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 00636f0c7abc; files: src/agents/bash-tools.exec-notify.ts)
  • Peter Steinberger: Raw commit 71e2f57 adds src/agents/openclaw-tools.requester-yield.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 71e2f57f04e5; files: src/agents/openclaw-tools.requester-yield.ts)
  • Josh Lehman: Raw commit b461970 adds src/agents/openclaw-tools.requester-yield.ts:47 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b46197029a3a; files: src/agents/openclaw-tools.requester-yield.ts)
  • Jacob Riff: Raw commit 3fa91cd adds src/agents/tools/sessions-yield-tool.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 3fa91cd69d5d; files: src/agents/tools/sessions-yield-tool.ts)

PR surface

Source +173, Tests +98, Docs +15. Total +286 across 28 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 14 223 50 +173
Tests 10 121 23 +98
Docs 4 20 5 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 364 78 +286

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated polling consumes model turns in delegated and scheduled work, but the existing manual-collection path can complete these tasks.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 (2 earlier review cycles)
  • reviewed 2026-11-14T22:48:12.313Z sha bfd56dc :: needs changes before merge. :: [P2] [P2] Preserve manual collection when sessions_yield is unavailable
  • reviewed 2026-11-14T23:59:16.493Z sha d51e737 :: needs maintainer review before merge. :: none

Reviewed November 14, 2026, 7:47 PM ET / November 15, 2026, 00:47 UTC (Revision 3).

@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@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. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
obviyus and others added 2 commits November 15, 2026 05:36
…one-shot runs

Hidden subagents and isolated cron runs end with their final reply, so a
background command's exit could not resume them and they polled instead.
sessions_yield now also awaits the wake-armed commands the current run
started (bounded by each command's deadline). The exit resumes a yielded
hidden subagent through an ordinary exec wake turn that continues its paused
task, and resumes a yielded cron run in place with the same wake content.

Co-authored-by: obviyus <[email protected]>
… callable

Collectors and tool policies can remove sessions_yield while keeping exec
and process. Their one-shot commands keep manual-collection guidance, read
from the run's final callable tool set like process availability.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the fix/sessions-yield-exec-wake branch from d51e737 to cace873 Compare November 15, 2026 00:12
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override for exact head cace873 (ClawSweeper ready on this head):

  • checks-ui-e2e (1/2): inherited. The only failure is ui/src/e2e/chat-cli-history-redaction.e2e.test.ts:119, which waits for .activity-empty; that element no longer exists in the UI on main after improve(ui): remove browser-local Activity tool feed #199168, while the test still expects it. The same test file fails identically when run locally on origin/main 92016ce978f0 and on this head. Other PRs pass this shard only because their changed files do not select this test. This PR changes no ui/ files.
  • openclaw/ci-gate: aggregate of the above.

All other required jobs are green on this head.

@obviyus
obviyus merged commit 1fff14f into main Nov 15, 2026
146 of 149 checks passed
@obviyus
obviyus deleted the fix/sessions-yield-exec-wake branch November 15, 2026 00:52
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 1fff14f. Hidden subagents and cron agent turns can now call sessions_yield on a wake-armed background command; its exit resumes the run with the result. Real-agent E2E (Claude Opus): process polls 76 -> 0 (subagent), 61 -> 0 (cron), 12 -> 0 (dashboard).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…one-shot runs (openclaw#199283)

## What Problem This Solves

Fixes: one-shot runs cannot wait for a background command without polling. A hidden subagent or an isolated cron agent turn ends with its final reply, so "end the turn and let the exit wake you" does not work there:

- A hidden subagent gets the exit only as a passive system event in its next turn, which never comes. Its running result therefore says "Automatic completion wake is unavailable … use poll with a timeout", and the agent calls `process poll` every 10–30 s for the whole wait.
- An isolated cron run gets the same manual-collection guidance. When the run ends first, a queued exit still arrives later as an extra follow-up turn, which answers `NO_REPLY`.
- `sessions_yield` only awaited child sessions. With a running command and no child, it said "No pending child completion … did not pause the turn". In a hidden subagent it refused outright ("Use process to poll and collect it before yielding").

## User Impact

User impact: a subagent or automation that waits for CI, a deploy or any long command starts one background command and calls `sessions_yield`. The command's exit resumes the same run with the exit result, and the run reports normally. No poll loop, fewer model round trips and tokens, and no spurious `NO_REPLY` turns after a cron run. Ordinary chat sessions are unchanged: their exit still wakes the conversation when the turn ends.

## Why This Change Was Made

**Owners extended (no new tool, parameter, state or stored row):**

- **Exec wake target capture** (`prepareExecExitNotification`): hidden subagent and cron-run commands now capture their own session as the wake target and record `exitWakeAfterYield`, but only when `sessions_yield` is callable in that run. The exec tool reads this from the run's final callable tool set, the same way it reads `process` availability. Collectors (which never get `sessions_yield`) and tool policies that remove it keep the previous manual-collection guidance. `hasExitWake` stays the single fact that the running result, idle `process poll` text and the Control UI waiting card read. For a one-shot run it also requires a deadline, so a wait is always bounded by the command's `timeoutSeconds`. A timeout already ends the command, and that exit resumes the run. `timeoutSeconds: 0` keeps manual-collection guidance.
- **Running result text** (`describeExitWake`): one-shot runs read "This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it or start another command for the same result." Ordinary sessions keep the step 2 text.
- **Yield claim** (`createRequesterYieldCallback`): a wake-armed running command that the current run started (`originRunId`) is a completion claim, like a pending child. An accepted yield marks those commands (`resumesYieldedRun`). The step 2 refusal of a hidden-subagent yield with uncollected background work stays for commands whose exit cannot resume the run.
- **Hidden subagent resume** (`maybeNotifyOnExit` + `prepareReplySubagentContinuation`): the exit of an awaited command is sent as the ordinary exec wake turn (same content as step 2: exit code, duration, 2,000-char tail) instead of a passive event. It carries the starting run as `sourceRunId`. Reply admission treats an `exec` wake exactly like a tool handoff result: it continues the paused task only when that run is the yielded one, so the subagent's final reply still goes to its requester through the registry. A hidden subagent that did not yield still gets only the passive notice.
- **Cron run resume** (`executeCronRun`): the cron executor opens a per-run resume slot. A yield on the run's own commands returns `{ resumesInPlace: true }`; the embedded runner ends the turn but keeps the reply operation open, and the executor runs the next turn in the same operation with the exit text as the prompt. The resumed turn's reply is the run's result. A cron yield for children keeps the existing scheduler-owned behavior. A requested Stop or kill releases the wait without a turn.
- **Text and docs**: `sessions_yield` and exec descriptions, the cron unattended preamble (the "will not resume after `sessions_yield`" sentence now applies only to child yields), `docs/tools/exec.md`, `docs/gateway/background-process.md`, `docs/tools/subagents/tool-reference.md`, `docs/concepts/subagent-yield-handoff.md`. Prompt snapshots regenerated.

**Accepted edge cases** (named, no code): a command that exits in the instant between an accepted subagent yield and the pause being published runs as a separate follow-up turn instead of continuing the paused task (same window as the existing tool-handoff resume). The Control UI waiting card in a hidden subagent session now shows for wake-armed commands, because the exit can resume the run. An interactive session that calls `sessions_yield` on a wake-armed command gets `yielded`, which ends the turn exactly as ending it normally would.

Production delta: +199/−49 lines in `src` (excluding tests).

## Evidence

**Real agent, isolated source Gateway** (`ocx src`, pinned Bun fork, own state/port/HOME, `env -i`). Claude Opus through the shared Claude proxy, OpenClaw runtime, direct tool surface, `automations` denied. A fake CI flips to passed 240 s after the first status check. Fresh session per trial, 6 trials per arm, measured from the Gateway's own transcript store. base = `8ae26d8ad99d` (`main` at branch time), fix = `bfd56dc84d66` (first head). The second head (`d51e737ba7da`, manual collection kept where `sessions_yield` is not callable) reran 3 hidden-subagent and 3 cron trials: 6/6 delivered, **0** polls, 5/5 background waiters resumed by their exit (1 cron trial waited in turn).

| Scenario | Arm | Final result delivered | `process poll` calls | Exit resumed the run | Spurious `NO_REPLY` turns | Tokens / trial |
|---|---|---|---|---|---|---|
| (a) parent spawns a hidden subagent that waits for CI, parent reports | base | 6/6 | **76** (all in the subagent) | 0/6 | 0 | 594k |
| | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 314k |
| (b) isolated cron agent turn waits for CI | base | 6/6 | **61** (12 idle) | 0/6 (2 exits arrived after the run) | **3** | 477k |
| | fix | 6/6 | **0** | 5/5 waiters (1 trial waited in turn) | 0 | 156k |
| (c) ordinary dashboard session, S2 (`ci-status`) | base | 6/6 | 12 | 6/6 | 0 | 296k |
| | fix | 6/6 | **0** | 6/6 | 0 | 198k |

(a) parent: in every fix trial the parent yielded for the child and received the child's final summary through the existing subagent completion; in 5/6 the child's reply came from the exec-resumed turn. (b) base: the run polled until CI passed, answered, and the queued exit then started an extra follow-up turn in 3 trials. (c): the ordinary session's running-result text is unchanged. Claude calls `sessions_yield` after starting the waiter in 4/6 trials on base and 4/6 on this head. On base that returns `nothing_pending` and the agent then polls in 3 of those trials (12 polls); here the yield is accepted, the turn ends and the exit wakes the conversation. Two fix trials ran in a supplemental 2-trial arm, because a concurrent packaging step briefly rewrote `package.json` and broke two trial sends in the first arm.

Redacted trace, hidden subagent, fix (P = parent, S = subagent):

```text
P +13s sessions_spawn → accepted
P +17s sessions_yield → {"status":"yielded"}
S +22s exec {"yieldMs":120000,"timeoutSeconds":1500} 'cd pr-1 && …loop until ci-status passes…'
S +142s  -> Command still running (session delta-sage:…, pid …), times out in 23m. This run resumes with its result when it exits, silent success included, if you call sessions_yield. If only waiting remains, call sessions_yield now; do not poll it …
S +145s sessions_yield → {"status":"yielded"}
S +263s USER: Exec completed (delta-sa, code 0, 4m1s): … PR openclaw#4241: all 15 checks passed. Summary: build-1-… green
S +266s write pr-1/RESULT.md
S +269s reply: All 15 CI checks on PR openclaw#4241 have passed. … PR openclaw#4241: all 15 checks passed. Summary: build-1-… green
P +270s USER: [Subagent Context] Every subagent in this batch has now settled …
P +279s reply: The subagent says CI on PR openclaw#4241 passed. Its summary line is: PR openclaw#4241: all 15 checks passed …
```

Same scenario, base: the subagent's running result says "Automatic completion wake is unavailable after ending this turn … use poll with a timeout", then 14 `process poll timeout=30000` calls each return `PR openclaw#4241: 4 checks pending, 11 passed … Process still running.` until it exits.

Cron, fix: `exec` → running result with the `sessions_yield` text → `sessions_yield` → `{"status":"yielded"}` → `Exec completed (tender-c, code 0, 4m1s): …` as the next turn of the same run → `ci-status > RESULT.md` → final reply `PR openclaw#4241: all 15 checks passed …`, recorded as the run summary.

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

- `bash-tools.exec-background-followup.test.ts`: a hidden subagent's command resumes it only after `sessions_yield` awaits it (passive notice otherwise; wake turn with `source: "exec"`, `sourceRunId` and the step 2 content when yielded); a yielded cron run resumes in place with the exit text and sends no session event; cron running results carry the `sessions_yield` text.
- `bash-tools.exec-background-followup.test.ts` also keeps the `main` behavior where `sessions_yield` is not callable: a hidden subagent gets manual-collection guidance and no wake promise, and a cron run is told to collect before ending the turn.
- `openclaw-tools.requester-yield.test.ts`: a wake-armed command the run started is a yield claim only when it has a deadline; only an accepted yield arms the resume.
- The two new tests fail on `main`, where the resume path does not exist; the updated cron assertions also fail there. The exec/process, descriptions, `sessions_yield` tool, requester yield, embedded runner yield orchestration, cron run lifecycle, model-switch retry and prompt-snapshot suites pass. `tsgo:core` passes.

**Full tier**: `ocx build --dts` on the rebased head (`cace873cdf6c`), then a packed tarball install: tarball integrity, `openclaw --version` (`2026.11.3 (cace873)`) and `gateway --help` pass; the packed `bash-tools.exec-output` chunk carries the new guidance.

**Limits:**

- Claude only, direct tool surface; OpenAI and Code Mode were not measured for this step.
- In one trial per fix arm (a) and (b), the agent waited in turn with a capped `yieldMs` block instead of backgrounding; it made no polls.
- The cron harness has no chat channel, so every run (base and fix) records `completionStatus: failed` for delivery; the run summary is the agent's final reply in both arms.
- Gateway restart mid-wait is out of scope (step 5).

**CI:** rebased onto `main` `d0193c2d8434` (picks up openclaw#199113, which only changed the exec-completion enqueue import; no conflict in the yield/wake path). Focused yield, exec, cron and embedded-runner suites and `tsgo:core` pass on the rebased head. If `checks-ui-e2e (1/2)` fails in `ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` ("preserves tool source in Activity while bounding the visible preview", waiting for `.activity-empty`), that failure is on `main`: openclaw#199168 removed the Activity element, but this test still waits for it. Locally, `pnpm test:ui:e2e ui/src/e2e/chat-cli-history-redaction.e2e.test.ts` fails the same way on `main` `d0193c2d8434` and on this head (1 failed, 1 passed in both). This PR touches no `ui/` file. Other PRs pass that shard because their changed files select only 6 UI test files that do not include this one; this PR's change set selects 19.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 16, 2026
…r a follow-up run (#200046)

## What Problem This Solves

Fixes: a yielded subagent's final reply sometimes never reaches its requester. The child's task stays at `waiting for external continuation; delivery=pending; requester_continuation=pending` after the child wrote its answer.

A paused subagent task continues under a new run id each time an exit wake resumes it (#199283). `adoptPausedSubagentRunForFollowUp` moves the task row, the completion custody and the settle batch to the new run. It did not move the background commands. Each command kept the run that started it as `originRunId`.

When such a command exited after a later run had yielded, the failure was:

1. Its wake carried the retired run as `inputProvenance.runId` (`bash-tools.exec-notify.ts`, `sourceRunId: session.originRunId`).
2. `prepareReplySubagentContinuation` passes that id as `pausedRunId` (`src/auto-reply/reply/agent-runner-subagent.ts:47`).
3. `reactivateCompletedSubagentSession` returns false because the paused row now carries the newer run id (`src/gateway/session-subagent-reactivation.ts:48-52`).
4. The turn runs as a separate follow-up. The task row stays paused (`pauseReason: "sessions_yield"`), and the child's final reply is not tied to the task. Nothing announces it.

The later run also could not yield on those commands: `listYieldAwaitableExecs(runId)` matches `originRunId === runId` (`bash-tools.exec-notify.ts:108-116`), so its `sessions_yield` returned `nothing_pending` or "its exit cannot resume this run", and the model started to poll.

It is intermittent because it needs a command that outlives the run that started it while another wake continues the task first. A child that waits on one command at a time, or that the parent resumes with `sessions_send`, does not hit it.

## Production evidence (read-only, copied state DB)

Child `land_cache_pair` (redacted to the shape):

- Registry row: `runId` = the second run, `generation: 3`, `pauseReason: "sessions_yield"`, `execution.endedAt` set at the second run's yield, `delivery.status: "pending"`, `requesterSettleWake.status: "pending"`.
- Transcript: the second run started a pack-smoke command and yielded. Later wakes carried the starting run ids of earlier runs (`exec` wakes named run 1 three times while run 3+ was current). Every later `sessions_yield` returned `nothing_pending` or the "cannot resume this run" error, the agent polled, and the final reply (`stopReason: stop`) went nowhere. No announce lines exist for the child.

## Why This Change Was Made

- `moveRunningSessionsToRun(previousRunId, nextRunId)` in `bash-process-registry.ts`, the owner of process sessions.
- `replaceSubagentRunAfterSteer` calls it when it replaces a `sessions_yield`-paused row, next to the existing settle-batch remap and controller-input retirement. Ordinary steers and completed-run follow-ups are unchanged.
- Docs: `docs/concepts/subagent-yield-handoff.md`, `docs/plugins/tool-plugins.md` and the `inputProvenance` doc comment now say the wake names the run that owns the command.

No new state, stored row, schema or protocol field. Production delta: +20/-2 lines in `src`, most of it comments.

## Evidence

**Real agent, isolated source Gateway** (`ocx src`, scratch state/port/HOME, `env -i`), Claude Opus through the shared Claude proxy. A UI parent spawns a hidden subagent and yields. The child starts commands A (15 s) and B (50 s) and yields. A's exit continues the task in run 2, which starts C (70 s) and yields. B (started by run 1) then exits while run 2 is the paused run. base = merge base `bef242d04174`, head = this PR.

| Arm | B's wake `runId` | Run 2's next `sessions_yield` | Registry row at end | Parent got the result |
|---|---|---|---|---|
| base | run 1 (retired) | `nothing_pending` (then polls) | `generation=2 pause=sessions_yield delivery=pending wake=pending` | **no** |
| head | run 2 (current) | `yielded` | `generation=4 pause=- delivery=delivered` | **yes** (`subagent_settle`, 9 s after the child's reply) |

A first base trial with C at 110 s delivered by chance: the model polled until C finished, and C's own wake (owned by run 2) continued the task. That is the same intermittency seen in production.

**Unit regression** (`ocx test`, vitest from source): `subagent-registry.test.ts` › "moves the commands of the paused run to the follow-up that continues the task". It fails on base (`listYieldAwaitableExecs(followup)` is `[]`) and passes on head.

**Gates**: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`. `ocx test` on `src/agents/subagents/registry/`, `openclaw-tools.requester-yield`, `bash-tools.exec-background-followup`, `bash-process-registry`: all pass.

**Full tier**: `ocx build --dts` on `d61294e737ef`, then a packed tarball: tarball integrity and the dist import graph pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…r a follow-up run (openclaw#200046)

## What Problem This Solves

Fixes: a yielded subagent's final reply sometimes never reaches its requester. The child's task stays at `waiting for external continuation; delivery=pending; requester_continuation=pending` after the child wrote its answer.

A paused subagent task continues under a new run id each time an exit wake resumes it (openclaw#199283). `adoptPausedSubagentRunForFollowUp` moves the task row, the completion custody and the settle batch to the new run. It did not move the background commands. Each command kept the run that started it as `originRunId`.

When such a command exited after a later run had yielded, the failure was:

1. Its wake carried the retired run as `inputProvenance.runId` (`bash-tools.exec-notify.ts`, `sourceRunId: session.originRunId`).
2. `prepareReplySubagentContinuation` passes that id as `pausedRunId` (`src/auto-reply/reply/agent-runner-subagent.ts:47`).
3. `reactivateCompletedSubagentSession` returns false because the paused row now carries the newer run id (`src/gateway/session-subagent-reactivation.ts:48-52`).
4. The turn runs as a separate follow-up. The task row stays paused (`pauseReason: "sessions_yield"`), and the child's final reply is not tied to the task. Nothing announces it.

The later run also could not yield on those commands: `listYieldAwaitableExecs(runId)` matches `originRunId === runId` (`bash-tools.exec-notify.ts:108-116`), so its `sessions_yield` returned `nothing_pending` or "its exit cannot resume this run", and the model started to poll.

It is intermittent because it needs a command that outlives the run that started it while another wake continues the task first. A child that waits on one command at a time, or that the parent resumes with `sessions_send`, does not hit it.

## Production evidence (read-only, copied state DB)

Child `land_cache_pair` (redacted to the shape):

- Registry row: `runId` = the second run, `generation: 3`, `pauseReason: "sessions_yield"`, `execution.endedAt` set at the second run's yield, `delivery.status: "pending"`, `requesterSettleWake.status: "pending"`.
- Transcript: the second run started a pack-smoke command and yielded. Later wakes carried the starting run ids of earlier runs (`exec` wakes named run 1 three times while run 3+ was current). Every later `sessions_yield` returned `nothing_pending` or the "cannot resume this run" error, the agent polled, and the final reply (`stopReason: stop`) went nowhere. No announce lines exist for the child.

## Why This Change Was Made

- `moveRunningSessionsToRun(previousRunId, nextRunId)` in `bash-process-registry.ts`, the owner of process sessions.
- `replaceSubagentRunAfterSteer` calls it when it replaces a `sessions_yield`-paused row, next to the existing settle-batch remap and controller-input retirement. Ordinary steers and completed-run follow-ups are unchanged.
- Docs: `docs/concepts/subagent-yield-handoff.md`, `docs/plugins/tool-plugins.md` and the `inputProvenance` doc comment now say the wake names the run that owns the command.

No new state, stored row, schema or protocol field. Production delta: +20/-2 lines in `src`, most of it comments.

## Evidence

**Real agent, isolated source Gateway** (`ocx src`, scratch state/port/HOME, `env -i`), Claude Opus through the shared Claude proxy. A UI parent spawns a hidden subagent and yields. The child starts commands A (15 s) and B (50 s) and yields. A's exit continues the task in run 2, which starts C (70 s) and yields. B (started by run 1) then exits while run 2 is the paused run. base = merge base `0f25b0abd8d2`, head = this PR.

| Arm | B's wake `runId` | Run 2's next `sessions_yield` | Registry row at end | Parent got the result |
|---|---|---|---|---|
| base | run 1 (retired) | `nothing_pending` (then polls) | `generation=2 pause=sessions_yield delivery=pending wake=pending` | **no** |
| head | run 2 (current) | `yielded` | `generation=4 pause=- delivery=delivered` | **yes** (`subagent_settle`, 9 s after the child's reply) |

A first base trial with C at 110 s delivered by chance: the model polled until C finished, and C's own wake (owned by run 2) continued the task. That is the same intermittency seen in production.

**Unit regression** (`ocx test`, vitest from source): `subagent-registry.test.ts` › "moves the commands of the paused run to the follow-up that continues the task". It fails on base (`listYieldAwaitableExecs(followup)` is `[]`) and passes on head.

**Gates**: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`. `ocx test` on `src/agents/subagents/registry/`, `openclaw-tools.requester-yield`, `bash-tools.exec-background-followup`, `bash-process-registry`: all pass.

**Full tier**: `ocx build --dts` on `d61294e737ef`, then a packed tarball: tarball integrity and the dist import graph 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 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: M 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