fix(plugin): stop MCP servers on quit - #1793
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds a plugin shutdown lifecycle to DeepChat's main process: ChangesPlugin Shutdown Lifecycle
Sequence Diagram(s)sequenceDiagram
participant Presenter
participant PluginPresenter
participant McpPresenter
participant McpClient
participant terminateProcessTree
rect rgba(99, 179, 237, 0.5)
note over Presenter,PluginPresenter: Phase 1 – Plugin-scoped cleanup
Presenter->>PluginPresenter: await shutdown()
PluginPresenter->>McpPresenter: stopServer(plugin-owned running server)
McpPresenter->>McpClient: disconnect()
McpClient->>terminateProcessTree: await terminateProcessTree(_process, {graceMs:2000})
terminateProcessTree-->>McpClient: done
McpClient->>McpClient: await transport.close()
McpClient-->>McpPresenter: stopped
McpPresenter-->>PluginPresenter: done
PluginPresenter->>PluginPresenter: unregisterPluginToolPolicies()
PluginPresenter->>PluginPresenter: closeAllPluginSettingsWindows()
PluginPresenter-->>Presenter: done
end
rect rgba(154, 205, 50, 0.5)
note over Presenter,McpPresenter: Phase 2 – Global MCP cleanup
Presenter->>McpPresenter: await shutdown()
McpPresenter->>McpClient: stopServer(remaining running clients)
McpClient-->>McpPresenter: stopped (errors logged, not thrown)
McpPresenter-->>Presenter: done
end
Presenter->>Presenter: destroyRemoteControl() + rest of teardown
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/presenter/index.ts`:
- Around line 896-897: The destroy() method's calls to
this.pluginPresenter.shutdown() and this.mcpPresenter.shutdown() will abort the
entire destroy process if either throws an error, preventing subsequent cleanup
steps from executing. Wrap each of these two shutdown calls in separate
try/catch blocks to isolate failures, logging any caught errors appropriately
while allowing the method to continue and complete all remaining cleanup.
Maintain the existing order with pluginPresenter shutdown first, followed by
mcpPresenter shutdown.
In `@src/main/presenter/mcpPresenter/mcpClient.ts`:
- Around line 551-560: In the closeTransport method, if terminateProcessTree
throws an error, the subsequent transport.close() call will not execute, leaving
transport resources open. Wrap the process termination logic (the
StdioClientTransport check and terminateProcessTree call) in a try-catch block
or use a try-finally structure to ensure that transport.close() is always
invoked regardless of whether the process tree termination succeeds or fails.
In `@test/main/presenter/pluginPresenter.test.ts`:
- Around line 930-951: The test sets up a spy on console.warn at the beginning
but never asserts that it was called, which means any regression in the failure
logging path would not be caught. Since the test mocks mcpPresenter.stopServer
to reject with an error on the first call (simulating a failure), add an expect
assertion after the presenter.shutdown() call to verify that consoleWarnSpy was
called, ensuring the warning is actually logged when the shutdown process
encounters the failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9dcaa214-6d67-40e3-aedf-9b2d6cc09658
📒 Files selected for processing (11)
docs/issues/plugin-shutdown-lifecycle/plan.mddocs/issues/plugin-shutdown-lifecycle/spec.mddocs/issues/plugin-shutdown-lifecycle/tasks.mdsrc/main/presenter/index.tssrc/main/presenter/mcpPresenter/index.tssrc/main/presenter/mcpPresenter/mcpClient.tssrc/main/presenter/pluginPresenter/index.tssrc/shared/types/presenters/core.presenter.d.tstest/main/presenter/mcpClient.test.tstest/main/presenter/mcpPresenter.test.tstest/main/presenter/pluginPresenter.test.ts
Summary
Tests
Summary by CodeRabbit
Release Notes
Bug Fixes
Improvements
Tests