fix(browser-files): resolve bounded object URL source inside the result boundary (R-2.1)

boundedObjectUrlHandoff called resolveByteSource outside its try/finally.
When the authorized source open threw or was aborted, deliver() rejected
with an AbortError instead of returning {ok:false, ABORTED}, the observer
saw nothing, and the holder was never latched closed, so a lease that
arrived later was never closed by compensateLateSource.

Source resolution now runs inside the existing try/catch/finally, the same
shape promptAndStream already uses. The explicit closeHeldSource calls on
the early-return paths are covered by the finally.

Verified: "resolves ABORTED and closes a late lease when a bounded source
open is aborted" failed before the fix (promise rejected with AbortError)
and passes now. check:architecture, check:types:app, check:types:test,
lint, test:component pass. test:unit passes except removal-fixture, which
needs generated artifacts/release files that a fresh worktree lacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:15:58 +09:00
co-authored by Claude Opus 5.5
parent 997761f1ba
commit 54abaec12a
2 changed files with 88 additions and 24 deletions
@@ -731,34 +731,34 @@ async function boundedObjectUrlHandoff(context: Readonly<{
);
}
const sourceHolder = createSourceHolder();
const sourceResult = await resolveByteSource(
context.input,
context.input.signal,
context.options,
sourceHolder,
);
if (!sourceResult.ok) {
closeHeldSource(sourceHolder);
return observeResult(sourceResult, context.options.observer);
}
const source = sourceResult.value;
if (
source.byteLength !== null &&
(source.byteLength > context.input.maxBufferedBytes ||
source.byteLength > context.input.maxTransferBytes)
) {
closeHeldSource(sourceHolder);
return observeResult(
browserDataFailure("LIMIT_EXCEEDED", "DOWNLOAD"),
context.options.observer,
source.byteLength,
);
}
const chunks: ArrayBuffer[] = [];
let transferred = 0;
let lease: ObjectUrlLease | undefined;
try {
// Inside the try: an open that throws or is aborted must still resolve to
// a Result and reach the finally that latches the holder for late leases.
const sourceResult = await resolveByteSource(
context.input,
context.input.signal,
context.options,
sourceHolder,
);
if (!sourceResult.ok) {
return observeResult(sourceResult, context.options.observer);
}
const source = sourceResult.value;
if (
source.byteLength !== null &&
(source.byteLength > context.input.maxBufferedBytes ||
source.byteLength > context.input.maxTransferBytes)
) {
return observeResult(
browserDataFailure("LIMIT_EXCEEDED", "DOWNLOAD"),
context.options.observer,
source.byteLength,
);
}
context.progress.report("PREPARING", 0, source.byteLength, true);
for await (const chunkResult of abortableFileChunks(
source,