fix(browser-transfer): let dispose() retry after an expired drain (R-1.1)

dispose() cached its drain promise. When the cleanup deadline expired it
returned UNAVAILABLE/retryable but kept that promise, so a later dispose()
replayed the same failure even after all work had settled: the checkpoint
store was never closed and lifecycle stayed CLOSING.

The one-shot admission close and the quiescence promise now live in
beginTeardown(); each dispose() races that shared quiescence against a new
deadline, and an expired drain resets so the next call can close the store.

Verified: RED "closes on a later dispose() once work that outlived the
deadline settles" (tests/unit/resumable-upload-runtime-teardown.test.ts)
failed with { ok: false } on the second dispose before the fix and passes
after. Gates: check:architecture, check:types:app, check:types:test, lint,
test:component pass; test:unit passes except removal-fixture.test.ts, which
needs untracked artifacts/release/* absent from a fresh worktree (unrelated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 11:55:57 +09:00
co-authored by Claude Opus 5.5
parent f0d3953ef2
commit 3f2cd87f6f
2 changed files with 80 additions and 19 deletions
@@ -185,4 +185,57 @@ describe("TR-04 teardown waits for raw provider work, not only its wrapper", ()
await expect(disposing).resolves.toMatchObject({ ok: true });
expect(runtime.lifecycle()).toBe("CLOSED");
});
// R-1.1. The expired drain was cached, so a retry after the work settled
// returned the same failure and the store stayed open forever.
it("closes on a later dispose() once work that outlived the deadline settles", async () => {
const harness = createControlHarness();
const checkpoints = new MemoryCheckpointStore();
let releaseProvider: (() => void) | undefined;
harness.control.createSession = () =>
new Promise((resolve) => {
releaseProvider = () =>
resolve(
browserDataFailure("UNAVAILABLE", "UPLOAD_SESSION", {
retryable: true,
recovery: "RESUME",
}),
);
});
const runtime = createResumableUploadRuntime({
controlPlane: harness.control,
partExecutor: executorFor(harness),
checkpoints,
mutationLock: noContentionLock,
crypto,
policy: runtimePolicy({
providerAttemptTimeoutMs: 5,
cleanupDeadlineMs: 25,
maxRetries: 0,
}),
now: () => 1_000,
random: () => 0,
sleep: async () => {},
});
const uploading = runtime.upload({
uploadKey: "upload_key_retry",
purpose: "attachment",
mediaType: "application/octet-stream",
source: byteStreamSource(new Uint8Array([1, 2, 3, 4, 5])),
signal: activeSignal,
});
await vi.waitFor(() => expect(releaseProvider).toBeDefined());
await uploading;
const first = await runtime.dispose();
expect(first.ok).toBe(false);
expect(runtime.lifecycle()).toBe("CLOSING");
releaseProvider?.();
await expect(runtime.dispose()).resolves.toMatchObject({ ok: true });
expect(runtime.lifecycle()).toBe("CLOSED");
expect(checkpoints.closed).toBe(true);
});
});