fix(tools/git): ci-queue-wait.sh treats 404 branch-absent as queue-clear #874

Merged
Mos merged 2 commits from fix/ci-queue-wait-404-branch-absent into main 2026-07-23 17:08:58 +00:00
Owner

What

ci-queue-wait.sh is a mandatory pre-push CI queue guard. Its Gitea branch-head lookup
(gitea_get_branch_head_sha) called curl -fsSL .../branches/<branch>. For a branch that has
never been pushed to the remote yet, Gitea's API returns 404 for that endpoint. curl -f fails
on the 404, produces empty stdout, and the downstream python3 -c 'json.load(sys.stdin)' raises
JSONDecodeError -- crashing the guard. Since this guard runs before the first push, every new
feature branch's first push was blocked.

Fix

Capture the HTTP status via curl -sS -w '\n%{http_code}' instead of relying on curl -f:

  • 404 -> echo __BRANCH_ABSENT__, return 0. A branch that doesn't exist on the remote yet has
    no in-flight pipeline, so the pre-push guard should treat this as "queue clear," not crash.
  • non-200 -> return 1 (still fail-closed on a genuine API error, e.g. 500).
  • 200 -> parse the JSON as before (existing-branch behavior is unchanged).

The caller checks for the __BRANCH_ABSENT__ sentinel and exits 0 with a
branch not yet on remote -- queue clear message.

ci-queue-wait.ps1 had the identical bug (Invoke-RestMethod throws on any non-2xx status,
including 404, and the catch block unconditionally wrote an error and exited 1). Ported the
equivalent fix there: the catch block now inspects the caught exception's HTTP status code and
exits 0 with the same "queue clear" message on 404, while still failing closed on any other error.

Tests

Added packages/mosaic/framework/tools/git/test-ci-queue-wait-branch-absent.sh, a self-contained
regression harness (curl stubbed) covering:

  1. 404 branch-absent -> exit 0, "queue clear" message.
  2. 200 existing branch with a terminal CI status -> unchanged behavior (HEAD SHA resolved and
    logged as before).
  3. Genuine API error (500) -> still fails closed (nonzero exit, no "queue clear" message).

Verified red-first: run against the unpatched script, case 1 crashes with an uncaught
json.decoder.JSONDecodeError traceback and exits 1. Restoring the fix turns all 3 cases green.
Wired into packages/mosaic/package.json's test:framework-shell script, alongside the existing
git-wrapper regression tests, so it runs as part of pnpm test.

Quality gates

  • shellcheck on both changed/added shell files: clean except a pre-existing informational
    SC1091 (not-following a sourced sibling script) that is also present on the unmodified
    original file.
  • pwsh -NoProfile parser check on the .ps1 file: no parse errors.
  • pnpm --filter @mosaicstack/mosaic run test:framework-shell: all green, including the new test.
  • pnpm --filter @mosaicstack/mosaic run lint: clean.
  • pnpm typecheck (full monorepo via turbo): all 42 tasks green.
  • pnpm format:check: clean for every file this PR touches.

Incidental

Bundled as a separate commit: fixes pre-existing #868 README prettier drift
(packages/mosaic/framework/tools/orchestrator/README.md) to satisfy the repo-wide mandatory
pre-push format gate (pnpm typecheck && pnpm lint && pnpm format:check), which currently fails
on origin/main as-is regardless of this PR. Whitespace/table-alignment only, via
prettier --write -- no content change. Kept as its own commit so it no-ops cleanly once #868's
own fix lands on main.

Upstreams Mos host-local tooling-patch kit (2026-07-23), Patch 3.

Closes #872

## What `ci-queue-wait.sh` is a mandatory pre-push CI queue guard. Its Gitea branch-head lookup (`gitea_get_branch_head_sha`) called `curl -fsSL .../branches/<branch>`. For a branch that has never been pushed to the remote yet, Gitea's API returns 404 for that endpoint. `curl -f` fails on the 404, produces empty stdout, and the downstream `python3 -c 'json.load(sys.stdin)'` raises `JSONDecodeError` -- crashing the guard. Since this guard runs *before* the first push, every new feature branch's first push was blocked. ## Fix Capture the HTTP status via `curl -sS -w '\n%{http_code}'` instead of relying on `curl -f`: - **404** -> echo `__BRANCH_ABSENT__`, return 0. A branch that doesn't exist on the remote yet has no in-flight pipeline, so the pre-push guard should treat this as "queue clear," not crash. - **non-200** -> return 1 (still fail-closed on a genuine API error, e.g. 500). - **200** -> parse the JSON as before (existing-branch behavior is unchanged). The caller checks for the `__BRANCH_ABSENT__` sentinel and exits 0 with a `branch not yet on remote -- queue clear` message. `ci-queue-wait.ps1` had the identical bug (`Invoke-RestMethod` throws on any non-2xx status, including 404, and the `catch` block unconditionally wrote an error and exited 1). Ported the equivalent fix there: the `catch` block now inspects the caught exception's HTTP status code and exits 0 with the same "queue clear" message on 404, while still failing closed on any other error. ## Tests Added `packages/mosaic/framework/tools/git/test-ci-queue-wait-branch-absent.sh`, a self-contained regression harness (curl stubbed) covering: 1. 404 branch-absent -> exit 0, "queue clear" message. 2. 200 existing branch with a terminal CI status -> unchanged behavior (HEAD SHA resolved and logged as before). 3. Genuine API error (500) -> still fails closed (nonzero exit, no "queue clear" message). Verified red-first: run against the unpatched script, case 1 crashes with an uncaught `json.decoder.JSONDecodeError` traceback and exits 1. Restoring the fix turns all 3 cases green. Wired into `packages/mosaic/package.json`'s `test:framework-shell` script, alongside the existing git-wrapper regression tests, so it runs as part of `pnpm test`. ## Quality gates - `shellcheck` on both changed/added shell files: clean except a pre-existing informational `SC1091` (not-following a sourced sibling script) that is also present on the unmodified original file. - `pwsh -NoProfile` parser check on the `.ps1` file: no parse errors. - `pnpm --filter @mosaicstack/mosaic run test:framework-shell`: all green, including the new test. - `pnpm --filter @mosaicstack/mosaic run lint`: clean. - `pnpm typecheck` (full monorepo via turbo): all 42 tasks green. - `pnpm format:check`: clean for every file this PR touches. ## Incidental Bundled as a separate commit: fixes pre-existing #868 README prettier drift (`packages/mosaic/framework/tools/orchestrator/README.md`) to satisfy the repo-wide mandatory pre-push format gate (`pnpm typecheck && pnpm lint && pnpm format:check`), which currently fails on `origin/main` as-is regardless of this PR. Whitespace/table-alignment only, via `prettier --write` -- no content change. Kept as its own commit so it no-ops cleanly once #868's own fix lands on `main`. Upstreams Mos host-local tooling-patch kit (2026-07-23), Patch 3. Closes #872
jason.woltje added 2 commits 2026-07-23 16:44:04 +00:00
gitea_get_branch_head_sha() looked up a branch's head SHA via
`curl -fsSL .../branches/<branch>`. For a branch not yet pushed to the
remote, Gitea returns 404, curl -f fails, stdin is empty, and the
downstream `json.load` raises JSONDecodeError -- crashing the guard.
Since ci-queue-wait.sh is a mandatory pre-push check, every new feature
branch's first push was blocked.

Capture the HTTP status via `curl -sS -w '\n%{http_code}'`:
- 404  -> echo __BRANCH_ABSENT__, return 0 (no in-flight pipeline on a
          branch that doesn't exist yet -- queue is clear).
- non-200 -> return 1 (still fail-closed on a genuine API error).
- 200  -> parse the JSON as before (existing-branch behavior unchanged).

The caller checks for the __BRANCH_ABSENT__ sentinel and exits 0 with a
"branch not yet on remote -- queue clear" message.

ci-queue-wait.ps1 had the same bug (Invoke-RestMethod throws on any
non-2xx, including 404, and the catch block exited 1) -- ported the
equivalent fix there via the caught exception's HTTP status code.

Adds a red-first regression harness (test-ci-queue-wait-branch-absent.sh)
covering: 404 branch-absent -> queue clear; 200 existing branch with a
terminal CI state -> unchanged behavior; 500 genuine API error -> still
fail-closed. Verified failing against the unpatched script (crashes with
JSONDecodeError) and passing after the fix. Wired into
package.json's test:framework-shell alongside the existing git-wrapper
regression tests.

Upstreams Mos host-local tooling-patch kit (2026-07-23), Patch 3.
chore(orchestrator): fix pre-existing #868 README prettier drift
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
23cbdaf8df
packages/mosaic/framework/tools/orchestrator/README.md fails
`pnpm format:check` on origin/main as-is (confirmed against the
unmodified origin/main blob directly, unrelated to this branch's
Patch-3 change). The repo-wide mandatory pre-push hook
(`pnpm typecheck && pnpm lint && pnpm format:check`) blocks any push
based on current main until this is fixed.

Whitespace/table-alignment only via `prettier --write` -- no content
change. Kept as its own commit so blame stays clean and this no-ops
cleanly whenever #868's own fix lands on main first.
Mos approved these changes 2026-07-23 17:08:28 +00:00
Mos left a comment
First-time contributor

Gate-16 APPROVE -- stamped by Mos (id-11)

Registered under the distinct Mos bot identity (id-11) for cryptographic author!=reviewer separation on PR #874: PR author jason.woltje (id2) != approver Mos (id11). Registers the finalized verdict of the independent reviewer (fresh checkout, diff re-derived, adversarial); MS-LEAD prepared/relayed the RoR, Mos stamps+merges (MS-LEAD never touches id-11).

VERDICT: APPROVE @ 23cbdaf8df (Closes #872).

Finding-0 (commit-author metadata): both PR commits carry local git author/committer ms-lead-reviewer reviewer@mosaic.local (shared-checkout config used by all fleet subagents). The independent reviewer confirmed via the Gitea commit API that this resolves to author:null / committer:null (NO linked account) and verification.verified:false (unsigned) -- inert, unauthenticated local metadata, NOT a credential and never the load-bearing signal. The load-bearing Gate-16 separations HOLD: authenticated PR-author jason.woltje (id2) != authenticated approver Mos (id11); process independence is real (distinct adversarial subagents; this chain surfaced real defects incl. the C1 exports bug, the destructive test, and Finding-0 itself). Durable hygiene fix (c) tracked.

Independent review -- all 8 criteria PASS: (1) fix correctness 404->BRANCH_ABSENT/exit0, non-200 fail-closed; (2) PowerShell .ps1 parity; (3) red-first test reproduced + wired into test:framework-shell; (4) README chore whitespace-only; (5) scope tight; (6) firewall clean; (7) open/mergeable/CI green wp1974; (8) gates green.

6-CHECK re-verified by Mos @23cbdaf8df28fc6bcb894347feeaaea2d48a410b: open/not-merged/mergeable/base main; CI combined=success @exact head; reviewed==CI==merge head (full-40); independent APPROVE author!=reviewer no REQUEST-CHANGES; body Closes #872; queue-guard clear.

## Gate-16 APPROVE -- stamped by Mos (id-11) Registered under the distinct Mos bot identity (id-11) for cryptographic author!=reviewer separation on PR #874: PR author jason.woltje (id2) != approver Mos (id11). Registers the finalized verdict of the independent reviewer (fresh checkout, diff re-derived, adversarial); MS-LEAD prepared/relayed the RoR, Mos stamps+merges (MS-LEAD never touches id-11). VERDICT: APPROVE @ 23cbdaf8df28fc6bcb894347feeaaea2d48a410b (Closes #872). Finding-0 (commit-author metadata): both PR commits carry local git author/committer ms-lead-reviewer <reviewer@mosaic.local> (shared-checkout config used by all fleet subagents). The independent reviewer confirmed via the Gitea commit API that this resolves to author:null / committer:null (NO linked account) and verification.verified:false (unsigned) -- inert, unauthenticated local metadata, NOT a credential and never the load-bearing signal. The load-bearing Gate-16 separations HOLD: authenticated PR-author jason.woltje (id2) != authenticated approver Mos (id11); process independence is real (distinct adversarial subagents; this chain surfaced real defects incl. the C1 exports bug, the destructive test, and Finding-0 itself). Durable hygiene fix (c) tracked. Independent review -- all 8 criteria PASS: (1) fix correctness 404->__BRANCH_ABSENT__/exit0, non-200 fail-closed; (2) PowerShell .ps1 parity; (3) red-first test reproduced + wired into test:framework-shell; (4) README chore whitespace-only; (5) scope tight; (6) firewall clean; (7) open/mergeable/CI green wp1974; (8) gates green. 6-CHECK re-verified by Mos @23cbdaf8df28fc6bcb894347feeaaea2d48a410b: open/not-merged/mergeable/base main; CI combined=success @exact head; reviewed==CI==merge head (full-40); independent APPROVE author!=reviewer no REQUEST-CHANGES; body Closes #872; queue-guard clear.
Mos merged commit 48fd1df28a into main 2026-07-23 17:08:58 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#874