fix(scripts): SIGPIPE-safe first-line selection in 5 scripts#1023
Merged
Lightheartdevs merged 1 commit intoLight-Heart-Labs:mainfrom Apr 27, 2026
Merged
Conversation
Five scripts used `| head -1 |` (or `| head -n 1 |`) inside pipelines under `set -euo pipefail`. When the upstream producer emits multiple lines, `head` closes its stdin after reading line 1 and SIGPIPE (141) propagates back, terminating the pipeline and — under pipefail — aborting the script. Trigger cases: - Multi-GPU NVIDIA hosts: nvidia-smi emits N lines -> pre-download.sh and dream-preflight.sh abort during model selection / GPU probe. - 2+ downloaded GGUFs: ls -1 *.gguf -> check-offline-models.sh aborts. - Duplicate keys in .env: grep matches multiple lines -> read_env_value and read_searxng_secret silently return empty values (|| true suppresses abort but VAR is empty/truncated). Replace with `| sed -n '1p' |` -- identical on BSD and GNU sed, consumes full stdin so upstream producers never receive SIGPIPE.
4 tasks
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.
What
Replace
| head -1 |/| head -n 1 |with| sed -n '1p' |in five scripts to eliminate SIGPIPE termination underset -euo pipefail.Why
head -1closes its stdin after consuming one line. When the upstream pipeline stage produces multiple lines (multi-GPU nvidia-smi output, multiple GGUFs, duplicate .env keys), the resulting SIGPIPE (exit 141) propagates back through the pipeline and — because all five files run underset -euo pipefail— aborts the script entirely. The three distinct trigger conditions are:nvidia-smi --query-gpu=...emits one line per GPU.pre-download.sh(VRAM detection) anddream-preflight.sh(GPU probe) both abort on the SIGPIPE.ls -1 data/models/*.ggufon a host with 2+ downloaded models causescheck-offline-models.shto abort before reporting status..env:grepreturns multiple matches;read_env_value(dream-macos.sh + env-generator.sh) andread_searxng_secret(env-generator.sh) silently return empty strings — the|| trueguard prevents script abort but leaves the variable empty/truncated.How
Six targeted substitutions across 5 files:
dream-server/scripts/pre-download.shhead -1→sed -n '1p'dream-server/scripts/dream-preflight.shhead -1→sed -n '1p'dream-server/scripts/check-offline-models.shhead -1→sed -n '1p'dream-server/installers/macos/dream-macos.shhead -n 1→sed -n '1p'dream-server/installers/macos/lib/env-generator.shhead -n 1→sed -n '1p'dream-server/installers/macos/lib/env-generator.shhead -n 1→sed -n '1p'sed -n '1p'consumes the full stdin stream before exiting, so the upstream producer never receives SIGPIPE. It is identical in behaviour on BSD sed (macOS) and GNU sed (Linux).Testing
bash -nsyntax check passes on all 5 files. ShellCheck: no new warnings introduced.dream-server/scripts/pre-download.shanddream-server/scripts/dream-preflight.shon a host with 2+ GPUs — both should complete without SIGPIPE exit 141..gguffiles indata/models/and rundream-server/scripts/check-offline-models.sh— should enumerate correctly..envand run through the macOS installerread_env_valuepath — should return the first value, not empty.Platform Impact
dream-macos.shandenv-generator.shfixes apply here only.pre-download.shanddream-preflight.shfixes apply to multi-GPU NVIDIA hosts.check-offline-models.shfix applies to any platform with 2+ GGUFs.Known Considerations
None — mechanical substitutions only; no logic changes.