fix(browser-transfer): keep the resourceId of a completed or lost-complete upload (01-02)
A failed checkpoint cleanup after a committed complete returned a failure and dropped the resourceId, and abort() on ALREADY_COMPLETED returned no id. The upload now succeeds, abort() reads the id from status first, and the port and design doc state the in-progress complete contract (429 + Retry-After). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5cc1d002d2
commit
7b2cefbd32
@@ -1107,12 +1107,11 @@ async function completeUpload<Capability>(
|
||||
{ recovery: "RECONCILE" },
|
||||
);
|
||||
}
|
||||
const removed = await removeCheckpoint(
|
||||
dependencies,
|
||||
checkpoint,
|
||||
request.signal,
|
||||
);
|
||||
if (!removed.ok) return removed;
|
||||
// 01-02. The server has committed the resource. A failed local cleanup (an
|
||||
// IndexedDB error, or the caller aborting right after complete) must not
|
||||
// turn that into a failure and drop the resourceId. The leftover row is
|
||||
// reconciled to this same resource by the next upload() or abort().
|
||||
await removeCheckpoint(dependencies, checkpoint, request.signal);
|
||||
return browserDataSuccess(
|
||||
quarantinedOutcome(value.resourceId, sessionFromCheckpoint(checkpoint), false),
|
||||
);
|
||||
@@ -1213,6 +1212,16 @@ async function executeAbort<Capability>(
|
||||
recovery: "RECONCILE",
|
||||
});
|
||||
}
|
||||
let resourceId: string | undefined;
|
||||
if (aborted.value.state === "ALREADY_COMPLETED") {
|
||||
// 01-02. The checkpoint is the last local link to a completed resource
|
||||
// (typically a complete whose response was lost), so its id is read before
|
||||
// the row goes. A transient status failure keeps the ABORT_PENDING row for
|
||||
// the next abort(); a definitive one has nothing left to read.
|
||||
const completed = await readCompletedResourceId(dependencies, checkpoint, signal);
|
||||
if (!completed.ok) return completed;
|
||||
resourceId = completed.value ?? undefined;
|
||||
}
|
||||
const removed = await dependencies.checkpoints.remove({
|
||||
uploadKey,
|
||||
expectedRevision: checkpoint.revision,
|
||||
@@ -1225,7 +1234,46 @@ async function executeAbort<Capability>(
|
||||
: aborted.value.state === "ALREADY_COMPLETED"
|
||||
? "ALREADY_COMPLETED"
|
||||
: "ORPHANED";
|
||||
return browserDataSuccess(Object.freeze({ state }));
|
||||
return browserDataSuccess(
|
||||
Object.freeze(resourceId ? { state, resourceId } : { state }),
|
||||
);
|
||||
}
|
||||
|
||||
async function readCompletedResourceId<Capability>(
|
||||
dependencies: RuntimeDependencies<Capability>,
|
||||
checkpoint: ResumableUploadCheckpoint,
|
||||
signal: AbortSignal,
|
||||
): Promise<BrowserDataResult<string | null>> {
|
||||
const status = await callWithRetry(
|
||||
dependencies,
|
||||
"UPLOAD_RECONCILE",
|
||||
signal,
|
||||
async (attemptSignal) =>
|
||||
await dependencies.controlPlane.getStatus({
|
||||
protocol: RESUMABLE_UPLOAD_PROTOCOL,
|
||||
sessionId: checkpoint.sessionId,
|
||||
requestBindingSha256: checkpoint.requestBindingSha256,
|
||||
fingerprint: checkpoint.fingerprint,
|
||||
signal: attemptSignal,
|
||||
}),
|
||||
);
|
||||
if (!status.ok) {
|
||||
return status.error.code === "NOT_FOUND" ||
|
||||
status.error.code === "EXPIRED_RESOURCE"
|
||||
? browserDataSuccess(null)
|
||||
: remapResult(stripProviderFailure(status), "UPLOAD_ABORT");
|
||||
}
|
||||
const value = status.value;
|
||||
return browserDataSuccess(
|
||||
value?.state === "QUARANTINED" &&
|
||||
value.session?.sessionId === checkpoint.sessionId &&
|
||||
value.session.requestBindingSha256 ===
|
||||
checkpoint.requestBindingSha256 &&
|
||||
typeof value.resourceId === "string" &&
|
||||
SAFE_OPAQUE_ID.test(value.resourceId)
|
||||
? value.resourceId
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/** Drops the durable checkpoint a finished or dead session no longer needs. */
|
||||
|
||||
Reference in New Issue
Block a user