{"record":{"id":"1046082f3c13f2cc","repo":"clockworklabs/SpacetimeDB","slug":"called-nonvaluechange-on-a-valuedelta-in-an-ambigu","errorCode":null,"errorMessage":"Called NonValueChange on a ValueDelta in an ambiguous state: {this}","messagePattern":"Called NonValueChange on a ValueDelta in an ambiguous state: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"sdks/csharp/src/MultiDictionary.cs","lineNumber":509,"sourceCode":"                    else\n                    {\n                        // Now we're in a weird place.\n                        // We're not an update, but D2 is initialized.\n                        // This means that at least one of D1 or D2 has Delta == 0.\n                        // If exactly one of them has Delta == 0, we're okay:\n                        if (D1.Delta == 0 && D2.Value.Delta != 0)\n                        {\n                            return D2.Value;\n                        }\n                        else if (D1.Delta != 0 && D2.Value.Delta == 0)\n                        {\n                            return D1;\n                        }\n                        else\n                        {\n                            // In this case, something strange is going on: both values have the same sign.\n                            // There's nothing sensible to do here, and this represents a server-side error, so just throw.\n                            throw new InvalidOperationException($\"Called NonValueChange on a ValueDelta in an ambiguous state: {this}\");\n                        }\n                    }\n                }\n            }\n\n            /// <summary>\n            /// Add a copy of this Value to this KeyDelta.\n            /// </summary>\n            /// <param name=\"value\"></param>\n            /// <param name=\"equalityComparer\"></param>\n            public void Add(TValue value, IEqualityComparer<TValue> equalityComparer)\n            {\n                if (equalityComparer.Equals(value, D1.Value))\n                {\n                    D1.Delta += 1;\n                }\n                else if (D2 == null)\n                {","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/sdks/csharp/src/MultiDictionary.cs#L491-L527","documentation":"The client-side cache for MultiDictionary tables accumulates signed multiplicity deltas per key, holding at most two distinct values (D1/D2). NonValueChange requires exactly one of them to have a zero delta; when both are zero or both are non-zero with the same sign, the invariant is broken. The code comment explicitly calls this a server-side error and throws — it is not an application-logic failure.","triggerScenarios":"Applying subscription/transaction updates to a table stored in a MultiDictionary when the server diff for one key degenerates into an ambiguous two-value state. Typically coincides with SDK/server version mismatch or a server diff-generation bug; an inconsistent custom IEqualityComparer<TValue> can also collapse distinct values incorrectly.","commonSituations":"Client cache updates after a long-lived subscription on SDK and server versions that drifted apart; custom equality comparers on the value type; reproduces consistently on the same reducer/transaction.","solutions":["Update the C# SDK and the SpacetimeDB server to matching released versions","If you pass a custom IEqualityComparer<TValue> to MultiDictionary, verify it is a proper, stable equality (consistent with value equality the server observes)","Reconnect and resubscribe to rebuild the client cache from a clean snapshot","Capture the exception plus the reducer/transaction context and file a SpacetimeDB bug — the source marks this as a server error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Around the code that drives FrameTick / message processing in non-Unity hosts:\ntry { conn.FrameTick(); }\ncatch (InvalidOperationException e) when (e.Message.Contains(\"ambiguous state\"))\n{ /* client/server cache desync: disconnect, rebuild the connection, resubscribe */ }","preventionTips":["Keep SDK and server versions in lockstep; this path indicates a server-side diff bug","Avoid custom IEqualityComparer implementations that disagree with value equality","Capture and report the exact transaction that triggers it"],"tags":["client-cache","database-update","csharp","server-bug"],"backgroundTag":"malformed-server-update","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}