fix: prevent macOS Metal JSON query aborts after successful output#687
Open
sk-holmes wants to merge 1 commit into
Open
fix: prevent macOS Metal JSON query aborts after successful output#687sk-holmes wants to merge 1 commit into
sk-holmes wants to merge 1 commit into
Conversation
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.
Problem
On macOS Metal,
qmd query --jsonandqmd deep-search --jsoncan 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
queryanddeep-searchruns.The parent process runs the query in a child process and accepts success only when both conditions are true:
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.mjsnode ./node_modules/typescript/bin/tsc -p tsconfig.build.json --noEmitQMD_FORCE_CPU=0 QMD_LLAMA_GPU=metal:qmd query "metal cleanup" --json -c docsqmd deep-search "metal cleanup" --json -c docsNotes
The workaround is intentionally narrow: Darwin only, JSON only,
query/deep-searchonly, non-child process only, and disabled for explicit CPU/no-GPU runs.