Skip to content

fix(scripts): abort deploy when compose_file_args reports a missing compose file - #7862

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jaytbarimbao-collab:fix-compose-args-exit-7765
Jul 21, 2026
Merged

fix(scripts): abort deploy when compose_file_args reports a missing compose file#7862
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jaytbarimbao-collab:fix-compose-args-exit-7765

Conversation

@jaytbarimbao-collab

Copy link
Copy Markdown
Contributor

Closes #7765

compose_file_args() (scripts/lib/selfhost-deploy-common.sh) exit 1s on a missing compose file, but all 4 callers consumed it through a process substitution:

mapfile -t compose_args < <(compose_file_args)

The process substitution runs compose_file_args in a subshell, so its exit 1 only kills that subshell — mapfile itself returns 0, set -e never fires, and the caller keeps going. Verified:

bash -c 'set -e; mapfile -t arr < <(false); echo "reached, len=${#arr[@]}"'   # -> reached, len=0

So a stale/mistyped docker-compose.override.yml or a bad SELFHOST_COMPOSE_FILES entry printed the intended error: compose file not found: X, but the deploy script continued and ran docker compose … pull/up/ps with an empty or truncated -f set instead of aborting.

Fix: consume it via a checked command-substitution assignment at all 4 call sites (deploy-selfhost-image.sh, deploy-selfhost-prebuilt.sh, selfhost-post-update-check.sh, selfhost-post-update-regression-gate.sh):

if ! compose_args_raw="$(compose_file_args)"; then
  exit 1
fi
mapfile -t compose_args <<< "$compose_args_raw"

A command-substitution assignment does propagate the inner exit code (including the truncated-partial-output case), regardless of set -e. compose_file_args's own logic is unchanged. Since it always emits at least one -f <file> pair on success, the here-string split can't produce a spurious empty element.

Tests: adds a compose_file_args exit propagation (#7765) block to selfhost-deploy-common.test.ts (which didn't cover it) — happy path continues with the right -f args, a missing sole file aborts before the consumer runs, and a later missing file aborts instead of continuing with a truncated arg list (the case a naive non-empty check would miss). Verified locally: bash -n clean on all 4 scripts, 11/11 tests pass, tsc --noEmit clean for the changed files. (scripts/** and test/** are outside the src/** 99% patch gate.)

compose_file_args() exits 1 on a missing compose file, but all 4 callers
consumed it via `mapfile -t compose_args < <(compose_file_args)`. The
process substitution runs the function in a subshell, so its exit 1 only
kills that subshell; mapfile itself returns 0, so set -e never fires and
the caller kept going -- invoking `docker compose` with an empty or
truncated -f set instead of aborting on a stale/mistyped compose path.

Consume it via a checked command-substitution assignment
(`if ! compose_args_raw="$(compose_file_args)"; then exit 1; fi`) at all 4
call sites, then split into the array with a here-string. This propagates
the real exit code (including the truncated-partial-output case) regardless
of set -e. compose_file_args's own logic is unchanged.

Adds compose_file_args exit-propagation tests to
selfhost-deploy-common.test.ts: happy path continues, a missing sole file
aborts before the consumer, and a later missing file aborts instead of
continuing with a truncated arg list.

Closes JSONbored#7765
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (299c842) to head (e6772ee).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7862   +/-   ##
=======================================
  Coverage   91.37%   91.37%           
=======================================
  Files         729      729           
  Lines       74694    74694           
  Branches    22795    22792    -3     
=======================================
  Hits        68252    68252           
  Misses       5396     5396           
  Partials     1046     1046           
Flag Coverage Δ
shard-1 54.49% <ø> (ø)
shard-2 55.19% <ø> (ø)
shard-3 51.32% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 21, 2026
@loopover-orb

loopover-orb Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-21 15:34:40 UTC

5 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This fixes a real bug: `mapfile -t compose_args < <(compose_file_args)` runs the function in a process substitution subshell, so `compose_file_args`'s `exit 1` on a missing compose file never propagates and `mapfile` returns 0 regardless — the caller continues with `set -e` never firing. The fix (checked command-substitution assignment, then `mapfile <<< "$var"`) correctly restores exit-code propagation at all 4 call sites, and the description's own repro (`bash -c 'set -e; mapfile -t arr < <(false); echo reached'` → reached) is accurate and verifiable bash behavior. The included tests exercise the real consumer idiom end-to-end (happy path, sole-file-missing, and the truncated-later-file-missing case a naive `[ -z ]` check would miss), which is solid coverage of the actual fix rather than a fabricated scenario.

Nits — 3 non-blocking
  • The identical fix + comment block is duplicated verbatim across 4 scripts (deploy-selfhost-image.sh, deploy-selfhost-prebuilt.sh, selfhost-post-update-check.sh, selfhost-post-update-regression-gate.sh) — since all 4 already source `lib/selfhost-deploy-common.sh`, consider hoisting this into a `compose_args_or_exit` helper there to avoid drifting copies next time this idiom needs to change.
  • In `compose_file_args exit propagation (compose_file_args()'s fatal exit 1 is silently neutered by mapfile < <(...) at all 4 call sites #7765)` test block, `runConsumer` doesn't clean up on the happy path's leftover trap/state between calls, but this is minor given each test uses a fresh tmpdir.
  • Consider adding a `compose_args_or_exit()` wrapper in scripts/lib/selfhost-deploy-common.sh that encapsulates the checked-assignment + mapfile idiom, replacing the 4 duplicated blocks with a single call site each.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7765
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 152 registered-repo PR(s), 73 merged, 16 issue(s).
Contributor context ✅ Confirmed Gittensor contributor jaytbarimbao-collab; Gittensor profile; 152 PR(s), 16 issue(s).
Improvement ℹ️ Insufficient signal risk: clean · value: insufficient-signal · LLM: moderate
Linked issue satisfaction

Addressed
The PR replaces the faulty `mapfile -t compose_args < <(compose_file_args)` idiom at all 4 named call sites with a checked command-substitution assignment that propagates the exit code and aborts before mapfile runs, exactly matching the issue's suggested fix, and adds a dedicated test block covering happy-path, sole-missing-file, and later-missing-file (truncation) scenarios.

Review context
  • Author: jaytbarimbao-collab
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Rust
  • Official Gittensor activity: 152 PR(s), 16 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 2ac97ad into JSONbored:main Jul 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compose_file_args()'s fatal exit 1 is silently neutered by mapfile < <(...) at all 4 call sites

1 participant