fix(browser-files): observe dismissals as DISMISSED instead of SUCCEEDED (02-06)

A cancelled save dialog and a browser handoff were both recorded as
DOWNLOAD SUCCEEDED, so the cancel rate hid inside the handoff success rate.
BrowserDataObservation.outcome gains DISMISSED (additive).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-26 00:20:17 +09:00
co-authored by Claude Opus 5.5
parent 55c0bf52bb
commit d76653bfcd
3 changed files with 46 additions and 3 deletions
+4 -2
View File
@@ -17,7 +17,9 @@ type BrowserFileObservation = Readonly<{
/**
* File adapters use the platform BrowserDataObserver as the telemetry SSOT.
* The helper below is the sole mapper from file-local dismissal semantics.
* The helper below is the sole mapper from file-local outcomes. A dismissal
* stays `DISMISSED` (02-06): folded into `SUCCEEDED` it hid the save-dialog
* cancel rate inside the browser handoff success rate.
*/
export type BrowserFileObserver = BrowserDataObserver;
@@ -30,7 +32,7 @@ export function observeBrowserFile(
Object.freeze({
operation: observation.operation,
outcome:
observation.outcome === "FAILED" ? "FAILED" : "SUCCEEDED",
observation.outcome === "SUCCESS" ? "SUCCEEDED" : observation.outcome,
...(observation.failureCode
? { failureCode: observation.failureCode }
: {}),
@@ -96,7 +96,8 @@ export type BrowserDataResult<Value> = Result<Value, BrowserDataFailure>;
export type BrowserDataObservation = Readonly<{
operation: BrowserDataOperation;
outcome: "SUCCEEDED" | "FAILED" | "DEGRADED";
/** `DISMISSED`: the user closed a picker or save dialog; not a failure. */
outcome: "SUCCEEDED" | "FAILED" | "DEGRADED" | "DISMISSED";
failureCode?: BrowserDataFailureCode;
durationBucket?: "LT100MS" | "100_TO_499MS" | "500_TO_1999MS" | "GTE2000MS";
byteBucket?: "ZERO" | "LT1MIB" | "1_TO_9MIB" | "10_TO_99MIB" | "GTE100MIB";
+40
View File
@@ -605,6 +605,46 @@ describe("browser download delivery", () => {
expect(events).toEqual(["hash", "write:2", "abort"]);
});
it("records a save-picker dismissal apart from a browser handoff (02-06)", async () => {
const records: unknown[] = [];
const adapter = createDownloadDeliveryAdapter({
...HARD_LIMITS,
policies,
host: { handoff: vi.fn() },
browserManagedCapabilities: capabilityResolver(
(resourceId) => `/downloads/${resourceId}`,
),
showSaveFilePicker: async () => {
throw new DOMException("dismissed", "AbortError");
},
baseOrigin: "https://app.example",
userActivation: { isActive: true },
observer: { record: (observation) => records.push(observation) },
});
await adapter.deliver(
deliveryInput(
{
kind: "BROWSER_MANAGED_RESOURCE",
resourceId: "artifact-1",
capabilityReceipt,
},
"BROWSER_MANAGED",
),
);
await adapter.deliver(
deliveryInput(
{ kind: "GENERATED", bytes: byteSource([new Uint8Array([1])]) },
"PROMPT_AND_STREAM",
),
);
expect(records).toEqual([
{ operation: "DOWNLOAD", outcome: "SUCCEEDED" },
{ operation: "DOWNLOAD", outcome: "DISMISSED" },
]);
});
it("distinguishes save-picker dismissal from active cancellation", async () => {
const dismissed = createDownloadDeliveryAdapter({
...HARD_LIMITS,