test(sync): audit browser recovery paths

This commit is contained in:
slhx agent
2026-07-13 22:46:03 +02:00
parent d2ae025e13
commit 98b00920b9
5 changed files with 70 additions and 31 deletions
+19 -1
View File
@@ -443,6 +443,21 @@ async function continuePendingWork() {
setTimeout(() => synchronize(validatePending(commands[0])).catch(failPermanently), 0);
}
async function renewOfflineLease(command) {
if (stopped || root.getAttribute("data-sync-phase") !== "offline") return;
const lease = await claimUploaderLease(database);
publishLease(lease);
if (!lease.leader) {
setPhase("standby", "Another tab owns sync; waiting for lease takeover.");
leaseTimer = setTimeout(() => runLeaseLoop(command).catch(failPermanently), LEASE_POLL_MS);
return;
}
leaseTimer = setTimeout(
() => renewOfflineLease(command).catch(failPermanently),
LEASE_MS / 2,
);
}
async function synchronize(command) {
if (synchronizing) return;
synchronizing = true;
@@ -455,7 +470,10 @@ async function synchronize(command) {
}
clearTimeout(leaseTimer);
leaseTimer = setTimeout(() => {
if (!stopped && root.getAttribute("data-sync-phase") !== "acknowledged") {
if (stopped || root.getAttribute("data-sync-phase") === "acknowledged") return;
if (root.getAttribute("data-sync-phase") === "offline") {
renewOfflineLease(command).catch(failPermanently);
} else {
synchronize(command).catch(failPermanently);
}
}, LEASE_MS / 2);