fix(mcp): env-scoped stdio start runs inline instead of bridging (#87) - #145
Merged
Merged
Conversation
… bridge Pins the fix before it lands: ENGRAM_SCOPE / ENGRAM_READ_SCOPES on a stdio start force inline without probing, ENGRAM_DB_PATH bridges only when the daemon's /health reports the same database, and an end-to-end child with ENGRAM_SCOPE set never opens a daemon session. Autoresearch baseline (iteration 0): these fail on main. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BoKzYWjzY9jngoKL35LWSA
Root cause: decideStdioMode probed /health first and bridged whenever the daemon answered, while runBridge forwards tools/call verbatim — so ENGRAM_SCOPE / ENGRAM_READ_SCOPES / ENGRAM_DB_PATH in the stdio process's env (every Hermes profile child sets the first two) were resolved under the daemon's env instead. Every profile wrote global and read every scope. Fix, at the one decision point all stdio starts route through: - ENGRAM_SCOPE / ENGRAM_READ_SCOPES set (non-blank) → inline, no probe, reason names the variable. - /health now carries dbPath; ENGRAM_DB_PATH set and different → inline. A daemon without dbPath (older build) keeps bridging. Docs: README, CLAUDE.md, integrate-your-agent, CHANGELOG (Fixed). Autoresearch iteration 1: bridge.test.ts failures 3 → 0, lint passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BoKzYWjzY9jngoKL35LWSA
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.
Closes #87.
Root cause
decideStdioMode(src/interfaces/mcp/bridge.ts) probed/healthbefore looking at its own env, andrunBridgeforwardstools/callverbatim — soENGRAM_SCOPE/ENGRAM_READ_SCOPES/ENGRAM_DB_PATHof the stdio process were resolved under the daemon's env. The Hermes plugin is stdio-only and always setsENGRAM_SCOPE, so every profile wroteglobaland read every scope whenever the daemon was up.Fix
At the one decision point every stdio start routes through:
ENGRAM_SCOPE/ENGRAM_READ_SCOPES(non-blank) → inline, no probe; stderr names the variable:running inline (ENGRAM_SCOPE=hermes:career is per-process; the daemon would ignore it)./healthnow reportsdbPath; withENGRAM_DB_PATHset the bridge is used only when it matches (path.resolve), else inline. A daemon withoutdbPath(older build) keeps bridging.Docs: README, CLAUDE.md,
docs/integrate-your-agent.md, CHANGELOG (Fixed).Tests
Three regression tests in
tests/interfaces/mcp/bridge.test.ts(unit for both rules, plus an end-to-end child withENGRAM_SCOPEand a healthy daemon that never opens a daemon session). They fail onmain(3) and pass here (0).npm run lintclean; full suite 132 files / 1692 tests pass.Not done (deliberately): translating env into per-call
scope/read_scopesinside the bridge — tools without those params (show,fetch_snippets,recall_drill) still read env, so translation would leak. Inline is the only complete fix.🤖 Generated with Claude Code
https://claude.ai/code/session_01BoKzYWjzY9jngoKL35LWSA