Repository navigation
fix(agents): prevent early aborts of silent MCP tools - #149206
Conversation
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 12:12 PM ET / 16:12 UTC (Revision 2). ClawSweeper reviewWhat this changesRoutes bundled MCP and language-server tools through OpenClaw’s existing execution lifecycle wrapper and adds regression coverage for direct and cataloged result delivery. Merge readiness✅ Ready for maintainer review This remains a useful fix: current main still omits lifecycle tracking for directly exposed MCP tools. The supplied runtime evidence supports the repair, and the reviewed patch has no actionable correctness findings. Priority: P1 Review scores
Verification
How this fits togetherThe embedded agent runner assembles tools from configured servers and plugins for model calls. Execution lifecycle events tell recovery tracking when a tool is active and when its result has arrived. flowchart TD
A[Configured MCP and language servers] --> B[Tool policy and normalization]
B --> C[Shared execution lifecycle]
C --> D[Direct or cataloged invocation]
D --> E[Tool result returned to model]
C --> F[Run activity tracking]
F --> G[Bounded stuck-run recovery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -1, Tests +251. Total +250 across 6 files. View PR surface stats
Review metricsNone. 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 one lifecycle owner for direct and cataloged tools, preserving finite recovery, cancellation, and transport deadlines without adding configuration. Do we have a high-confidence way to reproduce the issue? Yes: a directly exposed silent MCP call lasting seven minutes exceeds the untracked-run recovery window, and current-main source lacks the lifecycle wrapper that activates the existing tracked-tool allowance. The PR records before/after execution; this read-only review did not rerun it. Is this the best way to solve the issue? Yes: applying the existing wrapper at bundle assembly repairs the missing lifecycle at its producer, while catalog deduplication and shared context avoid competing tracking paths. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31557782c749. 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)
|
|
landpr-approve-admin-merge |
|
landpr-approve-unrelated-red |
|
Thanks @wujialeHK! Proof: A silent local MCP tool completed after 420 seconds with one start and one completion event, and its result reached the next provider request and final answer. Cancellation, transport timeout, catalog execution, and hung-tool recovery also passed.
|
## What Problem This Solves Silent configured MCP calls were aborted after about six minutes, before their results arrived. Closes openclaw#140671. ## Why This Change Was Made Bundle assembly attaches the existing lifecycle wrapper before direct or catalog exposure. Both paths share one attempt context; this state has one writer. The wrapper emits start and terminal events, and the activity owner derives the recovery allowance. ### Production size and ownership Runtime production changes total 23 added lines and 24 removed lines, for a net reduction of one line. | File | Net lines | Responsibility | | --- | ---: | --- | | `attempt-bundle-tools.ts` | +2 | Apply the existing lifecycle wrapper before direct or catalog exposure. | | `attempt-tool-prepare.ts` | +17 | Prepare the shared attempt context once. | | `attempt-tool-catalog.ts` | -19 | Reuse that context and remove duplicate construction. | | `attempt.ts` | -1 | Remove the redundant catalog trace argument. | ## User Impact Healthy silent tools receive the existing 15-minute tracked-tool allowance and return their results. ## Evidence `pnpm openclaw agent --agent proof --message 'Run the delayed local tool' --timeout 1000 --json` With tool search disabled, an isolated Gateway, a silent 420-second stdio tool, and `requestTimeoutMs: 900000`: - Before: recovery aborted at 382s, with no result delivered; CLI exit 1. - After: the tool returned at 420s; exactly one trusted start and one completion share the run/session/call correlation. The tool activity retired after completion, the next provider request contained its result, and the final CLI payload contained that result; exit 0. Cancellation, a three-second transport timeout, and catalog execution each recorded one MCP start and terminal event. A hung tool still recovered at 918s. The retained owner/sibling suite passed 387 tests on a merge with main. ## Tests The registered `runEmbeddedAttempt` regression drives real tool-base, bundle, catalog and session adaptation. It checks pending lifecycle correlation, result delivery, and duplicate events in catalog execution. The direct case fails on the baseline; the catalog case passes. Both pass with the fix, alongside ten catalog-abort tests. The hosted selector includes the new test once in `agents-embedded-agent-run`; 737 routing tests passed. The original 38 bundle policy tests remain unchanged. ## Compatibility No timeout policy, configuration key, protocol, or stored-state changes. ### Related recovery behavior This change composes with openclaw#148959. Foreground commands retain the accepted process deadline and its final recovery recheck. Configured tools use the existing finite tracked-tool allowance. Cancellation and transport timeouts remain active. ## Consumers Direct and cataloged bundled tools use the same lifecycle boundary. ## Invalidation Terminal events retire activity; permission refresh keeps the current abort signal. ## Evidence limits The measured transport is local stdio with a deterministic loopback provider. The regression controls the transport response while retaining real embedded preparation and session adapters. No channel-delivery or remote-transport behavior is asserted. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Silent configured MCP calls were aborted after about six minutes, before their results arrived. Closes #140671.
Why This Change Was Made
Bundle assembly attaches the existing lifecycle wrapper before direct or catalog exposure. Both paths share one attempt context; this state has one writer. The wrapper emits start and terminal events, and the activity owner derives the recovery allowance.
Production size and ownership
Runtime production changes total 23 added lines and 24 removed lines, for a net reduction of one line.
attempt-bundle-tools.tsattempt-tool-prepare.tsattempt-tool-catalog.tsattempt.tsUser Impact
Healthy silent tools receive the existing 15-minute tracked-tool allowance and return their results.
Evidence
pnpm openclaw agent --agent proof --message 'Run the delayed local tool' --timeout 1000 --jsonWith tool search disabled, an isolated Gateway, a silent 420-second stdio tool, and
requestTimeoutMs: 900000:Cancellation, a three-second transport timeout, and catalog execution each recorded one MCP start and terminal event. A hung tool still recovered at 918s. The retained owner/sibling suite passed 387 tests on a merge with main.
Tests
The registered
runEmbeddedAttemptregression drives real tool-base, bundle, catalog and session adaptation. It checks pending lifecycle correlation, result delivery, and duplicate events in catalog execution. The direct case fails on the baseline; the catalog case passes. Both pass with the fix, alongside ten catalog-abort tests.The hosted selector includes the new test once in
agents-embedded-agent-run; 737 routing tests passed. The original 38 bundle policy tests remain unchanged.Compatibility
No timeout policy, configuration key, protocol, or stored-state changes.
Related recovery behavior
This change composes with #148959. Foreground commands retain the accepted process deadline and its final recovery recheck. Configured tools use the existing finite tracked-tool allowance. Cancellation and transport timeouts remain active.
Consumers
Direct and cataloged bundled tools use the same lifecycle boundary.
Invalidation
Terminal events retire activity; permission refresh keeps the current abort signal.
Evidence limits
The measured transport is local stdio with a deterministic loopback provider. The regression controls the transport response while retaining real embedded preparation and session adapters. No channel-delivery or remote-transport behavior is asserted.