Repository navigation
Description
Context
packages/ui-react/tests/draft-files.test.ts builds a draft client in every scene and never disposes it. Citations are at main d79eeed0a.
- The scene creates the client and then drops it:
const client = createDraftClient(ui, …)(function scene,packages/ui-react/tests/draft-files.test.ts:26-50, client at:44). The scene's return value does not carry it. Teardown disposes only the roots (afterEach,draft-files.test.ts:18), and a root'sdispose()does not reach the client. - A failed save puts the client into backoff.
backoffre-armsschedulewith the nextRETRY_MSstep (backoff,packages/ui-react/src/lib/draft-client.ts:98-102;const RETRY_MS = [2_000, 4_000, 8_000, 16_000, 30_000, 60_000],:43).schedulearmssetTimeout(() => { timers.delete(draftId); void sync(draftId); }, delay)wheneverlive()holds (function schedule,draft-client.ts:79-83). Only the client'sdispose()clears those timers, the orphan and refresh retries, the full-pool recheck and the window listeners (dispose(),draft-client.ts:902-917). - "a save that gets no answer never acknowledges the binding" (
draft-files.test.ts:92-101) callssilence(), so its saves fail, and it ends with the draft still unsaved. - Since test: finish the real-time wait census with a second re-census and its slices (#3332) #3719 (merged as
5de219acf, after1619741f2) the file runs on a fake clock:vi.useFakeTimers()inbeforeEachandvi.useRealTimers()inafterEach(draft-files.test.ts:17-18). That probably stops the backoff chain at teardown. It does not stop a save still in flight at teardown from callingscheduleon the restored realsetTimeout, and the undisposed client keeps its store subscriptions and window listeners for the rest of the process.
Hypothesis (not proven). #3574's first hosted witness may be this client. In scheduled main run 42442301080, unit (3) job 128614069929, at 1619741f2, "a dirty failed mount discards its resources before the next independent case" failed at timers.expectEmpty("fresh-native-sockets-closed") (packages/ui-server/tests/http-supported-mounts.test.ts:327). The one pending handle was a ref'd 60 000 ms timeout. Its recorded callback source was () => { timers.delete(draftId); sync(draftId); }, the transpiled form of schedule's callback, and 60 000 ms is the last RETRY_MS step. At 1619741f2, draft-files.test.ts had no fake clock, and it ran in the same shard about 90 s before that case. The observer replaces globalThis.setTimeout and records every timer created while it observes, whichever file owns it (observeMountTimers, packages/ui-server/tests/helpers/http-mount-timers.ts:20-46; get pending, :65-72; expectEmpty, :84-89). A real-timer backoff that re-armed during that case would be counted. The log does not show that both files ran in the same worker process. #3574's body and its 2026-11-10 comment record the evidence and the missing step.
The only direct createDraftClient( call in package tests is draft-files.test.ts:44. Production code builds draft clients through createAccountServices (packages/ui-react/src/ws-client/account.ts:52), whose dispose() disposes them (account.ts:89-91).
Scope
- Return the client from
scene()and dispose every scene's client in teardown, before the roots and before the real clock is restored. - Add a regression check that fails when a scene's client is left undisposed or leaves a timer behind. For example, assert after disposal that the fake clock holds no pending timer, and that no real
setTimeoutis created by draft code after teardown. The mechanism is the implementer's choice, but it must fail when the client'sdispose()call is removed. - Grep
packages/ui-react/testsfor other draft clients, or websocket clients that own one, that are created and not disposed. Fix any you find in the same way and list them in the PR. - Produce the attribution receipt ui-server: failed-mount disposal and mount-timer cases leave a pending timer under full-suite load #3574 is missing (see Acceptance criteria). This issue does not fix or close ui-server: failed-mount disposal and mount-timer cases leave a pending timer under full-suite load #3574.
Out of scope
observeMountTimersand anything inpackages/ui-server/tests/helpers/http-mount-timers.ts. The observer counting every in-process timer is intended, so do not narrow, filter or exempt it.- ui-server: failed-mount disposal and mount-timer cases leave a pending timer under full-suite load #3574's own fix, its labels and its 20 ms
failed-startup-disposedhandle, which stays unattributed here. draft-client.tsbehaviour:RETRY_MS, the debounce andlive(). Change the source only if the regression check provesdispose()itself leaks, and say so in the PR.- Test isolation across shards or processes, and the test runner (
scripts/test.ts).
Acceptance criteria
- Every client that
scene()creates indraft-files.test.tsis disposed in teardown, and the file passes. - A named regression assertion fails when the client's
dispose()call is removed from teardown, and passes when it is restored. The PR records both runs, and the failure is on that assertion, not a module-load error. - The PR lists the other undisposed draft or websocket clients the
packages/ui-react/testsgrep found, each fixed, or says none were found. - An attribution receipt is posted on ui-server: failed-mount disposal and mount-timer cases leave a pending timer under full-suite load #3574. One
bun testprocess runsdraft-files.test.tsand then a probe that spiesglobalThis.setTimeoutthe wayobserveMountTimersdoes, observing for at least 65 s (longer than 2+4+8+16+30 s plus the 60 s step's arm). At1619741f2(before test: finish the real-time wait census with a second re-census and its slices (#3332) #3719), the receipt states whether the probe records a 60 000 ms timer whose callback is the draft client's. At this issue's head, it states that the probe records none. The probe goes in a throwaway worktree and is not committed.
Verification
From packages/ui-react, because the package test script expands to bun test tests:
bun test --timeout 30000 tests/draft-files.test.tsMutation: delete the client dispose() call in teardown, rerun, see the regression assertion fail, then restore it. Attribution: run the probe ordering above in one bun test process at 1619741f2 and at the branch head, and post both results on #3574 with the Bun version. Run bun run check:pr --base origin/main before marking the PR ready.
Contract impact
None. This changes test teardown and adds a test assertion. No CLI --json, MCP, wire, frontmatter or package API changes.
Priority
priority: p1 matches #3574 (p1, 0.45.0). This is the most specific lead for #3574's only hosted witness, and its attribution receipt is the reproduction step #3574 has needs: repro for. If the receipt excludes the draft client, lower this to p2. The teardown hygiene is still worth doing at that priority.
Activity
schlessera commentedon Nov 10, 2026
Teardown repair in #3892 (test-health batch
e3855-ui-react-05, commitdee877888). This advances this issue but does not close it.scene()records each draft client, andafterEachdisposes every client before its root, while the fake clock is still installed. The regression assertionDISPOSED_DRAFT_CLIENT_SAVES_NOTHING_LATERthen advances the fake clock 130 s, past everyRETRY_MSstep, and checks that no scene's host received another save.client.dispose()loop from teardown fails that assertion on "a save that gets no answer never acknowledges the binding". Restoring it passes. The receipt is in the run directory.createDraftClient(appears in no other file underpackages/ui-react/tests. Root-owned clients come fromcreateAccountServicesand are disposed byroot.dispose(). No other undisposed draft clients were found.vi.getTimerCount() === 0after both disposals still sees one fake timer in the save-failure cases. InstrumentingsetTimeout,setIntervaland their clears showed that every draft-client timer is cleared bydispose(). The remaining counted timer is not created through those globals during the test, so the regression check asserts the behaviour (no later save) instead of the raw timer count.1619741f2and at this head. This issue stays open for that.schlessera commentedon Nov 14, 2026
Closing as completed (2026-11-14): the last open criterion, the attribution receipt, is now posted on #3574.
Receipt. In one
bun testprocess at1619741f2, the 80 s afterdraft-files.test.tssee four draft-client timers on the real clock, ending with the 60,000 ms step at +56.4 s, each with the callback() => { timers.delete(draftId); sync(draftId); }. At maind64f893b5the same probe records none. Bun 1.4.4.Acceptance criteria:
dee877888).DISPOSED_DRAFT_CLIENT_SAVES_NOTHING_LATER, with its mutation recorded in the 2026-11-10 comment.priority: p1was the right call and nothing is left to lower.Milestone 0.45.0 stays, matching #3892.