Summary
When a linksMode hasMany relationship has already been accessed/materialized, a later remote update can change the canonical relationship state without resynchronizing the materialized local state when there is no local mutation to reconcile.
Reproduction
- Seed two
user records and two pet records with user.pets <-> pet.owner.
- Start from:
user:1.pets = ["1"]
user:2.pets = ["2"]
- Access
user1.pets so the linksMode hasMany is materialized.
- Send
PATCH /api/user/1 updating pets to [{ type: "pet", id: "1" }, { type: "pet", id: "2" }].
- Send another
PATCH /api/user/1 updating pets to [{ type: "pet", id: "1" }].
Expected
After each remote update, if there are no local additions, removals, or local reordering to preserve, the materialized linksMode hasMany should match the canonical remote state.
Actual
The canonical/inverse state updates, but the already-accessed materialized hasMany can remain stale after repeated remote updates.
For example, after the second PATCH, pet2.owner is cleared but user1.pets can still contain ["1", "2"] instead of ["1"].
Suspected Area
This looks like a policy bug in replaceRelatedRecordsRemote:
|
function replaceRelatedRecordsRemote(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) { |
The relevant case is:
hasMany
linksMode
- relationship already accessed/materialized
- remote membership changed
- no local mutation is present
Environment
- WarpDrive:
5.8.1
- Node:
25.8.0
- pnpm:
10.31.0
Summary
When a
linksModehasManyrelationship has already been accessed/materialized, a later remote update can change the canonical relationship state without resynchronizing the materialized local state when there is no local mutation to reconcile.Reproduction
userrecords and twopetrecords withuser.pets <-> pet.owner.user:1.pets = ["1"]user:2.pets = ["2"]user1.petsso thelinksModehasManyis materialized.PATCH /api/user/1updatingpetsto[{ type: "pet", id: "1" }, { type: "pet", id: "2" }].PATCH /api/user/1updatingpetsto[{ type: "pet", id: "1" }].Expected
After each remote update, if there are no local additions, removals, or local reordering to preserve, the materialized
linksModehasManyshould match the canonical remote state.Actual
The canonical/inverse state updates, but the already-accessed materialized
hasManycan remain stale after repeated remote updates.For example, after the second
PATCH,pet2.owneris cleared butuser1.petscan still contain["1", "2"]instead of["1"].Suspected Area
This looks like a policy bug in
replaceRelatedRecordsRemote:warp-drive/warp-drive-packages/core/src/graph/-private/operations/replace-related-records.ts
Line 178 in b3372e5
The relevant case is:
hasManylinksModeEnvironment
5.8.125.8.010.31.0