Skip to content

fix(sessions): avoid duplicate work after waited child replies - #147394

Merged
obviyus merged 6 commits into
mainfrom
bugloop/waited-child-inline-reply
Sep 13, 2026
Merged

obviyus merged 6 commits into
mainfrom
bugloop/waited-child-inline-reply

Conversation

@obviyus

@obviyus obviyus commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A waited sessions_send to an agent's own visible child starts duplicate reply and announcement work after the child's reply already returned inline.

Supersedes #144320 by @ylcn91. Closes #144265, reported by @tonyisblind.

Why This Change Was Made

Use the durable requester key and stored spawn lineage in the existing send owner. Suppress the extra work only when the reply returns inline; keep the continuation when the wait expires. Preserve the reload handling from #146799.

User Impact

The parent receives one inline child reply without re-entering the child. Late results still reach the parent. No configuration, storage, or protocol change is required.

Evidence

Real Discord recordings captured the same registered spawn/send flow:

main a2b2391e353: reply inline, delivery=pending, extra parent calls=1, extra child calls=1
candidate fe90c7249869: reply inline, delivery=skipped, extra calls=0
wait expiry: accepted/pending, then the held child reply reached the parent

The same two-turn QA direct-message Gateway test failed on unfixed main 6f58faf3eb0d (exit 1): the inline reply had pending delivery and one extra parent reply step. It passed unchanged on the candidate and fresh merge (exit 0), with exact parent lineage, one child send, and no extra reply/announcement calls. Title requests were counted separately.

188 tests passed on merge f62c21d708b4 with parents fe90c7249869 and main 6f58faf3eb0d, including the reload sibling. Commands:

node scripts/run-vitest.mjs src/agents/openclaw-tools.sessions.test.ts src/agents/tools/sessions-send-tool.a2a.test.ts src/agents/tools/openclaw-tools.spawn-session-key.test.ts src/agents/tools/sessions.test.ts

OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_PROOF_VISIBLE_CHILD_SEND=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts src/gateway/gateway.sessions-send-hot-reload.e2e.test.ts test/e2e/qa-lab/runtime/sessions-send-visible-child.product-proof.e2e.test.ts

Formatting, source lint, assertion/file-size guards, unused-export scans, and architecture checks passed. CI owns typechecking.

The delayed recording reached the parent, then logged the existing final-announcement error Async work scope is closed, also observed on main. This change does not claim to repair that separate error.

Consumers

The requester-key change also affects session visibility and label lookup, self-send detection, reply addressing, watch ownership, and inter-session provenance. These now use the same durable requester identity as spawn and session lookup. Authenticated caller routing and tool policy retain their existing inputs. The worker send path keeps its exact-session-instance restrictions.

Visible and hidden owned-child tests release a held reply after the sending caller returns, then check that the parent receives it and retained work settles. Exact-session-instance tests still forbid detached delivery and durable watches. The existing reload continuation scopes remain intact.

The separate final-announcement scope error remains excluded. Late-delivery evidence proves that the parent receives the held reply within the existing continuation window; it does not promise another public channel message or an unlimited wait.

Supersedes #144320 by @ylcn91, whose four commits retain their authorship. Thanks to @tonyisblind for #144265.

ylcn91 and others added 6 commits September 14, 2026 01:45
…against visible spawn children

A waited sessions_send to a native child that the requester spawned skips the
generic A2A ping-pong and announce flow, because the child's reply already
returns inline. That guard only recognized subagent-keyed targets, so visible
children created with sessions_spawn visible:true, which live under persistent
dashboard keys, were treated as peers. The follow-up announce run re-entered
the child session and could fail with "prepared model runtime plugin
generation was superseded".

Treat a spawnedBy match as authoritative lineage regardless of key shape; keep
the parentSessionKey match limited to subagent keys, since that field also
records ordinary UI threading and forks.

Closes #144265

(cherry picked from commit 5ec4e33)
…ned children match their parent

Spawned children persist spawnedBy under the durable run session key, because
the Gateway canonicalizes the spawn parent on sessions.create. sessions_send
was the one session tool still built with the channel route key, so a parent
running from a DM mapped to its main session never matched its own visible
child and started the A2A announce flow after a waited reply. Hand
sessions_send runSessionKey ?? agentSessionKey like sessions_spawn and the
other session tools (see #137779), add the factory wiring regression, and add
the gated real-Gateway product-proof lane that reproduces the visible spawn,
waited send, and absence of a follow-up announce run.

(cherry picked from commit e3acfe3)
…ld outlives the wait

Native-parent suppression of the A2A flow is only right when the child's
reply already returned inline. A send to a spawned child is not a registered
spawn run, so when the wait expires before the child finishes, the detached
continuation is the only path that brings the late reply back to the parent.
Apply the native-parent skip to inline replies only and report delivery as
pending for the timed-out send.

(cherry picked from commit 8dc24fd)
@clawsweeper

clawsweeper Bot commented Sep 13, 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: L maintainer Maintainer-authored PR labels Sep 13, 2026
@obviyus

obviyus commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 147394
head: fe90c72
scope: owner-review

@obviyus
obviyus marked this pull request as ready for review September 13, 2026 20:56
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 5:18 PM ET / 21:18 UTC (Revision 2).

ClawSweeper review

What this changes

The PR prevents duplicate follow-up work after a parent receives its spawned child’s reply inline, while retaining delivery when the child outlasts the wait.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful fix absent from current main and the latest release. No blocking correctness findings remain, and the supplied runtime evidence supports the intended behavior.

Priority: P1
Reviewed head: fe90c72498693b479290888bdb806672ea791cdf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant runtime evidence and regression coverage, with no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied Discord runtime output exercises registered spawn/send on the candidate and shows an inline reply with skipped delivery and zero extra calls, plus late delivery after wait expiry; the inspected real-Gateway QA scenario corroborates lineage and request counts.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Supplied Discord runtime output exercises registered spawn/send on the candidate and shows an inline reply with skipped delivery and zero extra calls, plus late delivery after wait expiry; the inspected real-Gateway QA scenario corroborates lineage and request counts.
Evidence reviewed 9 items Current main still needs the fix: Current main still rejects dashboard-keyed children before inspecting spawnedBy, and its tool factory still passes agentSessionKey alone to sessions_send.
Latest release retains the restrictive child check: The v2026.9.4 source also requires a subagent-shaped key before consulting persisted lineage.
Inline and delayed delivery remain distinct: The introduced guard recognizes native spawned children through spawnedBy, retains the key restriction for ordinary parentSessionKey relationships, and preserves ACP and exact-incarnation suppression for detached work.
Findings None None.
Security None None.

How this fits together

OpenClaw’s session-send tool lets one agent message another session and optionally wait for its response. It uses session lineage and completion results to choose between returning the reply inline and continuing delivery in the background.

flowchart TD
  A[Parent agent sends message] --> B[Resolve durable session and access]
  B --> C[Run target child]
  C --> D{Reply arrives within wait?}
  D -->|Yes, owned child| E[Return inline and skip duplicate work]
  D -->|No| F[Retain bounded continuation]
  F --> G[Deliver late reply to parent]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +12, Tests +496. Total +508 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 27 15 +12
Tests 4 673 177 +496
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 700 192 +508

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +12 lines; tests net +496 lines The small production increase separates inline and delayed outcomes; most growth exercises the registered Gateway flow and lifecycle boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #144265
Summary: This PR is a candidate fix for the visible-child classification report and carries forward the earlier implementation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep lineage classification and inline-versus-delayed delivery in the existing send owner, using the same durable requester identity as spawn and preserving scoped access.

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

Yes: spawn a visible child, then send it a waited message from its parent; current main’s key-shape guard misclassifies that child. Source inspection and supplied red/green runtime results establish the path; this review did not execute it.

Is this the best way to solve the issue?

Yes: the patch repairs the existing owner and factory wiring without adding another delivery mechanism, while retaining delayed replies, ordinary peer behavior, and exact-incarnation restrictions.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The linked official-release report demonstrates duplicate agent work and failed follow-up execution in an existing child-session workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Supplied Discord runtime output exercises registered spawn/send on the candidate and shows an inline reply with skipped delivery and zero extra calls, plus late delivery after wait expiry; the inspected real-Gateway QA scenario corroborates lineage and request counts.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied Discord runtime output exercises registered spawn/send on the candidate and shows an inline reply with skipped delivery and zero extra calls, plus late delivery after wait expiry; the inspected real-Gateway QA scenario corroborates lineage and request counts.

Evidence

What I checked:

  • Current main still needs the fix: Current main still rejects dashboard-keyed children before inspecting spawnedBy, and its tool factory still passes agentSessionKey alone to sessions_send. (src/agents/tools/sessions-send-tool.ts:284, a941bb47519c)
  • Latest release retains the restrictive child check: The v2026.9.4 source also requires a subagent-shaped key before consulting persisted lineage. (src/agents/tools/sessions-send-tool.ts, 3a9d69db306c)
  • Inline and delayed delivery remain distinct: The introduced guard recognizes native spawned children through spawnedBy, retains the key restriction for ordinary parentSessionKey relationships, and preserves ACP and exact-incarnation suppression for detached work. (src/agents/tools/sessions-send-tool.ts:1063, fe90c7249869)
  • Requester identity follows the existing durable owner: The factory aligns send with spawn and session lookup. The authenticated Gateway caller wrapper and tool-policy inputs retain their original options; the change does not mint a new authorization grant or alter persisted settings. (src/agents/openclaw-tools.ts:575, fe90c7249869)
  • Existing session contract: Documentation identifies visible spawns as persistent dashboard sessions, distinguishes local sessions from external conversation addresses, and defines waited replies and pending announcement delivery separately. Public docs: docs/concepts/session-tool.md. (docs/concepts/session-tool.md:117, fe90c7249869)
  • Real behavior evidence: The captured PR body reports the registered Discord spawn/send flow changing from inline reply plus extra parent/child calls to delivery=skipped with zero extra calls on fe90c72; a held reply also reached the parent after wait expiry. The committed QA Gateway scenario exercises two real tool turns, verifies persisted lineage and complete receipts, and counts requests through shutdown. The body reports unchanged red/green execution and 188 passing tests; these were not rerun during this read-only review. Captured context sourceRevision: f5470266717c4720a1dac2b3020a8b15daf31b3452e04e9b4e577f47859df26b. (test/e2e/qa-lab/runtime/sessions-send-visible-child.product-proof.e2e.test.ts:316, fe90c7249869)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T21:01:00.857Z sha fe90c72 :: needs maintainer review before merge. :: none

@obviyus
obviyus merged commit 09b032a into main Sep 13, 2026
263 checks passed
@obviyus
obviyus deleted the bugloop/waited-child-inline-reply branch September 13, 2026 21:21
@obviyus

obviyus commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @ylcn91 and @tonyisblind!

Proof: The two-turn direct-message test fails on unfixed main and passes with this fix. The real channel recording also returns one inline reply, and a timed-out wait still delivers the late reply to the parent.

  • Bug: A waited send to an owned visible child started extra parent/child work after its reply had returned.
  • Fix: The send owner uses durable spawn lineage and skips the extra work only for an inline reply.
Before After
Inline reply followed by pending delivery and another parent reply step Inline reply with skipped delivery and no extra reply step

vincentkoc added a commit to Alix-007/openclaw that referenced this pull request Sep 13, 2026
…1-prep

* commit '912ae8d96e5964dfdcdf419b79613fb941cdf0a8': (350 commits)
  fix: keep workspace preparation responsive during cleanup (openclaw#147358)
  docs: alphabetize donors and sponsors and add Red Hat logo (openclaw#147302)
  fix(plugins): retain update authority through doctor effects (openclaw#144316)
  refactor(qa): share Multipass mount retry lifecycle (openclaw#147084)
  fix(memory): emit one JSON result for command failures (openclaw#147366)
  improve(plugins): speed up cold metadata loading (openclaw#147411)
  fix(sessions): avoid duplicate work after waited child replies (openclaw#147394)
  fix(agents): retain outstanding child results in parent context (openclaw#112623)
  test: preserve native workflow loader selection (openclaw#147403)
  fix: reduce repeated work while polling session pull requests (openclaw#147373)
  test(qa): preserve task cancellation across process replacement (openclaw#147382)
  fix: prevent sidebar refresh storms during session activity (openclaw#147400)
  refactor: simplify skills CLI formatting (openclaw#147368)
  fix: prevent Git checkout certificate failures behind egress proxy (openclaw#147410)
  fix(qa): stop live threads after their process leader exits (openclaw#147386)
  refactor(release): share agent turn retry lifecycle (openclaw#147076)
  fix(ui): keep uploaded images aligned with their prompts (openclaw#147389)
  fix(fs): guard skill reads and bound worker bundle staging (openclaw#147336)
  fix(ci): restore Linux service ownership fixtures (openclaw#147398)
  fix(plugins): preserve manifest permissions when building plugins (openclaw#147393)
  ...
obviyus added a commit that referenced this pull request Sep 13, 2026
Related: #146331. Supersedes #146595 by @MasterSwords1. Thanks @fray-ai for reporting it.

## What Problem This Solves

After replay cleanup removes old messages, an assistant can lose the current task and successful tool results from later requests, even though chat history still shows them.

## Why This Change Was Made

Normalize replay before prompt preparation records the history boundary. Session setup seeds the count; prompt preparation replaces it after history assembly and cleanup. Submission consumes that prepared history; it no longer shortens history after the boundary is set. The contributor's production fix is preserved. Tests now use complete fixtures and real prompt preparation/submission, with a clean-history control.

## User Impact

Current instructions and tool results remain available across multiple tool calls. No setting or migration is needed.

## Evidence

Authenticated Gateway `chat.send`, an isolated history-only context engine, and two actual file reads:

| Captured request | Main, six silent history messages | Candidate |
| --- | --- | --- |
| First | Current task present | Current task present |
| Second | Task and first result absent | Task and first result present |
| Third | Task and both results absent | Task and both results present |

Both runs completed the reads and retained the entire turn in chat history. The no-silent-history control passes on both. Responses were deterministic; this proves request contents, not model answer quality.

The corrected regression fails on main because the active prompt is missing, and passes with the fix. Five selected test files pass on fresh merge `3e4442b9890b85e579eb36f657e88261ca0ef825` (parents `aa2bcb6ebe293c76eb1c715dae9a386da3750dfc` and `fa5b2d16805c7c81e2c395fbbc0ff27312b16da1`): 160 distinct tests, 250 successful executions across the two test configurations.

<details>
<summary>Commands and captured result</summary>

Gateway driver commands, using the retained proof directory:

```sh
node "$PROOF/reproduce.mjs" candidate-six 6
node "$PROOF/assert-tail.mjs" candidate-six
node "$PROOF/reproduce.mjs" candidate-clean 0
node "$PROOF/assert-tail.mjs" candidate-clean
```

Both candidate assertions exit 0. The same assertion exits 1 on the recorded main reproduction. Captured candidate checks: three requests; two completed reads; current task retained in every request; first result retained in request two; both results retained in request three; chat history retains all markers.

Selected tests:

```sh
node scripts/run-vitest.mjs \
  src/agents/embedded-agent-runner/run/attempt-context-advancement.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-context.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-submit.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-phase.test.ts \
  src/agents/embedded-agent-runner/tool-result-context-guard.test.ts
```

The fresh merge used `node --import tsx scripts/ci-run-node-test-shard.mts`, with these five include paths and the embedded-agent and embedded-agent-run configurations. Exit 0. Six additional direct-caller files also passed on that merge (165 tests), covering replay recovery, projections, settlement, media hints, and tool-result budgets. Typechecks remain for CI.

</details>

## Compatibility

No schema, protocol, dependency, configuration, or durable transcript change. Existing context-engine commit semantics remain intact.

## Consumers

The shared boundary also serves turn completion, usage fallback, and legacy context finalization. They consume the normalized count. The independent CLI history boundary is unchanged.

## Invalidation

Each attempt computes the boundary after replay cleanup. No persistent cache or new state owner is added.

### Ordering and consumers

Session setup seeds the history count. Prompt preparation replaces it after history assembly and replay cleanup, then submission consumes the prepared history. The same count serves tool-loop advancement, reply flushing, usage fallback, and legacy turn completion. Hook and budget projections and the active-run snapshot use that prepared history. Optional settled-turn finalization still reads the newly completed assistant from the stream subscription, preserving the authored `NO_REPLY` behavior from #145343.

### Validation scope

The retained Gateway proof checks actual request contents and completed file reads with deterministic responses. Main loses the active task and results after replay cleanup; the candidate retains them. Both clean-history controls pass. Runtime proof was captured at `9dc8e3a19ad7ea694bc40ca520f1e2597e7fdc22`; the final commit changes only tests. The fresh merge includes #145343, #147139, and #147394. Its selected suites pass 160 distinct tests, with 250 executions due to configuration overlap, plus 165 tests in six additional consumer files. This does not claim a separate fresh execution of the finalizer-silence scenario, browser rendering, or answer quality. Typechecks remain for CI.

CI run [34789473564](https://github.com/openclaw/openclaw/actions/runs/34789473564) completed successfully at `aa2bcb6ebe293c76eb1c715dae9a386da3750dfc`, including the hosted type checks.

Co-authored-by: MasterSwords1 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…law#147394)

## What Problem This Solves

A waited `sessions_send` to an agent's own visible child starts duplicate reply and announcement work after the child's reply already returned inline.

Supersedes openclaw#144320 by @ylcn91. Closes openclaw#144265, reported by @tonyisblind.

## Why This Change Was Made

Use the durable requester key and stored spawn lineage in the existing send owner. Suppress the extra work only when the reply returns inline; keep the continuation when the wait expires. Preserve the reload handling from openclaw#146799.

## User Impact

The parent receives one inline child reply without re-entering the child. Late results still reach the parent. No configuration, storage, or protocol change is required.

## Evidence

Real Discord recordings captured the same registered spawn/send flow:

```text
main a9d0dc3: reply inline, delivery=pending, extra parent calls=1, extra child calls=1
candidate fe90c72: reply inline, delivery=skipped, extra calls=0
wait expiry: accepted/pending, then the held child reply reached the parent
```

The same two-turn QA direct-message Gateway test failed on unfixed main `3eafa82bb6c6` (exit 1): the inline reply had pending delivery and one extra parent reply step. It passed unchanged on the candidate and fresh merge (exit 0), with exact parent lineage, one child send, and no extra reply/announcement calls. Title requests were counted separately.

188 tests passed on merge `f62c21d708b4` with parents `fe90c7249869` and main `3eafa82bb6c6`, including the reload sibling. Commands:

```sh
node scripts/run-vitest.mjs src/agents/openclaw-tools.sessions.test.ts src/agents/tools/sessions-send-tool.a2a.test.ts src/agents/tools/openclaw-tools.spawn-session-key.test.ts src/agents/tools/sessions.test.ts

OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_PROOF_VISIBLE_CHILD_SEND=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts src/gateway/gateway.sessions-send-hot-reload.e2e.test.ts test/e2e/qa-lab/runtime/sessions-send-visible-child.product-proof.e2e.test.ts
```

Formatting, source lint, assertion/file-size guards, unused-export scans, and architecture checks passed. CI owns typechecking.

The delayed recording reached the parent, then logged the existing final-announcement error `Async work scope is closed`, also observed on main. This change does not claim to repair that separate error.

## Consumers

The requester-key change also affects session visibility and label lookup, self-send detection, reply addressing, watch ownership, and inter-session provenance. These now use the same durable requester identity as spawn and session lookup. Authenticated caller routing and tool policy retain their existing inputs. The worker send path keeps its exact-session-instance restrictions.

Visible and hidden owned-child tests release a held reply after the sending caller returns, then check that the parent receives it and retained work settles. Exact-session-instance tests still forbid detached delivery and durable watches. The existing reload continuation scopes remain intact.

The separate final-announcement scope error remains excluded. Late-delivery evidence proves that the parent receives the held reply within the existing continuation window; it does not promise another public channel message or an unlimited wait.

Supersedes openclaw#144320 by @ylcn91, whose four commits retain their authorship. Thanks to @tonyisblind for openclaw#144265.

Co-authored-by: Yalçın Doksanbir <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…47531)

Related: openclaw#146331. Supersedes openclaw#146595 by @MasterSwords1. Thanks @fray-ai for reporting it.

## What Problem This Solves

After replay cleanup removes old messages, an assistant can lose the current task and successful tool results from later requests, even though chat history still shows them.

## Why This Change Was Made

Normalize replay before prompt preparation records the history boundary. Session setup seeds the count; prompt preparation replaces it after history assembly and cleanup. Submission consumes that prepared history; it no longer shortens history after the boundary is set. The contributor's production fix is preserved. Tests now use complete fixtures and real prompt preparation/submission, with a clean-history control.

## User Impact

Current instructions and tool results remain available across multiple tool calls. No setting or migration is needed.

## Evidence

Authenticated Gateway `chat.send`, an isolated history-only context engine, and two actual file reads:

| Captured request | Main, six silent history messages | Candidate |
| --- | --- | --- |
| First | Current task present | Current task present |
| Second | Task and first result absent | Task and first result present |
| Third | Task and both results absent | Task and both results present |

Both runs completed the reads and retained the entire turn in chat history. The no-silent-history control passes on both. Responses were deterministic; this proves request contents, not model answer quality.

The corrected regression fails on main because the active prompt is missing, and passes with the fix. Five selected test files pass on fresh merge `3e4442b9890b85e579eb36f657e88261ca0ef825` (parents `aa2bcb6ebe293c76eb1c715dae9a386da3750dfc` and `4492504cc1f3704f8b3a5459f75a9c57e1f96edd`): 160 distinct tests, 250 successful executions across the two test configurations.

<details>
<summary>Commands and captured result</summary>

Gateway driver commands, using the retained proof directory:

```sh
node "$PROOF/reproduce.mjs" candidate-six 6
node "$PROOF/assert-tail.mjs" candidate-six
node "$PROOF/reproduce.mjs" candidate-clean 0
node "$PROOF/assert-tail.mjs" candidate-clean
```

Both candidate assertions exit 0. The same assertion exits 1 on the recorded main reproduction. Captured candidate checks: three requests; two completed reads; current task retained in every request; first result retained in request two; both results retained in request three; chat history retains all markers.

Selected tests:

```sh
node scripts/run-vitest.mjs \
  src/agents/embedded-agent-runner/run/attempt-context-advancement.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-context.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-submit.test.ts \
  src/agents/embedded-agent-runner/run/attempt-prompt-phase.test.ts \
  src/agents/embedded-agent-runner/tool-result-context-guard.test.ts
```

The fresh merge used `node --import tsx scripts/ci-run-node-test-shard.mts`, with these five include paths and the embedded-agent and embedded-agent-run configurations. Exit 0. Six additional direct-caller files also passed on that merge (165 tests), covering replay recovery, projections, settlement, media hints, and tool-result budgets. Typechecks remain for CI.

</details>

## Compatibility

No schema, protocol, dependency, configuration, or durable transcript change. Existing context-engine commit semantics remain intact.

## Consumers

The shared boundary also serves turn completion, usage fallback, and legacy context finalization. They consume the normalized count. The independent CLI history boundary is unchanged.

## Invalidation

Each attempt computes the boundary after replay cleanup. No persistent cache or new state owner is added.

### Ordering and consumers

Session setup seeds the history count. Prompt preparation replaces it after history assembly and replay cleanup, then submission consumes the prepared history. The same count serves tool-loop advancement, reply flushing, usage fallback, and legacy turn completion. Hook and budget projections and the active-run snapshot use that prepared history. Optional settled-turn finalization still reads the newly completed assistant from the stream subscription, preserving the authored `NO_REPLY` behavior from openclaw#145343.

### Validation scope

The retained Gateway proof checks actual request contents and completed file reads with deterministic responses. Main loses the active task and results after replay cleanup; the candidate retains them. Both clean-history controls pass. Runtime proof was captured at `9dc8e3a19ad7ea694bc40ca520f1e2597e7fdc22`; the final commit changes only tests. The fresh merge includes openclaw#145343, openclaw#147139, and openclaw#147394. Its selected suites pass 160 distinct tests, with 250 executions due to configuration overlap, plus 165 tests in six additional consumer files. This does not claim a separate fresh execution of the finalizer-silence scenario, browser rendering, or answer quality. Typechecks remain for CI.

CI run [34789473564](https://github.com/openclaw/openclaw/actions/runs/34789473564) completed successfully at `aa2bcb6ebe293c76eb1c715dae9a386da3750dfc`, including the hosted type checks.

Co-authored-by: MasterSwords1 <[email protected]>
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 maintainer Maintainer-authored PR 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: L 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.

[Bug]: sessions_send misclassifies visible dashboard spawn-child sessions and triggers stale runtime announce failures

2 participants