Skip to content

fix(agents): prevent early aborts of silent MCP tools - #149206

Merged
obviyus merged 3 commits into
mainfrom
bugloop/direct-mcp-tool-lifecycle-events
Sep 15, 2026
Merged

obviyus merged 3 commits into
mainfrom
bugloop/direct-mcp-tool-lifecycle-events

Conversation

@obviyus

@obviyus obviyus commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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 #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.

@clawsweeper

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

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 12:12 PM ET / 16:12 UTC (Revision 2).

ClawSweeper review

What this changes

Routes 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
Reviewed head: 35a3affa8514608078b426e966355f655ca205fe

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant production observations and meaningful entrypoint regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured CLI/Gateway stdio run exercises the changed bundle lifecycle boundary: the silent call completes at 420 seconds with correlated lifecycle events and its result reaches both the provider and caller; cancellation, transport timeout, catalog execution, and bounded hang recovery are also recorded.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured CLI/Gateway stdio run exercises the changed bundle lifecycle boundary: the silent call completes at 420 seconds with correlated lifecycle events and its result reaches both the provider and caller; cancellation, transport timeout, catalog execution, and bounded hang recovery are also recorded.
Evidence reviewed 8 items Introduced production repair: The pinned introduced diff attaches the existing lifecycle wrapper after bundle filtering and normalization, before direct or catalog exposure; the outer abort wrapper continues to use the current tool-generation signal.
Current main still needs the repair: Fetched main normalizes bundled tools and adds abort handling without the before-tool-call lifecycle wrapper. The latest-release source lookup was unavailable, so no shipped-fix claim is made.
Existing lifecycle and cancellation boundary: The reused wrapper rechecks abort and runtime validity immediately before source execution, emits lifecycle diagnostics, and closes liveness in finally. Catalog registration recognizes already-wrapped tools rather than stacking another lifecycle wrapper.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1, Tests +251. Total +250 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 23 24 -1
Tests 2 253 2 +251
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 276 26 +250

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #140671
Summary: This PR addresses the linked issue’s silent-MCP abort mechanism; foreground exec deadline handling is adjacent, distinct work.

Members:

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

Technical review

Best 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.

Labels

Label justifications:

  • P1: The linked report and recorded baseline show healthy long-running MCP calls aborting entire agent turns before their results arrive.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured CLI/Gateway stdio run exercises the changed bundle lifecycle boundary: the silent call completes at 420 seconds with correlated lifecycle events and its result reaches both the provider and caller; cancellation, transport timeout, catalog execution, and bounded hang recovery are also recorded.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured CLI/Gateway stdio run exercises the changed bundle lifecycle boundary: the silent call completes at 420 seconds with correlated lifecycle events and its result reaches both the provider and caller; cancellation, transport timeout, catalog execution, and bounded hang recovery are also recorded.

Evidence

What I checked:

  • Introduced production repair: The pinned introduced diff attaches the existing lifecycle wrapper after bundle filtering and normalization, before direct or catalog exposure; the outer abort wrapper continues to use the current tool-generation signal. (src/agents/embedded-agent-runner/run/attempt-bundle-tools.ts:205, 35a3affa8514)
  • Current main still needs the repair: Fetched main normalizes bundled tools and adds abort handling without the before-tool-call lifecycle wrapper. The latest-release source lookup was unavailable, so no shipped-fix claim is made. (src/agents/embedded-agent-runner/run/attempt-bundle-tools.ts:204, 31557782c749)
  • Existing lifecycle and cancellation boundary: The reused wrapper rechecks abort and runtime validity immediately before source execution, emits lifecycle diagnostics, and closes liveness in finally. Catalog registration recognizes already-wrapped tools rather than stacking another lifecycle wrapper. (src/agents/agent-tools.before-tool-call.wrapper.ts:536, 35a3affa8514)
  • Recorded production behavior: The captured PR body records an isolated Gateway and real local stdio MCP transport with a deterministic loopback provider: a silent 420-second call previously aborted at 382 seconds, then completed with one correlated start/completion, result delivery to the next provider request, and CLI exit zero. Cancellation, a three-second transport timeout, catalog dispatch, and hang recovery at 918 seconds are also recorded. This is supplied runtime evidence, not reviewer execution; captured context identity is sourceRevision 7ab791e11d1bcf245cc99173fe67209fb23ec8fefcc052aa7b2206199ec36b6f.
  • Registered-entrypoint regression: The new parameterized test drives runEmbeddedAttempt with real tool preparation, materialization, catalog dispatch, Agent execution, and session tool adaptation while controlling the transport response. It checks pending lifecycle correlation, exactly one terminal event, and result delivery; the body records baseline failure for the direct case. (src/agents/embedded-agent-runner/run/attempt.configured-mcp-lifecycle.test.ts:50, 35a3affa8514)
  • Re-review continuity: The four production files are unchanged from the previously reviewed head. The prior completed review retained no findings or published rank-up moves; the new head strengthens regression coverage. (35a3affa8514)

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: 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-15T15:31:10.031Z sha 974b903 :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 149206
head: 35a3aff
scope: owner-review

@obviyus
obviyus marked this pull request as ready for review September 15, 2026 16:06
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-unrelated-red
pr: 149206
head: 35a3aff
run: 34992864261 attempt: 2
failed: checks-node-changed-extensions-config-56 job=104476963689 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit 3fc1d89 into main Sep 15, 2026
392 of 397 checks passed
@obviyus
obviyus deleted the bugloop/direct-mcp-tool-lifecycle-events branch September 15, 2026 17:08
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

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.

  • Bug: Healthy silent MCP calls lost their run after about six minutes.
  • Fix: Bundle assembly now applies the shared execution lifecycle before direct or catalog exposure.
Before After
Recovery aborted the silent call at 382 seconds. The result arrived at 420 seconds; genuinely hung work still recovered at 918 seconds.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
## 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]>
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: M 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]: stuck-session watchdog aborts long-running silent MCP tool calls at 360s — no exemption for active tool execution, threshold not configurable

1 participant