Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

12.6 KB
Raw Blame

Desktop backups follow the system network

简体中文

Problem and outcome

Desktop synchronization uses Electron networking, but the backup worker uses Node's global fetch. On a network that requires the system proxy, synchronization succeeds while the first scheduled backup times out connecting to /api/v1/backups/state. Backups and restores should follow each user's system network settings, without hardcoded proxy addresses or changes to the operating system.

The shared session also enables HTTP caching. Attachment responses are cacheable for an hour while replacement preserves the download URL. A backup can therefore receive old bytes after its data pages report a new SHA-256, failing with incompleteResources. Backup transport must bypass this cache so each archive matches current metadata.

Product changes cover desktop backup/restore network execution only, without note-list ordering or sharing changes. Reuse upstream's general CI stabilization rather than retaining independent import or appearance changes in this PR.

Allowed changes and acceptance

  1. Run desktop backup network requests through Electron's Chromium network stack and the same default session used by synchronization. This covers backup state/pages/attachment downloads and restore requests/uploads. Keep explicit bearer authentication and credentials: "omit"; do not start sending cookies. Users without a proxy continue to connect directly.

  2. Keep archive creation, validation, encryption and disk work off the main process. Prefer Electron's existing utility-process API, with a thin adapter retaining the manager's message, cancellation, failure and termination contract. Preserve streaming downloads and bounded multipart uploads rather than buffering entire attachments/archives or relaying their bytes through the main process. Retain Node-worker execution for existing non-Electron tests/callers, not as a network fallback.

  3. Preserve scheduling, unchanged-source checks, retention, paths, archive format, restore confirmation, account isolation, error diagnostics and request counts. Add no retry, timeout, proxy setting, certificate exception, migration or dependency.

  4. Exercise the actual Electron runtime against a proxy-only fixture and a direct fixture, including export, attachment integrity, restore, cancellation/failure and worker exit. Verify streaming resource use with a representative attachment, compare request paths/counts, and reuse the existing focused backup tests. Run the required Web/mobile type checks and Web build for this branch.

  5. Verify the real Cloudflare desktop workflow with a local candidate: load the existing backup configuration, create an archive containing the synced test note, inspect cumulative D1 reads without production full scans/stress, and keep the application and backup settings usable. Distinguish candidate execution from installation/release; do not deploy this dirty source tree or publish a release.

  6. Align the independent branch with the latest upstream main and verify backup behavior with the updated shared archive/client code. Add a directly runnable backup-network test command and a path-filtered CI workflow running the same real Electron proxy/direct scenarios on macOS, Windows and Linux, with Xvfb on Linux and an official-repository job gate before runner allocation. Use cross-platform fixture entrypoint paths and isolate fixture data from user configuration; add no product network retry, timeout or proxy setting. Distinguish CI runtime evidence from packaged-release acceptance.

    Fixture children have a 40-second deadline inside the 45-second test timeout; cleanup waits for servers and children to close. Beyond the SQLite query-cache capacity, Bun 1.3.14's ordinary close() can leave statements and Windows file locks alive (Bun #36572). Collect temporary statements and require close(true) before removing fixture directories. This replaces deletion retries so database-handle release does not depend on retry timing. Linux CI configures the downloaded chrome-sandbox owner/mode as required by Electron rather than disabling its sandbox. These settings apply only to isolated fixtures.

  7. Integrate upstream CI stabilization 1bdcdefc: import fixtures use the real self-hosted server's WAL/NORMAL, foreign-key and busy-timeout settings, and the long appearance test is split into independent scenarios. Adopt this shared solution instead of this branch's earlier transactional fixture setup; final import/appearance test source must match upstream. Change no product import/appearance behavior, test timeout, retry or test selection. Verify the complete import file and existing Ubuntu bun run test/browser CI entrypoints alongside the backup runtime on current upstream.

  8. Force cache: "no-store" after caller options for Electron backup/restore requests, neither reading nor populating the shared HTTP cache. Retain session/proxy selection, bearer authentication, cookie omission, streaming and cancellation; do not clear the user's global cache or change non-Electron callers. Keep fixture attachment responses cacheable: successfully export once, replace attachment bytes/SHA-256 and advance the backup revision without changing its URL or length, then export again in the same session. The second export must download current bytes from the server and restore them successfully through both proxy and direct connections. Retain large-attachment streaming and unchanged-source checks; download each attachment once per new archive without adding retries, polling or metadata scans.

Boundaries, risk and recovery

The value is consistent connectivity without requiring users to configure two networking stacks. The main risks are worker lifecycle differences and loss of streaming/cancellation behavior; worst cases are a failed backup/restore request or a worker left running. Preserve manager publication/verification safeguards so a failed task is not recorded as a completed archive. Roll back the independent transport adapter and worker entrypoint; no stored format or configuration migration is involved.

Installation, automatic updates, data storage, authentication and server protocols are unchanged. Existing archives and backup configuration must remain readable. Keep actual installed application files and user data intact; use a separate candidate and retain the official installer. Windows/Linux runtime behavior and packaged signing remain unverified until those platforms/releases are exercised; macOS checks do not establish cross-platform acceptance.

Implementation decision

Use Electron utility processes with the default session and net.fetch, keeping the existing backup algorithm and streaming pipeline in the background. This avoids introducing a proxy parser/agent, a per-machine configuration, or a custom main-process streaming bridge. Keep the Node worker port as an execution adapter for existing tests, not a fallback after failed requests.

Force cache: "no-store" only in the backup transport adapter, after caller options. Do not clear the shared session cache or change server attachment cache headers, preserving normal note-browsing caching. Each attachment is still downloaded once per new archive, and unchanged-source checks still skip archive generation.

Run real Electron regressions in a separate, path-filtered CI workflow rather than starting desktop processes during ordinary Bun unit tests or charging unrelated Web changes for three-platform runs. Each platform covers proxy/direct transport and worker exit because this change replaces the desktop worker runtime. Packaged signing, in-app updates and release acceptance remain with the existing release workflows.

Adopt upstream 1bdcdefc for general CI instead of this branch's earlier transactional import fixture. Its SQLite settings match scripts/self-hosted-server.mjs and the real runtime more closely; appearance checks are split by independent behavior while retaining assertions and deadlines. Do not layer a second fixture-initialization mechanism or change product storage/UI behavior.

Completion check

  • Desktop entry now supplies a utility-process worker bound to session.defaultSession; the bundled worker selects net.fetch only in that runtime. Its Node thread entry and injected worker contract remain usable. The manager, archive/storage/authentication logic and server code are unchanged. The build keeps electron external, and fixture scripts live under the existing excluded tests directory.
  • The proxy-only regression failed with the original Node worker before implementation. The real Electron proxy/direct scenarios pass: scheduled export, 32 MiB attachment round trip, unchanged-source due check, confirmed restore, HTTP 503, cancellation and all five worker exits. Both transports issued the same 47 fixture API requests; the due unchanged check did not create another archive. Bearer headers were retained and session cookies were omitted. Run bun run test:desktop:backup-network, which builds the worker first; set EDGE_EVER_BACKUP_ATTACHMENT_MIB=128 for the larger fixture. The 57 existing backup manager/IPC/Node-worker tests also pass, as do both required type checks and the desktop Web build.
  • The 128 MiB proxy fixture exported and restored successfully. Main-process working set stayed about 144 MiB for both 32 and 128 MiB attachments; utility-worker peaks were about 301 and 318 MiB. The original Node-thread 32 MiB case peaked at about 434 MiB in the main process, versus about 445 MiB for the sum of the new main/worker peaks. These local per-process peaks are not necessarily simultaneous and omit the network service; they show bounded growth rather than an archive-sized main-process buffer. Maximum 25 ms timer lateness in the measured candidate fixtures was below 9 ms. Machine-readable evidence.
  • A local candidate reused the real official v2.16.1 profile, its enabled weekly/one-copy settings, and the unchanged official renderer/native sidecar. A manual Cloudflare backup completed: 175,373 bytes, 41 ZIP entries, CRC verification passed, and the previously synced validation note's exact body was present. The next real scheduled run is not due; scheduled behavior was verified in the isolated Electron fixture. The D1 24-hour row chart moved approximately 19.08k → 19.81k during connection/backup validation, including ordinary usage and initialization; this is not a per-backup or large-library cost measurement. No production scan/stress was used.
  • Scope reconciliation: actual product changes are the runtime/factory adapters, desktop wiring, the external Electron build import and backup-only cache bypass, corresponding to items 1–3 and 8. Tests, CI and evidence cover items 4–8. No proxy configuration, request retry, archive/state format, storage/authentication mechanism, dependency or server change was added. The official v2.16.1 client could still read the completed backup history and existing schedule written by the candidate; this compatibility check used a candidate runtime, not a packaged release installation. All three runtimes must pass backup-network CI; packaged artifacts, signing and cross-version release acceptance remain with the release stage.
  • The independent PR branch integrates upstream main (1bdcdefc); import/appearance test source matches upstream, and all 71 import cases with 621 assertions pass. Existing evidence for the 57 related tests, Web/mobile type checks and Web build remains applicable to unchanged paths. The backup command builds the worker automatically. A path-filtered workflow gates runner allocation to the official repository, runs proxy/direct regressions on macOS/Windows/Linux and saves reports. Fixture children are terminated/waited for within test deadlines before cleanup; these limits do not alter product requests.
  • The same-URL regression reproduced incompleteResources before the product fix. Both proxy/direct cases pass with no-store. Retain the 32 MiB streaming attachment and add a 64 KiB cacheable attachment so different runner cache sizes do not hide the regression. Before the second export, change one byte without changing length/URL, update its hash and advance the backup revision via the resource trigger. The second archive restores current bytes; each new archive downloads that attachment once while responses remain private, max-age=3600. Each expanded default scenario makes 66 API requests and reaps all six workers; larger attachments add only the existing 8 MiB upload parts. Earlier single-archive/47-request performance measurements still describe that original scenario. Type checking, worker build and changed-file lint pass.