Skip to content

fix: add QMD_MAX_PARALLEL_CONTEXTS env var to prevent Metal deadlocks#569

Open
hteddy64 wants to merge 1 commit intotobi:mainfrom
hteddy64:fix/parallel-context-deadlock
Open

fix: add QMD_MAX_PARALLEL_CONTEXTS env var to prevent Metal deadlocks#569
hteddy64 wants to merge 1 commit intotobi:mainfrom
hteddy64:fix/parallel-context-deadlock

Conversation

@hteddy64
Copy link
Copy Markdown

Summary

  • Adds QMD_MAX_PARALLEL_CONTEXTS env var check at the top of computeParallelism() in src/llm.ts
  • When set (e.g., QMD_MAX_PARALLEL_CONTEXTS=1), caps context count before any GPU/CPU heuristic runs
  • Prevents node-llama-cpp Metal deadlocks when running as MCP server with multiple concurrent getEmbeddingFor/rankAll calls via Promise.all

Context

This was already patched in dist/llm.js as a production hotfix (2026-04-11). This PR ports the identical fix to the TypeScript source so it survives bun install -g @tobilu/qmd.

The deadlock manifests on macOS with Metal GPU acceleration when multiple MCP tool calls trigger parallel embedding/reranking contexts. Setting the env var to 1 in .mcp.json serializes context creation and eliminates the deadlock.

Test plan

  • Verified fix matches the working dist/llm.js patch (identical logic)
  • Build from source and confirm QMD_MAX_PARALLEL_CONTEXTS=1 limits to 1 context
  • Run MCP server with concurrent queries to confirm no deadlock

🤖 Generated with Claude Code

When running as an MCP server, multiple contexts calling
getEmbeddingFor/rankAll via Promise.all can deadlock on macOS Metal.
Setting QMD_MAX_PARALLEL_CONTEXTS=1 in the MCP config prevents this
by capping context count before any GPU/CPU heuristic runs.

This was already patched in dist/llm.js (production fix 2026-04-11).
This commit ports the same fix to the TypeScript source so it survives
the next `bun install -g @tobilu/qmd`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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