Skip to content

fix: prevent macOS Metal JSON query aborts after successful output#687

Open
sk-holmes wants to merge 1 commit into
tobi:mainfrom
sk-holmes:fix/metal-json-cleanup
Open

fix: prevent macOS Metal JSON query aborts after successful output#687
sk-holmes wants to merge 1 commit into
tobi:mainfrom
sk-holmes:fix/metal-json-cleanup

Conversation

@sk-holmes
Copy link
Copy Markdown

Problem

On macOS Metal, qmd query --json and qmd deep-search --json can produce valid JSON and then abort during native llama.cpp cleanup. That leaves callers with a non-zero exit even though the command already completed successfully.

This mainly breaks machine-readable JSON workflows. The output is valid, but the process lifecycle reports failure.

Fix

This adds a macOS-only supervised exit path for GPU-backed JSON query and deep-search runs.

The parent process runs the query in a child process and accepts success only when both conditions are true:

  • stdout parses as valid JSON
  • the child writes a success sentinel on a side-channel fd after output is flushed

The child then terminates before native Metal finalizers can abort after successful output. Real query failures still return through the normal failure path.

I also tightened the GPU env handling so the supervisor only runs when GPU use is actually enabled, and the CLI reuses the same GPU-disabled semantics as the LLM layer.

Verification

  • node scripts/build.mjs
  • node ./node_modules/typescript/bin/tsc -p tsconfig.build.json --noEmit
  • full Node/Vitest suite: 24 files passed, 824 passed, 73 skipped
  • real macOS fixture checks with QMD_FORCE_CPU=0 QMD_LLAMA_GPU=metal:
    • qmd query "metal cleanup" --json -c docs
    • qmd deep-search "metal cleanup" --json -c docs

Notes

The workaround is intentionally narrow: Darwin only, JSON only, query/deep-search only, non-child process only, and disabled for explicit CPU/no-GPU runs.

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