#166 — startBuild refuses a rebuild while one is in flight #167

Merged
matou-build-agent merged 1 commit from agent/issue-166 into main 2026-09-27 16:33:45 +00:00

closes #166

Closes #166.

What

startBuild (server/src/build-pipeline.ts) now refuses to dispatch while a build is already in flight (the ticket's proposed default, option 1). When status.state === 'building' it dispatches nothing, rewrites no kit.json, and returns the in-flight status untouched — so rebuild/triggerBuild hand back "building (build N)".

Why

A second dispatch before the first coa-builds run's prepare stage rewrote kit.json to build N+1. The runner fetches kit.json at run time and fails any run whose number moved on (kit build N+1 != N), so the first, still-queued build N went red for a build that was never lost (whakatohea-demo builds 8/9, coa-builds run 21).

Details

  • Escape hatch BUILD_STALE_MS (2 h): a building older than the window (a dead runner) may still be superseded.
  • /api/submit's same-address rebuild path already refused an in-flight slug (idss#1855); this closes the same gap for make rebuild / make build-app and any other startBuild caller.
  • Two regression tests: two dispatches in a row leave exactly one build that can succeed with no failure recorded for the other; a stale building is superseded. The existing "bumps the build number on rebuild" test now completes the prior build first.
  • On "who dispatched build 9": the /api/submit rebuild path already declined an in-flight building by name, so the duplicate came from another startBuild caller (a second make rebuild/build-app or the IDSS card try again) — exactly the gap this closes.

Tests

pnpm -r typecheck and pnpm -r test green (server 133, site 72).

Screenshots: none — server/schema seam change with no UI surface; verified by Vitest regression tests.

🤖 Generated with Claude Code

closes #166 Closes #166. ## What `startBuild` (`server/src/build-pipeline.ts`) now refuses to dispatch while a build is already in flight (the ticket's proposed default, option 1). When `status.state === 'building'` it dispatches nothing, rewrites no `kit.json`, and returns the in-flight status untouched — so `rebuild`/`triggerBuild` hand back "building (build N)". ## Why A second dispatch before the first coa-builds run's prepare stage rewrote `kit.json` to build N+1. The runner fetches `kit.json` at run time and fails any run whose number moved on (`kit build N+1 != N`), so the first, still-queued build N went red for a build that was never lost (whakatohea-demo builds 8/9, coa-builds run 21). ## Details - Escape hatch `BUILD_STALE_MS` (2 h): a `building` older than the window (a dead runner) may still be superseded. - `/api/submit`'s same-address rebuild path already refused an in-flight slug (idss#1855); this closes the same gap for `make rebuild` / `make build-app` and any other `startBuild` caller. - Two regression tests: two dispatches in a row leave exactly one build that can succeed with no failure recorded for the other; a stale `building` is superseded. The existing "bumps the build number on rebuild" test now completes the prior build first. - On "who dispatched build 9": the `/api/submit` rebuild path already declined an in-flight `building` by name, so the duplicate came from another `startBuild` caller (a second `make rebuild`/`build-app` or the IDSS card *try again*) — exactly the gap this closes. ## Tests `pnpm -r typecheck` and `pnpm -r test` green (server 133, site 72). **Screenshots:** none — server/schema seam change with no UI surface; verified by Vitest regression tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sandcastle: #166 — startBuild refuses a rebuild while one is in flight
All checks were successful
ci / seam (pull_request) Successful in 51s
7964aa5bf0
A second build dispatch before the first coa-builds run's prepare stage
rewrote kit.json to build N+1, so the runner (which fetches kit.json at run
time) failed the still-queued build N with `kit build N+1 != N` and reported
a real-looking failure (whakatohea-demo builds 8/9, coa-builds run 21).

startBuild now refuses while a build is in flight (option 1, the ticket's
proposed default): with status.state === 'building' it dispatches nothing,
rewrites no kit, and returns the in-flight status untouched, so rebuild /
triggerBuild hand back "building (build N)". Escape hatch BUILD_STALE_MS (2 h)
supersedes a dead runner's building. /api/submit's same-address rebuild path
already refused an in-flight slug (idss#1855); this closes the same gap for
make rebuild / make build-app and any other startBuild caller.

- server/src/build-pipeline.ts: buildInFlight guard + BUILD_STALE_MS
- server/test/build-pipeline.test.ts: two regression tests (two dispatches
  leave exactly one build to succeed, no failure for the other; a stale
  building is superseded); existing "bumps on rebuild" completes the prior
  build first
- docs/GOTCHAS.md 24; STATUS.md header + log

Two-way door (revertible code, provable by tests) — ruled by agent under ADR 0002.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/coa!167
No description provided.