Skip to content

ui-react: draft-files tests never dispose their draft clients, so a failed save's retry timer can outlive the file #3835

Closed

Description

@schlessera

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's dispose() does not reach the client.
  • A failed save puts the client into backoff. backoff re-arms schedule with the next RETRY_MS step (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). schedule arms setTimeout(() => { timers.delete(draftId); void sync(draftId); }, delay) whenever live() holds (function schedule, draft-client.ts:79-83). Only the client's dispose() 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) calls silence(), 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, after 1619741f2) the file runs on a fake clock: vi.useFakeTimers() in beforeEach and vi.useRealTimers() in afterEach (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 calling schedule on the restored real setTimeout, 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).

Refs #3574, #3719

Scope

Out of scope

  • observeMountTimers and anything in packages/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-disposed handle, which stays unattributed here.
  • draft-client.ts behaviour: RETRY_MS, the debounce and live(). Change the source only if the regression check proves dispose() 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 in draft-files.test.ts is 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/tests grep 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 test process runs draft-files.test.ts and then a probe that spies globalThis.setTimeout the way observeMountTimers does, observing for at least 65 s (longer than 2+4+8+16+30 s plus the 60 s step's arm). At 1619741f2 (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.ts

Mutation: 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

  1. added
    type: test
    area: ui-react
    priority: p1
    agent-ready
    on Nov 10, 2026
  2. added this to the 0.45.0 milestone on Nov 10, 2026
  3. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    Teardown repair in #3892 (test-health batch e3855-ui-react-05, commit dee877888). This advances this issue but does not close it.

    • Done. scene() records each draft client, and afterEach disposes every client before its root, while the fake clock is still installed. The regression assertion DISPOSED_DRAFT_CLIENT_SAVES_NOTHING_LATER then advances the fake clock 130 s, past every RETRY_MS step, and checks that no scene's host received another save.
      • Mutation: deleting the 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.
      • 10 shuffled runs: no failure.
    • Grep. createDraftClient( appears in no other file under packages/ui-react/tests. Root-owned clients come from createAccountServices and are disposed by root.dispose(). No other undisposed draft clients were found.
    • Observed, not resolved. An assertion on vi.getTimerCount() === 0 after both disposals still sees one fake timer in the save-failure cases. Instrumenting setTimeout, setInterval and their clears showed that every draft-client timer is cleared by dispose(). 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.
    • Remaining. The attribution receipt for ui-server: failed-mount disposal and mount-timer cases leave a pending timer under full-suite load #3574 has not been produced: the 65 s probe at 1619741f2 and at this head. This issue stays open for that.
  4. schlessera commented on Nov 14, 2026

    @schlessera
    OwnerAuthor

    Closing as completed (2026-11-14): the last open criterion, the attribution receipt, is now posted on #3574.

    Receipt. In one bun test process at 1619741f2, the 80 s after draft-files.test.ts see 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 main d64f893b5 the same probe records none. Bun 1.4.4.

    Acceptance criteria:

    Milestone 0.45.0 stays, matching #3892.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-reactpriority: p1type: test

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions