Fix false conflicts when serverOnlyField is absent from stored doc#403
Open
Fix false conflicts when serverOnlyField is absent from stored doc#403
Conversation
…ng on stored doc `mergeServerDocumentFieldsMonad` wrote a `null` value for server-only fields that were absent from the stored server document. When the push endpoint later called `masterWrite`, the merged `assumedMasterState` had an extra key compared to the stored master state, so the `isEqual` check reported a conflict that did not actually exist and the client's update was silently reverted. The merge helper now deletes the property in that case so the merged row matches the stored master state. Added an end-to-end replication test and a performance test covering the serverOnlyFields path.
Owner
Author
|
@copilot do not add performance tests in this pr |
Agent-Logs-Url: https://github.com/pubkey/rxdb-server/sessions/84ce6512-541e-4da8-94e4-aeb7c0f3fb64 Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Contributor
Removed the performance-test additions from this PR in commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains:
Describe the problem you have without this PR
During replication push, when a
serverOnlyFieldis absent from the stored server document (e.g., because the field is optional and was never set), the push endpoint would merge anullvalue for that field into theassumedMasterStatebefore callingmasterWrite. This causedmasterWrite'sisEqualcheck to fail because the storedmasterStatehad no such property, resulting in a false conflict that silently reverted the client's update.The Fix
Modified
mergeServerDocumentFieldsMonadinsrc/plugins/server/helper.tsto:serverDocif they actually exist on that documentserverDoc, rather than setting it tonullisEqualcheckTests
'should not produce false conflicts when a serverOnlyField is absent from the stored document'inendpoint-replication.test.tsthat reproduces the bug scenarioserver.test.tsto verify the fix:'should not add the field when serverDoc lacks it'- verifies the field is absent, notnull'should strip client-sent values for server-only fields missing on serverDoc'- ensures malicious clients cannot inject values for missing server-only fields'should not produce extra keys when serverDoc is missing the field'- verifies key count matches between merged and master stateperformance.test.tsto measure replication throughput with server-only fieldsTodos
https://claude.ai/code/session_01XBbmafik7iAy5Hs7Zw9kQR