fix: prevent stdout pollution breaking MCP JSON protocol#48
fix: prevent stdout pollution breaking MCP JSON protocol#48Tapiocapioca wants to merge 1 commit intoobra:mainfrom
Conversation
The embeddings module was outputting messages to stdout via console.log and @xenova/transformers progress callbacks. In MCP context, stdout is reserved for JSON-RPC communication, so any non-JSON output corrupts the protocol and causes connection errors like: "Unexpected token 'L', "Loading em"... is not valid JSON" Changes: - Change console.log -> console.error for status messages - Add progress_callback: null to silence @xenova/transformers output - Configure env settings to prevent additional stdout pollution Tested and verified working in Claude Code 2.1.2 on Windows. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe embeddings module is configured to use local models, disable browser caching, suppress pipeline initialization progress output to reduce noise, and redirect logging output from stdout to stderr for improved clarity. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-12-21T08:52:59.897ZApplied to files:
🧬 Code graph analysis (1)src/embeddings.ts (1)
🔇 Additional comments (4)
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 |
- Redirect embedding model log messages from stdout to stderr and suppress @xenova/transformers progress callbacks. Stdout is reserved for MCP JSON-RPC communication and any non-JSON output corrupts the protocol. (credit: obra#48) - Add 'clear' to the SessionStart hook matcher so conversations are archived when users run /clear, not just on startup/resume. (credit: obra#51) - Add SIGHUP handler and stdin close detection to the MCP server wrapper so child processes are cleaned up when the terminal closes or Claude crashes. (credit: obra#54)
Summary
Hey Jesse! 👋
Gran lavoro con episodic-memory, è fantastico! Ho trovato un piccolo bug e ho già preparato il fix - magari ti può aiutare!
The Problem
The
embeddings.tsmodule outputs messages to stdout viaconsole.logand@xenova/transformersprogress callbacks. In MCP context, stdout is reserved for JSON-RPC communication, so any non-JSON output corrupts the protocol.Error seen in Claude Code debug logs:
The Fix
console.log→console.errorfor status messages (stderr is safe in MCP){ progress_callback: null }to silence@xenova/transformersprogress outputTesting
Tested and verified working in Claude Code 2.1.2 on Windows 11.
Related issue: #47
🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.