fix(cli): process.exit at entry point to prevent ONNX event loop hang#1441
Open
marioja wants to merge 1 commit intoruvnet:mainfrom
Open
fix(cli): process.exit at entry point to prevent ONNX event loop hang#1441marioja wants to merge 1 commit intoruvnet:mainfrom
marioja wants to merge 1 commit intoruvnet:mainfrom
Conversation
alzweidi
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1428 —
ruflo memory init,ruflo memory stats, and other memory subcommands hang indefinitely after completing because ONNX/WASM worker threads (from@xenova/transformers/all-MiniLM-L6-v2) keep the Node.js event loop alive.Root cause
When any memory subcommand calls
callMCPTool(), it triggersensureInitialized()inmemory-tools.ts, which loads the ONNX embedding model. The ONNX runtime spawns worker threads that are never terminated, preventing Node.js from exiting naturally.Why the fix is in
bin/cli.jsand not ininitMemoryCommandThe original inline fix (removed in this PR) placed a
setTimeout(() => process.exit(0), 500).unref()insideinitMemoryCommand. This was wrong for several reasons:Only fixed one command. Every memory subcommand (
stats,store,search,list,cleanup,compress, etc.) triggers the same ONNX load viaensureInitialized(), so every one of them hangs. Fixing them individually means 20+ call sites, each a maintenance burden and a place to forget.Commands shouldn't call
process.exit(). A command'sactionfunction is a library method — it returns a result object ({ success, data }) to its caller. Callingprocess.exit()inside it breaks testability (unit tests mockprocess.exitand the mock throws, failing the test) and violates separation of concerns. The command doesn't know if it's being called from a CLI binary, a test harness, or programmatic API usage.The entry point is the right place.
bin/cli.jsis the actual process boundary — it creates theCLIinstance, callscli.run(), and is responsible for process lifecycle. Adding.then(() => process.exit(0))here means:CLI.run()stays a pure library method that tests canawaitwithout side effectsChanges
bin/cli.jsprocess.exit(0)in.then()aftercli.run()resolvessrc/commands/memory.tssetTimeout/process.exithack frominitMemoryCommandTesting
Unit tests: 32 passed, 1 skipped (unchanged from baseline).
🤖 Generated with claude-flow