From 2e9bc86f7772e9205bd7b03cb76fbc3dc08cf86b Mon Sep 17 00:00:00 2001 From: kualta Date: Thu, 26 Nov 2026 12:28:30 -0500 Subject: [PATCH 1/5] Say when Flow ID is out of reach or busy instead of its code --- README.md | 1 + manifest.json | 2 +- package.json | 4 +-- src/controller.ts | 21 +++++++++------- src/device.ts | 24 ++++++++++++++++++ src/obsidian/modals.ts | 5 ++-- src/obsidian/settings.ts | 3 ++- tests/controller.test.ts | 43 ++++++++++++++++++++++++++++++++ tests/e2e.test.ts | 54 +++++++++++++++++++++++++++++++++++++++- versions.json | 3 ++- 10 files changed, 142 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 58bc02c..3b83617 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Syncing starts once the device has read your whole notepad. Until then, nothing - **Renames** carry across, including folder renames. A rename the plugin didn't see (Obsidian was closed) is recognised by the file's unchanged content. When you rename here with **Automatically update internal links** on, Obsidian's link edits sync like any other edit, and NOTE repairs only the links Obsidian never updates, those in `.mdx` notes, rather than repairing Obsidian's a second time. A rename Obsidian didn't see (made outside it, or while it was closed), or made with that setting off, has NOTE repair every link. A rename made in NOTE arrives with NOTE's link repair already done. - **Deletions** carry across. In NOTE they go to NOTE's trash. Here they follow Obsidian's **Deleted files** setting: the system trash, the vault's `.trash` folder, or, if you chose to delete permanently, a permanent deletion, though NOTE's trash still has the file. An edit beats a deletion: if one side edited a file the other deleted, it comes back. Before a sync would delete more than fifty files, or more than ten that are also over a tenth of the vault, the plugin asks. - **Swapped names** carry across too: two files that trade names, on either side, converge. While one waits for the other to leave its name, it may briefly sit beside it as ` moving <8 hex>.md`, and a sync that stops right then finishes the move next time. +- **Out of reach:** when Flow ID can't be reached, or is busy with other uploads, nothing stops. Changes stay queued, the status bar says so, and sync tries again on its own: within 30 seconds, or within a minute when busy. Only a vault that can't reach Flow ID as it opens stops, and settings offer **Retry**. - **Conflicts:** when both sides changed the same file, NOTE's version keeps the name and this vault's is saved beside it. A note's copy is named ` conflict <8 hex>.md`, the way NOTE names its own conflict copies; an attachment's keeps its extension last, ` conflict <8 hex>.png`, so Obsidian still opens it. Nothing is overwritten while you type: a file that changes during a sync, or an open note with unsaved typing, is left alone until the next sync. The same holds in NOTE: every write names the version it was planned from, so an edit that reaches NOTE during a sync is never replaced or trashed; the sync reads again and plans from there. **Not synced:** diff --git a/manifest.json b/manifest.json index a7d48ec..ce3b9ca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "flow-note", "name": "FLOW NOTE Sync", - "version": "0.1.2", + "version": "0.1.3", "minAppVersion": "1.11.5", "description": "Sync your vault both ways with your end-to-end encrypted NOTE notepad, linked once through your browser.", "author": "Flow Industries", diff --git a/package.json b/package.json index 43cdad1..4d07019 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "flow-note-sync", "private": true, - "version": "0.1.2", + "version": "0.1.3", "description": "FLOW NOTE Sync for Obsidian", "license": "MIT", "type": "module", @@ -30,6 +30,6 @@ "typescript-eslint": "8.72.1" }, "dependencies": { - "@flow-industries/seal": "^0.3.1" + "@flow-industries/seal": "^0.4.0" } } diff --git a/src/controller.ts b/src/controller.ts index 521ab1c..16f8bf1 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -1,12 +1,13 @@ import { type LinkedAccount, linkedAccount } from "./account"; import type { Custody } from "./custody"; -import type { - DeviceOptions, - DeviceVault, - LinkOptions, - LinkPrompt, - NoteDeviceFetch, - TrustLoss, +import { + type DeviceOptions, + type DeviceVault, + failureWords, + type LinkOptions, + type LinkPrompt, + type NoteDeviceFetch, + type TrustLoss, } from "./device"; import { type Deletions, @@ -502,5 +503,7 @@ export class SyncController { } } -const messageOf = (error: unknown) => - error instanceof Error ? error.message : String(error); +/** What the person reads for a failure: words for one Flow ID reported by code, else its own message. */ +export const messageOf = (error: unknown) => + failureWords(error) ?? + (error instanceof Error ? error.message : String(error)); diff --git a/src/device.ts b/src/device.ts index 5c9845c..d833cba 100644 --- a/src/device.ts +++ b/src/device.ts @@ -1,8 +1,11 @@ import { + failureReason, NoteChangedError, parseSyncBackoff, + SYNC_BUSY, SYNC_QUOTA_REACHED, SYNC_TOO_LARGE, + SYNC_UNREACHABLE, SYNCED, } from "@flow-industries/seal"; @@ -47,3 +50,24 @@ export function followsRead(status: string): boolean { refusal === SYNC_TOO_LARGE ); } + +export const UNREACHABLE = + "Couldn't reach Flow ID. Your changes are kept; try again once it's back."; +export const BUSY = + "Flow ID is busy. Your changes are kept; try again in a moment."; + +/** Words for a failure Flow ID reported by its code, so no code reaches the person: undefined for any other failure. */ +export function failureWords(error: unknown): string | undefined { + const reason = failureReason(error); + if (reason === "connection") return UNREACHABLE; + if (reason === "busy") return BUSY; + return undefined; +} + +/** What the status bar says for a device status. Flow ID out of reach or busy reads as a wait, since the device retries on its own. */ +export function statusWords(status: string): string { + if (status === SYNC_UNREACHABLE) + return "Couldn't reach Flow ID; changes are kept and will sync when it's back"; + if (status === SYNC_BUSY) return "Syncing again in a moment"; + return status; +} diff --git a/src/obsidian/modals.ts b/src/obsidian/modals.ts index afbf045..584ba4f 100644 --- a/src/obsidian/modals.ts +++ b/src/obsidian/modals.ts @@ -1,6 +1,6 @@ import { type App, Modal, Notice, Setting } from "obsidian"; import { handleDomain, type LinkedAccount } from "../account"; -import type { SyncController } from "../controller"; +import { messageOf, type SyncController } from "../controller"; import type { LinkPrompt } from "../device"; import { linkPageFor } from "../link-page"; @@ -227,8 +227,7 @@ export class LinkModal extends Modal { this.abort.signal, ); } catch (error) { - if (!this.abort.signal.aborted) - this.error = error instanceof Error ? error.message : String(error); + if (!this.abort.signal.aborted) this.error = messageOf(error); } finally { this.abort = null; this.render(); diff --git a/src/obsidian/settings.ts b/src/obsidian/settings.ts index 1c68917..f2f680f 100644 --- a/src/obsidian/settings.ts +++ b/src/obsidian/settings.ts @@ -1,5 +1,6 @@ import { type App, type Plugin, PluginSettingTab, Setting } from "obsidian"; import type { Phase, SyncController } from "../controller"; +import { statusWords } from "../device"; import type { RoundResult } from "../engine"; import { accountName, confirm } from "./modals"; import { custodyNote, updatesLinks } from "./vault"; @@ -23,7 +24,7 @@ export function statusText(phase: Phase, round: RoundResult | null): string { const failed = round?.failed.length ?? 0; const held = (round?.held.local ?? 0) + (round?.held.remote ?? 0); return [ - `FLOW NOTE: ${phase.status}`, + `FLOW NOTE: ${statusWords(phase.status)}`, failed ? `${failed} not synced` : "", held ? `${held} deletions held` : "", ] diff --git a/tests/controller.test.ts b/tests/controller.test.ts index 43db968..dce345a 100644 --- a/tests/controller.test.ts +++ b/tests/controller.test.ts @@ -1,8 +1,10 @@ import { describe, expect, test } from "bun:test"; import { + SYNC_BUSY, SYNC_PENDING, SYNC_QUOTA_REACHED, SYNC_RATE_LIMITED, + SYNC_UNREACHABLE, SYNCED, type SyncListener, } from "@flow-industries/seal"; @@ -10,15 +12,19 @@ import { type ControllerOptions, KEY_MISSING, LOCKED_ELSEWHERE, + messageOf, REMOVED, STRANDED, SyncController, } from "../src/controller"; import { Custody, type SecretBackend } from "../src/custody"; import { + BUSY, type DeviceOptions, type DeviceVault, followsRead, + statusWords, + UNREACHABLE, } from "../src/device"; import { sha256 } from "../src/hash"; import { isStale, MemoryIndex, MemoryRemote, MemoryVault } from "./fakes"; @@ -350,6 +356,43 @@ describe("controller", () => { // A rate limit can refuse the read itself, so it never counts. expect(followsRead(`${SYNC_RATE_LIMITED} · Next sync 12:00`)).toBe(false); expect(followsRead(SYNC_PENDING)).toBe(false); + // Nor can a read that never got an answer, or a busy Flow ID's. + expect(followsRead(SYNC_UNREACHABLE)).toBe(false); + expect(followsRead(SYNC_BUSY)).toBe(false); + }); + + test("Flow ID out of reach or busy stops an open in words, never a code", async () => { + for (const [code, status, words] of [ + ["CONNECTION_LOST", 0, UNREACHABLE], + ["UPLOAD_INCOMPLETE", 408, UNREACHABLE], + ["UPLOAD_BUSY", 429, BUSY], + ] as const) { + const h = await harness({ + onOpen: () => { + // How the device client throws a transport refusal: an Error whose message is the code. + throw Object.assign(new Error(code), { code, status }); + }, + }); + await h.controller.start(); + expect(h.controller.phase).toEqual({ kind: "stopped", message: words }); + expect(h.notices).toEqual([`Syncing stopped. ${words}`]); + expect(messageOf(Object.assign(new Error(code), { code }))).toBe(words); + } + expect(messageOf(new Error(LOCKED_ELSEWHERE))).toBe(LOCKED_ELSEWHERE); + expect(messageOf("plain")).toBe("plain"); + }); + + test("the status bar reads Flow ID out of reach or busy as a wait, and passes every other status through", () => { + expect(statusWords(SYNC_UNREACHABLE)).toBe( + "Couldn't reach Flow ID; changes are kept and will sync when it's back", + ); + expect(statusWords(SYNC_BUSY)).toBe("Syncing again in a moment"); + for (const status of [ + SYNCED, + SYNC_PENDING, + `${SYNC_RATE_LIMITED} · Next sync 12:00`, + ]) + expect(statusWords(status)).toBe(status); }); test("a close while the vault still opens keeps the lock until that open settles and stops", async () => { diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index b9ae62e..7e2cdd1 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,4 +1,5 @@ import { afterEach, describe, expect, test } from "bun:test"; +import { SYNC_UNREACHABLE } from "@flow-industries/seal"; import * as kit from "@flow-industries/seal/internal/testing/kit"; import { type AdminBrowser, @@ -27,6 +28,7 @@ import { openDeviceVault, SYNC_LOCKED, type TrustLoss, + UNREACHABLE, } from "../src/device"; import { type Deletions, SyncEngine, type SyncIndex } from "../src/engine"; import { linkPageFor } from "../src/link-page"; @@ -58,6 +60,8 @@ function obsidian(note: FakeFlowId, name: string) { const notices: string[] = []; /** Every mass deletion a round asked to confirm; each is approved, so a planned deletion would run. */ const asked: Deletions[] = []; + /** While down, no request reaches Flow ID: what a dropped network looks like to the device. */ + const network = { down: false }; const controller: SyncController = new SyncController({ custody, device: { @@ -69,7 +73,10 @@ function obsidian(note: FakeFlowId, name: string) { stale: isStaleWrite, }, host: TEST_HOST, - fetch: (url, init) => note.fetch(url, init), + fetch: (url, init) => + network.down + ? Promise.reject(new TypeError("Failed to fetch")) + : note.fetch(url, init), local, configDir: ".obsidian", updatesLinks: () => links.updated, @@ -112,6 +119,7 @@ function obsidian(note: FakeFlowId, name: string) { losses, notices, asked, + network, turn, }; } @@ -288,6 +296,50 @@ describe("two Obsidian vaults synced through NOTE", () => { expect(note.violations).toEqual([]); }, 60_000); + test("Flow ID out of reach reads as a wait, never a code, and syncs once it's back", async () => { + const note = fakeFlowId(); + const admin = await adminBrowser(note); + const a = obsidian(note, "dddddd"); + opened.push(a); + a.local.put("Before.md", "synced first"); + await link(admin, a); + await a.controller.confirm(); + await a.controller.syncNow(); + + // Open: the device's own sync can't reach Flow ID, keeps the edit and says it will retry. + a.network.down = true; + a.local.put("Open.md", "written while open"); + await a.controller.syncNow(); + expect(a.controller.phase).toEqual({ + kind: "open", + status: SYNC_UNREACHABLE, + }); + a.controller.close(); + + // Closed: an open that can't reach Flow ID stops in words. + a.local.put("Closed.md", "written while closed"); + await a.controller.start(); + expect(a.controller.phase).toEqual({ + kind: "stopped", + message: UNREACHABLE, + }); + expect(a.notices).toEqual([`Syncing stopped. ${UNREACHABLE}`]); + + a.network.down = false; + await a.controller.syncNow(); + expect(a.controller.phase.kind).toBe("open"); + await a.controller.syncNow(); + const web = await openAdminVault(admin); + await web.sync(); + expect((await web.read()).notes.map((item) => item.path).sort()).toEqual([ + "Before.md", + "Closed.md", + "Open.md", + ]); + web.lock(); + expect(note.violations).toEqual([]); + }, 60_000); + test("an edit that reaches the device mid-round becomes a conflict copy, never overwritten", async () => { const note = fakeFlowId(); const admin = await adminBrowser(note); diff --git a/versions.json b/versions.json index ff8dd16..1d15a4f 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,6 @@ { "0.1.0": "1.11.5", "0.1.1": "1.11.5", - "0.1.2": "1.11.5" + "0.1.2": "1.11.5", + "0.1.3": "1.11.5" } From ce7fc7d8e05c71adb0d970c0175b3f9e3b9841de Mon Sep 17 00:00:00 2001 From: kualta Date: Thu, 26 Nov 2026 14:03:50 -0500 Subject: [PATCH 2/5] Read Flow ID's transient failures through seal's transientFailure --- src/device.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/device.ts b/src/device.ts index d833cba..68094c1 100644 --- a/src/device.ts +++ b/src/device.ts @@ -1,5 +1,4 @@ import { - failureReason, NoteChangedError, parseSyncBackoff, SYNC_BUSY, @@ -7,6 +6,7 @@ import { SYNC_TOO_LARGE, SYNC_UNREACHABLE, SYNCED, + transientFailure, } from "@flow-industries/seal"; /** The one place the plugin imports the NOTE device client from. */ @@ -58,9 +58,9 @@ export const BUSY = /** Words for a failure Flow ID reported by its code, so no code reaches the person: undefined for any other failure. */ export function failureWords(error: unknown): string | undefined { - const reason = failureReason(error); - if (reason === "connection") return UNREACHABLE; - if (reason === "busy") return BUSY; + const transient = transientFailure(error); + if (transient === "connection") return UNREACHABLE; + if (transient === "busy") return BUSY; return undefined; } From 82829a6e526336a0d39b78bcf75aa4a42c2846bd Mon Sep 17 00:00:00 2001 From: kualta Date: Thu, 26 Nov 2026 15:06:33 -0500 Subject: [PATCH 3/5] Word every Flow ID refusal and keep link errors to the link --- README.md | 2 +- src/controller.ts | 13 +++++++++++-- src/device.ts | 29 ++++++++++++++++++++++------- tests/controller.test.ts | 26 ++++++++++++++++++++------ tests/e2e.test.ts | 6 +++--- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3b83617..0edc1a1 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Syncing starts once the device has read your whole notepad. Until then, nothing - **Renames** carry across, including folder renames. A rename the plugin didn't see (Obsidian was closed) is recognised by the file's unchanged content. When you rename here with **Automatically update internal links** on, Obsidian's link edits sync like any other edit, and NOTE repairs only the links Obsidian never updates, those in `.mdx` notes, rather than repairing Obsidian's a second time. A rename Obsidian didn't see (made outside it, or while it was closed), or made with that setting off, has NOTE repair every link. A rename made in NOTE arrives with NOTE's link repair already done. - **Deletions** carry across. In NOTE they go to NOTE's trash. Here they follow Obsidian's **Deleted files** setting: the system trash, the vault's `.trash` folder, or, if you chose to delete permanently, a permanent deletion, though NOTE's trash still has the file. An edit beats a deletion: if one side edited a file the other deleted, it comes back. Before a sync would delete more than fifty files, or more than ten that are also over a tenth of the vault, the plugin asks. - **Swapped names** carry across too: two files that trade names, on either side, converge. While one waits for the other to leave its name, it may briefly sit beside it as ` moving <8 hex>.md`, and a sync that stops right then finishes the move next time. -- **Out of reach:** when Flow ID can't be reached, or is busy with other uploads, nothing stops. Changes stay queued, the status bar says so, and sync tries again on its own: within 30 seconds, or within a minute when busy. Only a vault that can't reach Flow ID as it opens stops, and settings offer **Retry**. +- **Out of reach:** when Flow ID can't be reached, or is busy with other uploads, nothing stops. Changes stay queued, the plugin's status says so (in the status bar, or in its settings on mobile), and sync tries again on its own: within 30 seconds, or within a minute when busy. Only a vault that can't reach Flow ID as it opens stops, and settings offer **Retry**. - **Conflicts:** when both sides changed the same file, NOTE's version keeps the name and this vault's is saved beside it. A note's copy is named ` conflict <8 hex>.md`, the way NOTE names its own conflict copies; an attachment's keeps its extension last, ` conflict <8 hex>.png`, so Obsidian still opens it. Nothing is overwritten while you type: a file that changes during a sync, or an open note with unsaved typing, is left alone until the next sync. The same holds in NOTE: every write names the version it was planned from, so an edit that reaches NOTE during a sync is never replaced or trashed; the sync reads again and plans from there. **Not synced:** diff --git a/src/controller.ts b/src/controller.ts index 16f8bf1..ac6b46c 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -208,7 +208,7 @@ export class SyncController { } catch (error) { if (!this.live(generation)) return; this.close(); - this.set({ kind: "stopped", message: messageOf(error) }); + this.set({ kind: "stopped", message: stopMessageOf(error) }); } } @@ -456,7 +456,7 @@ export class SyncController { if (!this.live(generation)) return; this.close(); if (this.phase.kind !== "removed") - this.set({ kind: "stopped", message: messageOf(error) }); + this.set({ kind: "stopped", message: stopMessageOf(error) }); } finally { seed?.fill(0); } @@ -507,3 +507,12 @@ export class SyncController { export const messageOf = (error: unknown) => failureWords(error) ?? (error instanceof Error ? error.message : String(error)); + +/** Said after a stop Flow ID caused: syncing stopped, but nothing here changed. */ +export const KEPT = "Your changes are kept."; + +/** What a stop says: one Flow ID caused also says the files here are kept. */ +const stopMessageOf = (error: unknown) => { + const words = failureWords(error); + return words ? `${words} ${KEPT}` : messageOf(error); +}; diff --git a/src/device.ts b/src/device.ts index 68094c1..7e0f2d5 100644 --- a/src/device.ts +++ b/src/device.ts @@ -51,17 +51,32 @@ export function followsRead(status: string): boolean { ); } -export const UNREACHABLE = - "Couldn't reach Flow ID. Your changes are kept; try again once it's back."; -export const BUSY = - "Flow ID is busy. Your changes are kept; try again in a moment."; +export const UNREACHABLE = "Couldn't reach Flow ID. Try again once it's back."; +export const BUSY = "Flow ID is busy. Try again in a moment."; +export const REFUSED = "Flow ID couldn't complete that. Try again later."; -/** Words for a failure Flow ID reported by its code, so no code reaches the person: undefined for any other failure. */ +/** The code of a refusal Flow ID's SDK threw: a string `code` beside a numeric `status`. */ +function refusalCode(error: unknown): string | undefined { + if (typeof error !== "object" || error === null) return undefined; + if (!("code" in error) || !("status" in error)) return undefined; + return typeof error.code === "string" && typeof error.status === "number" + ? error.code + : undefined; +} + +/** + * Words for a failure Flow ID reported by its code, so no code reaches the + * person; undefined for any other failure, which says what went wrong itself. + * `PDS_UNAVAILABLE` is also what an error page without a code reads as, such + * as a gateway's during an outage, so it reads as out of reach. + */ export function failureWords(error: unknown): string | undefined { const transient = transientFailure(error); - if (transient === "connection") return UNREACHABLE; if (transient === "busy") return BUSY; - return undefined; + const code = refusalCode(error); + if (transient === "connection" || code === "PDS_UNAVAILABLE") + return UNREACHABLE; + return code === undefined ? undefined : REFUSED; } /** What the status bar says for a device status. Flow ID out of reach or busy reads as a wait, since the device retries on its own. */ diff --git a/tests/controller.test.ts b/tests/controller.test.ts index dce345a..9918458 100644 --- a/tests/controller.test.ts +++ b/tests/controller.test.ts @@ -10,6 +10,7 @@ import { } from "@flow-industries/seal"; import { type ControllerOptions, + KEPT, KEY_MISSING, LOCKED_ELSEWHERE, messageOf, @@ -23,6 +24,7 @@ import { type DeviceOptions, type DeviceVault, followsRead, + REFUSED, statusWords, UNREACHABLE, } from "../src/device"; @@ -361,24 +363,36 @@ describe("controller", () => { expect(followsRead(SYNC_BUSY)).toBe(false); }); - test("Flow ID out of reach or busy stops an open in words, never a code", async () => { + test("a Flow ID refusal stops an open in words, never a code, and says the changes are kept", async () => { for (const [code, status, words] of [ ["CONNECTION_LOST", 0, UNREACHABLE], ["UPLOAD_INCOMPLETE", 408, UNREACHABLE], + ["PDS_UNAVAILABLE", 503, UNREACHABLE], ["UPLOAD_BUSY", 429, BUSY], + ["RATE_LIMITED", 429, REFUSED], + ["RECONNECT_REQUIRED", 403, REFUSED], + ["DEVICE_LINKING_DISABLED", 403, REFUSED], ] as const) { + // How the device client throws a transport refusal: an Error whose message is the code. + const refusal = () => Object.assign(new Error(code), { code, status }); const h = await harness({ onOpen: () => { - // How the device client throws a transport refusal: an Error whose message is the code. - throw Object.assign(new Error(code), { code, status }); + throw refusal(); }, }); await h.controller.start(); - expect(h.controller.phase).toEqual({ kind: "stopped", message: words }); - expect(h.notices).toEqual([`Syncing stopped. ${words}`]); - expect(messageOf(Object.assign(new Error(code), { code }))).toBe(words); + const stopped = `${words} ${KEPT}`; + expect(h.controller.phase).toEqual({ kind: "stopped", message: stopped }); + expect(h.notices).toEqual([`Syncing stopped. ${stopped}`]); + // A link has no changes in play, so the link modal's words leave that out. + expect(messageOf(refusal())).toBe(words); + expect(messageOf(refusal())).not.toContain(code); } expect(messageOf(new Error(LOCKED_ELSEWHERE))).toBe(LOCKED_ELSEWHERE); + // A code without a status isn't Flow ID's, so it keeps its own message. + expect( + messageOf(Object.assign(new Error("no such file"), { code: "ENOENT" })), + ).toBe("no such file"); expect(messageOf("plain")).toBe("plain"); }); diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 7e2cdd1..558bc8b 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -13,7 +13,7 @@ import { TEST_DID, TEST_HOST, } from "@flow-industries/seal/testing"; -import { REMOVED, SyncController } from "../src/controller"; +import { KEPT, REMOVED, SyncController } from "../src/controller"; import { Custody, type SecretBackend } from "../src/custody"; import { createDeviceSeed, @@ -321,9 +321,9 @@ describe("two Obsidian vaults synced through NOTE", () => { await a.controller.start(); expect(a.controller.phase).toEqual({ kind: "stopped", - message: UNREACHABLE, + message: `${UNREACHABLE} ${KEPT}`, }); - expect(a.notices).toEqual([`Syncing stopped. ${UNREACHABLE}`]); + expect(a.notices).toEqual([`Syncing stopped. ${UNREACHABLE} ${KEPT}`]); a.network.down = false; await a.controller.syncNow(); From 414507b35e2f9eca1b359a7489c0485461681212 Mon Sep 17 00:00:00 2001 From: kualta Date: Thu, 26 Nov 2026 15:22:19 -0500 Subject: [PATCH 4/5] Word a failed connection to Flow ID without saying it was unreachable --- README.md | 2 +- src/device.ts | 23 ++++++++++++++--------- tests/controller.test.ts | 19 ++++++++++--------- tests/e2e.test.ts | 14 ++++++++------ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0edc1a1..58dba5a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Syncing starts once the device has read your whole notepad. Until then, nothing - **Renames** carry across, including folder renames. A rename the plugin didn't see (Obsidian was closed) is recognised by the file's unchanged content. When you rename here with **Automatically update internal links** on, Obsidian's link edits sync like any other edit, and NOTE repairs only the links Obsidian never updates, those in `.mdx` notes, rather than repairing Obsidian's a second time. A rename Obsidian didn't see (made outside it, or while it was closed), or made with that setting off, has NOTE repair every link. A rename made in NOTE arrives with NOTE's link repair already done. - **Deletions** carry across. In NOTE they go to NOTE's trash. Here they follow Obsidian's **Deleted files** setting: the system trash, the vault's `.trash` folder, or, if you chose to delete permanently, a permanent deletion, though NOTE's trash still has the file. An edit beats a deletion: if one side edited a file the other deleted, it comes back. Before a sync would delete more than fifty files, or more than ten that are also over a tenth of the vault, the plugin asks. - **Swapped names** carry across too: two files that trade names, on either side, converge. While one waits for the other to leave its name, it may briefly sit beside it as ` moving <8 hex>.md`, and a sync that stops right then finishes the move next time. -- **Out of reach:** when Flow ID can't be reached, or is busy with other uploads, nothing stops. Changes stay queued, the plugin's status says so (in the status bar, or in its settings on mobile), and sync tries again on its own: within 30 seconds, or within a minute when busy. Only a vault that can't reach Flow ID as it opens stops, and settings offer **Retry**. +- **Connection trouble:** when the connection to Flow ID fails, or Flow ID is busy with other uploads, nothing stops. Changes stay queued, the plugin's status says so (in the status bar, or in its settings on mobile), and sync tries again on its own: within 30 seconds, or within a minute when busy. Only a vault whose connection fails as it opens stops, and settings offer **Retry**. - **Conflicts:** when both sides changed the same file, NOTE's version keeps the name and this vault's is saved beside it. A note's copy is named ` conflict <8 hex>.md`, the way NOTE names its own conflict copies; an attachment's keeps its extension last, ` conflict <8 hex>.png`, so Obsidian still opens it. Nothing is overwritten while you type: a file that changes during a sync, or an open note with unsaved typing, is left alone until the next sync. The same holds in NOTE: every write names the version it was planned from, so an edit that reaches NOTE during a sync is never replaced or trashed; the sync reads again and plans from there. **Not synced:** diff --git a/src/device.ts b/src/device.ts index 7e0f2d5..2945de5 100644 --- a/src/device.ts +++ b/src/device.ts @@ -2,9 +2,9 @@ import { NoteChangedError, parseSyncBackoff, SYNC_BUSY, + SYNC_CONNECTION_FAILED, SYNC_QUOTA_REACHED, SYNC_TOO_LARGE, - SYNC_UNREACHABLE, SYNCED, transientFailure, } from "@flow-industries/seal"; @@ -51,8 +51,12 @@ export function followsRead(status: string): boolean { ); } -export const UNREACHABLE = "Couldn't reach Flow ID. Try again once it's back."; -export const BUSY = "Flow ID is busy. Try again in a moment."; +export const CONNECTION_FAILED = + "The connection to Flow ID failed. Try again in a moment."; +export const UNAVAILABLE = + "Flow ID isn't available right now. Try again in a moment."; +export const BUSY = + "Flow ID is busy with other uploads from your account. Try again in a moment."; export const REFUSED = "Flow ID couldn't complete that. Try again later."; /** The code of a refusal Flow ID's SDK threw: a string `code` beside a numeric `status`. */ @@ -67,22 +71,23 @@ function refusalCode(error: unknown): string | undefined { /** * Words for a failure Flow ID reported by its code, so no code reaches the * person; undefined for any other failure, which says what went wrong itself. + * A failed connection may be on either side, so its words blame neither. * `PDS_UNAVAILABLE` is also what an error page without a code reads as, such - * as a gateway's during an outage, so it reads as out of reach. + * as a gateway's during an outage. */ export function failureWords(error: unknown): string | undefined { const transient = transientFailure(error); + if (transient === "connection") return CONNECTION_FAILED; if (transient === "busy") return BUSY; const code = refusalCode(error); - if (transient === "connection" || code === "PDS_UNAVAILABLE") - return UNREACHABLE; + if (code === "PDS_UNAVAILABLE") return UNAVAILABLE; return code === undefined ? undefined : REFUSED; } -/** What the status bar says for a device status. Flow ID out of reach or busy reads as a wait, since the device retries on its own. */ +/** What the status bar says for a device status. A failed connection or a busy Flow ID reads as a wait, since the device retries on its own. */ export function statusWords(status: string): string { - if (status === SYNC_UNREACHABLE) - return "Couldn't reach Flow ID; changes are kept and will sync when it's back"; + if (status === SYNC_CONNECTION_FAILED) + return "Connection to Flow ID failed; changes are kept and sync resumes once it's back"; if (status === SYNC_BUSY) return "Syncing again in a moment"; return status; } diff --git a/tests/controller.test.ts b/tests/controller.test.ts index 9918458..2d0972d 100644 --- a/tests/controller.test.ts +++ b/tests/controller.test.ts @@ -1,10 +1,10 @@ import { describe, expect, test } from "bun:test"; import { SYNC_BUSY, + SYNC_CONNECTION_FAILED, SYNC_PENDING, SYNC_QUOTA_REACHED, SYNC_RATE_LIMITED, - SYNC_UNREACHABLE, SYNCED, type SyncListener, } from "@flow-industries/seal"; @@ -21,12 +21,13 @@ import { import { Custody, type SecretBackend } from "../src/custody"; import { BUSY, + CONNECTION_FAILED, type DeviceOptions, type DeviceVault, followsRead, REFUSED, statusWords, - UNREACHABLE, + UNAVAILABLE, } from "../src/device"; import { sha256 } from "../src/hash"; import { isStale, MemoryIndex, MemoryRemote, MemoryVault } from "./fakes"; @@ -359,15 +360,15 @@ describe("controller", () => { expect(followsRead(`${SYNC_RATE_LIMITED} · Next sync 12:00`)).toBe(false); expect(followsRead(SYNC_PENDING)).toBe(false); // Nor can a read that never got an answer, or a busy Flow ID's. - expect(followsRead(SYNC_UNREACHABLE)).toBe(false); + expect(followsRead(SYNC_CONNECTION_FAILED)).toBe(false); expect(followsRead(SYNC_BUSY)).toBe(false); }); test("a Flow ID refusal stops an open in words, never a code, and says the changes are kept", async () => { for (const [code, status, words] of [ - ["CONNECTION_LOST", 0, UNREACHABLE], - ["UPLOAD_INCOMPLETE", 408, UNREACHABLE], - ["PDS_UNAVAILABLE", 503, UNREACHABLE], + ["CONNECTION_LOST", 0, CONNECTION_FAILED], + ["UPLOAD_INCOMPLETE", 408, CONNECTION_FAILED], + ["PDS_UNAVAILABLE", 503, UNAVAILABLE], ["UPLOAD_BUSY", 429, BUSY], ["RATE_LIMITED", 429, REFUSED], ["RECONNECT_REQUIRED", 403, REFUSED], @@ -396,9 +397,9 @@ describe("controller", () => { expect(messageOf("plain")).toBe("plain"); }); - test("the status bar reads Flow ID out of reach or busy as a wait, and passes every other status through", () => { - expect(statusWords(SYNC_UNREACHABLE)).toBe( - "Couldn't reach Flow ID; changes are kept and will sync when it's back", + test("the status bar reads a failed connection or a busy Flow ID as a wait, and passes every other status through", () => { + expect(statusWords(SYNC_CONNECTION_FAILED)).toBe( + "Connection to Flow ID failed; changes are kept and sync resumes once it's back", ); expect(statusWords(SYNC_BUSY)).toBe("Syncing again in a moment"); for (const status of [ diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 558bc8b..b0abc51 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, test } from "bun:test"; -import { SYNC_UNREACHABLE } from "@flow-industries/seal"; +import { SYNC_CONNECTION_FAILED } from "@flow-industries/seal"; import * as kit from "@flow-industries/seal/internal/testing/kit"; import { type AdminBrowser, @@ -16,6 +16,7 @@ import { import { KEPT, REMOVED, SyncController } from "../src/controller"; import { Custody, type SecretBackend } from "../src/custody"; import { + CONNECTION_FAILED, createDeviceSeed, type DeviceCheckpoint, deleteDeviceStorage, @@ -28,7 +29,6 @@ import { openDeviceVault, SYNC_LOCKED, type TrustLoss, - UNREACHABLE, } from "../src/device"; import { type Deletions, SyncEngine, type SyncIndex } from "../src/engine"; import { linkPageFor } from "../src/link-page"; @@ -296,7 +296,7 @@ describe("two Obsidian vaults synced through NOTE", () => { expect(note.violations).toEqual([]); }, 60_000); - test("Flow ID out of reach reads as a wait, never a code, and syncs once it's back", async () => { + test("a failed connection to Flow ID reads as a wait, never a code, and syncs once it's back", async () => { const note = fakeFlowId(); const admin = await adminBrowser(note); const a = obsidian(note, "dddddd"); @@ -312,7 +312,7 @@ describe("two Obsidian vaults synced through NOTE", () => { await a.controller.syncNow(); expect(a.controller.phase).toEqual({ kind: "open", - status: SYNC_UNREACHABLE, + status: SYNC_CONNECTION_FAILED, }); a.controller.close(); @@ -321,9 +321,11 @@ describe("two Obsidian vaults synced through NOTE", () => { await a.controller.start(); expect(a.controller.phase).toEqual({ kind: "stopped", - message: `${UNREACHABLE} ${KEPT}`, + message: `${CONNECTION_FAILED} ${KEPT}`, }); - expect(a.notices).toEqual([`Syncing stopped. ${UNREACHABLE} ${KEPT}`]); + expect(a.notices).toEqual([ + `Syncing stopped. ${CONNECTION_FAILED} ${KEPT}`, + ]); a.network.down = false; await a.controller.syncNow(); From bdec1d10f4d1111df7f4e838692a9bea0f36e4c3 Mon Sep 17 00:00:00 2001 From: kualta Date: Thu, 26 Nov 2026 16:53:45 -0500 Subject: [PATCH 5/5] Lock the published Seal 0.4.0 --- bun.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bun.lock b/bun.lock index dd32b0d..89bf82c 100644 --- a/bun.lock +++ b/bun.lock @@ -5,7 +5,7 @@ "": { "name": "flow-note-sync", "dependencies": { - "@flow-industries/seal": "^0.3.1", + "@flow-industries/seal": "^0.4.0", }, "devDependencies": { "@biomejs/biome": "2.5.8", @@ -83,11 +83,11 @@ "@floating-ui/utils": ["@floating-ui/utils@0.2.12", "", {}, "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww=="], - "@flow-industries/id": ["@flow-industries/id@0.37.0", "", { "dependencies": { "@flow-industries/ui": "^0.27.0", "@opentelemetry/api": "1.9.1", "jose": "^6.1.3", "lucide-react": "^0.563.0", "zod": "^4.3.6" }, "peerDependencies": { "@tanstack/react-start": ">=1.168.0", "@wagmi/core": ">=3.0.0", "ox": ">=0.14.0", "react": ">=18", "react-dom": ">=18", "viem": ">=2.47.10" }, "optionalPeers": ["@tanstack/react-start", "@wagmi/core", "react", "react-dom"] }, "sha512-oyrU70zsTeFCmvqcKOiqsHBdjS8dsViASg1BihTobP9oAGoR0FdVIFwG7edAdtEBQdUfC8ei9wMkY6lSmLSKlA=="], + "@flow-industries/id": ["@flow-industries/id@0.38.2", "", { "dependencies": { "@opentelemetry/api": "1.9.1", "jose": "^6.1.3", "lucide-react": "^0.563.0", "zod": "^4.3.6" }, "peerDependencies": { "@flow-industries/ui": "^0.28.0", "@tanstack/react-start": ">=1.168.0", "@wagmi/core": ">=3.0.0", "ox": ">=0.14.0", "react": ">=18", "react-dom": ">=18", "viem": ">=2.47.10" }, "optionalPeers": ["@tanstack/react-start", "@wagmi/core", "react", "react-dom"] }, "sha512-VKVU4BIDk+9WLlW9YkPKriK6+qYnO7KEymEwqSk9bGq+j5Io/I3WVnsALygEzIJKVnj1crNCCI0/wrgM2PVXQw=="], "@flow-industries/lint": ["@flow-industries/lint@0.3.1", "", {}, "sha512-oKTw7fMCZBlshRixumpXrUJUmbJx3HqiGs72F43d920yy1fCtOuAjlnbY8SXBZZ7TnEibuYY2FVjAZcQSg6COQ=="], - "@flow-industries/seal": ["@flow-industries/seal@0.3.1", "", { "dependencies": { "@flow-industries/id": "^0.37.0", "@lezer/markdown": "1.8.0", "dexie": "^4.4.6", "fflate": "^0.8.3", "libsodium-wrappers-sumo": "0.8.4", "yaml": "^2.9.1", "zod": "^4.6.5" } }, "sha512-B53/Sy5WZuH2mpspHM86oF7bUhOHVJooV4bJg1DSiMSKulSQWo561yunlyMjtoNNm8bIUgsYchZkicfZs9lICA=="], + "@flow-industries/seal": ["@flow-industries/seal@0.4.0", "", { "dependencies": { "@flow-industries/id": "^0.38.1", "@lezer/markdown": "1.8.0", "dexie": "^4.4.6", "fflate": "^0.8.3", "libsodium-wrappers-sumo": "0.8.4", "yaml": "^2.9.1", "zod": "^4.6.5" } }, "sha512-IjnUQxnx06sA93WVbVuw/spRjttdGIuSEMGdSdKpG0Hf1MHDLcetho5m0x3eUZPfwC8l5PPJuACK8Ssl4DWXrw=="], "@flow-industries/ui": ["@flow-industries/ui@0.27.0", "", { "dependencies": { "@base-ui/react": "^1.3.0", "@hookform/resolvers": "^5.2.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "date-fns": "^4.1.0", "embla-carousel-react": "^8.6.0", "input-otp": "^1.4.2", "lucide-react": "^0.562.0", "motion": "^12.24.0", "react-hook-form": "^7.70.0", "react-resizable-panels": "^4.9.0", "recharts": "3.8.0", "tailwind-merge": "^3.4.0", "tw-animate-css": "^1.4.0", "zod": "^4.3.5" }, "peerDependencies": { "@flow-industries/id": ">=0.22.0", "react": ">=19.0.0", "react-dom": ">=19.0.0", "tailwindcss": ">=4.0.0" }, "optionalPeers": ["@flow-industries/id"] }, "sha512-lTrfDnt8B1o2c/ny3lst3b8sjYWmluo6T7jVGtjKpwxsxzCdiVapqcF80lIkuUeqytdaXkhm8H7+//KCF9+crQ=="],