Skip to content

Stop reporting a restore the page walked away from as a failure - #1681

Merged
joepio merged 1 commit into
developfrom
claude/project-thread-8tdupo
Sep 24, 2026
Merged

joepio merged 1 commit into
developfrom
claude/project-thread-8tdupo

Conversation

@joepio

@joepio joepio commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Requested by Joep · project thread

Before: navigating away while a Cloud Vault restore was still fetching printed [cloud-vault] restore failed TypeError: Failed to fetch in 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, so restoreFromVault warned 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 at onboarding.spec.ts:16 whenever a restore happened to be in flight, with /api/drives/catalog, /api/cloud-vault/<pseudonym>/objects and /api/me all 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: restoreFromVault takes pageRequestSignal() before its first request, so the signal's pagehide listener is registered while this document is still the live one, and the catch skips the warning when that signal has fired. The outcome stays failed, since no caller can act on a page that is leaving, so no call site changes. This is the line Client.fetchResourceHTTP already draws for reads, where it reports such a read as cancelled, and the one the backup path in the same file draws for its own cancellation. pageRequestSignal was internal to @tomic/lib and 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

  • Add changelog entry linking to issue, describe API changes
  • Add or update tests if needed
  • Update docs if needed

vaultAutoBackup.test.ts covers 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.

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 joepio self-assigned this Sep 24, 2026
@joepio
joepio marked this pull request as ready for review September 24, 2026 06:20
@joepio
joepio merged commit ae18582 into develop Sep 24, 2026
1 check passed
@joepio
joepio deleted the claude/project-thread-8tdupo branch 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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant