Repository navigation
Stop reporting a restore the page walked away from as a failure - #1681
Merged
Merged
Conversation
A vault restore that is still fetching when the document is discarded has its
requests cancelled by the browser, and those rejections arrive as
`TypeError: Failed to fetch`. `restoreFromVault` warned on them, so an
ordinary navigation during a restore printed
[cloud-vault] restore failed TypeError: Failed to fetch
with nobody left on that page to read it. In atomic-saas's portal e2e the
browser-diagnostics fixture treats any unexpected console warning as a
failure, so the nodeless leg went red on onboarding.spec.ts:16 whenever a
restore was in flight at the wrong moment: three control-plane requests
(`/api/drives/catalog`, `/api/cloud-vault/<pseudonym>/objects` and `/api/me`)
abort within 40 ms of each other, which only a document-level cancellation
does.
Take `pageRequestSignal()` before the first request, so its pagehide listener
is registered while this document is still live, and skip the warning when it
has fired. The outcome stays `failed`, since no caller can do anything else
with a page that is going away, and a restore that really fails on a live page
still warns. This is the line `Client.fetchResourceHTTP` already draws for
reads (it reports such a read as `cancelled`), and the one the backup path
draws for its own cancellation a few hundred lines above.
`pageRequestSignal` was internal to @tomic/lib and is now exported, rather
than duplicating the listener in the data browser and having two answers to
"is this document still here".
Covered both ways: the discard case is quiet, and the existing failure test
now also asserts that a live-page failure still says so.
joepio
marked this pull request as ready for review
September 24, 2026 06:20
joepio
added a commit
that referenced
this pull request
Sep 24, 2026
The discarded-document test added in #1681 stubbed `window` with a bare EventTarget and only then built its Store. `new Store()` reads `localStorage` behind a `typeof window !== 'undefined'` guard, so the stub made that read reachable with no `localStorage` beside it: the test threw `ReferenceError: localStorage is not defined` before its own `vi.unstubAllGlobals()`, leaving the half-made window standing for the rest of the file. Twelve tests in `watchForVaultBackups` then failed the same way, which is every develop and branch run since #1681 merged, none of which had a verdict of its own to show it. The store is built before the stub now, and the unstub moved into the file's `afterEach`, where a throwing test cannot skip it.
3 tasks done
claude Bot
pushed a commit
that referenced
this pull request
Sep 24, 2026
develop's unit tests have been red since #1681. The new test for a restore the page walked away from stubs `window` with a bare EventTarget and then builds a Store. The Store constructor reads `localStorage` whenever a `window` exists, and a stubbed one has none, so the test threw on its own first line and never reached its `vi.unstubAllGlobals()`. The stub stayed for the rest of the file, and eleven later tests died on `localStorage is not defined` with nothing wrong in them. Build the store before the stub, and unstub in `afterEach` so no test can leak one again. 38 of 38 pass, against 12 failing. This is why no develop run has produced an e2e verdict today: the Dagger job stops at `data-browser test`, eight minutes in, long before e2e.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Joep · project thread
Before: navigating away while a Cloud Vault restore was still fetching printed
[cloud-vault] restore failed TypeError: Failed to fetchin the console of a page that no longer exists. The browser cancels a discarded document's requests, and those rejections are indistinguishable by type from a control plane that is really unreachable, sorestoreFromVaultwarned about both. In atomic-saas's portal e2e, where the browser-diagnostics fixture treats any unexpected console warning as a failure, this turned an ordinary navigation into a red test: the nodeless leg stopped atonboarding.spec.ts:16whenever a restore happened to be in flight, with/api/drives/catalog,/api/cloud-vault/<pseudonym>/objectsand/api/meall aborting within 40 ms of each other, which only a document-level cancellation does.After: a restore interrupted by the page going away is silent. A restore that fails on a live page still warns, exactly as before.
How:
restoreFromVaulttakespageRequestSignal()before its first request, so the signal'spagehidelistener is registered while this document is still the live one, and the catch skips the warning when that signal has fired. The outcome staysfailed, since no caller can act on a page that is leaving, so no call site changes. This is the lineClient.fetchResourceHTTPalready draws for reads, where it reports such a read ascancelled, and the one the backup path in the same file draws for its own cancellation.pageRequestSignalwas internal to@tomic/liband is now exported, rather than duplicating the listener in the data browser and keeping two answers to "is this document still here".Related Issues
No issue; found while tracing atomic-saas's red portal e2e (ontola/atomic-saas#135).
Checklist
vaultAutoBackup.test.tscovers it both ways: a discard mid-restore stays quiet, and the existing failure test now also asserts that a live-page failure still says so. 38 of 38 in that file pass locally.