Skip to content

fix(agents): record a child's message to its parent without a parent turn - #204167

Merged
obviyus merged 3 commits into
mainfrom
fix/child-progress-as-history
Nov 23, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/child-progress-as-history

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a child session calls sessions_send to the parent that spawned it (for example, to report progress), OpenClaw starts a new, hidden parent turn for each message. Each parent turn spends a model call, usually replies back to the child, and marks the parent chat unread although the chat shows nothing new. One child that sent 15 progress updates started 15 hidden parent turns.

Change

A supervised child's sessions_send to its completion owner (the parent that the child's end state reports to: hidden, ACP and visible supervised children) no longer starts a parent turn (mode: "notify" keeps its existing ephemeral next-turn behavior):

  • Parent mid-turn: the message steers into the running turn (the existing active-run injection).
  • Parent idle: the message is appended to the parent's transcript as one model-visible, chat-hidden custom entry (sessions-send-child-message). The parent reads it on its next turn.
  • The child gets status: "accepted" with delivery: { status: "skipped" } at once. It does not wait for a parent reply, because no parent turn runs.
  • Only the child's end state wakes the parent (the existing completion wake).

All other sessions_send uses do not change: parent to child, peers, agentId targets, self-sends, sends to people's sessions, and sends from unsupervised sessions_create sessions to their creator (they have no completion that would wake the creator, so they keep the ordinary recipient turn).

The sessions_send tool description and docs/concepts/session-tool.md now tell a child that a message to its parent is recorded for the parent's next turn and gets no reply. Prompt snapshots are regenerated.

Codex works the same way: inter-agent progress and completion messages use trigger_turn: false and are recorded in history without starting a turn.

Production line delta

+73 / −1 (excludes tests, docs and snapshots). The new code is one function, recordSessionsSendForRequester, which reuses the existing active-run steering and the existing transcript report append. No new tool parameter, config option, state or retry.

Accepted edge case

If the parent is mid-turn but refuses the steer (for example, the running turn does not accept the child's requester authority), the message is appended to the transcript instead. The parent reads it on its next turn. No turn starts.

Review

Local review round 1 found that sessions_create sessions also carry parent lineage but have no completion owner, so their messages to an idle creator would wait with nothing to wake it. Fixed: the history path now keys on completionOwnerSessionKey, and a test proves an unsupervised session's send still starts a creator turn. Round 2 found that mode: "notify" entered the new path before its own handling, and that the tool description did not limit the rule to supervised children. Fixed both: notify is handled first, as before, and the description and docs name supervised children only (prompt snapshots regenerated).

Evidence

  • New tests in src/agents/openclaw-tools.sessions-steering.test-support.ts, through the real sessions_send tool path:
    • a supervised child's send to its parent starts no parent turn (idle, busy). Red on the merge base: a parent agent turn starts and the child gets the parent's reply. Green on this head: idle → one transcript entry and no agent call; busy → one steer and no agent call.
    • an unsupervised session's send to its creator still starts a turn.
    • The existing parent-to-child steering tests in the same file stay green.
  • ocx test on every test file that imports a changed source, plus src/agents/agent-tools.prefix-stability.test.ts: 28 files plus the prefix-stability test, 8 Vitest shards, all passed. After the review fix: openclaw-tools.sessions.test.ts, sessions-send-tool.admission.test.ts, sessions-send-acp-custody.test.ts passed.
  • pnpm check:changed: typecheck, guards, format and prompt-snapshot drift passed; baseline ratchets (session identity, line cap) pass after the review fix. One Knip full-tree finding is in scripts/lib/docker-e2e-watchdog.mjs, a file this PR does not touch.
  • pnpm prompt:snapshots:check with a clean HOME: current.
  • E2E, isolated Gateway from source on a real Claude Sonnet route. The parent spawns a visible child; the child sends the parent 3 progress messages with sessions_send, then replies DONE. Model requests were counted at a logging proxy:
    • Merge base: the parent ran 4 turns after spawning: 3 hidden turns (one per progress message, each told to reply through the message tool) and the completion wake.
    • This change: the parent ran 1 turn after spawning, the completion wake. Its request contained the 3 progress messages once each, before the completion. Its reply: "The child finished. I received these PROGRESS codes from it, in order: 1. PROGRESS-1-… 2. PROGRESS-2-… 3. PROGRESS-3-…"

…turn

A child's sessions_send to the session that spawned it (spawnedBy for hidden children,
parentSessionKey for visible ones) now steers an active parent run or appends one
model-visible, chat-hidden entry to the parent's history. It never starts a parent turn,
so the parent no longer spends a model call, replies back to the child, or goes unread
for nothing. Only the child's end state wakes the parent.

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 docs Improvements or additions to documentation 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. labels Nov 23, 2026

@THE-NAVVV THE-NAVVV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​

Only a supervised child (one whose completion owner is the target) records its
message as parent history. A sessions_create session has lineage but no completion
owner, so nothing would wake its creator; its sends keep the ordinary recipient turn.

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

mode:notify keeps its ephemeral next-turn handling before the parent-history path.
The sessions_send description and docs name supervised children only, since
sessions_create sessions keep ordinary turns to their creator.

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

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • [P2] Preserve explicit send modes before applying passive parent delivery (sessions-send-executor.ts): rejected. The approved change is that a supervised child's sessions_send to its completion parent never starts a parent turn, whatever the mode. Keeping mode: "followup" on the old path restores the hidden parent turn and the reply back to the child, which is the behavior this PR removes; a model would simply pick followup to keep the ping-pong. The child gets its parent's answer through the parent's own later sessions_send to the child or after the child finishes. mode: "steer" to an idle parent now records the message for the parent's next turn instead of refusing; nothing is lost and no turn starts. The tool description says so ("starts no parent turn and gets no reply"). mode: "notify" keeps its own path (round 2 fix).

@obviyus
obviyus merged commit ef48c71 into main Nov 23, 2026
131 of 132 checks passed
@obviyus
obviyus deleted the fix/child-progress-as-history branch November 23, 2026 18:10
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in ef48c71. A supervised child's sessions_send to its parent now joins the parent's running turn or is recorded in its history, and starts no hidden parent turn. Proof: red-on-base/green tool-path tests, and a real-model E2E where three progress messages led to one parent turn (the completion wake) instead of four.

obviyus added a commit that referenced this pull request Nov 23, 2026
…4270)

## Result

The 12 refusal-class test files that turned scheduled run 45259316971 (`cded11f8`) red pass again. Two one-time-admission PRs caused these reds. Nine files change here; the other three were already fixed on `main` (#204191, #204255, 4efdef5). Each changed case is deleted (it asserted a mid-run permission refusal that was removed on purpose) or keeps its condition with the new refusal text. There is no production change.

## Introducing PR per file

I ran all 12 files at each suspect merge and at its parent (`ab24e714` → `8ea0f171`, `412df906` → `515a93c6`). The parent `ab24e714` is green. Every failure shows up at the merge named below. #204167 (`ef48c716`) adds no failure.

| File | Introduced by | Action | Why |
|---|---|---|---|
| `src/agents/command/model-selection.configured.test.ts` | #204155 | deleted "rechecks operator authority after loading the thinking catalog" | #204155 removed the `authority.assertCurrent` composition from `createOperatorModelSelectionAssertion`. A started selection now finishes after the authority ends; the next request is admitted again |
| `src/gateway/operator-run-authority.worker.test.ts` | #204155 | deleted the "role facts reader throws after abort" loop; cancellation of `assertCurrent` is kept | #204155 removed the `readCurrentRoleFacts` re-check wrapper. Role facts are the admitted snapshot |
| `src/gateway/local-request-context.session-tools.test.ts` | #204155 | none: #204255 already changed it on `main` (the revoked participant now gets a structured denial) | The participant `assertCurrent` was removed in `session-controller.tool-authority.ts` |
| `src/agents/tools/image-tool.runtime-abort.test.ts` | #204155 | deleted the 2 "retired after download" rows; the denied-override and permitted-fallback rows are kept | Same as the `pdf-tool` "retired after extraction" case that #204155 deleted |
| `src/gateway/sessions-patch.operator-model-policy.test.ts` | #204155 | deleted the source-revocation steps (4 cases); the admitted model policy, the denied model, the wildcard family and the policy-tightening checks are kept | #204155 removed the source composition from `createOperatorModelSelectionAssertion` |
| `src/gateway/server-methods/ui-command.test.ts` | #204155 | none: 4efdef5 already dropped the mid-turn revoke step on `main` | Same participant re-check |
| `src/model-picker/apply-session-model-selection.operator-context.test.ts` | #204155 | deleted "rechecks caller authority after model preparation before mutation" and its `assertCurrent` fixture plumbing | Same composition |
| `src/gateway/session-access-authority.test.ts` | #204134 | text only: `/could not start\|Session access changed/` | The refusal is still at admission, before route effects. The handler is not called and the leases are released. #204134 reworded `prepareGatewayOperatorRunAuthority` to "Gateway request could not start. Reconnect and try again." |
| `src/gateway/server-plugins.panels.test.ts` | #204134 | text only, "caller revoked" and "requester disconnected" rows | The same admission refusal. No delivery happens (`broadcastToConnIds` is not called) |
| `src/gateway/server-methods/users-personal-file.test.ts` | #204134 | text only: `/could not start\|connection/` | The change happens during operator-run preparation (admission). The request is still refused, and no `USER.md` is written (asserted after the refusal) |
| `test/cli-message-authority.integration.test.ts` | #204134 | text only, registration row: `/was reloaded during/` | The plugin-reload fence is kept. #204134 reworded it to "Plugin discord was reloaded during alias resolution. Retry the action." |
| `src/gateway/server-plugins.session-facts.test.ts` | #204134 | none: #204191 already rewrote it on `main` | See the leak check below |

`server.chat-goal.test.ts` (small-4) is the known #204187 race. This PR does not change it.

## Leak check

- `server-plugins.session-facts` "private cached snapshot": the consumer callback belongs to a request that was admitted before the grant, role or profile change. That request may finish (AGENTS.md "Check authority one time"). The next disclosure is refused at admission (`main` test, line 362). No snapshot goes to a caller who was refused at admission. **No leak.**
- `users-personal-file`: the refusal still occurs at admission and nothing is written. Only the text changed. **No leak.**

## Evidence

- Red on the scheduled run: 45259316971, shards large-8/19/20/22/28/32/37/41/42 and small-4.
- Local attribution runs (12 files each): `ab24e714` green; `8ea0f171` and `412df906` show the 5 #204134 files red; `515a93c6` adds the 7 #204155 files.
- Head: the 12 files pass locally (one unrelated `cli-message-authority` timeout under host load 66 passed on the rerun). CI on the head is green. Local ClawSweeper: patch is correct, no findings.

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

## Problem

When a child session calls `sessions_send` to the parent that spawned it (for example, to report progress), OpenClaw starts a new, hidden parent turn for each message. Each parent turn spends a model call, usually replies back to the child, and marks the parent chat unread although the chat shows nothing new. One child that sent 15 progress updates started 15 hidden parent turns.

## Change

A supervised child's `sessions_send` to its completion owner (the parent that the child's end state reports to: hidden, ACP and visible supervised children) no longer starts a parent turn (`mode: "notify"` keeps its existing ephemeral next-turn behavior):

- Parent mid-turn: the message steers into the running turn (the existing active-run injection).
- Parent idle: the message is appended to the parent's transcript as one model-visible, chat-hidden custom entry (`sessions-send-child-message`). The parent reads it on its next turn.
- The child gets `status: "accepted"` with `delivery: { status: "skipped" }` at once. It does not wait for a parent reply, because no parent turn runs.
- Only the child's end state wakes the parent (the existing completion wake).

All other `sessions_send` uses do not change: parent to child, peers, `agentId` targets, self-sends, sends to people's sessions, and sends from unsupervised `sessions_create` sessions to their creator (they have no completion that would wake the creator, so they keep the ordinary recipient turn).

The `sessions_send` tool description and `docs/concepts/session-tool.md` now tell a child that a message to its parent is recorded for the parent's next turn and gets no reply. Prompt snapshots are regenerated.

Codex works the same way: inter-agent progress and completion messages use `trigger_turn: false` and are recorded in history without starting a turn.

## Production line delta

+73 / −1 (excludes tests, docs and snapshots). The new code is one function, `recordSessionsSendForRequester`, which reuses the existing active-run steering and the existing transcript report append. No new tool parameter, config option, state or retry.

## Accepted edge case

If the parent is mid-turn but refuses the steer (for example, the running turn does not accept the child's requester authority), the message is appended to the transcript instead. The parent reads it on its next turn. No turn starts.

## Review

Local review round 1 found that `sessions_create` sessions also carry parent lineage but have no completion owner, so their messages to an idle creator would wait with nothing to wake it. Fixed: the history path now keys on `completionOwnerSessionKey`, and a test proves an unsupervised session's send still starts a creator turn. Round 2 found that `mode: "notify"` entered the new path before its own handling, and that the tool description did not limit the rule to supervised children. Fixed both: notify is handled first, as before, and the description and docs name supervised children only (prompt snapshots regenerated).

## Evidence

- New tests in `src/agents/openclaw-tools.sessions-steering.test-support.ts`, through the real `sessions_send` tool path:
  - `a supervised child's send to its parent starts no parent turn` (idle, busy). Red on the merge base: a parent `agent` turn starts and the child gets the parent's reply. Green on this head: idle → one transcript entry and no `agent` call; busy → one steer and no `agent` call.
  - `an unsupervised session's send to its creator still starts a turn`.
  - The existing parent-to-child steering tests in the same file stay green.
- `ocx test` on every test file that imports a changed source, plus `src/agents/agent-tools.prefix-stability.test.ts`: 28 files plus the prefix-stability test, 8 Vitest shards, all passed. After the review fix: `openclaw-tools.sessions.test.ts`, `sessions-send-tool.admission.test.ts`, `sessions-send-acp-custody.test.ts` passed.
- `pnpm check:changed`: typecheck, guards, format and prompt-snapshot drift passed; baseline ratchets (session identity, line cap) pass after the review fix. One Knip full-tree finding is in `scripts/lib/docker-e2e-watchdog.mjs`, a file this PR does not touch.
- `pnpm prompt:snapshots:check` with a clean HOME: current.
- E2E, isolated Gateway from source on a real Claude Sonnet route. The parent spawns a visible child; the child sends the parent 3 progress messages with `sessions_send`, then replies `DONE`. Model requests were counted at a logging proxy:
  - Merge base: the parent ran 4 turns after spawning: 3 hidden turns (one per progress message, each told to reply through the message tool) and the completion wake.
  - This change: the parent ran 1 turn after spawning, the completion wake. Its request contained the 3 progress messages once each, before the completion. Its reply: "The child finished. I received these PROGRESS codes from it, in order: 1. PROGRESS-1-… 2. PROGRESS-2-… 3. PROGRESS-3-…"

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

## Result

The 12 refusal-class test files that turned scheduled run 45259316971 (`7172fc1f`) red pass again. Two one-time-admission PRs caused these reds. Nine files change here; the other three were already fixed on `main` (openclaw#204191, openclaw#204255, 85559c3). Each changed case is deleted (it asserted a mid-run permission refusal that was removed on purpose) or keeps its condition with the new refusal text. There is no production change.

## Introducing PR per file

I ran all 12 files at each suspect merge and at its parent (`28d97119` → `d4ff1834`, `f88a49de` → `8d86eea4`). The parent `28d97119` is green. Every failure shows up at the merge named below. openclaw#204167 (`941e90a3`) adds no failure.

| File | Introduced by | Action | Why |
|---|---|---|---|
| `src/agents/command/model-selection.configured.test.ts` | openclaw#204155 | deleted "rechecks operator authority after loading the thinking catalog" | openclaw#204155 removed the `authority.assertCurrent` composition from `createOperatorModelSelectionAssertion`. A started selection now finishes after the authority ends; the next request is admitted again |
| `src/gateway/operator-run-authority.worker.test.ts` | openclaw#204155 | deleted the "role facts reader throws after abort" loop; cancellation of `assertCurrent` is kept | openclaw#204155 removed the `readCurrentRoleFacts` re-check wrapper. Role facts are the admitted snapshot |
| `src/gateway/local-request-context.session-tools.test.ts` | openclaw#204155 | none: openclaw#204255 already changed it on `main` (the revoked participant now gets a structured denial) | The participant `assertCurrent` was removed in `session-controller.tool-authority.ts` |
| `src/agents/tools/image-tool.runtime-abort.test.ts` | openclaw#204155 | deleted the 2 "retired after download" rows; the denied-override and permitted-fallback rows are kept | Same as the `pdf-tool` "retired after extraction" case that openclaw#204155 deleted |
| `src/gateway/sessions-patch.operator-model-policy.test.ts` | openclaw#204155 | deleted the source-revocation steps (4 cases); the admitted model policy, the denied model, the wildcard family and the policy-tightening checks are kept | openclaw#204155 removed the source composition from `createOperatorModelSelectionAssertion` |
| `src/gateway/server-methods/ui-command.test.ts` | openclaw#204155 | none: 85559c3 already dropped the mid-turn revoke step on `main` | Same participant re-check |
| `src/model-picker/apply-session-model-selection.operator-context.test.ts` | openclaw#204155 | deleted "rechecks caller authority after model preparation before mutation" and its `assertCurrent` fixture plumbing | Same composition |
| `src/gateway/session-access-authority.test.ts` | openclaw#204134 | text only: `/could not start\|Session access changed/` | The refusal is still at admission, before route effects. The handler is not called and the leases are released. openclaw#204134 reworded `prepareGatewayOperatorRunAuthority` to "Gateway request could not start. Reconnect and try again." |
| `src/gateway/server-plugins.panels.test.ts` | openclaw#204134 | text only, "caller revoked" and "requester disconnected" rows | The same admission refusal. No delivery happens (`broadcastToConnIds` is not called) |
| `src/gateway/server-methods/users-personal-file.test.ts` | openclaw#204134 | text only: `/could not start\|connection/` | The change happens during operator-run preparation (admission). The request is still refused, and no `USER.md` is written (asserted after the refusal) |
| `test/cli-message-authority.integration.test.ts` | openclaw#204134 | text only, registration row: `/was reloaded during/` | The plugin-reload fence is kept. openclaw#204134 reworded it to "Plugin discord was reloaded during alias resolution. Retry the action." |
| `src/gateway/server-plugins.session-facts.test.ts` | openclaw#204134 | none: openclaw#204191 already rewrote it on `main` | See the leak check below |

`server.chat-goal.test.ts` (small-4) is the known openclaw#204187 race. This PR does not change it.

## Leak check

- `server-plugins.session-facts` "private cached snapshot": the consumer callback belongs to a request that was admitted before the grant, role or profile change. That request may finish (AGENTS.md "Check authority one time"). The next disclosure is refused at admission (`main` test, line 362). No snapshot goes to a caller who was refused at admission. **No leak.**
- `users-personal-file`: the refusal still occurs at admission and nothing is written. Only the text changed. **No leak.**

## Evidence

- Red on the scheduled run: 45259316971, shards large-8/19/20/22/28/32/37/41/42 and small-4.
- Local attribution runs (12 files each): `28d97119` green; `d4ff1834` and `f88a49de` show the 5 openclaw#204134 files red; `8d86eea4` adds the 7 openclaw#204155 files.
- Head: the 12 files pass locally (one unrelated `cli-message-authority` timeout under host load 66 passed on the rerun). CI on the head is green. Local ClawSweeper: patch is correct, no findings.

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 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. docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants