Skip to content

fix(agents): answer Control UI users once after a child finishes - #204098

Merged
obviyus merged 1 commit into
mainfrom
fix/completion-single-visible-reply
Nov 23, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/completion-single-visible-reply

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In a Control UI chat, when a child finished and the parent sent its update with the message tool, the user saw two bubbles: the update, then a second, third-person one ("I sent the user the corrected dates... Still waiting on: ...").

Cause: the requester-settle wake is an inter-session turn. Since #164860, every inter-session internal-sink send was treated as transcript-only. The tool told the model "Recorded reply in the current chat history ... did not deliver it to an external channel", and neither the embedded delivery fact nor the Claude CLI tracker (#170534) counted the send as the turn's answer. A reply was still owed, so the model wrote an epilogue to the inter-session sender, and Control UI showed it as a normal assistant row.

Solution

  • One fact, computed where the message tool is built: an internal-sink send is transcript-only only when the turn is inter-session and the session has an external delivery record (sessionDeliveryChannel(entry), the same record resolveAnnounceOrigin treats as the external binding). It feeds the receipt and the embedded delivery fact (messageDelivery.sourceReplyDelivered).
  • The Claude CLI tracker no longer runs its own inputProvenance.kind !== "inter_session" check. It reads the message tool's messageDelivery.sourceReplyDelivered fact, which it already consumed. The duplicate branch is deleted.
  • The settle-wake instruction for yielded deliverables now says child results are not a message from the user, and the answer goes to the user of the original conversation, addressed to them directly.

The #164860 case stays fixed: a WhatsApp/Telegram DM-scope main session gets delivery.kind = "external" during session init before its first agent turn (src/auto-reply/reply/session.ts), and Control UI turns do not replace an external record (session-delivery.ts, metadata-projection.ts). So a route-less inter-session turn there still gets the transcript-only receipt.

Accepted edge (no code): a session used from both an external chat and the Control UI keeps today's behavior (transcript-only receipt on inter-session turns).

Not changed: later assistant finals after a send are not hidden; the private-completion path and NO_REPLY policy for completion turns are unchanged.

User impact

Control UI users get one message, addressed to them, when a delegated task finishes. External-chat sessions behave as before.

Evidence

  • Regression tests, red on merge base 59b0aec099f5, green on head:
    • message-tool.internal-source-reply.integration.test.ts › "answers a Control UI user from an inter-session result turn": visible receipt and sourceReplyDelivered: true.
    • cli-runner.reliability.test.ts (via cli-runner.reply-completion.test-support.ts) › "ends a Control UI child-result turn at its final message-tool answer": real message tool, CLI run settles as success with one assistant row.
  • The fix(message): agent reports a channel reply as sent when it only reached the transcript #164860 test now seeds an external delivery record and still gets the transcript-only receipt (green on base and head).
  • Importers of every changed source: 47 test files that import a changed source or test-support file: all green (ocx test, vitest-source). pnpm check:changed: typecheck, lint, format and guards pass; the one red is the dead-export scan on scripts/lib/docker-e2e-watchdog.mjs, which this PR does not touch.
  • pnpm prompt:snapshots:check (clean HOME): current.

Control UI E2E: before and after

Proof tier: source (ocx src, pinned Bun fork). Two isolated scratch Gateways (merge base 59b0aec099f5 and head 5505abef8ce2; the later head commit 56262188568a changes only a test fixture type). Real Anthropic model (anthropic/claude-sonnet-4-6), driven through the Control UI in a browser. Embedded OpenClaw runtime.

Steps (same on both sides, fresh dashboard session per trial): one prompt: "Delegate a quick schedule check to a child using sessions_spawn ..., wait with sessions_yield. When it finishes, send me the update with the message tool." The child runs sleep 15 and reports. The requester-settle wake (inter_session, subagent_settle) sends a targetless message with final: true.

Receipt on the settle wake (3/3) Visible settle bubbles per trial
Before (merge base) Recorded reply in the current chat history via internal-ui. This send did not deliver it to an external channel. 1, 2, 1 (the other two ended with hidden NO_REPLY)
After (this PR) Sent visible reply to the current source conversation via internal-ui. 1, 1, 1 (no later model message in the settle run)

The duplicate on the base (trial 2) was a second model response in the same settle run: "Done! The child subagent finished its sleep 15 and reported back. Here's the summary it delivered: ..." No empty-response or incomplete-turn errors on either side.

Gaps:

  • Claude CLI runtime: real CLI runs worked on both sides, but in this scratch setup the settle-wake message tool did not receive inter-session provenance on the base either (base receipt was already "Sent visible ..."), so the live CLI runs did not reach the changed condition. The CLI path is covered by the regression test that drives the real CLI runner and the real message tool (cli-runner.reliability.test.ts, red on base, green on head).
  • The sessions_send-to-a-kept-child variant was not run; the spawn + yield variant reaches the same settle wake.
  • The model's wording varied; the head reply was a direct update to the user in each trial.

Before: update plus a second Done! bubble
After: one update

Diff: production +9 / −14 (one fact, one deleted tracker branch, one prompt line, one comment).

Treat an inter-session internal-sink send as transcript-only only when the session has an external delivery record, so a Control UI parent's final message-tool update ends its turn instead of owing a third-person epilogue. The CLI tracker now reads the message tool's own delivery fact. The settle wake tells the parent to address the user directly.

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

clawsweeper Bot commented Nov 23, 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 agents Agent runtime and tooling size: S labels Nov 23, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Count final internal replies in Control UI completion turns as delivered answers and tell the parent to address the original user directly.

Example: A child finishes in Control UI session agent:main:dashboard:settle, and the parent sends “Your dates are corrected.” with final=true.

  • Before: The send is classified as transcript-only, leaving an answer owed and allowing a second, third-person reply.
  • After: The send carries the source-reply-delivered fact, allowing the existing completion machinery to finish the turn.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation appears correct, but required proof of the changed behavior through the shipped entry point is not yet supplied.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A parent’s update after child completion can be followed by an unnecessary, third-person assistant reply in Control UI.
Reason: The maintainer-authored change restores the existing single-answer contract without adding configuration or another delivery owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a source-verifiable reply-completion bug still present on main, and no definite introduced code defect was found.

Priority: P2
Reviewed head: 56262188568a8715fb6e2166f561ab8c0c61dafc

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Attach the promised real Gateway/Claude CLI Control UI comparison showing child completion produces one directly addressed answer, using screenshots, recording, or redacted logs with IPs, API keys, phone numbers, and non-public endpoints removed.
Agent review details

How this fits together

Child completion events resume the parent agent; its message tool records the reply and publishes delivery facts consumed by embedded and CLI completion handling.

flowchart TD
  A[Child completion] --> B[Parent settle turn]
  B --> C[Message tool]
  D[Session delivery record] --> C
  C --> E[Internal reply sink]
  E --> F[Control UI chat]
  C --> G[Delivery fact]
  G --> H[Runner completion]
Loading

Technical review

Best possible solution:

Use the message tool’s canonical delivery fact to complete Control UI replies while preserving transcript-only handling for externally bound sessions.

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

Current main excludes all inter-session internal-source sends from completion, and the added regressions target the resulting Control UI classification and settlement failures; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is a small, coherent repair using the existing session delivery record and message-tool delivery owner, with separate tests for classification and CLI consumption.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Transcript-only internal-source receipts changes intended behavior with a stated reason (3350e4f: Prevent agents from claiming external delivery when a route-less inter-session send only reached chat history.)
  • CLI final internal-source reply credit keeps the original intent (a2fd4c5: A final WebChat message-tool answer followed by NO_REPLY must count as answered without replaying the send.)
  • Inter-session result requirement changes intended behavior with a stated reason (bd5f760: Internal result-required turns must return a meaningful result; silence and progress alone do not prove completion.)
  • Yielded requester completion guidance keeps the original intent (4f0541e: Resume delegated work under the original conversation’s reply rules without hiding unfinished work or repeating delivered updates.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -5, Tests +123. Total +118 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 10 15 -5
Tests 2 147 24 +123
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 157 39 +118

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +10/-15; tests +147/-24 Production shrinks by removing duplicate classification; test growth covers distinct delivery-classification and CLI-settlement failures.

Labels

Label changes:

  • add P2: Duplicate, misaddressed completion replies create user confusion in delegated Control UI work without establishing a blocked core workflow.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Duplicate, misaddressed completion replies create user confusion in delegated Control UI work without establishing a blocked core workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 23, 2026, 9:57 AM ET / 14:57 UTC.

@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Control UI E2E: before and after

Proof tier: source (ocx src, pinned Bun fork). Two isolated scratch Gateways (merge base 59b0aec099f5 and head 5505abef8ce2; the later head commit 56262188568a changes only a test fixture type). Real Anthropic model (anthropic/claude-sonnet-4-6), driven through the Control UI in a browser. Embedded OpenClaw runtime.

Steps (same on both sides, fresh dashboard session per trial): one prompt: "Delegate a quick schedule check to a child using sessions_spawn ..., wait with sessions_yield. When it finishes, send me the update with the message tool." The child runs sleep 15 and reports. The requester-settle wake (inter_session, subagent_settle) sends a targetless message with final: true.

Receipt on the settle wake (3/3) Visible settle bubbles per trial
Before (merge base) Recorded reply in the current chat history via internal-ui. This send did not deliver it to an external channel. 1, 2, 1 (the other two ended with hidden NO_REPLY)
After (this PR) Sent visible reply to the current source conversation via internal-ui. 1, 1, 1 (no later model message in the settle run)

The duplicate on the base (trial 2) was a second model response in the same settle run: "Done! The child subagent finished its sleep 15 and reported back. Here's the summary it delivered: ..." No empty-response or incomplete-turn errors on either side.

Gaps:

  • Claude CLI runtime: real CLI runs worked on both sides, but in this scratch setup the settle-wake message tool did not receive inter-session provenance on the base either (base receipt was already "Sent visible ..."), so the live CLI runs did not reach the changed condition. The CLI path is covered by the regression test that drives the real CLI runner and the real message tool (cli-runner.reliability.test.ts, red on base, green on head).
  • The sessions_send-to-a-kept-child variant was not run; the spawn + yield variant reaches the same settle wake.
  • The model's wording varied; the head reply was a direct update to the user in each trial.

Before: update plus a second Done! bubble

After: one update

@obviyus
obviyus merged commit a9c1dd8 into main Nov 23, 2026
159 checks passed
@obviyus
obviyus deleted the fix/completion-single-visible-reply branch November 23, 2026 15:18
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in a9c1dd8. Control UI parents now send one update, addressed to the user, when a child finishes. An inter-session message send counts as transcript-only only when the session is bound to an external chat. Proof: regression tests for the message tool and the Claude CLI runner fail on the merge base and pass on the head. Control UI E2E on the embedded runtime: the base showed a duplicate bubble in 1 of 3 trials and the transcript-only receipt in 3 of 3. The head showed one bubble and the visible receipt in 3 of 3.

tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…203176)

## Problem

A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

## Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once.

- **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
- **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished.
- **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
- **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
- **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
- **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
- **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
- **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
- `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate.
- Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`.

Product decisions, under the rules "no stranded user" and "no false done":
- A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
- A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

## Evidence

**Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.
- Base `eb7ca3d33375`: both cases red (`expected [] to have a length of 1`: no wake).
- Head: both cases green.

**Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once).

**Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child).

**Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields.

| | alpha ended | first parent wake | beta yielded | beta ended | second parent wake |
|---|---|---|---|---|---|
| base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none |
| head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) |

The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change.

**Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `eb7ca3d33375` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

**Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

## Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

## Accepted edge cases

- If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
- A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

## Merge danger

- **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
- **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

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

(cherry picked from commit 09d956b)

Release adaptation: Kept stable QA Gateway fixture lifecycle; filtered intentionally silent partial-result wakes.

Companion audit: #203222 selected. #204249, #204069, #204048, #203892, #202513, #198960 not applicable (refactors/test cleanup); #204260, #204178, #204098, #204089, #203839, #203271 missing in lane and not prerequisites.

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

## Problem

In a Control UI chat, when a child finished and the parent sent its update with the `message` tool, the user saw two bubbles: the update, then a second, third-person one ("I sent the user the corrected dates... Still waiting on: ...").

Cause: the requester-settle wake is an inter-session turn. Since openclaw#164860, every inter-session internal-sink send was treated as transcript-only. The tool told the model "Recorded reply in the current chat history ... did not deliver it to an external channel", and neither the embedded delivery fact nor the Claude CLI tracker (openclaw#170534) counted the send as the turn's answer. A reply was still owed, so the model wrote an epilogue to the inter-session sender, and Control UI showed it as a normal assistant row.

## Solution

- One fact, computed where the message tool is built: an internal-sink send is transcript-only only when the turn is inter-session **and** the session has an external delivery record (`sessionDeliveryChannel(entry)`, the same record `resolveAnnounceOrigin` treats as the external binding). It feeds the receipt and the embedded delivery fact (`messageDelivery.sourceReplyDelivered`).
- The Claude CLI tracker no longer runs its own `inputProvenance.kind !== "inter_session"` check. It reads the message tool's `messageDelivery.sourceReplyDelivered` fact, which it already consumed. The duplicate branch is deleted.
- The settle-wake instruction for yielded deliverables now says child results are not a message from the user, and the answer goes to the user of the original conversation, addressed to them directly.

The openclaw#164860 case stays fixed: a WhatsApp/Telegram DM-scope main session gets `delivery.kind = "external"` during session init before its first agent turn (`src/auto-reply/reply/session.ts`), and Control UI turns do not replace an external record (`session-delivery.ts`, `metadata-projection.ts`). So a route-less inter-session turn there still gets the transcript-only receipt.

Accepted edge (no code): a session used from both an external chat and the Control UI keeps today's behavior (transcript-only receipt on inter-session turns).

Not changed: later assistant finals after a send are not hidden; the private-completion path and NO_REPLY policy for completion turns are unchanged.

## User impact

Control UI users get one message, addressed to them, when a delegated task finishes. External-chat sessions behave as before.

## Evidence

- Regression tests, red on merge base `43bef4fbcc7d`, green on head:
  - `message-tool.internal-source-reply.integration.test.ts` › "answers a Control UI user from an inter-session result turn": visible receipt and `sourceReplyDelivered: true`.
  - `cli-runner.reliability.test.ts` (via `cli-runner.reply-completion.test-support.ts`) › "ends a Control UI child-result turn at its final message-tool answer": real message tool, CLI run settles as success with one assistant row.
- The openclaw#164860 test now seeds an external delivery record and still gets the transcript-only receipt (green on base and head).
- Importers of every changed source: 47 test files that import a changed source or test-support file: all green (`ocx test`, vitest-source). `pnpm check:changed`: typecheck, lint, format and guards pass; the one red is the dead-export scan on `scripts/lib/docker-e2e-watchdog.mjs`, which this PR does not touch.
- `pnpm prompt:snapshots:check` (clean HOME): current.

### Control UI E2E: before and after

**Proof tier:** source (`ocx src`, pinned Bun fork). Two isolated scratch Gateways (merge base `43bef4fbcc7d` and head `5505abef8ce2`; the later head commit `56262188568a` changes only a test fixture type). Real Anthropic model (`anthropic/claude-sonnet-4-6`), driven through the Control UI in a browser. Embedded OpenClaw runtime.

**Steps (same on both sides, fresh dashboard session per trial):** one prompt: "Delegate a quick schedule check to a child using sessions_spawn ..., wait with sessions_yield. When it finishes, send me the update with the message tool." The child runs `sleep 15` and reports. The requester-settle wake (`inter_session`, `subagent_settle`) sends a targetless `message` with `final: true`.

| | Receipt on the settle wake (3/3) | Visible settle bubbles per trial |
|---|---|---|
| Before (merge base) | `Recorded reply in the current chat history via internal-ui. This send did not deliver it to an external channel.` | 1, **2**, 1 (the other two ended with hidden `NO_REPLY`) |
| After (this PR) | `Sent visible reply to the current source conversation via internal-ui.` | 1, 1, 1 (no later model message in the settle run) |

The duplicate on the base (trial 2) was a second model response in the same settle run: "Done! The child subagent finished its `sleep 15` and reported back. Here's the summary it delivered: ..." No empty-response or incomplete-turn errors on either side.

**Gaps:**
- Claude CLI runtime: real CLI runs worked on both sides, but in this scratch setup the settle-wake message tool did not receive inter-session provenance on the base either (base receipt was already "Sent visible ..."), so the live CLI runs did not reach the changed condition. The CLI path is covered by the regression test that drives the real CLI runner and the real message tool (`cli-runner.reliability.test.ts`, red on base, green on head).
- The `sessions_send`-to-a-kept-child variant was not run; the spawn + yield variant reaches the same settle wake.
- The model's wording varied; the head reply was a direct update to the user in each trial.

![Before: update plus a second Done! bubble](https://github.com/user-attachments/assets/50eb26e5-7db7-4a05-8655-e4ab5b81cf25)
![After: one update](https://github.com/user-attachments/assets/68ce9fb8-9ca8-40a6-86f6-f722e69b4710)

Diff: production +9 / −14 (one fact, one deleted tracker branch, one prompt line, one comment).

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…n its own part (#203174)

Root cause: src/shared/assistant-answer-text.ts:24 picks only text blocks that carry a signature as the answer, which is meant for OpenAI Responses item ids. Since #170534 (first shipped in 2026.11.5) it also picks empty signed blocks. Gemini 3 sends its thought signature on a separate empty part after the answer, so the selected answer is `""`, the turn is marked empty rather than silent, and the `NO_REPLY` text is delivered.

Fixes #203131

Thanks @Avi711 for the clear report and trace.

## What Problem This Solves

With Gemini 3 on a `google-generative-ai` provider, a reply of exactly `NO_REPLY` reaches the chat as the text "NO_REPLY" instead of ending the turn silently. It happens in direct chats and in automations that announce their result. 2026.8.2 stayed silent.

## User Impact

Gemini 3 replies of exactly `NO_REPLY` end the turn silently again, in direct chats and in announced automations. Normal Gemini answers are delivered as before.

## Why This Change Was Made

Signed-block selection now applies only to OpenAI Responses messages, where a text signature is an output item id. A Gemini thought signature is not an item id, so Gemini answers use all of their text blocks.

The Google stream reader still keeps the signature-only part as its own block. That keeps the next request byte-identical: the signature is replayed as its own empty part, as Gemini sent it. Attaching the signature to the previous text block would change those replayed bytes. Responses answer selection is unchanged.

## Evidence

Real Gateway (`ocx src`, isolated profile state) with the QA channel recording deliveries and a local `google-generative-ai` fixture that streams `{"text":"NO_REPLY"}` and then `{"text":"","thoughtSignature":"..."}`. Base is the merge base 423ae09.

| Check | Base | This PR |
|---|---|---|
| Direct chat, exact `NO_REPLY` | "NO_REPLY" delivered | nothing delivered |
| Announced automation, exact `NO_REPLY` | "NO_REPLY" delivered (`deliveryStatus: delivered`) | nothing delivered (`not-delivered`) |
| Normal answer with trailing signature part, 2 turns | delivered once per turn | delivered once per turn |
| Next request replays the signature | `[{"text":"Here is…"},{"text":"","thoughtSignature":"Q2lN…Sw=="}]` | identical bytes |

The new regression test fails on base (`disposition: 'empty'`, expected `'silent'`) and passes here; its OpenAI Responses row (signed empty item still wins) passes on both.

Observed proof lines: #203174 (comment)

Merge danger: two-way door. No stored state, config or published contract changes; a revert fully restores the old behavior. Blast radius: answer text selection for non-Responses messages that carry text signatures (Google Gemini), which now use all of their text blocks.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit fcfb114)

Follow-ups: e58ca10 fix: preserve runtime custody, inference history, and recovery (#203901) [not selected for this narrow backport]; 44f7c52 fix: keep automations silent when the model closes its reasoning before NO_REPLY (#203432) [not selected for this narrow backport]; 6c2ff33 fix(cron): optional-silent cron run fails after the agent collects its collector child's result (#164949) [not selected for this narrow backport]; a9c1dd8 fix(agents): answer Control UI users once after a child finishes (#204098) [separately ordered lane row]

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

## Problem

In a Control UI chat, when a child finished and the parent sent its update with the `message` tool, the user saw two bubbles: the update, then a second, third-person one ("I sent the user the corrected dates... Still waiting on: ...").

Cause: the requester-settle wake is an inter-session turn. Since #164860, every inter-session internal-sink send was treated as transcript-only. The tool told the model "Recorded reply in the current chat history ... did not deliver it to an external channel", and neither the embedded delivery fact nor the Claude CLI tracker (#170534) counted the send as the turn's answer. A reply was still owed, so the model wrote an epilogue to the inter-session sender, and Control UI showed it as a normal assistant row.

## Solution

- One fact, computed where the message tool is built: an internal-sink send is transcript-only only when the turn is inter-session **and** the session has an external delivery record (`sessionDeliveryChannel(entry)`, the same record `resolveAnnounceOrigin` treats as the external binding). It feeds the receipt and the embedded delivery fact (`messageDelivery.sourceReplyDelivered`).
- The Claude CLI tracker no longer runs its own `inputProvenance.kind !== "inter_session"` check. It reads the message tool's `messageDelivery.sourceReplyDelivered` fact, which it already consumed. The duplicate branch is deleted.
- The settle-wake instruction for yielded deliverables now says child results are not a message from the user, and the answer goes to the user of the original conversation, addressed to them directly.

The #164860 case stays fixed: a WhatsApp/Telegram DM-scope main session gets `delivery.kind = "external"` during session init before its first agent turn (`src/auto-reply/reply/session.ts`), and Control UI turns do not replace an external record (`session-delivery.ts`, `metadata-projection.ts`). So a route-less inter-session turn there still gets the transcript-only receipt.

Accepted edge (no code): a session used from both an external chat and the Control UI keeps today's behavior (transcript-only receipt on inter-session turns).

Not changed: later assistant finals after a send are not hidden; the private-completion path and NO_REPLY policy for completion turns are unchanged.

## User impact

Control UI users get one message, addressed to them, when a delegated task finishes. External-chat sessions behave as before.

## Evidence

- Regression tests, red on merge base `59b0aec099f5`, green on head:
  - `message-tool.internal-source-reply.integration.test.ts` › "answers a Control UI user from an inter-session result turn": visible receipt and `sourceReplyDelivered: true`.
  - `cli-runner.reliability.test.ts` (via `cli-runner.reply-completion.test-support.ts`) › "ends a Control UI child-result turn at its final message-tool answer": real message tool, CLI run settles as success with one assistant row.
- The #164860 test now seeds an external delivery record and still gets the transcript-only receipt (green on base and head).
- Importers of every changed source: 47 test files that import a changed source or test-support file: all green (`ocx test`, vitest-source). `pnpm check:changed`: typecheck, lint, format and guards pass; the one red is the dead-export scan on `scripts/lib/docker-e2e-watchdog.mjs`, which this PR does not touch.
- `pnpm prompt:snapshots:check` (clean HOME): current.

### Control UI E2E: before and after

**Proof tier:** source (`ocx src`, pinned Bun fork). Two isolated scratch Gateways (merge base `59b0aec099f5` and head `5505abef8ce2`; the later head commit `56262188568a` changes only a test fixture type). Real Anthropic model (`anthropic/claude-sonnet-4-6`), driven through the Control UI in a browser. Embedded OpenClaw runtime.

**Steps (same on both sides, fresh dashboard session per trial):** one prompt: "Delegate a quick schedule check to a child using sessions_spawn ..., wait with sessions_yield. When it finishes, send me the update with the message tool." The child runs `sleep 15` and reports. The requester-settle wake (`inter_session`, `subagent_settle`) sends a targetless `message` with `final: true`.

| | Receipt on the settle wake (3/3) | Visible settle bubbles per trial |
|---|---|---|
| Before (merge base) | `Recorded reply in the current chat history via internal-ui. This send did not deliver it to an external channel.` | 1, **2**, 1 (the other two ended with hidden `NO_REPLY`) |
| After (this PR) | `Sent visible reply to the current source conversation via internal-ui.` | 1, 1, 1 (no later model message in the settle run) |

The duplicate on the base (trial 2) was a second model response in the same settle run: "Done! The child subagent finished its `sleep 15` and reported back. Here's the summary it delivered: ..." No empty-response or incomplete-turn errors on either side.

**Gaps:**
- Claude CLI runtime: real CLI runs worked on both sides, but in this scratch setup the settle-wake message tool did not receive inter-session provenance on the base either (base receipt was already "Sent visible ..."), so the live CLI runs did not reach the changed condition. The CLI path is covered by the regression test that drives the real CLI runner and the real message tool (`cli-runner.reliability.test.ts`, red on base, green on head).
- The `sessions_send`-to-a-kept-child variant was not run; the spawn + yield variant reaches the same settle wake.
- The model's wording varied; the head reply was a direct update to the user in each trial.

![Before: update plus a second Done! bubble](https://github.com/user-attachments/assets/50eb26e5-7db7-4a05-8655-e4ab5b81cf25)
![After: one update](https://github.com/user-attachments/assets/68ce9fb8-9ca8-40a6-86f6-f722e69b4710)

Diff: production +9 / −14 (one fact, one deleted tracker branch, one prompt line, one comment).

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit a9c1dd8)

Follow-ups: cded11f fix(agents): deliver a child's end state as parent history, not a turn obligation (#204178) [not selected for this narrow backport]

Co-authored-by: RomneyDa <[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 P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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