Skip to content

ui-sdk: the abort-during-pipe-release case accepted a result once in a long run (ABORT_DURING_RELEASE_REFUSES) #3995

Closed

Description

@schlessera

Context

The 2026-11-16 reproduction comment supplies deterministic fixture-ordering evidence. The original natural failure retained limited diagnostics; that historical limitation remains.

In a whole-repository bun test run on a 4-CPU VM (Ubuntu 24.04, Bun 1.4.2) at main 631bbae2c on 2026-11-13, an abort that lands while a finished maintenance command's pipes close still refuses its result failed after 238 ms with error: ABORT_DURING_RELEASE_REFUSES ("ABORT_DURING_RELEASE_REFUSES", packages/ui-sdk/tests/worker-pipes.test.ts:195). The awaited run was not a DOMException; the run kept only the one-line failure, so what it was instead is not known.

The case orders its race with timers: it holds the work pool, and once the command's outputs have ended it aborts after 50 ms and releases the pool 200 ms later (test, packages/ui-sdk/tests/worker-pipes.test.ts:181-201). It passes its own tempDomain, so the shared maintenance ledger from #3019 does not reach it. A foreign holder of that ledger was live during the run all the same.

What was tried

  • The file alone on that VM, with and without the foreign holder: passes.
  • 2026-11-14, local host (16 CPUs, Bun 1.4.4), main 631bbae2c: 40 runs of the file beside 16 busy loops, 0 failures.
  • The case's name appears in 9 of the 84 failed-job logs on main CI from 2026-10-28 to 2026-11-13, always as a pass.

Scope

Find out what the run resolved to when the assertion failed, and whether the pool hold can lapse before the abort lands (for example when the process's work pool is busy with other files' work late in a long run).

Out of scope

Lengthening the 50 ms or 200 ms waits, retries, or weakening the refusal and pipe-release assertions.

Acceptance criteria

  • A failing run records the actual resolved value or exception and the order of command completion, pipe release, abort and pool release, with SHA/runtime/host conditions. Alternatively, a controlled ordering demonstrates the result being accepted before the abort.
  • The evidence distinguishes an expired pool hold or fixture ordering error from a production refusal defect; unrelated ledger contention is not assumed to be causal.
  • Any resulting correction preserves refusal after an abort that wins the race, has a named failing-first/restored receipt and passes the focused suite without longer timers or retries.

The 2026-11-16 controlled run meets the evidence criterion: foreign work can overtake the queued pool hold, returning the maintenance result before the timed abort. The production abort refusal holds when the abort wins. Correct only this fixture's ordering: retain a real descriptor on the worker FIFO before its stream starts, await output EOF, abort while that descriptor is still held, then release it and await the result. This removes the timer/pool-scheduling assumption and exercises the real descriptor-release path. Keep the other work-pool coverage and production refusal unchanged.

Verification

bun run test packages/ui-sdk/tests/worker-pipes.test.ts

Contract impact

None.

Found during the needs: repro triage of 2026-11-13.

Bounded control — 2026-11-14

At main faa480e8c864d547cd8b4eb75965b7d609284770, Ubuntu 26.04.1, 16 CPUs, Bun 1.4.4, bun run test packages/ui-sdk/tests/worker-pipes.test.ts packages/ui-server/tests/external-speech.test.ts passed 30 tests / 118 assertions / zero failures in 12.19 seconds, with the repository preload intact. This is one current-source control, not the reported Ubuntu 24.04 / 4-CPU / Bun 1.4.2 long-run condition and not a causal repair. An initial attempt before workspace dependency installation failed module loading; it is excluded from behavioral evidence.

2026-11-14 triage at main faa480e8c864d547cd8b4eb75965b7d609284770: Replaced the empty acceptance section with the existing investigation's checkable evidence and correction criteria; needs: repro remains.

2026-11-16 readiness reconciliation: folded the reproduced fixture attribution and scoped deterministic correction into the body. This explicit work request covers the fixture repair; no new product or contract policy is implied.

Activity

  1. added
    type: test
    area: ui-sdk
    needs: repro
    priority: p3
    on Nov 14, 2026
  2. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Reproduction — 2026-11-16

    Three agents on different models worked this independently, then cross-reviewed each other's write-ups. All three converged on a test-fixture ordering bug, not a production defect.

    holdWorkPool queues its blocking reads but never confirms that each pool thread has taken one. Pool work still in flight when the hold is placed can then run Bun's later descriptor close ahead of the queued hold reads. released() resolves before the abort, and the result is accepted.

    The forcing below reproduces the sighting on every run, and its controls never do. Removing needs: repro.

    The production refusal itself looked correct. One separate production question surfaced during this work and is filed as #4078: an unreadable descriptor table counts as released. It is very unlikely to be the cause here.

    Forcing reproduction for #3995. The pool hold is overtaken by foreign pool work, and the
    result is accepted before the abort.

    Requirements: Linux with mkfifo, taskset (util-linux), and bubblewrap able to create user,
    mount and network namespaces, as for any maintenance-worker test; Bun 1.4.2 or 1.4.4. No
    network and no API key.

    git clone https://github.com/schlessera/brain-kit && cd brain-kit
    git checkout 017af32f91598eb6e0f8470c91fcab2d9e751470   # any later commit where the case is unchanged
    bun install --frozen-lockfile
    git apply force-3995.diff                                # the diff below

    force-3995.diff changes only the test, never production code. Before the launch it occupies
    every Bun pool thread with a blocking read on a private FIFO. Once the command's outputs have
    ended, it frees those threads one at a time inside the 50 ms before the case's abort.

    --- a/packages/ui-sdk/tests/worker-pipes.test.ts
    +++ b/packages/ui-sdk/tests/worker-pipes.test.ts
    @@ -7,7 +7,7 @@
      */
     import { afterEach, expect, spyOn, test } from "bun:test";
     import { availableParallelism } from "node:os";
    -import { closeSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readlinkSync, rmSync, writeFileSync } from "node:fs";
    +import { closeSync, constants, existsSync, mkdirSync, mkdtempSync, openSync, read, readdirSync, readlinkSync, rmSync, writeFileSync, writeSync } from "node:fs";
     import { readFile, writeFile } from "node:fs/promises";
     import { basename, join, resolve } from "node:path";
     import { tmpdir } from "node:os";
    @@ -180,6 +180,17 @@
     
     test("an abort that lands while a finished maintenance command's pipes close still refuses its result", async () => {
       const f = brainFixture();
    +  // #3995 forcing: finite foreign work occupies every pool thread before the hold is queued,
    +  // then frees the threads one at a time inside the 50 ms before the abort.
    +  const FOREIGN = Number(process.env.FORCE_3995_FOREIGN ?? availableParallelism());
    +  const FIRST = Number(process.env.FORCE_3995_FIRST_MS ?? 2), STEP = Math.max(1, Math.floor(40 / Math.max(1, FOREIGN)));
    +  const plug = join(f.root, "foreign-work"); Bun.spawnSync(["mkfifo", plug]);
    +  const plugWriter = openSync(plug, constants.O_RDWR);
    +  const foreign = Array.from({ length: FOREIGN }, () => { const fd = openSync(plug, constants.O_RDONLY);
    +    return new Promise<void>(done => read(fd, Buffer.alloc(1), 0, 1, null, () => { closeSync(fd); done(); })); });
    +  const freeOne = () => writeSync(plugWriter, Buffer.alloc(1));
    +  const frees: ReturnType<typeof setTimeout>[] = [];
    +  await Bun.sleep(20);
       const startupView = createFixtureWorkerStartupView(f.brain);
       const tmp = ownedTmp();
       const controller = new AbortController();
    @@ -191,11 +202,12 @@
         run = refusal(() => runMaintenanceWorker({ brainPath: f.brain, startupView, command: ["/bin/sh", "-c", "printf ithaca"],
           env: { PATH: "/usr/bin:/bin" }, credentials: false, tempDomain: { statePath: join(f.root, "maintenance-state.db") }, signal: controller.signal }));
         // The command has finished; the abort lands while its pipes wait for the pool, which then frees.
    -    void outputs.ended.then(async () => { await Bun.sleep(50); controller.abort(); await Bun.sleep(200); await pool?.release(); });
    +    void outputs.ended.then(async () => { for (let i = 0; i < FOREIGN; i++) frees.push(setTimeout(freeOne, FIRST + i * STEP)); await Bun.sleep(50); controller.abort(); await Bun.sleep(200); await pool?.release(); });
         expect(await run, "ABORT_DURING_RELEASE_REFUSES").toBeInstanceOf(DOMException);
         expect(tmp.remains(), "ABORT_DURING_RELEASE_RELEASES_PIPES").toEqual({ directories: [], descriptors: [] });
       } finally {
         controller.abort(); await pool?.release(); await run;
    +    frees.forEach(clearTimeout); writeSync(plugWriter, Buffer.alloc(FOREIGN)); await Promise.all(foreign); closeSync(plugWriter);
         outputs.restore(); tmp.restore(); startupView.cleanup(); f.cleanup();
       }
     });

    Run (taskset -c 0-3 gives a 4-thread pool like the 4-CPU host where it was seen):

    T='pipes close still refuses'
    taskset -c 0-3 bun run test packages/ui-sdk/tests/worker-pipes.test.ts -t "$T" --rerun-each 10                          # forcing
    FORCE_3995_FOREIGN=0  taskset -c 0-3 bun run test packages/ui-sdk/tests/worker-pipes.test.ts -t "$T" --rerun-each 10    # control: no foreign work
    FORCE_3995_FIRST_MS=60 taskset -c 0-3 bun run test packages/ui-sdk/tests/worker-pipes.test.ts -t "$T" --rerun-each 10   # control: freed after the abort

    Observed at 017af32f9, on Bun 1.4.2 and on 1.4.4:

    Arm Bun 1.4.2 Bun 1.4.4
    forcing 10/10 fail, twice 10/10 fail, twice
    no foreign work 0/10 0/10
    freed after the abort 0/10 0/10

    Every failure is:

    error: ABORT_DURING_RELEASE_REFUSES
    Expected constructor: [class DOMException]
    Received value: undefined
    

    Each failure settles in about 90 ms, below the about 320 ms a refusing run needs.
    Received value: undefined is the success branch of the test's refusal() helper: the run
    returned {stdout: "ithaca", exitCode: 0, killed: false} before the abort. With only 3 of
    4 pool threads busy, the hit rate falls to between 0 and about 1 in 3 per batch of 10, and
    only on later iterations in a process.

    Reading: holdWorkPool (packages/ui-sdk/tests/helpers/work-pool.ts) queues its blocking
    reads but never confirms that every pool thread is parked on them. Pool work already in flight
    can finish and take Bun's later-queued duplicate-descriptor close first, so
    fifosReleased (packages/ui-sdk/src/server/worker-pipes.ts) resolves before the abort.
    runMaintenanceWorker then rightly returns the result, since the abort has not landed yet. The
    "freed after the abort" control refuses every time, which shows the production refusal holds
    whenever the abort wins.

  3. added
    agent-ready
    and removed
    needs: repro
    on Nov 16, 2026
  4. self-assigned this
    on Nov 16, 2026
  5. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-8010b2aa. Branch: test/4005-nested-runtime-prerequisite.

    Explicitly requested batch with #4005 and #3998. Closure-only overlaps include #4080; no direct path collision reported.

  6. added this to the 0.45.0 milestone on Nov 16, 2026
  7. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Implementation and readiness reconciliation — 2026-11-16. The body now incorporates the reproduction and scoped correction previously held in comments. The requested batch is implemented in #4084, head bb23e28df83c3afa1edbb982cbdd1ecbd7d16ca5, based on 3b104890f84e2eeca687d3c4fbdd1dbb02fb3ae9.

    The four-CPU foreign-work forcing fails the original abort assertion. Holding a real extra FIFO reader orders EOF, abort and release without timers. The corrected full file passes 6 tests / 22 assertions; 20 four-CPU iterations pass. Removing the production post-release abort check fails ABORT_DURING_RELEASE_REFUSES; the production source is restored and unchanged in the PR.

    Local bun run check:pr --base origin/main passes all gates and 1,208 affected fast tests. Root typecheck passes with an 8 GB V8 heap. PR and issue milestones are verified as 0.45.0. The PR stays draft while existing main incident #4081 blocks ordinary candidate confirmation; merge and closure are not yet claimed.

  8. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Merged in #4084 as ad3611ae15f3af82eba14ac9aaf4a8727b3920eb, verified as an ancestor of origin/main. Candidate run 43873943931, attempt 1, passes all selected fast jobs and proof; the selected job checkout logs identify 620cbd8eab58f34272ee7f294e4e19d38a82d02c, whose tree exactly matches the squash. The issue is closed and retains milestone 0.45.0, as does the PR.

    Local failing-first and restored-mutation evidence remains in the PR. Required proof on the actual squash is still running in main run 43877725319; full post-merge verification is not yet claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-sdkpriority: p3type: test

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions