Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(sync): take a baseline without recording the document's cover

Lincoln Stein69b4eff81cde
diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
index d3ca9145e8..c61acb6706 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
@@ -834,28 +834,32 @@ describe('authoritative project boards', () => {
expect(api.__records.get(draft.id)?.revision).toBe(1);
});
- it('retries rather than forks when the revision moved but the document did not', async () => {
- // A rename elsewhere bumps the revision and leaves the data alone. The
- // server's copy still carries the other session's search; compared as
- // this realm holds it, it is the baseline this edit started from.
+ it("retries rather than forks when only the other session's ranking moved", async () => {
+ // The other tab paged its ranking: the revision moved and the data changed
+ // only in the positions set against a search this realm cannot resolve.
+ // Compared as this realm holds it, the server's copy is the baseline this
+ // edit started from — a rename here is not in conflict with that.
const draft = { ...createDraftProject([]), name: 'Ranked elsewhere' };
const document = persistence.serializeProjectDocument(draft);
const widgetInstances = document.widgetInstances as Record<string, { state: { values: Record<string, unknown> } }>;
-
- widgetInstances.gallery!.state.values = {
+ const rankedValues = (galleryPage: number) => ({
...widgetInstances.gallery!.state.values,
- galleryPage: 3,
+ galleryPage,
paginationMode: 'paginated',
semanticImageQuery: { fileId: 'external-1-other-realm', kind: 'file', label: 'dropped.png' },
- };
+ });
+
+ widgetInstances.gallery!.state.values = rankedValues(3);
api.__seed(document);
seedSessionBlob({ openProjectIds: [draft.id] });
const loaded = await service.loadWorkbench();
const opened = loaded!.state.projects.find((project) => project.id === draft.id)!;
const record = api.__records.get(draft.id)!;
+ const pagedElsewhere = structuredClone(record.data) as typeof document;
- api.__records.set(draft.id, { ...record, name: 'Renamed elsewhere', revision: record.revision + 1 });
+ (pagedElsewhere.widgetInstances as typeof widgetInstances).gallery!.state.values = rankedValues(4);
+ api.__records.set(draft.id, { ...record, data: pagedElsewhere, revision: record.revision + 1 });
const result = await service.saveWorkbench(stateWithProjects([{ ...opened, name: 'Edited here' }]));
@@ -914,8 +918,8 @@ describe('authoritative project boards', () => {
describe('what a flush reports', () => {
/**
* `arrange` runs after the project is open and before the flush, so each row states exactly
- * what makes its outcome different. The un-renamed row still pushes: hydration normalizes the
- * document, so its serialized form differs from what the server holds.
+ * what makes its outcome different. The un-renamed row does not push: the baseline is the
+ * hydrated document, so a project that has only been opened has nothing to send.
*/
it.each([
['acknowledged', 'a push the server took', 'Edited', () => undefined],
diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
index 55b6ff0eac..be3f439807 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
@@ -208,15 +208,17 @@ const getSerializedProjectDocument = (
* that has only been opened is never pushed, and a real edit here conflicts
* with a real edit there exactly as before.
*/
-const adoptRecordBaseline = (
- syncState: SyncedPersistenceState,
- record: ProjectRecordDTO
-): { project: Project | null; pushedDoc: string } => {
+const adoptRecordBaseline = (record: ProjectRecordDTO): { project: Project | null; pushedDoc: string } => {
const project = deserializeProjectRecord(record);
+ // Serialized directly, not through `getSerializedProjectDocument`: that
+ // records the document's cover as a side effect, and a baseline is taken for
+ // documents this realm may never adopt — the server's copy during conflict
+ // recovery, which on a retry would leave the cover index naming the version
+ // the retry then overwrites.
return {
project,
- pushedDoc: project === null ? JSON.stringify(record.data) : getSerializedProjectDocument(syncState, project).json,
+ pushedDoc: project === null ? JSON.stringify(record.data) : JSON.stringify(serializeProjectDocument(project)),
};
};
@@ -317,7 +319,7 @@ const pushNewProject = async (syncState: SyncedPersistenceState, project: Projec
assertOwner(syncState);
syncState.syncEntries.set(project.id, {
- pushedDoc: adoptRecordBaseline(syncState, existing).pushedDoc,
+ pushedDoc: adoptRecordBaseline(existing).pushedDoc,
revision: existing.revision,
});
syncState.pendingBoardAssignments.push({ boardId: existing.board_id, projectId: project.id });
@@ -392,7 +394,7 @@ const recoverConflictingProject = async (
// taken: the wire bytes of an unchanged document differ from the baseline
// whenever hydration changes it, and that would read a revision that
// merely drifted as a divergence.
- const { project: serverProject, pushedDoc: serverDocJson } = adoptRecordBaseline(syncState, server);
+ const { project: serverProject, pushedDoc: serverDocJson } = adoptRecordBaseline(server);
syncState.syncEntries.set(project.id, { pushedDoc: serverDocJson, revision: server.revision });
@@ -739,7 +741,7 @@ const loadFromBackend = async (
continue;
}
- const { project, pushedDoc } = adoptRecordBaseline(syncState, record);
+ const { project, pushedDoc } = adoptRecordBaseline(record);
if (project) {
serverProjects.push(project);
@@ -939,7 +941,7 @@ export const createSyncedWorkbenchPersistence = (
const adoptProjectRecord = (record: ProjectRecordDTO): Project | null => {
assertOwner(syncState);
- const { project, pushedDoc } = adoptRecordBaseline(syncState, record);
+ const { project, pushedDoc } = adoptRecordBaseline(record);
if (!project) {
return null;