{"record":{"id":"d485e85a7a643935","repo":"tursodatabase/turso","slug":"expected-turso-sync-result-expected-got-actual","errorCode":null,"errorMessage":"Expected Turso sync result {expected}, got {actual}.","messagePattern":"Expected Turso sync result (.+?), got (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoSyncDatabase.cs","lineNumber":841,"sourceCode":"            RemoteEncryptionCipher = encryption?.NativeName,\n            PushOperationsThreshold = options.PushOperationsThreshold is null\n                ? 0\n                : (nuint)options.PushOperationsThreshold.Value,\n            PullBytesThreshold = options.PullBytesThreshold is null\n                ? 0\n                : (nuint)options.PullBytesThreshold.Value,\n            LogicalMvccPull = options.ForceLogicalMvccPull,\n            ExperimentalFeatures = options.ExperimentalFeatures,\n        };\n    }\n\n    private static void EnsureResultKind(\n        TursoSyncOperationHandle operation,\n        TursoSyncOperationResultKind expected)\n    {\n        var actual = TursoSyncBindings.GetResultKind(operation);\n        if (actual != expected)\n            throw new InvalidOperationException($\"Expected Turso sync result {expected}, got {actual}.\");\n    }\n\n    private static DateTimeOffset? ToTimestamp(long value)\n        => value <= 0 ? null : DateTimeOffset.FromUnixTimeSeconds(value);\n\n    private TursoSyncException CreateSyncException(\n        TursoSyncOperationKind operation,\n        Exception exception)\n    {\n        var transport = _lastTransportContext;\n        var message = RedactSecrets(exception.Message);\n        var innerException = ContainsSecret(exception.ToString())\n            ? new Exception(message)\n            : exception;\n        return new TursoSyncException(\n            operation,\n            $\"Turso sync {operation} failed: {message}\",\n            (exception as TursoSyncNativeException)?.StatusCode,","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoSyncDatabase.cs#L823-L859","documentation":"EnsureResultKind compares the result kind returned by the native sync bindings against the kind the calling code expected for the operation (e.g. frames vs. bootstrap) and throws this InvalidOperationException on mismatch. It signals an internal protocol/sequence bug: the native layer returned a different sync outcome than the managed state machine required at that point.","triggerScenarios":"A sync operation whose TursoSyncOperationHandle returns a result kind from TursoSyncBindings.GetResultKind that differs from the expected kind for the current step — e.g. expecting a frames result but the native side returned a bootstrap or error-pending kind, or reusing a handle after a state change.","commonSituations":"Version mismatch between the managed Turso.Data assembly and the native libturso sync bindings; calling sync APIs out of order (e.g. continuing a partial sync session in the wrong phase); concurrency bugs where one thread advances the operation before another checks its result.","solutions":["Ensure the managed Turso.Data package and the native libturso bindings are the same version; upgrade/reinstall both together","Do not reuse TursoSyncOperationHandle across phases; complete or dispose the operation and start a fresh sync","Avoid calling sync operations concurrently on the same TursoSyncDatabase instance; serialize sync calls","If reproducible, file a bug with the expected/actual result kinds — this indicates a client protocol defect"],"exampleFix":"// before: reusing an operation handle across sync phases\nvar handle = db.BeginSync();\nProcessFrames(handle);\nProcessFrames(handle); // may now be a different result kind\n// after: run one operation per phase\nusing var handle = db.BeginSync();\nProcessFrames(handle);","handlingStrategy":"try-catch","validationCode":"// keep managed assembly and native libturso versions aligned\nvar expected = typeof(TursoSyncDatabase).Assembly.GetName().Version;\n// assert against your deployment's native binding version before syncing","typeGuard":null,"tryCatchPattern":"try\n{\n    await db.SyncAsync(ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Expected Turso sync result\"))\n{\n    logger.LogError(ex, \"Native sync bindings returned an unexpected result kind; check version alignment and single-threaded sync usage.\");\n    throw;\n}","preventionTips":["Pin and deploy the managed package and native bindings as one matched unit","Never call sync APIs on the same TursoSyncDatabase from multiple threads; serialize sync operations","Do not reuse sync operation handles across phases; complete each operation before starting another"],"tags":["dotnet","sync","protocol","version-mismatch"],"backgroundTag":"sync-result-mismatch","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-31T11:17:35.598Z","contentChangedAt":"2026-08-31T11:17:35.598Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}