fix(storage): delete a partition's IndexedDB dataset when an authorized purge cannot open it (05-03)
LOGOUT and ACCOUNT_DELETION purged row by row and so needed an open that a corrupt budget or binding row always rejected, leaving personal rows on the device. After authority approval, a purge that finds the dataset rejected by admission now deletes that partition's own database and reports it; healthy datasets and other partitions are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9cae587aea
commit
3e37fbf0ed
@@ -605,9 +605,9 @@ export function createIndexedDbConnection<Failure>(
|
||||
|
||||
/**
|
||||
* In this module because it is the same `IDBOpenDBRequest` state machine as
|
||||
* `openIndexedDbDatabase`, not because three subsystems need it — only
|
||||
* `indexeddb-checkpoint-store.ts` deletes a database, and nothing here asks the
|
||||
* other three to start. Leaving it out would leave a third hand-written copy of
|
||||
* `openIndexedDbDatabase`. Two callers delete a database:
|
||||
* `indexeddb-checkpoint-store.ts`, and the IndexedDB runtime's authorized
|
||||
* LOGOUT/ACCOUNT_DELETION purge when its dataset fails admission. Leaving it out would leave a third hand-written copy of
|
||||
* the settle-once blocked-deadline latch eight lines away from the kernel's.
|
||||
*
|
||||
* There is deliberately no `signal`: the request cannot be cancelled after
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import { snapshotAbortTimers } from "../../platform/abortable-operation.ts";
|
||||
import {
|
||||
createIndexedDbConnection,
|
||||
deleteIndexedDbDatabase,
|
||||
openIndexedDbDatabase,
|
||||
type IndexedDbTranslate,
|
||||
} from "../../platform/indexeddb-connection.ts";
|
||||
@@ -2500,7 +2501,9 @@ export function createIndexedDbRuntime<Value, WireValue, Query>(
|
||||
cutoffEpochMs,
|
||||
);
|
||||
} else {
|
||||
result = await purgePartitionRecords(input, deadline);
|
||||
result =
|
||||
(await deleteUnadmittedDataset(input.signal)) ??
|
||||
(await purgePartitionRecords(input, deadline));
|
||||
}
|
||||
return observeResult(
|
||||
operation,
|
||||
@@ -2509,6 +2512,54 @@ export function createIndexedDbRuntime<Value, WireValue, Query>(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 05-03. A LOGOUT or ACCOUNT_DELETION purge must not depend on the dataset
|
||||
* passing admission: a corrupt governance row rejects every open, so no row
|
||||
* could ever be purged one by one. The authority has already approved this
|
||||
* purge, and the database name comes from this partition's own tokens, so
|
||||
* deleting the whole database touches no other partition. Returns `null`
|
||||
* when a connection is ready for the row-by-row purge.
|
||||
*/
|
||||
async function deleteUnadmittedDataset(
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<BrowserDataResult<IndexedDbLifecycleBatchReceipt> | null> {
|
||||
if (connection.current()) return null;
|
||||
const opened = await open(signal);
|
||||
if (opened.ok) return null;
|
||||
if (
|
||||
(opened.error.code !== "POLICY_REJECTED" &&
|
||||
opened.error.code !== "CORRUPT_DATA") ||
|
||||
disposed ||
|
||||
typeof factory?.deleteDatabase !== "function"
|
||||
) {
|
||||
return opened;
|
||||
}
|
||||
const deleted = await deleteIndexedDbDatabase<BrowserDataFailure>({
|
||||
factory,
|
||||
databaseName,
|
||||
translate: translateFor("INDEXEDDB_WRITE"),
|
||||
blockedTimeoutMs,
|
||||
timers,
|
||||
});
|
||||
if (!deleted.ok) return deleted;
|
||||
if (deleted.value.kind === "BLOCKED_DEADLINE") {
|
||||
// The request is still live and may yet land; the next call finds out.
|
||||
return browserDataFailure("BLOCKED", "INDEXEDDB_WRITE", {
|
||||
retryable: true,
|
||||
recovery: "RELOAD_OTHER_CONTEXTS",
|
||||
});
|
||||
}
|
||||
return browserDataSuccess(
|
||||
Object.freeze({
|
||||
state: "COMPLETE" as const,
|
||||
scannedRows: 0,
|
||||
deletedRows: 0,
|
||||
budgetExhausted: false,
|
||||
datasetDeleted: true as const,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
|
||||
@@ -144,6 +144,13 @@ export type IndexedDbLifecycleBatchReceipt = Readonly<{
|
||||
scannedRows: number;
|
||||
deletedRows: number;
|
||||
budgetExhausted: boolean;
|
||||
/**
|
||||
* 05-03. Present when an authorized LOGOUT or ACCOUNT_DELETION found the
|
||||
* dataset's governance rows unreadable, so no row could be purged one by
|
||||
* one, and deleted the partition's whole database instead. Rows are then
|
||||
* not counted.
|
||||
*/
|
||||
datasetDeleted?: true;
|
||||
}>;
|
||||
|
||||
export type IndexedDbLifecycleAuthorityRequest = Readonly<{
|
||||
|
||||
Reference in New Issue
Block a user