Skip to content

fix(scripts): SIGPIPE-safe first-line selection in 5 scripts#1023

Merged
Lightheartdevs merged 1 commit intoLight-Heart-Labs:mainfrom
yasinBursali:fix/shell-sigpipe-sweep-4scripts
Apr 27, 2026
Merged

fix(scripts): SIGPIPE-safe first-line selection in 5 scripts#1023
Lightheartdevs merged 1 commit intoLight-Heart-Labs:mainfrom
yasinBursali:fix/shell-sigpipe-sweep-4scripts

Conversation

@yasinBursali
Copy link
Copy Markdown
Contributor

What

Replace | head -1 | / | head -n 1 | with | sed -n '1p' | in five scripts to eliminate SIGPIPE termination under set -euo pipefail.

Why

head -1 closes 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 under set -euo pipefail — aborts the script entirely. The three distinct trigger conditions are:

  • Multi-GPU NVIDIA host: nvidia-smi --query-gpu=... emits one line per GPU. pre-download.sh (VRAM detection) and dream-preflight.sh (GPU probe) both abort on the SIGPIPE.
  • Multiple GGUFs present: ls -1 data/models/*.gguf on a host with 2+ downloaded models causes check-offline-models.sh to abort before reporting status.
  • Duplicate key in .env: grep returns multiple matches; read_env_value (dream-macos.sh + env-generator.sh) and read_searxng_secret (env-generator.sh) silently return empty strings — the || true guard prevents script abort but leaves the variable empty/truncated.

How

Six targeted substitutions across 5 files:

File Line Change
dream-server/scripts/pre-download.sh 112 head -1sed -n '1p'
dream-server/scripts/dream-preflight.sh 87 head -1sed -n '1p'
dream-server/scripts/check-offline-models.sh 27 head -1sed -n '1p'
dream-server/installers/macos/dream-macos.sh 158 head -n 1sed -n '1p'
dream-server/installers/macos/lib/env-generator.sh 39 head -n 1sed -n '1p'
dream-server/installers/macos/lib/env-generator.sh 51 head -n 1sed -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

  • Automated: bash -n syntax check passes on all 5 files. ShellCheck: no new warnings introduced.
  • Manual (Linux NVIDIA multi-GPU): Run dream-server/scripts/pre-download.sh and dream-server/scripts/dream-preflight.sh on a host with 2+ GPUs — both should complete without SIGPIPE exit 141.
  • Manual (macOS, multiple GGUFs): Place 2+ .gguf files in data/models/ and run dream-server/scripts/check-offline-models.sh — should enumerate correctly.
  • Manual (macOS, duplicate .env key): Add a duplicate key to .env and run through the macOS installer read_env_value path — should return the first value, not empty.

Platform Impact

  • macOS: Affected — dream-macos.sh and env-generator.sh fixes apply here only.
  • Linux (NVIDIA): Affected — pre-download.sh and dream-preflight.sh fixes apply to multi-GPU NVIDIA hosts.
  • Linux (AMD/CPU): check-offline-models.sh fix applies to any platform with 2+ GGUFs.
  • Windows (WSL2): Not directly affected — these scripts run on the Linux / macOS side. WSL2 inherits Linux behaviour if any of these scripts are invoked there.

Known Considerations

None — mechanical substitutions only; no logic changes.

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.
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.

2 participants