Repository navigation
fix(sessions): avoid duplicate work after waited child replies - #147394
Conversation
…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)
(cherry picked from commit 181ddef)
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
landpr-approve-admin-merge |
|
Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 5:18 PM ET / 21:18 UTC (Revision 2). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherOpenClaw’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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +12, Tests +496. Total +508 across 6 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
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.
|
…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) ...
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]>
…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]>
…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]>
What Problem This Solves
A waited
sessions_sendto 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:
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
f62c21d708b4with parentsfe90c7249869and main6f58faf3eb0d, including the reload sibling. Commands: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.