Skip to content

fix(platform): end itest /events tails and exit a truncated run - #4133

Merged
yannickmonney merged 2 commits into
mainfrom
fix/itest-bell-wire-sse-hang
Oct 3, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
fix/itest-bell-wire-sse-hang

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

The Backend integration job hung in lane 49, checkBellHintWire, five times in two days on unrelated PRs. After the 10-minute lane guard fired, it sat out the 30-minute step timeout with no tally. This fixes both defects at the root.

Root cause 1: the lane's abort was lost to garbage collection

routeVendorFetch (integration-vendor-stub.ts) is the harness's outbound boundary, installed as globalThis.fetch on 2026-10-01 (98d9965a2), the day before the first hang. It built new Request(input, init) and handed that request to fetch.

  • undici makes a request's signal follow the signal it was built from through a WeakRef to an AbortController that only that request holds.
  • Nothing held the intermediate request once fetch had answered. undici keeps only its own request alive (SSE connection may leak when fetch init.redirect = 'error' nodejs/undici#4627).
  • So a GC between the /events response and abort() dropped the link. The abort never reached the socket, the SSE body never ended, and await mateStream.done waited until the lane deadline.

Lane 49 has the widest gap between a tail's response and its abort (sleep 700 + read-all + waitFor), which is why it was always this lane.

Fix: the boundary hands fetch the caller's own signal (callerSignal), so fetch's kept-alive request follows it directly.

Root cause 2: a truncated run never reached its tally

main()'s finally closed the backend with a bare server.close(), which waits for every open connection. The stuck lane's /events tail never ends (15 s heartbeats). http-shutdown.test.ts already pins that premise ("a bare server.close() parks while an /events stream is open").

Fix: the teardown closes the backend with the deployment's own closeServerGracefully, which ends every live stream and then force-closes what remains. Every teardown step is bounded (settleTeardown, 60 s each): a step that hangs or throws is recorded as a failed check naming it, and the harness still prints its tally and exits.

Also

  • connectSse moves to integration-lane-helpers.ts with a bounded close(). It cancels the body reader before it aborts, so the read ends on this side even if an abort never reaches the connection. If the tail still doesn't settle, the lane fails within 5 s with closing the SSE tail /events?orgId=… did not settle within 5 s, not at the 10-minute guard. All six harness tails use it.
  • checkBellHintWire closes both tails and deletes p-bell-wire in finally, which is Follow-ups from the #4056 review: a stale unread row after a withheld undo, per-recipient access rechecks, bell-lane cleanup, test gaps and Watch wording #4077 item 5. Its assertions are unchanged.
  • withinDeadline and errorText move to the helpers, and deadlines under a minute now read in seconds.
  • The backend README documents the truncation exit and connectSse.
  • No migration, no product code, no retry.

Verification

Regression tests. Each fails on main and passes at this head.

Test On main Here
integration-vendor-stub.test.ts › ends a streamed response on abort after a garbage collection, as fetch does (real SSE server + forced GC; plain fetch as the control) fails: still open 2 s after the abort (the plain fetch: AbortError) passes
integration-lane-helpers.test.ts › connectSse › ends a tail whose abort never reaches its connection; fails a close it cannot finish within the bound, naming the tail cannot run: main's connectSse is private to integration-check.ts and has no bound. Its scenario on main is seam A below, which hangs to the lane deadline passes
integration-lane-helpers.test.ts › settleTeardown › names a step that never settles and still runs the next ones; closes the backend while a stuck lane's /events tail is still open (main's bare close is named as not settling, and the graceful close settles) cannot run: main's teardown is inline and unbounded. Its scenario on main is seam B below, which never prints a tally passes

Probe on CI's Node 22.21.1 (undici 6.22.0) and on Node 24.21.0 (undici 7.29.1): fetch(url,{signal}) + GC + abort gives AbortError. The old boundary + GC + abort leaves the body still open. Without GC, both give AbortError.

Real harness, local (PG 16.14 + pgvector, no pg_search, so the BM25 boot check fails locally; Node 22.21.1; ITEST_LANES=checkCollabEmitters,checkBellHintWire,checkBoardMoveEffects). The seams are uncommitted:

  • Seam A: one gc() between the mate's bell hint and the abort.
  • Seam B: the lane hangs holding both tails, with the lane deadline at 20 s.
Run main a7efe1c51 this head
Seam A (GC) 11:40:44 GC → 11:50:42 RUN TRUNCATED at lane 2 of 3 (checkBellHintWire) … did not settle within 10 min → no tally; killed by timeout at 11:56:07 (exit 124) 11:57:25 GC → PASS personal bell hint wire in the same second → [itest] 20/21 checks passed across 3/3 lanes, 38 s
Seam B (stuck lane) 11:59:21 RUN TRUNCATED → no tally; killed at 12:01:32 (exit 124) 11:58:24 RUN TRUNCATED … did not settle within 20 s → 11:58:25 [itest] RUN TRUNCATED at checkBellHintWire — 2/3 lanes ran + 18/20 checks passed, exit 1

Ten clean runs of the lane and its neighbours at this head (no seam, Node 22.21.1, a fresh database each): 10/10 have PASS personal bell hint wire and the tally 20/21 checks passed across 3/3 lanes, in 34–36 s each. The one failure in every run is the local BM25 boot check, which needs pg_search.

Gates run locally: vitest on the touched suites plus the two harness guards and http-shutdown.test.ts (52/52); oxlint --type-aware and oxfmt --check on the changed files; tsc --noEmit over the changed files and their imports (exit 0); knip on services/platform (no new finding).

Closes #4112. Refs #4077 (item 5 only).

The Backend integration job hung in lane 49 (checkBellHintWire) and then
sat out its 30-minute step timeout with no tally (#4112).

Root cause: the harness's outbound boundary (`routeVendorFetch`) built
`new Request(input, init)` and handed that request to fetch. undici makes
a request's signal follow the one it was built from through a weak
reference to an AbortController that only that request holds, and
nothing held the request once fetch had answered. A garbage collection
between the /events response and the lane's abort dropped the link: the
abort never reached the socket, the SSE body never ended, and the lane
waited on `done` until the 10-minute lane deadline. The boundary now
hands fetch the caller's own signal.

The truncated run then hung in its teardown: a bare `server.close()`
waits for every connection, and the stuck lane's tail never ends. The
teardown now closes the backend with the deployment's
`closeServerGracefully` and bounds every step (`settleTeardown`), so the
tally prints and the run exits with its code.

`connectSse` moves to the lane helpers with a bounded `close()` that
cancels the body before it aborts, failing the lane within 5 s with the
tail's name. checkBellHintWire closes its tails and deletes `p-bell-wire`
in `finally` (#4077 item 5).
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Exact-head CI at c604cfac451ba0e496f1437fe17561da8ea7e0db (merge aaba3bb into main 2bd3905f0): 50 pass, 12 skipped, 0 fail.

  • Backend integration (run 37121628940, job 111200291641) passed 1498/1498 checks across 219/219 lanes, with no FAIL line.
    • 12:22:49Z: PASS collab emitters: …
    • 12:22:51Z: PASS personal bell hint wire: app entity, recipient-only, read-all hints, about 2 s later. Lane 49 settled and the run went on.
    • 12:25:29Z: the tally [itest] 1498/1498 checks passed across 219/219 lanes.
  • The skips are by design: Candidate gate ×5, the two fork-PR jobs, and the AI gateway, Docs, UI docs and Web container tests (path-filtered). Trivy reports neutral.

An /events tail whose stream broke while its lane awaited something else
(the backend dropped the connection mid-lane) rejected `done` with no
handler attached, and Node's default ended the whole harness on the
unhandled rejection: no lane named, no tally. `connectSse` now logs the
failure as it happens and keeps it in `done`, named after the tail, for
`close()` or the lane to throw; `close()` cancels only a tail that is
still open.

The teardown test waits for the tail's first heartbeat instead of a fixed
300 ms, and gives the step a wider bound. The boundary's comments say when
the intermediate Request becomes collectable and what nodejs/undici#4627
changed.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4133 at e189d9eb7140eec2722aa4a4de4ed5f418ae68cf: source accepted, with LOW follow-ups. The merge is held until the implementer or the manager confirms this is the final head. There is no handoff: agent #6's runs (f5236c3e, 8c862198, and two retries) ended in harness_error/credential_cooldown at 13:23Z. e189d9eb7 came after the 12:10 checkpoint and the PR body doesn't describe it.

Runtime (mine; real PG 16.14 + pgvector, no pg_search)

Check main head e189d9eb7
integration-vendor-stub.test.ts, the GC case (head's tests against main's integration-vendor-stub.ts) fails: still open 2 s after the abort passes. Both harness test files pass 41/41.
Lanes checkCollabEmitters,checkBellHintWire,checkBoardMoveEffects — 20/21. PASS personal bell hint wire, 36 s; the only failure is BM25.
Your seam B (untracked: lane deadline 20 s, the lane hangs holding both tails), run in its own process group RUN TRUNCATED at lane 2 of 3, then no tally. Still running at 150 s, when my runner stopped its group (exit 143). RUN TRUNCATED, then the tally 18/20 … 2/3 lanes and exit 1 (50 s, boot included).

I didn't re-run seam A (one gc() in the lane). The unit GC case pins the same mechanism.

Root cause 1 holds against undici 7.29.1. A Request follows its source signal through a WeakRef, held only by that request's own kAbortController (request.js:425-444, :33-35). fetch keeps its own request alive (#4627), but nothing kept the boundary's intermediate request alive. Handing fetch the caller's signal (integration-vendor-stub.ts:300-306, :400) is correct for every call shape: a string or URL with init.signal; no signal; init.signal: null; a Request input; an already-aborted signal. Routing, bodies, duplex, redirects and headers are unchanged.

LOW

  1. checkBellHintWire's finally can replace the lane's real error (integration-check.ts:45311-45321). If the body throws and close() or the DELETE also throws, the RUN TRUNCATED … threw line names the tail and the first error is lost. This is diagnostics only.
    • Fix: rethrow a cleanup error only when the body succeeded.
  2. A lane that leaks a tail on its passing path now goes unnoticed (integration-check.ts:59357-59366 and http-shutdown.ts:47-66).
    • The graceful teardown ends the tail, logs ended 1 open SSE stream(s), and the run exits 0. On main it hung, so it was red but had no tally.
    • Fix: when a run wasn't truncated, count the streams teardown had to end and record a failed harness check if there were any.
  3. The GC test's native control depends on the runner's Node (integration-vendor-stub.test.ts:872-901). The Unit job uses the image's Node, with no setup-node. An undici without fix(sandbox): end stalled execs and refuse new ones in a session out of memory #4627 would fail the control deterministically.
    • Fix: pin Node in that job, or skip the routed assertion when the control itself loses the abort.

INFO

  • e189d9eb7 names a broken tail and rejects close() instead of leaving an unhandled rejection. A broken tail still truncates the run, as on main.
  • The chat-stream readers still abort without awaiting (:11699-11736, :11775-11809). They aren't awaited, so they can't hang a lane.

Verified correct

CI at the exact head (merge ref c919945 onto d39756043)

  • Workflows: Build, Checks, Commitlint, SAST and E2E all succeeded at attempt 1.
  • Check runs: 50 success, 11 skipped by design and 1 neutral (Trivy).
  • Backend integration (job 111210757667): 1498/1498 across 219/219 lanes, and the bell lane passes.

Merge: the next occurrence merges this exact head through the gate once the manager or the implementer confirms it is final, or reviews the delta if it changes.

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.

ci: Backend integration hangs in lane 49 (checkBellHintWire), then waits out the 30-minute step timeout

1 participant