Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update async mutation flow (#1404)

Leendert de Borst21496155ac11
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.ts
index e4102085c..91ddee616 100644
--- a/apps/browser-extension/src/entrypoints/background.ts
+++ b/apps/browser-extension/src/entrypoints/background.ts
@@ -9,7 +9,7 @@ import { handleClipboardCopied, handleCancelClipboardClear, handleGetClipboardCl
import { setupContextMenus } from '@/entrypoints/background/ContextMenu';
import { handleGetWebAuthnSettings, handleWebAuthnCreate, handleWebAuthnGet, handlePasskeyPopupResponse, handleGetRequestData } from '@/entrypoints/background/PasskeyHandler';
import { handleOpenPopup, handlePopupWithCredential, handleOpenPopupCreateCredential, handleToggleContextMenu } from '@/entrypoints/background/PopupMessageHandler';
-import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleLockVault, handleCreateIdentity, handleGetCredentials, handleGetFilteredCredentials, handleGetSearchCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVaultMetadata, handleSyncVault, handleUploadVault, handleGetOfflineMode, handleSetOfflineMode, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetHasPendingSync, handleSetHasPendingSync } from '@/entrypoints/background/VaultMessageHandler';
+import { handleCheckAuthStatus, handleClearPersistedFormValues, handleClearVault, handleLockVault, handleCreateIdentity, handleGetCredentials, handleGetFilteredCredentials, handleGetSearchCredentials, handleGetDefaultEmailDomain, handleGetDefaultIdentitySettings, handleGetEncryptionKey, handleGetEncryptionKeyDerivationParams, handleGetPasswordSettings, handleGetPersistedFormValues, handleGetVault, handlePersistFormValues, handleStoreEncryptionKey, handleStoreEncryptionKeyDerivationParams, handleStoreVaultMetadata, handleSyncVault, handleUploadVault, handleGetEncryptedVault, handleStoreEncryptedVault, handleGetSyncState, handleMarkVaultClean, handleGetServerRevision } from '@/entrypoints/background/VaultMessageHandler';
import { GLOBAL_CONTEXT_MENU_ENABLED_KEY } from '@/utils/Constants';
import { EncryptionKeyDerivationParams } from "@/utils/dist/core/models/metadata";
@@ -40,9 +40,10 @@ export default defineBackground({
onMessage('STORE_ENCRYPTION_KEY_DERIVATION_PARAMS', ({ data }) => handleStoreEncryptionKeyDerivationParams(data as EncryptionKeyDerivationParams));
onMessage('GET_ENCRYPTED_VAULT', () => handleGetEncryptedVault());
- onMessage('STORE_ENCRYPTED_VAULT', ({ data }) => handleStoreEncryptedVault(data as { vaultBlob: string; hasPendingSync: boolean; vaultRevisionNumber?: number }));
- onMessage('GET_HAS_PENDING_SYNC', () => handleGetHasPendingSync());
- onMessage('SET_HAS_PENDING_SYNC', ({ data }) => handleSetHasPendingSync(data as boolean));
+ onMessage('STORE_ENCRYPTED_VAULT', ({ data }) => handleStoreEncryptedVault(data as { vaultBlob: string; markDirty?: boolean; serverRevision?: number }));
+ onMessage('GET_SYNC_STATE', () => handleGetSyncState());
+ onMessage('MARK_VAULT_CLEAN', ({ data }) => handleMarkVaultClean(data as { mutationSeqAtStart: number; newServerRevision: number }));
+ onMessage('GET_SERVER_REVISION', () => handleGetServerRevision());
onMessage('CREATE_IDENTITY', ({ data }) => handleCreateIdentity(data));
onMessage('UPLOAD_VAULT', () => handleUploadVault());
@@ -50,10 +51,6 @@ export default defineBackground({
onMessage('LOCK_VAULT', () => handleLockVault());
onMessage('CLEAR_VAULT', () => handleClearVault());
- // Offline mode management messages
- onMessage('GET_OFFLINE_MODE', () => handleGetOfflineMode());
- onMessage('SET_OFFLINE_MODE', ({ data }) => handleSetOfflineMode(data as boolean));
-
onMessage('OPEN_POPUP', () => handleOpenPopup());
onMessage('OPEN_POPUP_WITH_CREDENTIAL', ({ data }) => handlePopupWithCredential(data));
onMessage('OPEN_POPUP_CREATE_CREDENTIAL', ({ data }) => handleOpenPopupCreateCredential(data));
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
index 5120de8a0..2278409e5 100644
--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts
@@ -167,20 +167,20 @@ export async function handleSyncVault(
return { success: false, error: await t('common.errors.' + statusError) };
}
- const vaultRevisionNumber = await storage.getItem('local:vaultRevisionNumber') as number;
+ const localServerRevision = await storage.getItem('local:serverRevision') as number | null ?? 0;
- if (statusResponse.vaultRevision > vaultRevisionNumber) {
+ if (statusResponse.vaultRevision > localServerRevision) {
// Retrieve the latest vault from the server.
const vaultResponse = await webApi.get<VaultResponse>('Vault');
- // Store in local: storage for persistence (fresh from server, no pending sync)
+ // Store in local: storage for persistence (fresh from server, not dirty)
await storage.setItems([
{ key: 'local:encryptedVault', value: vaultResponse.vault.blob },
{ key: 'local:publicEmailDomains', value: vaultResponse.vault.publicEmailDomainList },
{ key: 'local:privateEmailDomains', value: vaultResponse.vault.privateEmailDomainList },
{ key: 'local:hiddenPrivateEmailDomains', value: vaultResponse.vault.hiddenPrivateEmailDomainList },
- { key: 'local:vaultRevisionNumber', value: vaultResponse.vault.currentRevisionNumber },
- { key: 'local:hasPendingSync', value: false }
+ { key: 'local:serverRevision', value: vaultResponse.vault.currentRevisionNumber },
+ { key: 'local:isDirty', value: false }
]);
// Clear cached client since we received a new vault blob from server
@@ -204,7 +204,7 @@ export async function handleGetVault(
const publicEmailDomains = await storage.getItem('local:publicEmailDomains') as string[];
const privateEmailDomains = await storage.getItem('local:privateEmailDomains') as string[];
const hiddenPrivateEmailDomains = await storage.getItem('local:hiddenPrivateEmailDomains') as string[] ?? [];
- const vaultRevisionNumber = await storage.getItem('local:vaultRevisionNumber') as number;
+ const serverRevision = await storage.getItem('local:serverRevision') as number | null;
if (!encryptedVault) {
console.error('Vault not available');
@@ -227,7 +227,7 @@ export async function handleGetVault(
publicEmailDomains: publicEmailDomains ?? [],
privateEmailDomains: privateEmailDomains ?? [],
hiddenPrivateEmailDomains: hiddenPrivateEmailDomains ?? [],
- vaultRevisionNumber: vaultRevisionNumber ?? 0
+ serverRevision: serverRevision ?? 0
};
} catch (error) {
console.error('Failed to get vault:', error);
@@ -260,10 +260,11 @@ export function handleClearVault(): messageBoolResponse {
'local:publicEmailDomains',
'local:privateEmailDomains',
'local:hiddenPrivateEmailDomains',
- 'local:vaultRevisionNumber',
+ 'local:serverRevision',
+ 'local:isDirty',
+ 'local:mutationSequence',
'local:isOfflineMode',
- 'local:hasPendingSync',
- 'local:encryptionKeyDerivationParams'
+ 'local:encryptionKeyDerivationParams',
]);
// Clear session-only data
@@ -538,19 +539,28 @@ export async function handleGetEncryptionKeyDerivationParams(
/**
* Upload the currently stored vault to the server.
+ * Returns the upload status and captures the mutation sequence at start for race detection.
*/
export async function handleUploadVault(
) : Promise<messageVaultUploadResponse> {
try {
+ // Capture mutation sequence at start of upload for race detection
+ const mutationSeqAtStart = await storage.getItem('local:mutationSequence') as number | null ?? 0;
+
// Create sqlite client from the already-stored vault blob.
const sqliteClient = await createVaultSqliteClient();
// Upload the vault to the server.
const response = await uploadNewVaultToServer(sqliteClient);
- return { success: true, status: response.status, newRevisionNumber: response.newRevisionNumber };
+
+ return {
+ success: true,
+ status: response.status,
+ newRevisionNumber: response.newRevisionNumber,
+ mutationSeqAtStart
+ };
} catch (error) {
console.error('Failed to upload vault:', error);
- // hasPendingSync stays true since upload failed
return { success: false, error: await t('common.errors.unknownError') };
}
}
@@ -621,17 +631,11 @@ async function uploadNewVaultToServer(sqliteClient: SqliteClient) : Promise<Vaul
encryptionKey
);
- /*
- * Store in local: storage for persistence with pending sync flag.
- * We're about to upload, so mark as pending until confirmed.
- */
- await storage.setItems([
- { key: 'local:encryptedVault', value: encryptedVault },
- { key: 'local:hasPendingSync', value: true }
- ]);
+ // Store in local: storage for persistence
+ await storage.setItem('local:encryptedVault', encryptedVault);
- // Get metadata from local: storage
- const vaultRevisionNumber = await storage.getItem('local:vaultRevisionNumber') as number;
+ // Get server revision for API
+ const serverRevision = await storage.getItem('local:serverRevision') as number | null ?? 0;
// Upload new encrypted vault to server.
const username = await storage.getItem('local:username') as string;
@@ -641,7 +645,7 @@ async function uploadNewVaultToServer(sqliteClient: SqliteClient) : Promise<Vaul
blob: encryptedVault,
createdAt: new Date().toISOString(),
credentialsCount: sqliteClient.getAllCredentials().length,
- currentRevisionNumber: vaultRevisionNumber,
+ currentRevisionNumber: serverRevision,
emailAddressList: emailAddresses,
updatedAt: new Date().toISOString(),
username: username,
@@ -655,13 +659,10 @@ async function uploadNewVaultToServer(sqliteClient: SqliteClient) : Promise<Vaul
// Check if response is successful (.status === 0)
if (response.status === 0) {
- // Upload succeeded - update revision and clear pending sync
- await storage.setItems([
- { key: 'local:vaultRevisionNumber', value: response.newRevisionNumber },
- { key: 'local:hasPendingSync', value: false }
- ]);
+ // Upload succeeded - update server revision
+ await storage.setItem('local:serverRevision', response.newRevisionNumber);
} else {
- // Upload failed - hasPendingSync stays true (was set above)
+ // Upload failed
throw new Error(await t('common.errors.unknownError'));
}
@@ -703,60 +704,134 @@ async function createVaultSqliteClient() : Promise<SqliteClient> {
}
/**
- * Get offline mode status.
+ * Get the encrypted vault blob directly (for merge operations).
*/
-export async function handleGetOfflineMode(): Promise<boolean> {
- const isOffline = await storage.getItem('local:isOfflineMode') as boolean;
- return isOffline ?? false;
+export async function handleGetEncryptedVault(): Promise<string | null> {
+ return await storage.getItem('local:encryptedVault') as string | null;
}
/**
- * Set offline mode status.
+ * Store the encrypted vault blob and mark as dirty.
+ * Atomically increments mutation sequence for sync coordination.
+ *
+ * @param request Object with:
+ * - vaultBlob: The encrypted vault data
+ * - markDirty: If true, marks vault as dirty and increments mutation sequence
+ * - serverRevision: Optional explicit server revision (for sync operations)
*/
-export async function handleSetOfflineMode(isOffline: boolean): Promise<void> {
- await storage.setItem('local:isOfflineMode', isOffline);
-}
+export async function handleStoreEncryptedVault(request: {
+ vaultBlob: string;
+ markDirty?: boolean;
+ serverRevision?: number;
+}): Promise<{ mutationSequence: number }> {
+ let mutationSequence = await storage.getItem('local:mutationSequence') as number | null ?? 0;
+
+ if (request.markDirty) {
+ // Increment mutation sequence and mark dirty
+ mutationSequence++;
+ }
-/**
- * Get pending sync status (true if local vault has changes not yet uploaded to server).
- */
-export async function handleGetHasPendingSync(): Promise<boolean> {
- const hasPendingSync = await storage.getItem('local:hasPendingSync') as boolean;
- return hasPendingSync ?? false;
+ // Build items to store - use explicit typing for storage.setItems
+ if (request.markDirty && request.serverRevision !== undefined) {
+ await storage.setItems([
+ { key: 'local:encryptedVault', value: request.vaultBlob },
+ { key: 'local:mutationSequence', value: mutationSequence },
+ { key: 'local:isDirty', value: true },
+ { key: 'local:serverRevision', value: request.serverRevision }
+ ]);
+ } else if (request.markDirty) {
+ await storage.setItems([
+ { key: 'local:encryptedVault', value: request.vaultBlob },
+ { key: 'local:mutationSequence', value: mutationSequence },
+ { key: 'local:isDirty', value: true }
+ ]);
+ } else if (request.serverRevision !== undefined) {
+ await storage.setItems([
+ { key: 'local:encryptedVault', value: request.vaultBlob },
+ { key: 'local:serverRevision', value: request.serverRevision }
+ ]);
+ } else {
+ await storage.setItem('local:encryptedVault', request.vaultBlob);
+ }
+
+ // Clear cache since vault blob changed
+ cachedSqliteClient = null;
+ cachedVaultBlob = null;
+
+ return { mutationSequence };
}
/**
- * Set pending sync status.
+ * Mark the vault as clean after successful sync.
+ * Only clears dirty flag if no mutations happened during sync.
+ *
+ * @param mutationSeqAtStart - The mutation sequence when sync started
+ * @param newServerRevision - The new server revision after successful upload
+ * @returns Whether the dirty flag was cleared
*/
-export async function handleSetHasPendingSync(hasPendingSync: boolean): Promise<void> {
- await storage.setItem('local:hasPendingSync', hasPendingSync);
+export async function handleMarkVaultClean(request: {
+ mutationSeqAtStart: number;
+ newServerRevision: number;
+}): Promise<{ cleared: boolean; currentMutationSeq: number }> {
+ const currentMutationSeq = await storage.getItem('local:mutationSequence') as number | null ?? 0;
+
+ if (currentMutationSeq === request.mutationSeqAtStart) {
+ // No mutations during sync - safe to mark as clean
+ await storage.setItems([
+ { key: 'local:isDirty', value: false },
+ { key: 'local:serverRevision', value: request.newServerRevision }
+ ]);
+ return { cleared: true, currentMutationSeq };
+ }
+
+ // Mutations happened during sync - keep dirty, but still update server revision
+ await storage.setItem('local:serverRevision', request.newServerRevision);
+ return { cleared: false, currentMutationSeq };
}
/**
- * Get the encrypted vault blob directly (for merge operations).
+ * Get the current sync state.
*/
-export async function handleGetEncryptedVault(): Promise<string | null> {
- return await storage.getItem('local:encryptedVault') as string | null;
+export async function handleGetSyncState(): Promise<{
+ isDirty: boolean;
+ mutationSequence: number;
+ serverRevision: number;
+}> {
+ const [isDirty, mutationSequence, serverRevision] = await Promise.all([
+ storage.getItem('local:isDirty') as Promise<boolean | null>,
+ storage.getItem('local:mutationSequence') as Promise<number | null>,
+ storage.getItem('local:serverRevision') as Promise<number | null>
+ ]);
+
+ return {
+ isDirty: isDirty ?? false,
+ mutationSequence: mutationSequence ?? 0,
+ serverRevision: serverRevision ?? 0
+ };
}
/**
- * Store the encrypted vault blob with pending sync flag.
- * This is an atomic operation that should be used for all local vault mutations.
- *
- * @param request Object with vaultBlob, hasPendingSync flag, and optional vaultRevisionNumber
+ * Get the current server revision.
*/
-export async function handleStoreEncryptedVault(request: { vaultBlob: string; hasPendingSync: boolean; vaultRevisionNumber?: number }): Promise<void> {
- if (request.vaultRevisionNumber !== undefined) {
- // Store vault, pending sync flag, and revision number atomically
- await storage.setItems([
- { key: 'local:encryptedVault', value: request.vaultBlob },
- { key: 'local:hasPendingSync', value: request.hasPendingSync },
- { key: 'local:vaultRevisionNumber', value: request.vaultRevisionNumber }
- ]);
- } else {
- await storage.setItems([
- { key: 'local:encryptedVault', value: request.vaultBlob },
- { key: 'local:hasPendingSync', value: request.hasPendingSync }
- ]);
+export async function handleGetServerRevision(): Promise<number> {
+ // First try new key, then fall back to legacy key
+ let revision = await storage.getItem('local:serverRevision') as number | null;
+
+ if (revision === null) {
+ // Try legacy key - parse string format "250" or "250+1" to get server part
+ const legacyRevision = await storage.getItem('local:vaultRevisionNumber') as string | number | null;
+ if (legacyRevision !== null) {
+ if (typeof legacyRevision === 'number') {
+ revision = legacyRevision;
+ } else {
+ // Handle legacy "250+1" format - extract just the server part
+ const parts = legacyRevision.split('+');
+ revision = parseInt(parts[0], 10) || 0;
+ }
+ // Migrate to new key
+ await storage.setItem('local:serverRevision', revision);
+ }
}
+
+ return revision ?? 0;
}
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/OfflineIndicator.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/OfflineIndicator.tsx
index b01db915f..fdd6de8da 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/OfflineIndicator.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/OfflineIndicator.tsx
@@ -39,7 +39,7 @@ const OfflineIndicator: React.FC = () => {
}
// Show pending sync indicator (only when online but has pending changes)
- if (dbContext.hasPendingSync) {
+ if (dbContext.isDirty) {
return (
<div className="flex items-center gap-1.5 px-2 py-1 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 rounded-md text-xs font-medium">
<svg className="w-3.5 h-3.5 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
diff --git a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
index cfc021599..b688c5e8a 100644
--- a/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/context/DbContext.tsx
@@ -1,20 +1,36 @@
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
import { sendMessage } from 'webext-bridge/popup';
-import type { EncryptionKeyDerivationParams, VaultMetadata } from '@/utils/dist/core/models/metadata';
+import type { EncryptionKeyDerivationParams } from '@/utils/dist/core/models/metadata';
import SqliteClient from '@/utils/SqliteClient';
import type { VaultResponse as messageVaultResponse } from '@/utils/types/messaging/VaultResponse';
import { storage } from '#imports';
+/**
+ * Vault metadata including the server revision.
+ */
+type VaultMetadata = {
+ publicEmailDomains: string[];
+ privateEmailDomains: string[];
+ hiddenPrivateEmailDomains: string[];
+ serverRevision: number;
+};
+
type DbContextType = {
sqliteClient: SqliteClient | null;
dbInitialized: boolean;
dbAvailable: boolean;
isOffline: boolean;
- hasPendingSync: boolean;
+ /**
+ * True if local vault has changes not yet synced to server.
+ */
+ isDirty: boolean;
+ /**
+ * Current server revision number.
+ */
+ serverRevision: number;
setIsOffline: (offline: boolean) => Promise<void>;
- setHasPendingSync: (hasPendingSync: boolean) => Promise<void>;
/**
* Load a decrypted vault into memory (SQLite client).
*/
@@ -28,7 +44,10 @@ type DbContextType = {
storeEncryptionKeyDerivationParams: (params: EncryptionKeyDerivationParams) => Promise<void>;
clearDatabase: () => void;
getVaultMetadata: () => Promise<VaultMetadata | null>;
- setCurrentVaultRevisionNumber: (revisionNumber: number) => Promise<void>;
+ /**
+ * Refresh sync state (isDirty, serverRevision) from storage.
+ */
+ refreshSyncState: () => Promise<void>;
hasPendingMigrations: () => Promise<boolean>;
}
@@ -59,39 +78,39 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
const [isOffline, setIsOfflineState] = useState(false);
/**
- * Pending sync state. If true, the local vault has changes not yet uploaded to server.
+ * Dirty state - true if local vault has unsynced changes.
*/
- const [hasPendingSync, setHasPendingSyncState] = useState(false);
+ const [isDirty, setIsDirty] = useState(false);
/**
- * Set the offline mode state and persist it.
+ * Server revision number.
*/
- const setIsOffline = useCallback(async (offline: boolean) => {
- setIsOfflineState(offline);
- await sendMessage('SET_OFFLINE_MODE', offline, 'background');
- }, []);
+ const [serverRevision, setServerRevision] = useState(0);
/**
- * Set the pending sync state and persist it.
+ * Set the offline mode state and persist it to local storage.
*/
- const setHasPendingSync = useCallback(async (pendingSync: boolean) => {
- setHasPendingSyncState(pendingSync);
- await sendMessage('SET_HAS_PENDING_SYNC', pendingSync, 'background');
+ const setIsOffline = useCallback(async (offline: boolean) => {
+ setIsOfflineState(offline);
+ await storage.setItem('local:isOfflineMode', offline);
}, []);
/**
- * Load initial offline and pending sync state from storage.
+ * Load initial state from local storage.
*/
useEffect(() => {
/**
- * Load the offline mode and pending sync state from background storage.
+ * Load the offline mode and sync state from local storage.
*/
- const loadSyncState = async () : Promise<void> => {
- const offlineMode = await sendMessage('GET_OFFLINE_MODE', {}, 'background') as boolean;
- setIsOfflineState(offlineMode);
-
- const pendingSync = await sendMessage('GET_HAS_PENDING_SYNC', {}, 'background') as boolean;
- setHasPendingSyncState(pendingSync);
+ const loadSyncState = async (): Promise<void> => {
+ const [offlineMode, dirty, revision] = await Promise.all([
+ storage.getItem('local:isOfflineMode') as Promise<boolean | null>,
+ storage.getItem('local:isDirty') as Promise<boolean | null>,
+ storage.getItem('local:serverRevision') as Promise<number | null>
+ ]);
+ setIsOfflineState(offlineMode ?? false);
+ setIsDirty(dirty ?? false);
+ setServerRevision(revision ?? 0);
};
loadSyncState();
}, []);
@@ -143,10 +162,12 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
*/
const getVaultMetadata = useCallback(async () : Promise<VaultMetadata | null> => {
try {
- const publicEmailDomains = await storage.getItem('local:publicEmailDomains') as string[] | null;
- const privateEmailDomains = await storage.getItem('local:privateEmailDomains') as string[] | null;
- const hiddenPrivateEmailDomains = await storage.getItem('local:hiddenPrivateEmailDomains') as string[] | null;
- const vaultRevisionNumber = await storage.getItem('local:vaultRevisionNumber') as number | null;
+ const [publicEmailDomains, privateEmailDomains, hiddenPrivateEmailDomains, revision] = await Promise.all([
+ storage.getItem('local:publicEmailDomains') as Promise<string[] | null>,
+ storage.getItem('local:privateEmailDomains') as Promise<string[] | null>,
+ storage.getItem('local:hiddenPrivateEmailDomains') as Promise<string[] | null>,
+ storage.getItem('local:serverRevision') as Promise<number | null>
+ ]);
if (!publicEmailDomains && !privateEmailDomains) {
return null;
@@ -156,7 +177,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
publicEmailDomains: publicEmailDomains ?? [],
privateEmailDomains: privateEmailDomains ?? [],
hiddenPrivateEmailDomains: hiddenPrivateEmailDomains ?? [],
- vaultRevisionNumber: vaultRevisionNumber ?? 0,
+ serverRevision: revision ?? 0,
};
} catch (error) {
console.error('Error getting vault metadata from local storage:', error);
@@ -165,10 +186,15 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
}, []);
/**
- * Set the current vault revision number in local storage (persistent).
+ * Refresh sync state from storage (called after background updates it).
*/
- const setCurrentVaultRevisionNumber = useCallback(async (revisionNumber: number) => {
- await storage.setItem('local:vaultRevisionNumber', revisionNumber);
+ const refreshSyncState = useCallback(async (): Promise<void> => {
+ const [dirty, revision] = await Promise.all([
+ storage.getItem('local:isDirty') as Promise<boolean | null>,
+ storage.getItem('local:serverRevision') as Promise<number | null>
+ ]);
+ setIsDirty(dirty ?? false);
+ setServerRevision(revision ?? 0);
}, []);
/**
@@ -219,18 +245,18 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
dbInitialized,
dbAvailable,
isOffline,
- hasPendingSync,
+ isDirty,
+ serverRevision,
setIsOffline,
- setHasPendingSync,
loadDatabase,
loadStoredDatabase,
storeEncryptionKey,
storeEncryptionKeyDerivationParams,
clearDatabase,
getVaultMetadata,
- setCurrentVaultRevisionNumber,
+ refreshSyncState,
hasPendingMigrations,
- }), [sqliteClient, dbInitialized, dbAvailable, isOffline, hasPendingSync, setIsOffline, setHasPendingSync, loadDatabase, loadStoredDatabase, storeEncryptionKey, storeEncryptionKeyDerivationParams, clearDatabase, getVaultMetadata, setCurrentVaultRevisionNumber, hasPendingMigrations]);
+ }), [sqliteClient, dbInitialized, dbAvailable, isOffline, isDirty, serverRevision, setIsOffline, loadDatabase, loadStoredDatabase, storeEncryptionKey, storeEncryptionKeyDerivationParams, clearDatabase, getVaultMetadata, refreshSyncState, hasPendingMigrations]);
return (
<DbContext.Provider value={contextValue}>
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
index 74c36fd1c..730cf5758 100644
--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts
@@ -1,4 +1,4 @@
-import { useCallback, useState } from 'react';
+import { useCallback, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { sendMessage } from 'webext-bridge/popup';
@@ -18,14 +18,17 @@ type VaultMutationOptions = {
*
* Flow:
* 1. Execute the mutation on local database
- * 2. Save encrypted vault locally with hasPendingSync=true (atomic)
+ * 2. Save encrypted vault locally and mark as dirty (increments mutation sequence)
* 3. Trigger sync which handles: upload, merge if needed, offline mode
*
- * LWW (Last-Write-Wins) merge ensures conflicts are resolved by UpdatedAt timestamp,
- * so we don't need to pre-sync before mutations.
+ * The mutation sequence is used for race detection:
+ * - Each mutation increments the sequence
+ * - Sync captures sequence at start, only clears dirty if sequence unchanged
+ * - This ensures we never lose local changes during concurrent operations
*/
export function useVaultMutate(): {
executeVaultMutation: (operation: () => Promise<void>, options?: VaultMutationOptions) => Promise<void>;
+ executeVaultMutationAsync: (operation: () => Promise<void>) => Promise<void>;
isLoading: boolean;
syncStatus: string;
} {
@@ -35,12 +38,14 @@ export function useVaultMutate(): {
const dbContext = useDb();
const { syncVault } = useVaultSync();
+ // Track if a sync is currently in progress
+ const isSyncingRef = useRef(false);
+
/**
- * Execute the provided operation and save locally with pending sync flag.
+ * Execute the provided operation and save locally.
+ * Atomically increments mutation sequence and marks dirty.
*/
const saveLocally = useCallback(async (operation: () => Promise<void>): Promise<void> => {
- setSyncStatus(t('common.savingChangesToVault'));
-
// Execute the provided operation (e.g. create/update/delete credential)
await operation();
@@ -52,22 +57,86 @@ export function useVaultMutate(): {
encryptionKey
);
- // Store the updated vault locally with pending sync flag
+ // Store the updated vault locally, mark dirty, increment mutation sequence
await sendMessage('STORE_ENCRYPTED_VAULT', {
vaultBlob: encryptedVaultBlob,
- hasPendingSync: true
+ markDirty: true
}, 'background');
- // Update local state to reflect pending sync
- await dbContext.setHasPendingSync(true);
- }, [dbContext, t]);
+ // Refresh the sync state in React
+ await dbContext.refreshSyncState();
+ }, [dbContext]);
+
+ /**
+ * Trigger a sync cycle. If sync is already in progress, it will be queued.
+ * After sync completes, checks if more mutations happened and re-syncs if needed.
+ */
+ const triggerSync = useCallback(async (): Promise<void> => {
+ if (isSyncingRef.current) {
+ // Sync already in progress - it will re-sync if dirty when done
+ return;
+ }
+
+ isSyncingRef.current = true;
+
+ try {
+ await syncVault({
+ /**
+ * Handle successful sync completion.
+ */
+ onSuccess: async () => {
+ // Refresh state from storage
+ await dbContext.refreshSyncState();
+
+ // Check if still dirty (more mutations during sync)
+ const isDirty = await sendMessage('GET_SYNC_STATE', {}, 'background') as { isDirty: boolean };
+ if (isDirty.isDirty) {
+ isSyncingRef.current = false;
+ // Re-sync to pick up new changes
+ await triggerSync();
+ }
+ },
+ /**
+ * Handle offline mode - local save succeeded.
+ */
+ onOffline: () => {
+ // Offline mode - local save succeeded, will sync when back online
+ },
+ /**
+ * Handle sync errors.
+ * @param error - Error message from sync
+ */
+ onError: (error) => {
+ console.error('Background sync error:', error);
+ }
+ });
+ } catch (error) {
+ console.error('Error during background sync:', error);
+ } finally {
+ isSyncingRef.current = false;
+ }
+ }, [dbContext, syncVault]);
+
+ /**
+ * Execute a vault mutation asynchronously: save locally immediately, then
+ * trigger sync in background. This doesn't block the UI.
+ */
+ const executeVaultMutationAsync = useCallback(async (
+ operation: () => Promise<void>
+ ): Promise<void> => {
+ // 1. Execute mutation and save locally (fast, doesn't block)
+ await saveLocally(operation);
+
+ // 2. Trigger sync in background
+ void triggerSync();
+ }, [saveLocally, triggerSync]);
/**
- * Execute a vault mutation: save locally, then sync.
+ * Execute a vault mutation: save locally, then sync with server.
*
* The sync handles all scenarios:
- * - Online + same revision + hasPendingSync → upload
- * - Online + server newer + hasPendingSync → merge + upload
+ * - Online + same revision + isDirty → upload
+ * - Online + server newer + isDirty → merge + upload
* - Offline → changes are safe locally, will sync when back online
*/
const executeVaultMutation = useCallback(async (
@@ -76,6 +145,7 @@ export function useVaultMutate(): {
) => {
try {
setIsLoading(true);
+ setSyncStatus(t('common.savingChangesToVault'));
// 1. Execute mutation and save locally (always succeeds if no exceptions)
await saveLocally(operation);
@@ -90,7 +160,11 @@ export function useVaultMutate(): {
/**
* Handle successful sync completion.
*/
- onSuccess: () => options.onSuccess?.(),
+ onSuccess: async () => {
+ // Refresh state from storage
+ await dbContext.refreshSyncState();
+ options.onSuccess?.();
+ },
/**
* Handle offline mode - local save succeeded.
*/
@@ -112,10 +186,11 @@ export function useVaultMutate(): {
setIsLoading(false);
setSyncStatus('');
}
- }, [saveLocally, syncVault, t]);
+ }, [dbContext, saveLocally, syncVault, t]);
return {
executeVaultMutation,
+ executeVaultMutationAsync,
isLoading,
syncStatus,
};
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
index b8f6bec78..45b196b12 100644
--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultSync.ts
@@ -46,6 +46,17 @@ const withMinimumDelay = async <T>(operation: () => Promise<T>, minDelayMs: numb
/**
* Hook to sync the vault with the server.
* Supports offline mode: if server is unavailable, continues with local vault.
+ *
+ * Sync logic:
+ * - If server has newer vault AND we have local changes (isDirty) → merge then upload
+ * - If server has newer vault AND no local changes → just download
+ * - If server has same revision AND we have local changes → upload
+ * - If offline → keep local changes, sync later
+ *
+ * Race detection:
+ * - Upload captures mutationSequence at start
+ * - After upload, only clears isDirty if sequence unchanged
+ * - If sequence changed during upload, stays dirty for next sync
*/
export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Promise<boolean>; } => {
const { t } = useTranslation();
@@ -131,17 +142,18 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
await dbContext.setIsOffline(false);
}
- // Compare vault revisions
- const vaultMetadata = await dbContext.getVaultMetadata();
- const vaultRevisionNumber = vaultMetadata?.vaultRevisionNumber ?? 0;
+ // Get current sync state
+ const syncState = await sendMessage('GET_SYNC_STATE', {}, 'background') as {
+ isDirty: boolean;
+ mutationSequence: number;
+ serverRevision: number;
+ };
- if (statusResponse.vaultRevision > vaultRevisionNumber) {
+ if (statusResponse.vaultRevision > syncState.serverRevision) {
/*
* Server has a newer vault. Before overwriting local vault, check if we have
* pending local changes that need to be merged.
*/
- const hasPendingSync = await sendMessage('GET_HAS_PENDING_SYNC', {}, 'background') as boolean;
-
onStatus?.(t('common.syncingUpdatedVault'));
const vaultResponseJson = await withMinimumDelay(() => webApi.get<VaultResponse>('Vault'), 1000, enableDelay) as VaultResponse;
@@ -149,7 +161,7 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
// Get encryption key from background worker
const encryptionKey = await sendMessage('GET_ENCRYPTION_KEY', {}, 'background') as string;
- if (hasPendingSync) {
+ if (syncState.isDirty) {
/*
* We have local changes that haven't been synced to server.
* Merge local vault with server vault, then upload the merged result.
@@ -178,25 +190,26 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
vaultResponseJson.vault.blob = mergedEncryptedVault;
/*
- * Store the merged vault locally first, then upload to server.
- * Pass the server's revision as our base revision since we just fetched and merged with it.
+ * Store the merged vault locally, keeping it dirty since we need to upload.
+ * Update server revision to track what we merged with.
*/
await sendMessage('STORE_ENCRYPTED_VAULT', {
vaultBlob: mergedEncryptedVault,
- hasPendingSync: true,
- vaultRevisionNumber: statusResponse.vaultRevision
+ serverRevision: vaultResponseJson.vault.currentRevisionNumber
}, 'background');
onStatus?.(t('common.uploadingVault'));
const uploadResponse = await sendMessage('UPLOAD_VAULT', {}, 'background') as VaultUploadResponse;
if (uploadResponse.success && uploadResponse.status === 0) {
- // Upload succeeded - update revision
- await dbContext.setCurrentVaultRevisionNumber(uploadResponse.newRevisionNumber!);
- await dbContext.setHasPendingSync(false);
+ // Upload succeeded - try to clear dirty flag
+ await sendMessage('MARK_VAULT_CLEAN', {
+ mutationSeqAtStart: uploadResponse.mutationSeqAtStart,
+ newServerRevision: uploadResponse.newRevisionNumber
+ }, 'background');
+ await dbContext.refreshSyncState();
} else {
console.error('Failed to upload merged vault:', uploadResponse.error);
- // Keep hasPendingSync true so we retry later
}
} else {
console.error('Vault merge failed during sync, using server vault');
@@ -207,16 +220,18 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
/*
* Persist vault and metadata to local storage.
* If merge happened, the merged vault was already stored via STORE_ENCRYPTED_VAULT above.
- * If no merge (hasPendingSync was false), we store the server vault now.
+ * If no merge (isDirty was false), we store the server vault now.
*/
- if (!hasPendingSync) {
+ if (!syncState.isDirty) {
await sendMessage('STORE_ENCRYPTED_VAULT', {
vaultBlob: vaultResponseJson.vault.blob,
- hasPendingSync: false,
- vaultRevisionNumber: vaultResponseJson.vault.currentRevisionNumber,
+ serverRevision: vaultResponseJson.vault.currentRevisionNumber,
}, 'background');
}
+ // Refresh sync state after storing vault
+ await dbContext.refreshSyncState();
+
await sendMessage('STORE_VAULT_METADATA', {
publicEmailDomainList: vaultResponseJson.vault.publicEmailDomainList,
privateEmailDomainList: vaultResponseJson.vault.privateEmailDomainList,
@@ -243,21 +258,23 @@ export const useVaultSync = (): { syncVault: (options?: VaultSyncOptions) => Pro
// Vault could not be decrypted, throw an error
throw new Error('Vault could not be decrypted, if the problem persists please logout and login again.');
}
- } else if (statusResponse.vaultRevision === vaultRevisionNumber) {
+ } else if (statusResponse.vaultRevision === syncState.serverRevision) {
/**
* Server and local vault are at the same revision.
* If we have pending local changes, upload them now.
*/
- const hasPendingSync = await sendMessage('GET_HAS_PENDING_SYNC', {}, 'background') as boolean;
- if (hasPendingSync) {
+ if (syncState.isDirty) {
onStatus?.(t('common.uploadingVault'));
- // Vault is already stored locally with hasPendingSync=true, just upload it
+ // Vault is already stored locally, just upload it
const uploadResponse = await sendMessage('UPLOAD_VAULT', {}, 'background') as VaultUploadResponse;
if (uploadResponse.success && uploadResponse.status === 0) {
- // Upload succeeded - update revision and clear pending flag
- await dbContext.setCurrentVaultRevisionNumber(uploadResponse.newRevisionNumber!);
- await dbContext.setHasPendingSync(false);
+ // Upload succeeded - try to clear dirty flag
+ await sendMessage('MARK_VAULT_CLEAN', {
+ mutationSeqAtStart: uploadResponse.mutationSeqAtStart,
+ newServerRevision: uploadResponse.newRevisionNumber
+ }, 'background');
+ await dbContext.refreshSyncState();
} else if (uploadResponse.status === 2) {
/**
* Server returned Outdated - another device uploaded first.
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
index 40ec2dfeb..af51f3922 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
@@ -58,11 +58,10 @@ const Login: React.FC = () => {
* @returns The initialized SqliteClient
*/
const persistAndLoadVault = async (vaultResponse: VaultResponse, encryptionKey: string): Promise<SqliteClient> => {
- // Persist vault to local storage (fresh from server, no pending sync)
+ // Persist vault to local storage (fresh from server, not dirty)
await sendMessage('STORE_ENCRYPTED_VAULT', {
vaultBlob: vaultResponse.vault.blob,
- hasPendingSync: false,
- vaultRevisionNumber: vaultResponse.vault.currentRevisionNumber,
+ serverRevision: vaultResponse.vault.currentRevisionNumber,
}, 'background');
await sendMessage('STORE_VAULT_METADATA', {
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
index 54aaf0d37..9fe1030d8 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -359,7 +359,7 @@ const Unlock: React.FC = () => {
* Always unlock from local vault first.
* The /reinitialize page will call syncVault which handles:
* - Checking if server has newer version
- * - Merging local changes with server if hasPendingSync is true
+ * - Merging local changes with server if isDirty is true
* - Overwriting local with server if no local changes
*/
const sqliteClient = await dbContext.loadStoredDatabase();
@@ -438,7 +438,7 @@ const Unlock: React.FC = () => {
* Always unlock from local vault first.
* The /reinitialize page will call syncVault which handles:
* - Checking if server has newer version
- * - Merging local changes with server if hasPendingSync is true
+ * - Merging local changes with server if isDirty is true
* - Overwriting local with server if no local changes
*/
const sqliteClient = await dbContext.loadStoredDatabase();
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
index 4f5793667..d01471a89 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
@@ -58,7 +58,7 @@ const ItemAddEdit: React.FC = () => {
const itemTypeParam = searchParams.get('type') as ItemType | null;
const itemNameParam = searchParams.get('name');
- const { executeVaultMutation, syncStatus } = useVaultMutate();
+ const { executeVaultMutationAsync } = useVaultMutate();
const { setHeaderButtons } = useHeaderButtons();
const { setIsInitialLoading } = useLoading();
const { generateAlias, lastGeneratedValues } = useAliasGenerator();
@@ -419,7 +419,11 @@ const ItemAddEdit: React.FC = () => {
throw new Error('Database not initialized');
}
- await executeVaultMutation(async () => {
+ /*
+ * Use async mutation - saves locally and navigates immediately.
+ * Sync happens in background, status shown via header indicator.
+ */
+ await executeVaultMutationAsync(async () => {
if (isEditMode) {
await dbContext.sqliteClient!.updateItem(
updatedItem,
@@ -433,12 +437,15 @@ const ItemAddEdit: React.FC = () => {
}
});
- // Navigate back to details page
- navigate(`/items/${updatedItem.Id}`);
+ /*
+ * Navigate to details page, replacing the add/edit page in history.
+ * This way pressing back goes to items list, not back to the edit form.
+ */
+ navigate(`/items/${updatedItem.Id}`, { replace: true });
} catch (err) {
console.error('Error saving item:', err);
}
- }, [item, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutation, navigate, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes]);
+ }, [item, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutationAsync, navigate, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes]);
/**
* Handle delete action.
@@ -449,7 +456,7 @@ const ItemAddEdit: React.FC = () => {
}
try {
- await executeVaultMutation(async () => {
+ await executeVaultMutationAsync(async () => {
await dbContext.sqliteClient!.deleteItemById(item.Id);
});
@@ -459,7 +466,7 @@ const ItemAddEdit: React.FC = () => {
} finally {
setShowDeleteModal(false);
}
- }, [item, isEditMode, dbContext, executeVaultMutation, navigate]);
+ }, [item, isEditMode, dbContext, executeVaultMutationAsync, navigate]);
/**
* Add custom field handler.
@@ -928,13 +935,6 @@ const ItemAddEdit: React.FC = () => {
variant="danger"
/>
)}
-
- {/* Sync Status */}
- {syncStatus && (
- <div className="fixed bottom-4 right-4 bg-white dark:bg-gray-800 rounded-lg shadow-lg p-4 border border-gray-200 dark:border-gray-700">
- <p className="text-sm text-gray-700 dark:text-gray-300">{syncStatus}</p>
- </div>
- )}
</form>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
index 0bae47296..473a24a13 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx
@@ -276,13 +276,6 @@ const ItemsList: React.FC = () => {
navigate(`/items/folder/${folderId}`);
}, [navigate]);
- /**
- * Navigate back to root (items list)
- */
- const handleBackToRoot = useCallback(() => {
- navigate('/items');
- }, [navigate]);
-
/**
* Get folders with item counts (only for root level when not searching)
*/
@@ -383,20 +376,20 @@ const ItemsList: React.FC = () => {
return (
<div>
- <div className="flex justify-between items-center mb-4">
- <div className="relative flex-1">
+ <div className="flex justify-between items-center gap-2 mb-4">
+ <div className="relative min-w-0 flex-1">
<button
onClick={() => setShowFilterMenu(!showFilterMenu)}
- className="flex items-center gap-1 text-gray-900 dark:text-white text-xl hover:text-gray-700 dark:hover:text-gray-300 focus:outline-none"
+ className="flex items-center gap-1 text-gray-900 dark:text-white text-xl hover:text-gray-700 dark:hover:text-gray-300 focus:outline-none max-w-full"
>
- <h2 className="flex items-baseline gap-1.5">
- {getFilterTitle()}
- <span className="text-sm text-gray-500 dark:text-gray-400">
+ <h2 className="flex items-baseline gap-1.5 min-w-0 overflow-hidden">
+ <span className="truncate">{getFilterTitle()}</span>
+ <span className="text-sm text-gray-500 dark:text-gray-400 shrink-0">
({filteredItems.length})
</span>
</h2>
<svg
- className="w-4 h-4 mt-1"
+ className="w-4 h-4 mt-1 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
diff --git a/apps/browser-extension/src/utils/types/messaging/VaultResponse.ts b/apps/browser-extension/src/utils/types/messaging/VaultResponse.ts
index 202c0dbd5..0fdb285ec 100644
--- a/apps/browser-extension/src/utils/types/messaging/VaultResponse.ts
+++ b/apps/browser-extension/src/utils/types/messaging/VaultResponse.ts
@@ -4,5 +4,5 @@ export type VaultResponse = {
publicEmailDomains?: string[],
privateEmailDomains?: string[],
hiddenPrivateEmailDomains?: string[],
- vaultRevisionNumber?: number
+ serverRevision?: number
};
diff --git a/apps/browser-extension/src/utils/types/messaging/VaultUploadResponse.ts b/apps/browser-extension/src/utils/types/messaging/VaultUploadResponse.ts
index 657bbceec..96f761eaf 100644
--- a/apps/browser-extension/src/utils/types/messaging/VaultUploadResponse.ts
+++ b/apps/browser-extension/src/utils/types/messaging/VaultUploadResponse.ts
@@ -2,5 +2,7 @@ export type VaultUploadResponse = {
success: boolean,
error?: string,
status?: number,
- newRevisionNumber?: number
+ newRevisionNumber?: number,
+ /** Mutation sequence at the start of upload, for race detection */
+ mutationSeqAtStart?: number
};