[PR #7086] fix(mcp): retry only failed provider cleanup #7631

Open
opened 2026-11-03 13:39:14 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7086
Author: @Vaishnavi220506
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: fix/stage-provider-cleanup-retries


📝 Commits (1)

  • 697b408 fix(mcp): retry only failed provider cleanup

📊 Changes

2 files changed (+102 additions, -59 deletions)

View changed files

📝 src/server/createServer.ts (+68 -56)
📝 tests/boundary/mcp/serverLifecycleMcp.test.ts (+34 -3)

📄 Description

Summary

REA's MCP server retried every provider cleanup after any one provider failed. This change retains the existing concurrent cleanup and aggregate errors while retrying only providers whose cleanup did not complete.

Problem and expected behavior

When one provider close rejects, createServer clears the shared cleanup promise so a later server.close() or transport close can retry the failed owner. The retry currently invokes providers that already closed successfully as well. A focused regression on the upstream base observed a successful peer's close callback twice; the expected lifecycle contract is one call for the successful peer and a retry only for the failed provider.

Change and scope

Provider cleanup is represented as lazy close stages with per-stage completion flags. All unresolved stages still start concurrently and their failures are still aggregated as REA provider cleanup failed; a later attempt skips stages that resolved and retries only the retained failures.

This is an ordinary fix within REA's existing MCP/provider lifecycle boundary; no new provider, capability, target authority, or public tool is introduced. Follow the contribution scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage: createServer's provider cleanup coordinator; the provider close stage is marked complete only after its promise resolves.
  • Contribution scope fit and linked maintainer decision: ordinary existing-boundary fix; not applicable.
  • CLI and MCP/tool-catalog contract: no tool or catalog changes; MCP shutdown retries have narrower side effects.
  • Provider, bridge, target-format, or platform compatibility: all existing providers keep their current close calls, concurrency, and aggregate failure reporting; only successful stages are omitted from later retries.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; not applicable.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): no target selection or execution changes; failed cleanup ownership remains retryable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: Added does not repeat successful provider cleanup after a peer fails; updated the existing Inspector lifecycle assertion to require one close for the successful peer and two for the retained failing owner.
  • Base reproduction or other evidence: On clean origin/main at 80673b22a46d01899718e22584cf95d9f0529ab7, the new regression fails with expected "vi.fn()" to be called 1 times, but got 2 times. The failing provider is called twice as intended for retry, while the successful peer is also called twice by the base implementation.
  • User-visible CLI/MCP output (if applicable): not applicable; this changes shutdown cleanup behavior only.
  • Remaining proof gaps: The full suite and real optional providers were not run. Two unrelated existing tests in the lifecycle file require the packaged Windows native control artifact, which is unavailable in this worktree.

This covers REA's MCP boundary and lifecycle regression paths in tests/boundary/mcp/serverLifecycleMcp.test.ts, including retained cleanup, peer cleanup, and caller-owned provider behavior.

Validation performed

  • node node_modules/vitest/vitest.mjs run tests/boundary/mcp/serverLifecycleMcp.test.ts --reporter=verbose -t "does not repeat successful provider cleanup after a peer fails" on a clean base with only the regression test added — failed as expected with the duplicate successful-peer call.
  • node node_modules/vitest/vitest.mjs run tests/boundary/mcp/serverLifecycleMcp.test.ts tests/boundary/mcp/evmInterfaceMcp.test.ts --reporter=verbose -t "does not repeat successful provider cleanup|awaits SQLite cleanup|closes the bound Go|retries only the retained Inspector|does not close a caller-owned Inspector|retains the injected EVM owner" — 6 passed, 18 skipped.
  • npm run check:fast — typecheck and lint passed (2 tasks).
  • npm run format:check — passed; all matched files use the correct format.
  • git diff --check — passed.
  • Dependency setup used PowerShell $env:npm_config_engine_strict='false'; npm ci because the available Node.js is v24.14.1 while this checkout declares ^22.23.4 || ^24.22.1 || >=26.12.1; the focused validation therefore ran under the repository's declared-but-unsupported local runtime.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable to this provider-coordination change; the Windows native control artifact was unavailable for two existing platform-specific tests.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no target process is launched or modified; the fix reduces repeated cleanup side effects and preserves existing provider ownership.

Author readiness

Human owner: @Vaishnavi220506

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/7086 **Author:** [@Vaishnavi220506](https://github.com/Vaishnavi220506) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/stage-provider-cleanup-retries` --- ### 📝 Commits (1) - [`697b408`](https://github.com/morluto/rea/commit/697b4084f84f77ff34526ab96e3a893396c3e5d3) fix(mcp): retry only failed provider cleanup ### 📊 Changes **2 files changed** (+102 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `src/server/createServer.ts` (+68 -56) 📝 `tests/boundary/mcp/serverLifecycleMcp.test.ts` (+34 -3) </details> ### 📄 Description ## Summary REA's MCP server retried every provider cleanup after any one provider failed. This change retains the existing concurrent cleanup and aggregate errors while retrying only providers whose cleanup did not complete. ## Problem and expected behavior When one provider close rejects, `createServer` clears the shared cleanup promise so a later `server.close()` or transport close can retry the failed owner. The retry currently invokes providers that already closed successfully as well. A focused regression on the upstream base observed a successful peer's close callback twice; the expected lifecycle contract is one call for the successful peer and a retry only for the failed provider. ## Change and scope Provider cleanup is represented as lazy close stages with per-stage completion flags. All unresolved stages still start concurrently and their failures are still aggregated as `REA provider cleanup failed`; a later attempt skips stages that resolved and retries only the retained failures. This is an ordinary fix within REA's existing MCP/provider lifecycle boundary; no new provider, capability, target authority, or public tool is introduced. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). ## Contract and boundary impact - Semantic owner and earliest changed stage: `createServer`'s provider cleanup coordinator; the provider close stage is marked complete only after its promise resolves. - Contribution scope fit and linked maintainer decision: ordinary existing-boundary fix; not applicable. - CLI and MCP/tool-catalog contract: no tool or catalog changes; MCP shutdown retries have narrower side effects. - Provider, bridge, target-format, or platform compatibility: all existing providers keep their current close calls, concurrency, and aggregate failure reporting; only successful stages are omitted from later retries. - Evidence, artifact, provenance, or reconstruction contract: unchanged; not applicable. - Target selection, authority, upstream behavior, and cleanup details (if applicable): no target selection or execution changes; failed cleanup ownership remains retryable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: Added `does not repeat successful provider cleanup after a peer fails`; updated the existing Inspector lifecycle assertion to require one close for the successful peer and two for the retained failing owner. - Base reproduction or other evidence: On clean `origin/main` at `80673b22a46d01899718e22584cf95d9f0529ab7`, the new regression fails with `expected "vi.fn()" to be called 1 times, but got 2 times`. The failing provider is called twice as intended for retry, while the successful peer is also called twice by the base implementation. - User-visible CLI/MCP output (if applicable): not applicable; this changes shutdown cleanup behavior only. - Remaining proof gaps: The full suite and real optional providers were not run. Two unrelated existing tests in the lifecycle file require the packaged Windows native control artifact, which is unavailable in this worktree. This covers REA's MCP boundary and lifecycle regression paths in `tests/boundary/mcp/serverLifecycleMcp.test.ts`, including retained cleanup, peer cleanup, and caller-owned provider behavior. ## Validation performed - `node node_modules/vitest/vitest.mjs run tests/boundary/mcp/serverLifecycleMcp.test.ts --reporter=verbose -t "does not repeat successful provider cleanup after a peer fails"` on a clean base with only the regression test added — failed as expected with the duplicate successful-peer call. - `node node_modules/vitest/vitest.mjs run tests/boundary/mcp/serverLifecycleMcp.test.ts tests/boundary/mcp/evmInterfaceMcp.test.ts --reporter=verbose -t "does not repeat successful provider cleanup|awaits SQLite cleanup|closes the bound Go|retries only the retained Inspector|does not close a caller-owned Inspector|retains the injected EVM owner"` — 6 passed, 18 skipped. - `npm run check:fast` — typecheck and lint passed (2 tasks). - `npm run format:check` — passed; all matched files use the correct format. - `git diff --check` — passed. - Dependency setup used PowerShell `$env:npm_config_engine_strict='false'; npm ci` because the available Node.js is v24.14.1 while this checkout declares `^22.23.4 || ^24.22.1 || >=26.12.1`; the focused validation therefore ran under the repository's declared-but-unsupported local runtime. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable to this provider-coordination change; the Windows native control artifact was unavailable for two existing platform-specific tests. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no target process is launched or modified; the fix reduces repeated cleanup side effects and preserves existing provider ownership. ## Author readiness Human owner: @Vaishnavi220506 - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7631
No description provided.