Repository navigation
fix(subagents): subagent results sent straight to the chat fail with "Plugin invocation scope is closed" - #196940
Conversation
…nvocation scope is closed"
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR detaches subagent announcement routing from the finished child's plugin invocation scope. Example: A Telegram DM subagent returns CHILD_RESULT_42 and completion delivery falls back to text.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (failure trace). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this PR provides a focused correction for a current-main completion-delivery failure, with no actionable patch defects found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe announcement owner receives completed child events, resolves the requester and destination, and either dispatches a requester turn or sends a direct completion through the channel plugin. flowchart TD
A[Child completion] --> B[Host announcement routing]
B --> C[Requester and source checks]
C --> D[Requester agent turn]
D --> E[Direct completion fallback]
E --> F[Channel plugin owner]
F --> G[Parent chat]
Technical reviewBest possible solution: Land the focused scope-exit correction while preserving the existing requester, cancellation, plugin-revocation, and delivery checks. Do we have a high-confidence way to reproduce the issue? The wrapped channel classifier reaches PluginInvocationScope.lookup after the inherited scope is released, explaining the reported failure; the linked issue supplies repeated before/after runs, but no target code was executed during this review. Is this the best way to solve the issue? Exiting the finished producer's plugin context at the existing host announcement owner is the smallest complete fix; weakening closed-scope rejection or changing retry deadlines would leave the lifecycle mismatch unresolved. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c37e3897be60. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +5, Tests 0. Total +5 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 10, 2026, 7:51 PM ET / November 11, 2026, 00:51 UTC. |
|
Landed in afa73f3. Thanks @amittell and @ChuLaiTheGreat. |
…"Plugin invocation scope is closed" (openclaw#196940) fix(subagents): deliver direct subagent announcements outside the finished turn's plugin scope A finished subagent's announcement started from the child's completed turn and kept that turn's plugin invocation scope, which is released when the turn ends. The channel target lookup and send then failed with "Plugin invocation scope is closed", so the result never reached the chat after its retries. sendSubagentAnnounceDirectly now runs inside pluginInvocationContext.exit, the same pattern as openclaw#196750 and openclaw#196700. ChuLaiTheGreat found this path in openclaw#171315 and openclaw#178125; openclaw#178125 carries the same fix inside a feature. Evidence: a built Gateway on node:24.22.1 in secretless Docker with a stand-in model and a stand-in Telegram Bot API recording every sendMessage, two runs each. On main a DM subagent result was never delivered and each run logged 4 "Plugin invocation scope is closed" errors. With this change it is delivered once with no scope errors. A normal reply, a group subagent completion, the provider-failure notice, a steered follow-up answered NO_REPLY and a session-targeted cron reply are each delivered once on both, and plugin-invocation-scope tests pass on both, so closed scopes still throw. The two QA Smoke scenarios from openclaw#196899 could not run locally because the QA Telegram transport fails before any scenario starts on main and this branch alike. Closes openclaw#196899. Thanks @amittell for the report and @ChuLaiTheGreat for finding the path. Co-authored-by: Ayaan Zaidi <[email protected]>
…n already ended (#197658) fix(gateway): run subagent announce Gateway calls outside the finished turn's plugin scope When a child agent failed after its parent's turn had already ended, the completion announce's in-process Gateway calls (chat.history, and the related sessions.delete and chat.abort) ran inside the parent turn's closed plugin invocation scope. The chat.history read asks plugins which harness to use, so it failed with "Subagent announce failed: Plugin invocation scope is closed" and the parent never learned the child had failed. These in-process calls now run outside the closed scope, the same pattern as #196940, and go through normal Gateway admission, so nothing is granted or widened. No text changes. Evidence: a built Gateway in a secretless node:24.22.1 container with a stand-in model, two runs each. With an isolated cron run whose owed child's model call returns HTTP 400, main logged the scope error four times per run and the parent was never woken; with this change there are no scope errors and the parent is woken once with the child's failure. A non-cron failing child behaved the same way. A succeeding child, a fire-and-forget child, a cron run without a spawn and a plain non-cron announce deliver exactly once on both, with no duplicate announce. A closed-scope history read in the existing closed-caller test fails on main, at net 0 test lines. Details: #197658 (comment). Thanks @dankarization for reporting this bug family in #197335. Co-authored-by: Ayaan Zaidi <[email protected]>
…n already ended (openclaw#197658) fix(gateway): run subagent announce Gateway calls outside the finished turn's plugin scope When a child agent failed after its parent's turn had already ended, the completion announce's in-process Gateway calls (chat.history, and the related sessions.delete and chat.abort) ran inside the parent turn's closed plugin invocation scope. The chat.history read asks plugins which harness to use, so it failed with "Subagent announce failed: Plugin invocation scope is closed" and the parent never learned the child had failed. These in-process calls now run outside the closed scope, the same pattern as openclaw#196940, and go through normal Gateway admission, so nothing is granted or widened. No text changes. Evidence: a built Gateway in a secretless node:24.22.1 container with a stand-in model, two runs each. With an isolated cron run whose owed child's model call returns HTTP 400, main logged the scope error four times per run and the parent was never woken; with this change there are no scope errors and the parent is woken once with the child's failure. A non-cron failing child behaved the same way. A succeeding child, a fire-and-forget child, a cron run without a spawn and a plain non-cron announce deliver exactly once on both, with no duplicate announce. A closed-scope history read in the existing closed-caller test fails on main, at net 0 test lines. Details: openclaw#197658 (comment). Thanks @dankarization for reporting this bug family in openclaw#197335. Co-authored-by: Ayaan Zaidi <[email protected]>
…#197658) Exit the completed caller's plugin invocation scope for lifecycle history, abort and delete dispatch. Retain the captured Gateway owner, least-privilege method dispatch, request guard and pre/post-effect current-owner checks. Release adaptation: apply the identical production repair in the release's server-recovery-runtime-context.ts rather than importing main's renamed lifecycle runtime. Use the existing hosted Gateway fixture and current PluginInstance/PluginInvocationScope APIs to prove closed-caller history reads; no new fixture or runtime architecture. Allocate 31 regression lines. Companion audit: no later same-path or PR-number follow-ups through 7bccde6. Recovery dispatcher, announcement history consumer, plugin admission and live owner guards are present. The related #196940 direct-to-channel repair is a separate sibling path, not a prerequisite of this lifecycle read; report it for parent disposition. Proof: 13 hosted lifecycle and recovery-context tests pass (145.94s wrapper, 20ms new regression). Type-aware oxlint, formatting and diff check pass. Full core compiler and live cron/provider proof remain qualification work. Baseline negative-control execution was not run. (cherry picked from commit 4d9f782) Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 9adc76a6976dc17213eb6d221b2b15ee93015cb0)
Closes #196899
Problem
When a subagent finishes and its result has to be sent to the parent chat directly (for example a Telegram DM, where the completion falls back to sending the child's result as text), the send fails with
Plugin invocation scope is closed. The announcement is retried and fails the same way every time, so the user never gets the result. The same failure makes the QA smoke scenariossubagent-completion-direct-fallbackandsubagent-empty-completion-recoverytime out on main since #196570 (#196899).Root cause
The announcement is started from the child's finished turn and runs in that turn's async context, which still carries the child's plugin invocation scope. That scope is released when the turn ends. When the announcement then calls the channel plugin (Telegram's target lookup and send), the plugin call looks up the released scope and throws.
Fix
sendSubagentAnnounceDirectlyruns withpluginInvocationContext.exit(...), so the announcement no longer inherits the finished turn's scope and channel calls enter their own plugin owner. This is the same pattern as #196750 and #196700. Closed scopes still throw; no retry, timeout or delivery rule changes.ChuLaiTheGreat found this path in #171315 and #178125. #178125 carries the same one-line fix inside a Telegram progress feature (with a new SDK callback that needs an owner decision), so this PR lands only the fix. Thanks @ChuLaiTheGreat.
Evidence
A built Gateway on Node 24.22.1 in secretless Docker, with a scripted local stand-in model and a stand-in Telegram Bot API that records every
sendMessage. In a Telegram DM the model spawns a subagent; the child answersCHILD_RESULT_42, and the parent's completion turn answers in plain text, so the result is sent directly as text. Two runs each on mainff392dbeb0and this change7814ecdb87.Plugin invocation scope is closed)NO_REPLYkeeps the earlier answer (#196769)Plugin invocation scope is closedappears 4 times in each main Gateway log (Subagent completion direct announce failed) and never with this change. No message was sent twice.The QA smoke scenarios from #196899 could not be run here: in the Docker container the QA Telegram transport fails before any scenario starts (
Crabline Telegram getMe probe failed with HTTP 500), on main, on this change and for thetelegram-status-commandcontrol alike. #196899 reports that applying this same change to main makes both scenarios pass locally (2 of 2 each).Test:
subagent-announce-delivery.test.tsadds a case that routes a Telegram completion after the child's plugin scope is released. It fails on main (delivered: false) and passes with this change; the file nets zero test lines (removed four one-line fixture wrappers).plugin-invocation-scope.test.tspasses on both (closed scopes still throw).