The results from the versionFromSnapshot query and the latest version query are identical before a manual snapshot is submitted. However, after executing them multiple times, their results diverge.
I know this is related to Convex query caching. I’m not certain if this is the intended behavior or a bug. It will be nice if someone can briefly explain why the result diverges.
Here is the code
export const parentAdaptSnapshot = async (
ctx: AuthMutationCtx,
parentResolutionId: ResolutionId,
resolutionId: ResolutionId,
) => {
const snapshot = await ctx.runQuery(
api.components.resolutionProsemirror.getSnapshot,
{ id: resolutionId },
);
if (!snapshot.content) throw new ConvexError("Snapshot not found");
const parentSnapshot = await ctx.runQuery(
api.components.resolutionProsemirror.getSnapshot,
{ id: parentResolutionId },
);
const incorrectParentVersion = await ctx.runQuery(
components.resolutionProsemirrorSync.lib.latestVersion,
{ id: parentResolutionId },
);
console.log("parentSnapshot", parentSnapshot.version);
console.log("incorrectParentVersion", incorrectParentVersion);
if (!parentSnapshot.content)
throw new ConvexError("Parent snapshot not found");
const newParentVersion = (parentSnapshot as { version: number }).version + 1;
await ctx.runMutation(
components.resolutionProsemirrorSync.lib.submitSnapshot,
{
id: parentResolutionId,
version: newParentVersion,
content: snapshot.content,
},
);
return snapshot;
};
8/14/2025, 6:58:18 PM [CONVEX M(fn/resolutions/state:declareVoteResult)] [LOG] 'parentSnapshot' 12
8/14/2025, 6:58:18 PM [CONVEX M(fn/resolutions/state:declareVoteResult)] [LOG] 'incorrectParentVersion' 12
8/14/2025, 6:58:38 PM [CONVEX M(fn/resolutions/state:declareVoteResult)] [LOG] 'parentSnapshot' 13
8/14/2025, 6:58:38 PM [CONVEX M(fn/resolutions/state:declareVoteResult)] [LOG] 'incorrectParentVersion' 12
The results from the versionFromSnapshot query and the latest version query are identical before a manual snapshot is submitted. However, after executing them multiple times, their results diverge.
I know this is related to Convex query caching. I’m not certain if this is the intended behavior or a bug. It will be nice if someone can briefly explain why the result diverges.
Here is the code