Skip to content

Stabilize bb-app tarball smoke port ownership - #3459

Merged
ymichael merged 2 commits into
mainfrom
bb/ci-flake-fix-bb-app-tarball-daemon-port-collisio-thr_yc7s5evq5r
Sep 11, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/ci-flake-fix-bb-app-tarball-daemon-port-collisio-thr_yc7s5evq5r

Conversation

@ymichael

@ymichael ymichael commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The Linux Node 26 compatibility job reserved a unique set of smoke ports, closed every listener, and only then spawned the packaged server and daemons. That guaranteed uniqueness within the set but left every selected port unowned across the bind boundary. Because the reservation had successfully bound port 37357, the eventual owner necessarily acquired it after release; matrix jobs run on separate runners, so another matrix leg could not own it. A packaged Intel reproduction deliberately reclaimed the released daemon port and reproduced the second issue: the daemon reported EADDRINUSE, but its top-level failure handler only assigned process.exitCode, so resources created before the failed local API bind kept the daemon child alive and the join launcher's readiness poll consumed its full 60-second deadline. The CI log cannot identify the short-lived competing process after the fact, but the reservation chronology proves the close-before-bind race regardless of that process's identity.

What changed

  • Keep each port reservation bound until the exact process launch that needs it. The separate-server smoke releases the server reservation immediately before the server spawn and each daemon reservation immediately before that daemon spawn; unused stale-URL and later-daemon ports remain owned.
  • Detect only concrete EADDRINUSE/host-daemon collision diagnostics from the managed process and redirected service logs, clean the complete failed attempt, and retry at most three times with fresh ports and fresh data directories. Other startup failures remain failures.
  • Continue checking /health, and additionally require the separate server's launch ID plus each daemon's connected /status server identity so a foreign HTTP 200 cannot satisfy readiness.
  • Write fatal startup diagnostics to stderr and exit from the write callback, guaranteeing piped diagnostics flush before active partial-startup resources are terminated.
  • Await every process and reservation cleanup result, including when another cleanup operation fails.

The packaged launchers accept numeric ports and spawn the actual listeners in child/grandchild processes; they do not accept an inherited listening socket. Passing a bound descriptor through that public launch architecture would be a much broader contract change, so the smoke narrows the release window and retries only the positively identified bind race at the whole-attempt boundary. No timeout, retry interval, CLI contract, or server/daemon wire field changed.

How you verified

  • Frozen base and Intel gate: host_nwqfteeqz4, x86_64, Intel Core i5-1038NG7; original HEAD and required merge-base a4f513251851bc357fbc0f28e61c331ea3f9f2e4. origin/main advanced afterward, but the branch retained the instructed frozen base.
  • Red packaged collision probe: a separate listener owned the selected daemon port; the fatal bind diagnostic appeared after 4.0 seconds; the join process was still exitCode=null, signalCode=null two seconds later.
  • Green packaged collision probe after the flush-order correction: the same occupied-port path produced the fatal diagnostic after 1.9 seconds and the join process exited 1 within the following two seconds, rather than waiting 60 seconds.
  • Temporary local-only first-attempt takeover injection, removed before commit: Turbo smoke printed daemon join port collision on attempt 1; retrying with fresh reservations, then passed the fresh separate server and two joined daemons in 10.2 seconds. The full packed-tarball smoke passed in 205.3 seconds.
  • pnpm exec turbo run smoke:tarball --filter=bb-app --output-logs=new-only — 13/13 tasks; final committed harness passed in 116.5 seconds, including pack/install/repack, provider bridges, plugin worker, full stack, health/status identity, persisted server URL, and two joined daemons.
  • pnpm exec turbo run test --filter=@bb/host-daemon --filter=bb-app --concurrency=2 --force — 50 host-daemon files / 591 tests and 4 bb-app files / 79 tests passed.
  • pnpm exec turbo run typecheck --filter=@bb/host-daemon --filter=bb-app --force — 5/5 tasks passed.
  • pnpm exec turbo run build --filter=bb-app — 12/12 tasks passed.
  • Review follow-up: the focused startup-diagnostics test passed 3/3, focused host-daemon typecheck passed 4/4 Turbo tasks, and the rebuilt packaged collision probe preserved the diagnostic-before-exit behavior.
  • pnpm exec prettier --check apps/host-daemon/src/index.ts apps/host-daemon/src/startup-diagnostics.test.ts packages/bb-app/scripts/smoke-tarball.mjs, node --check packages/bb-app/scripts/smoke-tarball.mjs, and git diff --check passed.
  • Every build/test/smoke/probe group ran under an external wall-clock bound with signal cleanup. Final checks found no owned descendant processes, listening probe ports, or bb-app-tarball-* / bb-port-repro-* temp directories.

AGENT GENERATED

@ymichael
ymichael merged commit 0623d5e into main Sep 11, 2026
16 checks passed
@ymichael
ymichael deleted the bb/ci-flake-fix-bb-app-tarball-daemon-port-collisio-thr_yc7s5evq5r branch September 11, 2026 03:32
ymichael added a commit that referenced this pull request Sep 15, 2026
## Human comments

## What was wrong

The packaged smoke launched each long-running surface as a detached
process-group leader, signaled the whole group during cleanup, but
considered cleanup complete as soon as only the leader emitted `exit`.
For `bb-server`, that leader is a launcher around the real server child:
the launcher exits immediately on the group signal while the child
handles the same signal with asynchronous plugin shutdown. In the
failing [macOS Node 26
job](https://github.com/get-bb/bb/actions/runs/34905198646/job/104180134470),
every assertion passed and the pass banner printed before recursive
removal hit `ENOTEMPTY` in `join-server-data-1/plugins`. A later
unchanged smoke passed, consistent with the descendant shutdown race. On
the frozen Intel base, temporary instrumentation observed the old stop
function return while the real server child was still running with PPID
1 in the leader's process group; a daemon group also still contained its
parcel-watcher child. The outer `rm` could therefore race descendants
that still owned the temporary data tree.

## What changed

- Move managed-process shutdown into a focused script helper.
- On POSIX, keep the existing group-wide `SIGINT`, five-second graceful
deadline, and `SIGTERM` escalation, but resolve cleanup only after
signal-0 observes that the entire process group is gone.
- Preserve the existing child-exit behavior on Windows, where detached
POSIX process groups are not used.
- Add a real-process regression whose group leader exits immediately
while a descendant completes asynchronous shutdown and writes a marker.
The cleanup promise must wait for that marker-producing descendant.
- Include MJS regression files in the existing bb-app Vitest project.

There are no CLI, SDK, configuration, server/daemon wire, or protocol
contract changes. `HOST_DAEMON_PROTOCOL_VERSION` remains 208 because the
change is confined to the smoke harness's local process lifecycle.

## How you verified

- Frozen-base gate: enrolled Intel host `host_nwqfteeqz4`, Intel Core
i5-1038NG7, `x86_64`, clean initial worktree, and
HEAD/origin/main/merge-base all
`475f4d6239fdab634c0991bcf0e4da6508154807`.
- Repeated GitHub searches for `ENOTEMPTY "directory not empty"`,
`join-server-data-1/plugins`, `NOQCov`, and open bb-app tarball cleanup
PRs returned no overlap. BB search found only this child and its parent
as active owners. Merged PR #3459 was inspected; it addressed port
reservation and fatal startup exit, not this cleanup boundary.
- Before fix, a Node 26 installed-tarball observation captured
`bb-server` leader PID 31862 exited while real server PID 31863 remained
running with PPID 1 and PGID 31862. The unchanged smoke happened to pass
in 109.5s, matching the intermittent nature of the main failure.
- Red regression check: temporarily restoring leader-only waiting made
`test/managed-process.test.mjs` fail with `ENOENT` because
`descendant-finished` did not exist when cleanup returned.
- Green Node 26 focused check: `pnpm exec turbo run test --filter=bb-app
--force -- test/managed-process.test.mjs` — 1/1 test and 4/4 Turbo tasks
passed.
- Node 26 direct installed-tarball smoke — all existing assertions
passed in 109.7s.
- Node 26 `pnpm exec turbo run smoke:tarball --filter=bb-app --force
--output-logs=new-only` — 50/50 tasks passed; tarball smoke passed in
108.8s.
- `pnpm exec turbo run test --filter=bb-app --force
--output-logs=new-only` — 6 files / 82 tests and 4/4 Turbo tasks passed.
- `pnpm exec turbo run typecheck --filter=bb-app --force
--output-logs=new-only` — 3/3 tasks passed.
- `pnpm exec turbo run build --filter=bb-app --force
--output-logs=new-only` — 49/49 tasks passed.
- Prettier checks, Node syntax checks for all changed MJS files, and
`git diff --check` passed.
- Every build/test/smoke/probe used an external process-group deadline.
Final bounded-smoke sentinels reported no remaining groups, and
filesystem/process scans found no matching smoke, probe, fixture, or
temporary directories.

Limitation: the exact `ENOTEMPTY` did not recur in the bounded local
full-smoke runs. The CI failure supplies the filesystem symptom; local
old-code instrumentation directly observed the surviving actual
descendants, and the focused fixture deterministically reproduced the
premature completion contract without adding contention, retries, sleeps
as cleanup, or deadline increases.

> AGENT GENERATED: by GPT-5.6-Sol
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