Skip to content

fix(agents): keep a yielded subagent's command wakes on its task after a follow-up run - #200046

Merged
obviyus merged 1 commit into
mainfrom
fix/subagent-wake-completion
Nov 16, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/subagent-wake-completion

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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.

…r a follow-up run

A paused subagent task continues under a new run id each time an exit wake
resumes it. The commands that the earlier run started kept that run as their
owner. When one of them exited after a later run had yielded, its wake named
the retired run, so reply admission did not continue the task. The turn ran
as a separate follow-up, the task row stayed paused, and the child's final
reply never reached its requester. The later run also could not yield on
those commands ("its exit cannot resume this run").

Adoption of a paused row now moves the running commands of the retired run
to the new run, the same way it remaps the settle batch.

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

clawsweeper Bot commented Nov 16, 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 16, 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR transfers running commands to the successor run when a follow-up continues a yielded subagent task.

Example: A child starts A for 15 seconds and B for 50 seconds; A resumes it as run 2, which starts C for 70 seconds and yields.

  • Before: B's exit names retired run 1, leaving the task paused and its final reply undelivered.
  • After: B's exit names run 2, continues the task, and allows the final reply to reach the parent.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with supplied real-Gateway before/after results, a meaningful regression test, and green exact-head checks.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied isolated real-agent Gateway comparison exercises overlapping background exits through task adoption and records successor-run provenance, successful yield, delivered registry state, and parent receipt on the fix.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A yielded subagent can write its final answer while its requester remains waiting indefinitely.
Reason: The reported production failure is explained by current source, and the maintainer-authored patch restores the existing continuation contract with a narrow ownership transfer.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a current task-continuation defect, and no blocking code findings remain.

Priority: P1
Reviewed head: d61294e737efcce96e9c8d15ed5c1a16c9bd7c0c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The process registry tracks background commands; subagent adoption transfers task ownership, and exec completion provenance tells reply admission which paused task to continue.

flowchart TD
  A[Child starts background commands] --> B[Child yields]
  B --> C[First exit resumes child]
  C --> D[Registry adopts successor run]
  D --> E[Running commands transfer ownership]
  E --> F[Later exit names successor]
  F --> G[Task resumes and parent receives result]
Loading

Technical review

Best possible solution:

Keep running-command ownership aligned with the adopted task through the existing process registry operation at committed task handoff.

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

The overlapping-command sequence has a clear source-level failure path and supplied base/head Gateway results; this read-only review did not independently execute it.

Is this the best way to solve the issue?

The patch repairs the stale ownership value at its existing owner, preserves the paused-task admission check, and adds one focused adoption regression without new state or competing delivery paths.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exec completion provenance changes intended behavior with a stated reason (f6ee991: Allow plugins to correlate command completion with its originating run without granting owner authority.)
  • One-shot exec yield continuation keeps the original intent (1fff14f: Resume hidden subagents and cron runs on awaited command exits instead of requiring polling.)
  • Paused subagent adoption keeps the original intent (fix(agents): plugin follow-up admitted during a sub-agent's yield never reaches the requester #164101: Keep requester completion custody attached to the follow-up that continues the paused task.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 1fff14f adds docs/concepts/subagent-yield-handoff.md:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1fff14f6019c; files: docs/concepts/subagent-yield-handoff.md)

PR surface

Source +18, Tests +51, Docs +4. Total +73 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 20 2 +18
Tests 1 51 0 +51
Docs 2 9 5 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 80 7 +73

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 P1: The observed failure silently strands a delegated task and prevents its requester from receiving the final answer.
  • add merge-risk: 🚨 compatibility: Plugin-visible exec provenance follows the successor run after paused-task adoption; this scoped correlation change is explicitly documented and accepted by the maintainer-authored direction.
  • 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 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The observed failure silently strands a delegated task and prevents its requester from receiving the final answer.
  • merge-risk: 🚨 compatibility: Plugin-visible exec provenance follows the successor run after paused-task adoption; this scoped correlation change is explicitly documented and accepted by the maintainer-authored direction.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 4:34 AM ET / 09:34 UTC.

@obviyus
obviyus merged commit 317f065 into main Nov 16, 2026
142 checks passed
@obviyus
obviyus deleted the fix/subagent-wake-completion branch November 16, 2026 09:36
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 317f065.

  • Bug: a paused subagent task continues under a new run id, but its running commands kept the old run id. A later exit wake named the retired run, so the task was not continued and the final reply never reached the requester.
  • Fix: adoption of a paused row moves the running commands of the old run to the new run.
  • Proof: real-route source Gateway E2E, base vs head (base: parent never got the result; head: delivered via subagent_settle), plus a unit regression that fails on base.

obviyus added a commit that referenced this pull request Nov 16, 2026
…#200097)

## What Problem This Solves

Background commands, `sessions_yield` waits and exec-exit wakes were owned by the run that started them. A run id names one attempt, and a chat gets a new one on every turn. So every follow-up run lost the commands of the earlier runs:

- A later turn could not yield on a command that an earlier turn started. `listYieldAwaitableExecs(runId)` matched `originRunId === runId`, so `sessions_yield` returned `nothing_pending` and the model started to poll.
- A paused subagent task continued only when the wake named the paused run. #200046 patched one caller of this: it moved the running commands to the new run (`moveRunningSessionsToRun`).
- Child completions compared the captured requester session id and lifecycle revision. After a reset or a compaction successor, a private completion was withheld with "Subagent results from the previous session were not delivered".

## Why This Change Was Made

The bug class is "address work by an id that changes". The chat's session key is the only id that survives edits, resets, compaction and follow-up runs. This PR makes the key the owner:

- `listYieldAwaitableExecs`, `awaitExecsForYield` and `openExecYieldResume` are keyed by the chat: agent id plus session key, so a raw shared key such as `global` stays separate per agent. A yield awaits every wake-armed command of the chat, including commands from earlier runs.
- Reply admission continues the task that is paused in the chat, whichever run paused it (`continuesPausedTask` replaces `pausedRunId`).
- Child and harness completions, and the failure notice of a required completion, go to the requester chat as it is now. The reads of `completionRequesterSessionId` / `LifecycleRevision`, the settle-receipt exact compare, the collector and `agents_wait` incarnation filters, and the reset replacement notice are deleted.
- Deleted: `ProcessSession.originRunId`, `moveRunningSessionsToRun` (the #200046 patch), `matchesSubagentRequesterSession`, `recordRequesterReplacementNotice`, `listCollectorRunsForRequesterIncarnation` (now `listCollectorRunsForRequester`).
- Kept as a fact only: an exec wake still names the starting run in `inputProvenance.runId` (`ProcessSession.startedByRunId`), because plugins use it (#179816). It routes nothing.
- The requester id fields are still written for one release, so a downgrade keeps working. No schema, stored-row or protocol change.

Production delta: −227 lines in `src` (+127 / −354); whole PR −427.

## User Impact

- A chat can start a background command in one turn and wait for it with `sessions_yield` in a later turn. The exit continues the chat.
- A yielded subagent always continues its paused task when one of its commands exits, also after a follow-up run.
- A subagent result reaches the parent chat after `/new` or compaction instead of being withheld.

## Evidence

Real agent on an isolated source Gateway (`ocx src`, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge base `96ad377596ca`, head = this PR.

| Journey | base | head |
|---|---|---|
| J1: #200046 incident (paused child, A's exit continues the task in run 2, then B, started by run 1, exits) | parent got `child-final` (with the #200046 patch) | parent got `child-final` (patch deleted); registry `generation=4 delivery=delivered` |
| J2: run 1 starts a background command; run 2 calls `sessions_yield` | `{"status":"nothing_pending"}` | `{"status":"yielded"}`; the exit wakes the chat, which replies `j2-woke` |
| J3: parent spawns a child and does not yield | ordinary completion (`subagent_announce`) | ordinary completion (`subagent_announce`) |
| J1 parent side: parent yields on its child | private completion (`subagent_settle`) | private completion (`subagent_settle`) |

Head arms ran on the production code of `3793f6d`; later commits change only tests, docs and the failure-notice path of a required completion, which unit tests cover.

A `/new` while the parent is yielded on a running child interrupts the child on both arms, so that journey does not separate them and is not a claim of this PR.

Unit: `openclaw-tools.requester-yield.test.ts` now awaits a command with no starting run (fails on base). The delivery tests assert that a private completion reaches a replacement parent session.

Gates: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`, `ocx test` on `src/agents/subagents/`, requester-yield, exec background and notify suites, agents_wait, harness completion, session reactivation and adoption, `src/cron/isolated-agent`. Build, full suites and cross-OS checks: hosted CI on this head. `src/gateway/server-startup-post-attach.test.ts` fails the same way on the merge base `059db8a`; this PR does not touch it.

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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…openclaw#200097)

## What Problem This Solves

Background commands, `sessions_yield` waits and exec-exit wakes were owned by the run that started them. A run id names one attempt, and a chat gets a new one on every turn. So every follow-up run lost the commands of the earlier runs:

- A later turn could not yield on a command that an earlier turn started. `listYieldAwaitableExecs(runId)` matched `originRunId === runId`, so `sessions_yield` returned `nothing_pending` and the model started to poll.
- A paused subagent task continued only when the wake named the paused run. openclaw#200046 patched one caller of this: it moved the running commands to the new run (`moveRunningSessionsToRun`).
- Child completions compared the captured requester session id and lifecycle revision. After a reset or a compaction successor, a private completion was withheld with "Subagent results from the previous session were not delivered".

## Why This Change Was Made

The bug class is "address work by an id that changes". The chat's session key is the only id that survives edits, resets, compaction and follow-up runs. This PR makes the key the owner:

- `listYieldAwaitableExecs`, `awaitExecsForYield` and `openExecYieldResume` are keyed by the chat: agent id plus session key, so a raw shared key such as `global` stays separate per agent. A yield awaits every wake-armed command of the chat, including commands from earlier runs.
- Reply admission continues the task that is paused in the chat, whichever run paused it (`continuesPausedTask` replaces `pausedRunId`).
- Child and harness completions, and the failure notice of a required completion, go to the requester chat as it is now. The reads of `completionRequesterSessionId` / `LifecycleRevision`, the settle-receipt exact compare, the collector and `agents_wait` incarnation filters, and the reset replacement notice are deleted.
- Deleted: `ProcessSession.originRunId`, `moveRunningSessionsToRun` (the openclaw#200046 patch), `matchesSubagentRequesterSession`, `recordRequesterReplacementNotice`, `listCollectorRunsForRequesterIncarnation` (now `listCollectorRunsForRequester`).
- Kept as a fact only: an exec wake still names the starting run in `inputProvenance.runId` (`ProcessSession.startedByRunId`), because plugins use it (openclaw#179816). It routes nothing.
- The requester id fields are still written for one release, so a downgrade keeps working. No schema, stored-row or protocol change.

Production delta: −227 lines in `src` (+127 / −354); whole PR −427.

## User Impact

- A chat can start a background command in one turn and wait for it with `sessions_yield` in a later turn. The exit continues the chat.
- A yielded subagent always continues its paused task when one of its commands exits, also after a follow-up run.
- A subagent result reaches the parent chat after `/new` or compaction instead of being withheld.

## Evidence

Real agent on an isolated source Gateway (`ocx src`, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge base `2baaa3c275a3`, head = this PR.

| Journey | base | head |
|---|---|---|
| J1: openclaw#200046 incident (paused child, A's exit continues the task in run 2, then B, started by run 1, exits) | parent got `child-final` (with the openclaw#200046 patch) | parent got `child-final` (patch deleted); registry `generation=4 delivery=delivered` |
| J2: run 1 starts a background command; run 2 calls `sessions_yield` | `{"status":"nothing_pending"}` | `{"status":"yielded"}`; the exit wakes the chat, which replies `j2-woke` |
| J3: parent spawns a child and does not yield | ordinary completion (`subagent_announce`) | ordinary completion (`subagent_announce`) |
| J1 parent side: parent yields on its child | private completion (`subagent_settle`) | private completion (`subagent_settle`) |

Head arms ran on the production code of `3793f6d`; later commits change only tests, docs and the failure-notice path of a required completion, which unit tests cover.

A `/new` while the parent is yielded on a running child interrupts the child on both arms, so that journey does not separate them and is not a claim of this PR.

Unit: `openclaw-tools.requester-yield.test.ts` now awaits a command with no starting run (fails on base). The delivery tests assert that a private completion reaches a replacement parent session.

Gates: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`, `ocx test` on `src/agents/subagents/`, requester-yield, exec background and notify suites, agents_wait, harness completion, session reactivation and adoption, `src/cron/isolated-agent`. Build, full suites and cross-OS checks: hosted CI on this head. `src/gateway/server-startup-post-attach.test.ts` fails the same way on the merge base `113d415`; this PR does not touch it.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 29, 2026
)

Root cause: src/auto-reply/reply/session-event-target.ts:156 (base 03cdb2c) captures `deliver` from the producing run only, so a hidden subagent's exec-wake turn keeps the requester's chat route with delivery on, and its reply is posted to that chat.

Fixes #206556
Fixes #206708

Thanks @stealthybear for the report, the fix and the live repro, and @Nocha12 for #206708 and for #206709, whose active-binding exception (thread-bound subagents and persistent ACP sessions keep replying in their own conversation) this PR now carries.

## What Problem This Solves

When an agent hands work to a hidden helper (a subagent) that runs a background command and waits for it, the helper's reply after the command finishes is posted straight to your chat, for example your Telegram DM with the bot. The parent agent also gets that reply and posts its own summary, so you see two messages for one result: first the helper's raw report (sometimes with notes meant only for the parent), then the summary.

## User Impact

A hidden helper's wake reply now reaches only its parent agent, so you see one summary instead of two. The parent still gets the helper's result through its normal finished-task report. Visible spawned sessions keep posting to the chat as before, and thread-bound helpers and persistent ACP sessions bound to their own conversation keep replying in that thread. No setting, schema or migration.

## Why This Change Was Made

The event target capture, which already decides `deliver: false` for private producers, now also sets it when the destination is a hidden subagent (`isSubagentEnvelopeSession` and not `isVisibleSpawnedSession`) with no active conversation binding (`listSessionBindingsBySessionAsync`). Without the binding check a thread-bound subagent would stop replying in its own thread. The capabilities module is loaded lazily in the async capture because a static import formed a runtime import cycle (`subagent-capabilities -> config/sessions -> ... -> session-event-target`).

## Evidence

Live Telegram Test Server DM, real Gateway, Telegram delivery, spawn, exec, yield, wake and announce; only the model is scripted. The DM asks the agent to spawn a hidden helper that runs `exec` in the background, calls `sessions_yield`, and replies a marker when the exit wakes it.

| Build | Helper's raw reply in the DM | Parent got the helper's result | Parent's summary in the DM |
| --- | --- | --- | --- |
| main 73940d3 (2 runs), 03cdb2c (1 run) | yes, every run | yes | yes |
| this PR c428bfa (2 runs) | no | yes | yes |
| `visible: true` control, main and this PR | yes (posts as before) | n/a | n/a |

Thread-bound control: Telegram has no thread-bound spawn (its binding placement is `current`), so the thread case ran on Discord through QA Lab: on this head and on the earlier head without the binding check, `thread: true, mode: "session"` spawns, the child's exec wake runs and it replies. That lane's recorder cannot see SUT-created threads, so the thread message itself is covered by the unit case below, which fails without the binding check (`expected false to be undefined`) and passes with it.

Observed proof lines: #206570 (comment). Local review on c428bfa: no findings. Tests: `session-event-handoff.test.ts` plus the 12 test files that import `session-event-target.ts` pass (151 tests); `check:import-cycles` reports 0 cycles.

Earlier live evidence from @stealthybear (released 2026.11.10, real model on a real Telegram bot):

![Phone screenshots of the bot DM: the release posts HELPER RAW REPORT and PARENT SUMMARY, the fix posts only PARENT SUMMARY](https://raw.githubusercontent.com/stealthybear/openclaw/a9c8ba79ce9f4394d7a0df4f14fcfb46157985fa/real-before-after.png)

Related, separate: #168227, #198204, #200046.

Merge danger: two-way door. A revert restores the duplicate post; nothing is stored, migrated or published. Blast radius: event turns (exec wakes, tool handoff results) of hidden subagent sessions without an active binding; ordinary, visible and bound sessions are unchanged.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
)

Root cause: src/auto-reply/reply/session-event-target.ts:156 (base 03cdb2c) captures `deliver` from the producing run only, so a hidden subagent's exec-wake turn keeps the requester's chat route with delivery on, and its reply is posted to that chat.

Fixes #206556
Fixes #206708

Thanks @stealthybear for the report, the fix and the live repro, and @Nocha12 for #206708 and for #206709, whose active-binding exception (thread-bound subagents and persistent ACP sessions keep replying in their own conversation) this PR now carries.

## What Problem This Solves

When an agent hands work to a hidden helper (a subagent) that runs a background command and waits for it, the helper's reply after the command finishes is posted straight to your chat, for example your Telegram DM with the bot. The parent agent also gets that reply and posts its own summary, so you see two messages for one result: first the helper's raw report (sometimes with notes meant only for the parent), then the summary.

## User Impact

A hidden helper's wake reply now reaches only its parent agent, so you see one summary instead of two. The parent still gets the helper's result through its normal finished-task report. Visible spawned sessions keep posting to the chat as before, and thread-bound helpers and persistent ACP sessions bound to their own conversation keep replying in that thread. No setting, schema or migration.

## Why This Change Was Made

The event target capture, which already decides `deliver: false` for private producers, now also sets it when the destination is a hidden subagent (`isSubagentEnvelopeSession` and not `isVisibleSpawnedSession`) with no active conversation binding (`listSessionBindingsBySessionAsync`). Without the binding check a thread-bound subagent would stop replying in its own thread. The capabilities module is loaded lazily in the async capture because a static import formed a runtime import cycle (`subagent-capabilities -> config/sessions -> ... -> session-event-target`).

## Evidence

Live Telegram Test Server DM, real Gateway, Telegram delivery, spawn, exec, yield, wake and announce; only the model is scripted. The DM asks the agent to spawn a hidden helper that runs `exec` in the background, calls `sessions_yield`, and replies a marker when the exit wakes it.

| Build | Helper's raw reply in the DM | Parent got the helper's result | Parent's summary in the DM |
| --- | --- | --- | --- |
| main 73940d3 (2 runs), 03cdb2c (1 run) | yes, every run | yes | yes |
| this PR c428bfa (2 runs) | no | yes | yes |
| `visible: true` control, main and this PR | yes (posts as before) | n/a | n/a |

Thread-bound control: Telegram has no thread-bound spawn (its binding placement is `current`), so the thread case ran on Discord through QA Lab: on this head and on the earlier head without the binding check, `thread: true, mode: "session"` spawns, the child's exec wake runs and it replies. That lane's recorder cannot see SUT-created threads, so the thread message itself is covered by the unit case below, which fails without the binding check (`expected false to be undefined`) and passes with it.

Observed proof lines: #206570 (comment). Local review on c428bfa: no findings. Tests: `session-event-handoff.test.ts` plus the 12 test files that import `session-event-target.ts` pass (151 tests); `check:import-cycles` reports 0 cycles.

Earlier live evidence from @stealthybear (released 2026.11.10, real model on a real Telegram bot):

![Phone screenshots of the bot DM: the release posts HELPER RAW REPORT and PARENT SUMMARY, the fix posts only PARENT SUMMARY](https://raw.githubusercontent.com/stealthybear/openclaw/a9c8ba79ce9f4394d7a0df4f14fcfb46157985fa/real-before-after.png)

Related, separate: #168227, #198204, #200046.

Merge danger: two-way door. A revert restores the duplicate post; nothing is stored, migrated or published. Blast radius: event turns (exec wakes, tool handoff results) of hidden subagent sessions without an active binding; ordinary, visible and bound sessions are unchanged.

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

Follow-up scan: 34d4f8f improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292); 21786f6 refactor(ui): stop sending 28 additional unused labels to translators (#207982); 9cec330 refactor(workboard): group session tiles without rescanning each column (#207380); 16a2d4b refactor(ui): lowercase log search text only once (#207383). Other hits are not required by this focused beta.2 fix.

(cherry picked from commit 2a428f2)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
)

Root cause: src/auto-reply/reply/session-event-target.ts:156 (base 03cdb2c) captures `deliver` from the producing run only, so a hidden subagent's exec-wake turn keeps the requester's chat route with delivery on, and its reply is posted to that chat.

Fixes #206556
Fixes #206708

Thanks @stealthybear for the report, the fix and the live repro, and @Nocha12 for #206708 and for #206709, whose active-binding exception (thread-bound subagents and persistent ACP sessions keep replying in their own conversation) this PR now carries.

## What Problem This Solves

When an agent hands work to a hidden helper (a subagent) that runs a background command and waits for it, the helper's reply after the command finishes is posted straight to your chat, for example your Telegram DM with the bot. The parent agent also gets that reply and posts its own summary, so you see two messages for one result: first the helper's raw report (sometimes with notes meant only for the parent), then the summary.

## User Impact

A hidden helper's wake reply now reaches only its parent agent, so you see one summary instead of two. The parent still gets the helper's result through its normal finished-task report. Visible spawned sessions keep posting to the chat as before, and thread-bound helpers and persistent ACP sessions bound to their own conversation keep replying in that thread. No setting, schema or migration.

## Why This Change Was Made

The event target capture, which already decides `deliver: false` for private producers, now also sets it when the destination is a hidden subagent (`isSubagentEnvelopeSession` and not `isVisibleSpawnedSession`) with no active conversation binding (`listSessionBindingsBySessionAsync`). Without the binding check a thread-bound subagent would stop replying in its own thread. The capabilities module is loaded lazily in the async capture because a static import formed a runtime import cycle (`subagent-capabilities -> config/sessions -> ... -> session-event-target`).

## Evidence

Live Telegram Test Server DM, real Gateway, Telegram delivery, spawn, exec, yield, wake and announce; only the model is scripted. The DM asks the agent to spawn a hidden helper that runs `exec` in the background, calls `sessions_yield`, and replies a marker when the exit wakes it.

| Build | Helper's raw reply in the DM | Parent got the helper's result | Parent's summary in the DM |
| --- | --- | --- | --- |
| main 73940d3 (2 runs), 03cdb2c (1 run) | yes, every run | yes | yes |
| this PR c428bfa (2 runs) | no | yes | yes |
| `visible: true` control, main and this PR | yes (posts as before) | n/a | n/a |

Thread-bound control: Telegram has no thread-bound spawn (its binding placement is `current`), so the thread case ran on Discord through QA Lab: on this head and on the earlier head without the binding check, `thread: true, mode: "session"` spawns, the child's exec wake runs and it replies. That lane's recorder cannot see SUT-created threads, so the thread message itself is covered by the unit case below, which fails without the binding check (`expected false to be undefined`) and passes with it.

Observed proof lines: #206570 (comment). Local review on c428bfa: no findings. Tests: `session-event-handoff.test.ts` plus the 12 test files that import `session-event-target.ts` pass (151 tests); `check:import-cycles` reports 0 cycles.

Earlier live evidence from @stealthybear (released 2026.11.10, real model on a real Telegram bot):

![Phone screenshots of the bot DM: the release posts HELPER RAW REPORT and PARENT SUMMARY, the fix posts only PARENT SUMMARY](https://raw.githubusercontent.com/stealthybear/openclaw/a9c8ba79ce9f4394d7a0df4f14fcfb46157985fa/real-before-after.png)

Related, separate: #168227, #198204, #200046.

Merge danger: two-way door. A revert restores the duplicate post; nothing is stored, migrated or published. Blast radius: event turns (exec wakes, tool handoff results) of hidden subagent sessions without an active binding; ordinary, visible and bound sessions are unchanged.

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

(cherry picked from commit 2a428f2)

Release adaptation: Suppress only hidden unbound helper events at the stable target capture; honor explicit delivery restrictions, visible sessions, active bindings, and the existing scheduled/requester custody.

Companion audit: PR #206570 uses existing binding and spawn classifiers. Resume the stopped cherry-pick at the stable agent-run registry import anchor without importing main-only authority handlers.

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

Root cause: src/auto-reply/reply/session-event-target.ts:156 (base 7e9542f) captures `deliver` from the producing run only, so a hidden subagent's exec-wake turn keeps the requester's chat route with delivery on, and its reply is posted to that chat.

Fixes openclaw#206556
Fixes openclaw#206708

Thanks @stealthybear for the report, the fix and the live repro, and @Nocha12 for openclaw#206708 and for openclaw#206709, whose active-binding exception (thread-bound subagents and persistent ACP sessions keep replying in their own conversation) this PR now carries.

## What Problem This Solves

When an agent hands work to a hidden helper (a subagent) that runs a background command and waits for it, the helper's reply after the command finishes is posted straight to your chat, for example your Telegram DM with the bot. The parent agent also gets that reply and posts its own summary, so you see two messages for one result: first the helper's raw report (sometimes with notes meant only for the parent), then the summary.

## User Impact

A hidden helper's wake reply now reaches only its parent agent, so you see one summary instead of two. The parent still gets the helper's result through its normal finished-task report. Visible spawned sessions keep posting to the chat as before, and thread-bound helpers and persistent ACP sessions bound to their own conversation keep replying in that thread. No setting, schema or migration.

## Why This Change Was Made

The event target capture, which already decides `deliver: false` for private producers, now also sets it when the destination is a hidden subagent (`isSubagentEnvelopeSession` and not `isVisibleSpawnedSession`) with no active conversation binding (`listSessionBindingsBySessionAsync`). Without the binding check a thread-bound subagent would stop replying in its own thread. The capabilities module is loaded lazily in the async capture because a static import formed a runtime import cycle (`subagent-capabilities -> config/sessions -> ... -> session-event-target`).

## Evidence

Live Telegram Test Server DM, real Gateway, Telegram delivery, spawn, exec, yield, wake and announce; only the model is scripted. The DM asks the agent to spawn a hidden helper that runs `exec` in the background, calls `sessions_yield`, and replies a marker when the exit wakes it.

| Build | Helper's raw reply in the DM | Parent got the helper's result | Parent's summary in the DM |
| --- | --- | --- | --- |
| main 2877834 (2 runs), 7e9542f (1 run) | yes, every run | yes | yes |
| this PR c428bfa (2 runs) | no | yes | yes |
| `visible: true` control, main and this PR | yes (posts as before) | n/a | n/a |

Thread-bound control: Telegram has no thread-bound spawn (its binding placement is `current`), so the thread case ran on Discord through QA Lab: on this head and on the earlier head without the binding check, `thread: true, mode: "session"` spawns, the child's exec wake runs and it replies. That lane's recorder cannot see SUT-created threads, so the thread message itself is covered by the unit case below, which fails without the binding check (`expected false to be undefined`) and passes with it.

Observed proof lines: openclaw#206570 (comment). Local review on c428bfa: no findings. Tests: `session-event-handoff.test.ts` plus the 12 test files that import `session-event-target.ts` pass (151 tests); `check:import-cycles` reports 0 cycles.

Earlier live evidence from @stealthybear (released 2026.11.10, real model on a real Telegram bot):

![Phone screenshots of the bot DM: the release posts HELPER RAW REPORT and PARENT SUMMARY, the fix posts only PARENT SUMMARY](https://raw.githubusercontent.com/stealthybear/openclaw/a9c8ba79ce9f4394d7a0df4f14fcfb46157985fa/real-before-after.png)

Related, separate: openclaw#168227, openclaw#198204, openclaw#200046.

Merge danger: two-way door. A revert restores the duplicate post; nothing is stored, migrated or published. Blast radius: event turns (exec wakes, tool handoff results) of hidden subagent sessions without an active binding; ordinary, visible and bound sessions are unchanged.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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