🐛 Surface changes rejected by the server

The server now answers an invalid change per item instead of failing
the whole batch, and the client dropped such a change silently: the
round went through and nothing told the user that the edit never
reached the server. A rejected change now sets the sync status to
"<collection>: <error>", cut to 200 characters, so the sync button
shows its warning state. The change is not retried, as before.

The message survives the collections that still succeed in the same
round, since each of them used to clear the error. The next round
without a rejection clears it.
This commit is contained in:
2026-12-01 17:59:29 +01:00
parent 6ce66f81c7
commit bddabbf93d
2 changed files with 54 additions and 4 deletions
+11 -2
View File
@@ -32,7 +32,8 @@ type AnyCollection = Collection<AnyDoc, string>;
interface PushResult {
id: string;
collection: string;
status: 'ok' | 'stale' | 'forbidden' | 'readonly';
status: 'ok' | 'stale' | 'forbidden' | 'readonly' | 'invalid';
error?: unknown;
record?: Record<string, unknown> | null;
}
@@ -151,6 +152,8 @@ const pendingCursor = new Map<string, string>();
const staleBuffer = new Map<string, AnyDoc[]>();
/** Change records the last push of a collection sent; the pull after it keeps newer local changes. */
const pushedChanges = new Map<string, Set<string>>();
/** Set when the server rejected a change of the current round; its message stays until a round succeeds. */
let rejected = false;
/** Collections whose local state the sync is about to touch or is touching, by name and nesting depth. */
const applying = new Map<string, number>();
@@ -197,7 +200,7 @@ function onSynced(name: string) {
pendingCursor.delete(name);
}
status.lastSync = Date.now();
status.error = null;
if (!rejected) status.error = null;
}
class WotraSync extends SyncManager<Record<string, unknown>, AnyDoc, string> {
@@ -324,6 +327,11 @@ async function doOpenDb(uid: string): Promise<void> {
}
});
for (const r of res?.results ?? []) {
if (r.status === 'invalid') {
if (!rejected) status.error = `${name}: ${String(r.error ?? 'rejected')}`.slice(0, 200);
rejected = true;
continue;
}
if (r.status === 'ok' || !r.record || !isCollection(r.collection)) continue;
const list = staleBuffer.get(r.collection) ?? [];
list.push(toRecord(r.collection, r.record));
@@ -377,6 +385,7 @@ export function syncNow(): Promise<void> {
if (syncing) return syncing;
const m = sm;
if (!m || !status.online) return Promise.resolve();
rejected = false;
const run: Promise<void> = runBeforeSync()
.then(() => m.syncAll())
.catch((err: Error) => {