Skip to content

fix(release): stop SIGPIPE failing the checks that just succeeded - #43

Merged
stuffbucket merged 1 commit into
mainfrom
fix/release-verify-sigpipe
Sep 3, 2026
Merged

stuffbucket merged 1 commit into
mainfrom
fix/release-verify-sigpipe

Conversation

@stuffbucket

Copy link
Copy Markdown
Owner

v0.5.0-rc.4 produced a complete and correct release and the run still went red.

notice: maximal-v0.5.0-rc.4-darwin-arm64.dmg — 171287406 bytes, sha256 512120a8…, valid UDIF.
notice: All 4 assets are attached to v0.5.0-rc.4.
##[error]Process completed with exit code 1.

What actually failed

Not an assertion — the debug print above them:

ENTRIES="$(unzip -Z1 "$ZIP")"
echo "${ENTRIES}" | head -5          # ← here

The job runs under bash -eo pipefail. head exits after five lines, echo takes SIGPIPE, and pipefail promotes that 141 to the pipeline's status. The log shows exactly five entries printed and then the error — the tell.

The two printf … | grep -qxF assertions below it are the same bug and would have fired next: grep -q exits at the first match, so the closer a match is to the top of the listing, the more certainly the check fails. An Electron bundle lists thousands of entries, far past the 64K pipe buffer, so the writer can never finish first.

The zip was fine. Maximal.app/Contents/CodeResources — the stapled ticket — is right there in the listing the failing step printed.

Reproduction

6006-entry listing (396 KB), under bash -eo pipefail:

form exit
echo "$ENTRIES" | head -5 141
printf '%s\n' "$ENTRIES" | grep -qxF <early match> 141
head -5 <<< "$ENTRIES" 0
grep -qxF <early match> <<< "$ENTRIES" 0
grep -qxF <absent> <<< "$ENTRIES" 0, correctly reports absent

The fix

Herestrings. A herestring is a file, not a pipe, so there is no second exit status for pipefail to inherit, and the reader may exit whenever it likes.

The asset-wait loop gets the same treatment for a worse reason. There a SIGPIPE would not fail the step — it would take the || branch and record an asset that is attached as missing, then wait the full hour for it to appear.

Four pipelines are deliberately left alone: their input is a handful of short lines that fits in the pipe buffer in a single write().

Prior art

.macos-builder/build.sh already documents this exact hazard at its sidecar-provenance check, and uses process substitution to avoid it. This file reintroduced the pattern.

Related: #42 — because this fix lives in release.yml, it cannot apply to the already-cut v0.5.0-rc.4.

v0.5.0-rc.4 built, signed, notarized, stapled and uploaded all four
assets correctly, and the collect job still failed — at `echo "$ENTRIES"
| head -5`, before any assertion ran.

This job runs under `bash -eo pipefail`. Every reader in these pipelines
exits before consuming its input: `head` after five lines, `grep -q` at
the first match. The writer then takes SIGPIPE, and pipefail promotes
that 141 to the status of the whole pipeline, so a check that SUCCEEDED
reports failure. An Electron bundle lists thousands of entries, far past
the 64K pipe buffer, so the write cannot complete first — reproduced at
exit=141 with a 6006-entry listing, and at exit=0 after this change.

Herestrings instead: a file, not a pipe, so there is no second exit
status to inherit. The same hazard is documented at build.sh's
sidecar-provenance check; this file reintroduced it.

The asset-wait loop gets the same treatment for a worse reason. There a
SIGPIPE would not fail the step: it would take the `||` branch and
record an asset that IS attached as missing, then wait the full hour.

Untouched: four pipelines whose input is a handful of short lines that
fit in the pipe buffer in one write.
@stuffbucket
stuffbucket merged commit 8fbe94a into main Sep 3, 2026
6 checks passed
@stuffbucket
stuffbucket deleted the fix/release-verify-sigpipe branch September 3, 2026 23:52
stuffbucket added a commit that referenced this pull request Sep 4, 2026
Closes #42.

## Summary

Release verification logic moves out of `release.yml` into
`scripts/release/`, and a fixture-driven self-test runs it in the normal
PR gate. The goal is to make release shell testable before a tag is cut
rather than only during a release.

## Background

`release.yml` contained 522 lines of shell that executed for the first
time during a real release. A single iteration costs a tag, a 20-40
minute signed build, Apple's notarization queue, and a manual approval.
Two defects were found this way:

- **v0.5.0-rc.3**: the builder produced and checksummed the zip but
never uploaded it, because the workflow's upload allow-list omitted it.
- **v0.5.0-rc.4**: all four assets were built, signed, notarized,
stapled, and uploaded correctly, but the run failed on a debug line,
`echo "$ENTRIES" | head -5`.

`actionlint` and `shellcheck` both ran against this code and reported
nothing. Neither defect is detectable by static analysis; both are
detectable by execution.

## Changes

### New scripts

| Script | Responsibility |
|---|---|
| `contract.sh` | Parse `.macos-builder/config`, cross-check
`forge.config.ts`, expand `{tag}` and `{version}` |
| `verify-assets.sh` | Checksums, size floor, UDIF `koly` trailer, PKZip
magic, `Info.plist`, stapled-ticket marker |
| `prev-tag.sh` | Resolve the previously released tag |
| `selftest.sh` | Drive the above against fixtures, asserting both
success and failure paths |

`release.yml` retains only orchestration: the job graph, `gh` calls,
output wiring, and the asset wait loop. It drops from 522 to roughly 430
lines.

### CI

`selftest.sh` and `shellcheck` run in the `check` job, before the
install step. They are placed inside that job rather than in a separate
one because `build / typecheck / lint / test` is the only check required
by main's ruleset; a separate job would run without gating merges.

`shellcheck` coverage now includes `scripts/verify-dmg.sh`, which was
485 lines that no linter or test had previously exercised. It required
no changes.

### Contract resolution

The contract is now read from the tag via `git show`, while the scripts
and workflow come from the checkout:

| Source | Read from | Rationale |
|---|---|---|
| `release.yml`, `scripts/release/` | The dispatched branch | A fix to
release machinery can reach an already-cut tag |
| `.macos-builder/config`, `forge.config.ts` | The tag | The released
contract is always the tag's own |

On a tag push these are the same commit. On `workflow_dispatch` the
checkout is a branch, and this split prevents building the tag's commit
against `main`'s contract. This is the code-side prerequisite for #42;
see Follow-ups.

### Previous-tag selection

The prior implementation was:

```sh
git tag --list 'v*' --sort=-creatordate | grep -vxF "$TAG" | head -1
```

This returns the newest tag that is not `$TAG`, which is a *newer* tag
whenever an older tag is re-released. Against the current tag list,
re-releasing `v0.5.0-rc.3` would compare its bundle identity against
`v0.5.0-rc.5`. The replacement takes the entry following `$TAG` in a
newest-first listing, which is the previous release by construction.
Covered by four test cases.

## Verification

**Self-test**: 27 assertions, 0 failures, approximately 2 seconds.
Identical results on macOS (bash 3.2) and on the Ubuntu runner.

**Regression detection.** Reintroducing either failed form causes the
suite to fail:

| Reintroduced | Result |
|---|---|
| `echo "$ENTRIES" \| head -5` | Exit 141, matching the rc.4 failure |
| `printf … \| grep -qxF …` | Reports a stapled app as unstapled |

The second case is the more dangerous of the two: it does not crash, it
inverts the verdict of the check that guards offline launch.

**Real artifacts.** `verify-assets.sh` was run against the released
`v0.5.0-rc.4` dmg and zip (320 MB): the computed sha256 matches what the
release run reported, the UDIF trailer validates, and the zip's
`Maximal.app` is confirmed stapled. Exit 0 in 0.83s, including the
rewritten trailer read (`dd` at an offset, replacing `tail -c 512 | head
-c 4`), which costs 0.13s of CPU on a 171 MB image.

`shellcheck` and `actionlint` are clean.

## Correction to the rc.4 diagnosis

The commit message for #43 stated that the zip listing was "thousands of
entries, far past the 64K pipe buffer, so the write cannot complete."
This was incorrect.

The actual listing is 604 entries, 55,827 bytes, which is below a pipe's
64 KB capacity. The failure is a race rather than a size threshold:
`head` closes the read end after five lines, and whether the writer has
finished by then depends on scheduling. The Ubuntu runner lost the race;
the same pipeline over the same artifact exits 0 on macOS.

This makes the original defect intermittent and platform-dependent. The
zip fixture is therefore sized at 6,009 entries (353,196 bytes), roughly
six times the real listing, so that a reintroduced pipeline fails
deterministically on any machine. `selftest.sh` asserts the fixture
remains large enough, and fails if it does not.

## Follow-ups

This PR completes only the code half of #42. Dispatch-based recovery
additionally requires a branch to be added to the `release`
environment's deployment policy, which is a repository setting and not
changed here.
stuffbucket added a commit that referenced this pull request Sep 8, 2026
## Summary

- update the transitive `fast-uri` lockfile resolution from 3.1.5 to
3.1.6
- remediate Dependabot alerts #38, #39, #42, and #43
- retain `[email protected]`; its existing dependency range accepts the patched
release

## Security

GitHub reports four high-severity advisories affecting 3.1.5, covering
malformed IPv6 normalization, percent-encoded scheme normalization,
repeated hostname percent-decoding, and skipped IDN canonicalization.
All identify 3.1.6 as the first patched version.

## Validation

- `pnpm why fast-uri -r` resolves only `[email protected]`
- `pnpm audit --audit-level high` reports no high-severity findings
(three unrelated moderate findings remain)
- `pnpm test` passes: 15/15 Turbo tasks
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