Skip to content

Prevent CLI commands from hanging#178

Open
RyanJarv wants to merge 3 commits intoruvnet:mainfrom
RyanJarv:main
Open

Prevent CLI commands from hanging#178
RyanJarv wants to merge 3 commits intoruvnet:mainfrom
RyanJarv:main

Conversation

@RyanJarv
Copy link
Copy Markdown

Before when running ruv-swarm --help help was printed but then the process hangs.

  • Defer construction of the EnhancedMCPTools singleton by wrapping the default export in a lazy proxy. Importing mcp-tools-enhanced.js now leaves SQLite pools closed until the first real method call.
  • Adjust the secure, secure-heartbeat, and clean entry points to work with the lazily initialized toolset and explicitly process.exit(0) after printing help or version` output so these code paths terminate promptly.
  • The proxy approach retains backward-compatible semantics today; longer term we can migrate callers to an explicit getter and drop the proxy once we’re ready to touch those modules.

Introduce a lazy proxy for the shared EnhancedMCPTools singleton so importing the module does not create the SQLite pool up front. Update each CLI entry point to reuse the initialized toolset, guard against triggering the lazy proxy, and call process.exit(0) for help/version flows. These changes keep non-operational commands like --help and --version from initializing persistence and ensure they terminate immediately.
@RyanJarv
Copy link
Copy Markdown
Author

RyanJarv commented Oct 16, 2025

This also fixes ./claude-flow training neural-train --data recent --model task-predictor, before it would hang on ruv-swarm.

@RyanJarv RyanJarv changed the title Prevent informational CLI commands from hanging Prevent CLI commands from hanging Oct 16, 2025
@RyanJarv
Copy link
Copy Markdown
Author

RyanJarv commented Oct 16, 2025

Added another fix for ruv-swarm status and other commands hanging

  • Made RuvSwarm.destroy() async, awaiting agent termination, pooled persistence shutdown, and WASM cleanup so connections are released before exit (npm/src/index-enhanced.js:39).
  • Taught the singleton container to await async destroy/clear/reset, and adjusted global teardown hooks plus resetContainer() to cope with promises (npm/src/singleton-container.js:83).
  • Refreshed the container’s test harness to operate asynchronously and to await the new async lifecycle methods (npm/test/singleton-container.test.js:27).

* Made RuvSwarm.destroy() async, awaiting agent termination, pooled persistence shutdown, and WASM cleanup so connections are released before exit (npm/src/index-enhanced.js:39).
* Taught the singleton container to await async destroy/clear/reset, and adjusted global teardown hooks plus resetContainer() to cope with promises (npm/src/singleton-container.js:83).
* Refreshed the container’s test harness to operate asynchronously and to await the new async lifecycle methods (npm/test/singleton-container.test.js:27).
Refactor the command entry points to register shared cleanup handlers and run them once at the end of execution, instead of sprinkling per-command process exits. Neural commands now rely on an explicit cleanup hook while EnhancedMCPTools and ClaudeFlowEnhanced expose asynchronous destroy() methods so pooled SQLite workers close reliably. Singleton container tests were updated to await the async lifecycle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant