Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This changelog covers all five packages, as they are (for now) updated as a whol

## UNRELEASED

- A workspace a Cloud Server node refuses ("not enrolled") no longer sits on
"Connecting…" with changes pending forever. The server card says the server
doesn't host it, and "Sync this workspace with this server" can be turned
off even though the server won't answer, keeping it on this device. A
suspended Cloud Server enrollment no longer counts as hosted, so the app
stops pointing a drive at a node that will refuse it.
- A private workspace the app has to recreate is titled after whoever it
belongs to, like the one onboarding and an accepted invitation already
make. A returning account on a second device, and a sign-in whose cloud
Expand Down
2 changes: 1 addition & 1 deletion browser/data-browser/src/helpers/managed/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('evaluateServerReconciliation', () => {
expect(persist).toHaveBeenCalledWith('https://node1.atomicserver.eu');
});

it.each(['Pending', 'Disabled'])(
it.each(['Pending', 'Disabled', 'Suspended'])(
'does not connect a %s placement',
async status => {
mockFetch({
Expand Down
8 changes: 5 additions & 3 deletions browser/data-browser/src/helpers/managed/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ async function resolveHostedDriveOrigin(

const withOrigin = enrollments.filter(
// A placement is not a hosted copy. Keep the source until the node
// reports data, including after an interrupted setup.
// reports data, including after an interrupted setup. Only statuses the
// node serves count: a Suspended (or unknown) enrollment is off the node's
// allowlist, and pointing the drive at it gets every write refused.
e =>
e.status !== 'Disabled' &&
e.status !== /* @wc-ignore */ 'Pending' &&
(e.status === /* @wc-ignore */ 'Active' ||
e.status === /* @wc-ignore */ 'Error') &&
e.resource_count !== 0 &&
e.http_origin,
);
Expand Down
9 changes: 8 additions & 1 deletion browser/data-browser/src/locales/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,6 @@ msgstr ""
#: src/helpers/managed/cloudSync.ts
#: src/helpers/managed/prepareDriveSharing.ts
#: src/helpers/managed/reconcile.ts
#: src/helpers/managed/reconcile.ts
msgid "Disabled"
msgstr ""

Expand Down Expand Up @@ -12272,3 +12271,11 @@ msgstr ""
#: src/chunks/TablePage/Issues/IssuesView.tsx
msgid "Nothing closed."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "This server doesn’t host this workspace, so it refuses its changes. Set up Cloud Server to sync it here, or turn off sync to keep it on this device only."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "Not hosted here"
msgstr ""
9 changes: 8 additions & 1 deletion browser/data-browser/src/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,6 @@ msgstr "Search"
#: src/helpers/managed/cloudSync.ts
#: src/helpers/managed/prepareDriveSharing.ts
#: src/helpers/managed/reconcile.ts
#: src/helpers/managed/reconcile.ts
msgid "Disabled"
msgstr "Disabled"

Expand Down Expand Up @@ -12318,3 +12317,11 @@ msgstr "Nothing open."
#: src/chunks/TablePage/Issues/IssuesView.tsx
msgid "Nothing closed."
msgstr "Nothing closed."

#: src/routes/SyncRoute.tsx
msgid "This server doesn’t host this workspace, so it refuses its changes. Set up Cloud Server to sync it here, or turn off sync to keep it on this device only."
msgstr "This server doesn’t host this workspace, so it refuses its changes. Set up Cloud Server to sync it here, or turn off sync to keep it on this device only."

#: src/routes/SyncRoute.tsx
msgid "Not hosted here"
msgstr "Not hosted here"
9 changes: 8 additions & 1 deletion browser/data-browser/src/locales/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,6 @@ msgstr "Buscar"
#: src/helpers/managed/cloudSync.ts
#: src/helpers/managed/prepareDriveSharing.ts
#: src/helpers/managed/reconcile.ts
#: src/helpers/managed/reconcile.ts
msgid "Disabled"
msgstr ""

Expand Down Expand Up @@ -12272,3 +12271,11 @@ msgstr ""
#: src/chunks/TablePage/Issues/IssuesView.tsx
msgid "Nothing closed."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "This server doesn’t host this workspace, so it refuses its changes. Set up Cloud Server to sync it here, or turn off sync to keep it on this device only."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "Not hosted here"
msgstr ""
9 changes: 8 additions & 1 deletion browser/data-browser/src/locales/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,6 @@ msgstr "Rechercher"
#: src/helpers/managed/cloudSync.ts
#: src/helpers/managed/prepareDriveSharing.ts
#: src/helpers/managed/reconcile.ts
#: src/helpers/managed/reconcile.ts
msgid "Disabled"
msgstr ""

Expand Down Expand Up @@ -12272,3 +12271,11 @@ msgstr ""
#: src/chunks/TablePage/Issues/IssuesView.tsx
msgid "Nothing closed."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "This server doesn’t host this workspace, so it refuses its changes. Set up Cloud Server to sync it here, or turn off sync to keep it on this device only."
msgstr ""

#: src/routes/SyncRoute.tsx
msgid "Not hosted here"
msgstr ""
29 changes: 23 additions & 6 deletions browser/data-browser/src/routes/SyncRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,17 @@ function ServerCard({
isSelectedServer && !!status.drive && store.isLocalOnlyDrive(status.drive);
const isActive =
isSelectedServer && !!status.drive && store.isLiveSyncedDrive(status.drive);
// A managed node that does not host this drive refuses every push. Syncing
// can never finish, so say why instead of "Connecting…", and let the person
// turn sync off even though the server will not answer.
const refusedByServer =
isSelectedServer && store.isDriveRefusedByServer(status.drive);
const showWorkspaceSyncToggle =
isSelectedServer &&
!isRunningInTauri() &&
!isOriginWithoutNode(server) &&
isCloudSyncAvailable(managedInfo) &&
cloudEnrolled === false;
(refusedByServer ||
(isCloudSyncAvailable(managedInfo) && cloudEnrolled === false));
const isCloud = isActive && cloudHosted;
const serverHostname = status.serverUrl
? new URL(status.serverUrl).hostname
Expand Down Expand Up @@ -392,9 +397,11 @@ function ServerCard({
status={
localOnlyDrive
? { tone: 'unknown', label: 'Workspace sync off' }
: isActive
? { tone: serverStatus, label: statusLabel(serverStatus) }
: { tone: 'unknown', label: 'Not connected' }
: refusedByServer
? { tone: 'offline', label: 'Not hosted here' }
: isActive
? { tone: serverStatus, label: statusLabel(serverStatus) }
: { tone: 'unknown', label: 'Not connected' }
}
controls={
isSelectedServer ? (
Expand Down Expand Up @@ -464,6 +471,16 @@ function ServerCard({
subscription and price in billing.
</ConnMeta>
)}
{refusedByServer && (
<ConnError role='alert'>
<FaCircleExclamation aria-hidden />
<span>
This server doesn’t host this workspace, so it refuses its changes.
Set up Cloud Server to sync it here, or turn off sync to keep it on
this device only.
</span>
</ConnError>
)}
{showWorkspaceSyncToggle && (
<WorkspaceSyncRow>
<WorkspaceSyncControl>
Expand All @@ -472,7 +489,7 @@ function ServerCard({
checked={!localOnlyDrive}
disabled={
syncChange !== null ||
!status.serverConnected ||
(!status.serverConnected && !refusedByServer) ||
!hasWorkingLocalStore
}
onChange={next => void toggleWorkspaceSync(next)}
Expand Down
7 changes: 6 additions & 1 deletion browser/lib/src/local-outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ export function isTerminalCommitErrorMessage(message: string): boolean {
* Retrying spins the server (see the 401-flood); the only resolutions are a
* rights change or the user abandoning the edit — neither helped by hammering.
*/
/** A managed node's refusal of a drive it does not host ("not enrolled"). */
export function isNotEnrolledMessage(message: string | undefined): boolean {
return !!message?.includes('is not enrolled for sync on this node');
}

export function isUnrecoverableCommitErrorMessage(message: string): boolean {
// A causality rejection is deterministic for the same Loro update. Keep the
// local edit visible, but stop sending it once the bounded retry window ends.
Expand All @@ -225,7 +230,7 @@ export function isUnrecoverableCommitErrorMessage(message: string): boolean {
// Managed nodes refuse writes until enrollment/quota changes. Keep the edit,
// but park it after bounded retries rather than flooding the node forever.
if (
message.includes('is not enrolled for sync on this node') ||
isNotEnrolledMessage(message) ||
message.includes('has reached its storage quota on this node')
) {
return true;
Expand Down
71 changes: 71 additions & 0 deletions browser/lib/src/store.refused-drive.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, it, vi } from 'vitest';
import type { Agent } from './agent.js';
import type { ClientDbWorker } from './client-db.js';
import { Store } from './store.js';

const DRIVE = 'did:ad:personal';
const OTHER = 'did:ad:other';
const REFUSAL = `Drive ${DRIVE} is not enrolled for sync on this node.`;

function storeWithLocalCopy() {
const store = new Store({ serverUrl: 'http://localhost:9883' });
vi.spyOn(store, 'getAgent').mockReturnValue({} as Agent);
vi.spyOn(store, 'getClientDb').mockReturnValue({
isReady: true,
} as ClientDbWorker);

return store;
}

describe('a drive the server refuses as not enrolled', () => {
it('is reported as refused, and only for that drive', ({ expect }) => {
const store = new Store({ serverUrl: 'http://localhost:9883' });
expect(store.isDriveRefusedByServer(DRIVE)).toBe(false);

store.failDriveSync(DRIVE, REFUSAL);

expect(store.isDriveRefusedByServer(DRIVE)).toBe(true);
expect(store.isDriveRefusedByServer(OTHER)).toBe(false);
});

it('is not refused for any other sync error', ({ expect }) => {
const store = new Store({ serverUrl: 'http://localhost:9883' });
store.failDriveSync(
DRIVE,
`Drive ${DRIVE} has reached its storage quota on this node.`,
);

expect(store.isDriveRefusedByServer(DRIVE)).toBe(false);
});

it('can be made local without the server, dropping its refused writes', async ({
expect,
}) => {
const store = storeWithLocalCopy();
// No websocket and no server inventory: the refused path must not need them.
vi.spyOn(store, 'getDefaultWebSocket').mockReturnValue(undefined);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const outbox = (store as any).outbox;
outbox.markDirty(DRIVE);
store.failDriveSync(DRIVE, REFUSAL);

await store.makeDriveLocal(DRIVE);

expect(store.isLocalOnlyDrive(DRIVE)).toBe(true);
expect(store.isDriveRefusedByServer(DRIVE)).toBe(false);
expect(outbox.size).toBe(0);
expect(store.getSyncStatus().lastDriveSyncError).toBeUndefined();
});

it('still verifies the local copy for a drive the server hosts', async ({
expect,
}) => {
const store = storeWithLocalCopy();
vi.spyOn(store, 'getDefaultWebSocket').mockReturnValue(undefined);

await expect(store.makeDriveLocal(DRIVE)).rejects.toThrow(
'Open this drive with local storage available before disconnecting.',
);
expect(store.isLocalOnlyDrive(DRIVE)).toBe(false);
});
});
68 changes: 67 additions & 1 deletion browser/lib/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import {
isTerminalCommitError,
isUnrecoverableCommitError,
isBenignTerminalCommitError,
isNotEnrolledMessage,
type OutboxEntry,
} from './local-outbox.js';

Expand Down Expand Up @@ -914,11 +915,76 @@ export class Store {
this.localOnlyDrives.add(drive);
}

/**
* Whether the server in use refuses `drive` outright because it does not
* host it: a managed node answering "not enrolled" to our pushes, seen
* either on the last drive sync or on a parked outbox entry of that drive.
*/
public isDriveRefusedByServer(drive: string | undefined): boolean {
if (!drive || this.isLocalOnlyDrive(drive)) return false;

if (
this._lastDriveSyncError?.drive === drive &&
isNotEnrolledMessage(this._lastDriveSyncError.message)
) {
return true;
}

const normalized = this.normalizeSubject(drive);

return this.outbox
.pending()
.some(
entry =>
isNotEnrolledMessage(entry.lastAttemptError) &&
this.driveOf(this.normalizeSubject(entry.subject)) === normalized,
);
}

/** Switch this client to browser-only sync after verifying its local copy.
* Does not delete data from the server or alter other devices' configuration. */
* Does not delete data from the server or alter other devices' configuration.
*
* A drive the server refuses ({@link isDriveRefusedByServer}) skips the
* verification: the server will not serve its copy, so this device's copy
* is the only one there is, and waiting on its inventory or on the refused
* writes would never end. Those writes are dropped from the outbox, since a
* local-only drive is never pushed; turning sync on again resyncs the whole
* drive rather than replaying them. */
public async makeDriveLocal(drive: string): Promise<void> {
const db = this.getClientDb();
const agent = this.getAgent();

if (this.isDriveRefusedByServer(drive)) {
if (!db?.isReady || !agent)
throw new Error(
'Open this drive with local storage available before disconnecting.',
);

const normalized = this.normalizeSubject(drive);
this.registerLocalOnlyDrive(drive);
this.getDefaultWebSocket()?.unsubscribeFromDrive(drive);

for (const entry of this.outbox.pending()) {
const subject = this.normalizeSubject(entry.subject);

if (
subject === normalized ||
this.driveOf(subject) === normalized ||
this.isLocalOnlySubject(entry.subject)
) {
this.outbox.discard(entry.subject);
}
}

if (this._lastDriveSyncError?.drive === drive) {
this._lastDriveSyncError = undefined;
}

this.emitSyncStatus();

return;
}

const serverUrl = this.serverUrl;
const ws = this.getDefaultWebSocket();
if (!db?.isReady || !agent || !ws)
Expand Down