diff --git a/docs/architecture/presigned-transfer-and-image-cdn.md b/docs/architecture/presigned-transfer-and-image-cdn.md index a608520f..cce2e93c 100644 --- a/docs/architecture/presigned-transfer-and-image-cdn.md +++ b/docs/architecture/presigned-transfer-and-image-cdn.md @@ -390,7 +390,9 @@ complete 결과를 모를 때 클라이언트는 다음처럼 동작한다. resourceId 없이 닫는다(`resumable-upload-runtime.ts` `readCompletedResourceId`). - 서버가 complete를 반영한 뒤 로컬 checkpoint 삭제가 실패해도(IndexedDB 오류, complete 직후 caller abort) `upload()`는 성공을 돌려준다. 남은 행은 다음 - `upload()`나 `abort()`가 같은 자원으로 정리한다. + `upload()`나 `abort()`가 같은 자원으로 정리한다. 응답을 잃은 complete를 다음 + `upload()`가 재조정해 서버 status `QUARANTINED`를 찾았을 때도 같다 + (0929/01-02, `reconcileActiveCheckpoint`). 서버 계약 — complete 진행 중(`ResumableUploadControlPlane.complete` 주석): diff --git a/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts b/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts index 9599873d..da280ebe 100644 --- a/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts +++ b/src/adapters/browser-transfer/resumable-upload/resumable-upload-runtime.ts @@ -582,12 +582,11 @@ async function reconcileActiveCheckpoint( ); if (!status.ok) return status; if (status.value.state === "QUARANTINED") { - const removed = await removeCheckpoint( - dependencies, - checkpoint, - request.signal, - ); - if (!removed.ok) return removed; + // 0929/01-02. The server already holds the resource. A failed local + // cleanup leaves the row for the next upload() or abort(), which finds the + // same resource; it does not cost this caller the resourceId, as on the + // complete path. + await removeCheckpoint(dependencies, checkpoint, request.signal); return browserDataSuccess( Object.freeze({ kind: "COMPLETED" as const, diff --git a/tests/unit/resumable-upload-runtime-recovery.test.ts b/tests/unit/resumable-upload-runtime-recovery.test.ts index 5f0f8f27..35959762 100644 --- a/tests/unit/resumable-upload-runtime-recovery.test.ts +++ b/tests/unit/resumable-upload-runtime-recovery.test.ts @@ -751,6 +751,56 @@ describe("resumable upload completed-result reporting (01-02)", () => { expect(checkpoints.rows.has(key)).toBe(false); }); + // 0929/01-02 (2026-11-03 리뷰 2절). The reconcile path finds the lost + // complete applied; a failed local cleanup must not cost the caller the + // resourceId, exactly as on the complete path above. + it("reports the reconciled resource even when the local checkpoint cleanup fails", async () => { + const harness = committingHarness("LOST"); + const checkpoints = new MemoryCheckpointStore(); + const remove = checkpoints.remove.bind(checkpoints); + let failRemove = false; + checkpoints.remove = async (input) => + failRemove + ? browserDataFailure("UNAVAILABLE", "UPLOAD_RECONCILE", { + retryable: true, + recovery: "RESUME", + }) + : await remove(input); + const runtime = createResumableUploadRuntime({ + controlPlane: harness.control, + partExecutor: executorFor(harness), + checkpoints, + mutationLock: noContentionLock, + crypto, + policy: runtimePolicy({ maxRetries: 0 }), + now: () => 1_000, + sleep: async () => {}, + }); + const key = "upload_key_reconcile_cleanup_fails"; + expect((await runtime.upload(request(key))).ok).toBe(false); + + failRemove = true; + const reconciled = await runtime.upload(request(key)); + + expect(reconciled).toEqual({ + ok: true, + value: { + state: "QUARANTINED", + resourceId: "resource_01", + byteLength: 4, + replayed: true, + }, + }); + // The stale row is the next call's to clean up, with the same resource. + expect(checkpoints.rows.has(key)).toBe(true); + failRemove = false; + expect(await runtime.upload(request(key))).toMatchObject({ + ok: true, + value: { resourceId: "resource_01", replayed: true }, + }); + expect(checkpoints.rows.has(key)).toBe(false); + }); + it("returns the resourceId when abort() finds the lost complete already applied", async () => { const harness = committingHarness("LOST"); const checkpoints = new MemoryCheckpointStore();