Skip to content

fix(platform): keep a lane's error and fail its leaked SSE tails - #5124

Closed
tale-code-bot wants to merge 3 commits into
mainfrom
fix/itest-cleanup-errors-and-leaked-sse-tails
Closed

tale-code-bot wants to merge 3 commits into
mainfrom
fix/itest-cleanup-errors-and-leaked-sse-tails

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

Closes #4152. Board task: TALE-65.

This fixes the three LOW follow-ups from the independent review of #4133, one commit each. The INFO item (the chat-stream readers abort without awaiting) is unchanged. They do abort on their passing path, so the new per-lane check covers them.

LOW 1: a cleanup error no longer hides the lane's error

checkBellHintWire cleaned up in nested finally blocks.

  • A finally that throws replaces the error in flight. A lane that failed, and whose tail then would not close (or whose DELETE failed), truncated the run as RUN TRUNCATED … threw <the cleanup's error>. The lane's own failure was lost.
  • The Promise.all over the two closes also dropped the second close's error.

The fix is withCleanup(steps, body) in integration-lane-helpers.ts. It takes the TeardownStep shape that settleTeardown already uses.

  • It runs every step in order on every path. A step that throws never stops the next one.
  • If the body threw, its error propagates unchanged. Each cleanup failure is logged as an [itest] warning that names its step.
  • If the body passed, the first cleanup failure fails the lane (the cleanup step that <what> failed: …), and the others are warned.
  • The bell-wire lane now uses it with three steps: the owner's tail, the teammate's tail, and the project DELETE.

LOW 2: a lane that leaves an SSE stream open fails, and the check names the lane

Since #4133 the teardown's graceful close ends a leaked tail and logs ended N open SSE stream(s), and the run still exits 0.

  • realtime/sse.ts exposes liveStreamCount(). It returns the size of the registry the shutdown drains, which holds both /events and the chat progress streams.
  • recordOpenStreams(subject, record) runs in two places:
    • in runLanes, after every lane that completed, next to the env, boundary and membership checks;
    • once before the lanes, because checkAuthAndSse opens tails of its own and a leak there would otherwise be charged to the first lane.
  • It gives closing streams up to 5 s to leave the registry, because a tail that was just closed is still registered for a few ticks.
  • A stream still open after that is recorded as harness: <lane> leaves no SSE stream open, and then ended. The next lane starts with none, and teardown has nothing left to end silently.
  • When no stream is open it records nothing, so a clean run's tally and exit code don't change.
  • A truncated lane already fails the run and gets no such check, as the issue asks.
  • The count runs after each lane rather than once at teardown, because a count at teardown can't say which lane leaked.

LOW 3: the GC test's control is handled in code; Node is not pinned

Choice: the code-only option. I did not pin Node in the Unit job. That would be a workflow change, which is a maintainer's call, and triage on TALE-65 said the same.

  • The test now runs the native fetch control first.
  • Fetch itself can lose the abort after a collection, on an undici without the fix for SSE connection may leak when fetch init.redirect = 'error' nodejs/undici#4627. In that case the test is skipped (ctx.skip) with a note that names the Node and undici versions, instead of failing for a reason unrelated to the boundary.
  • Otherwise the routed assertion runs as before.

Tested

All runs were local, with the credential removed, on the tree of 99594c3f273f119a413cb7553439506c55f0798b.

Tests

  • bunx vitest --run --project server backend/integration-lane-helpers.test.ts backend/integration-vendor-stub.test.ts: 46 passed. That is 41 before this change plus 5 new.
  • The integration guards (tests/guards/integration-{scope,skips}.guard.test.ts), the touched tests, http-shutdown and realtime/*: 10 files, 102 tests passed.

Each new test fails without its fix. Each mutation was applied, run, then reverted:

Mutation Result
The old finally semantics The withCleanup test fails.
The leak check removed The leaky-lane test fails.
The settle-wait removed The tidy-lane test fails in 3 runs out of 3, because a tail that was just closed is still registered for a few ticks.
A control that drops the signal The GC test is skipped with its note after 2.2 s.
A routed fetch that drops the signal The GC test still fails (expected 'still open 2 s after the abort' to be 'AbortError').

Static checks

  • oxfmt --check and oxlint --type-aware on the touched files: clean.
  • tsc --noEmit on the platform, under CI's NODE_OPTIONS=--max-old-space-size=6144: 0 errors.
  • bun run knip:check: exit 0, with no finding for the new exports.
  • bun run lint:links: clean.

Not tested here

  • The full backend integration run (bun run backend:integration). It needs Postgres with pg_search and vector, and an object store. This PR's own Backend integration check runs it. That run is what proves no lane on main trips the new per-lane check. The last main integration log I read (merge-group run 40836489004 at 9be5cad) showed no ended N open SSE stream(s) at teardown.
  • Opengrep SAST. It isn't installed in my worker, and lint-staged skips it when uncached. CI runs it.

checkBellHintWire cleaned up in nested `finally` blocks. A `finally` that
throws replaces the error in flight, so a lane that failed and whose tail
then would not close (or whose DELETE failed) truncated the run under the
cleanup's error, and the lane's own failure was lost. Its Promise.all over
the two closes also dropped the second close's error.

withCleanup(steps, body) runs every step in order, on every path. When the
body threw, its error propagates and each cleanup failure is logged,
naming its step; when the body passed, the first cleanup failure fails the
lane, named the same way. The bell-wire lane uses it with three steps.

Refs #4152
Since #4133 the harness's teardown closes the backend the way a deployment
does: it ends every live SSE stream, logs `ended N open SSE stream(s)`,
and the run exits 0. A lane that leaked a tail on its passing path, which
used to hang the run, now went unnoticed.

recordOpenStreams counts the backend's live streams (liveStreamCount, the
size of the registry the shutdown drains) after every lane that completed,
and once before the lanes for the checks that open tails of their own. It
gives a closing stream a few seconds to leave the registry; whatever is
still open is recorded as `harness: <lane> leaves no SSE stream open` and
ended, so the next lane starts with none. With no stream open it records
nothing: a clean run's tally and exit code are unchanged. A truncated run
already fails and gets no such check.

Refs #4152
The test proves the harness's outbound boundary ends a streamed response
on abort after a garbage collection, with native fetch as its control.
The Unit job runs whatever Node its image brings, and an undici without
the fix for nodejs/undici#4627 loses that abort in fetch itself: the
control then failed the test deterministically, and said nothing about
the boundary.

The control now runs first. When fetch itself loses the abort, the test
is skipped with a note naming the Node and undici versions; otherwise the
routed assertion runs as before. The Unit job's Node stays unpinned: that
would be a workflow change, a maintainer's call.

Refs #4152
@yannickmonney

Copy link
Copy Markdown
Contributor

The autonomous cycle now lands each task through the merge train instead of its own pull request (.agents/repo.md on train), so this pull request closes. The branch fix/itest-cleanup-errors-and-leaked-sse-tails stays and the task goes on with it: the Reviewer reviews the branch's head on the task and squashes accepted work onto train.

tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
Reviewed in pull request #5124 and on the task at 99594c3.

Closes #4152
Task: TALE-65
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
Reviewed in pull request #5124 and on the task at 99594c3.

Closes #4152
Task: TALE-65
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
Reviewed in pull request #5124 and on the task at 99594c3.

Closes #4152
Task: TALE-65
@yannickmonney
yannickmonney deleted the fix/itest-cleanup-errors-and-leaked-sse-tails branch October 30, 2026 10:32
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.

Follow-ups from the #4133 review: a cleanup error can hide a lane's real error, and a passing lane's leaked SSE tail goes unnoticed

2 participants