{"record":{"id":"b451e9103301b9bd","repo":"tursodatabase/turso","slug":"remote-batch-returned-an-unexpected-result-shape","errorCode":null,"errorMessage":"Remote batch returned an unexpected result shape: {batch.StepResults.Count} results, {batch.StepErrors.Count} errors, expected {expectedCount}.","messagePattern":"Remote batch returned an unexpected result shape: (.+?) results, (.+?) errors, expected (.+?)\\.","errorType":"exception","errorClass":"TursoException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs","lineNumber":301,"sourceCode":"        {\n            case \"ok\":\n                if (result.Response?.Type != \"close\")\n                    throw new TursoException($\"{operation} returned unexpected response type: {result.Response?.Type}\");\n                break;\n\n            case \"error\":\n                break;\n\n            default:\n                throw new TursoException($\"{operation} returned unexpected result type: {result.Type}\");\n        }\n    }\n\n    private static List<RemoteStatementResult> ExtractBatchStepResults(RemoteBatchResult batch, int expectedCount)\n    {\n        if (batch.StepErrors.Count != expectedCount || batch.StepResults.Count != expectedCount)\n        {\n            throw new TursoException(\n                $\"Remote batch returned an unexpected result shape: {batch.StepResults.Count} results, {batch.StepErrors.Count} errors, expected {expectedCount}.\");\n        }\n\n        for (var i = 0; i < batch.StepErrors.Count; i++)\n        {\n            if (batch.StepErrors[i] is { } error)\n                throw CreateRemoteError(error);\n        }\n\n        var statementResults = new List<RemoteStatementResult>(expectedCount);\n        for (var i = 0; i < batch.StepResults.Count; i++)\n        {\n            var stepResult = batch.StepResults[i]\n                             ?? throw new TursoException($\"Remote batch did not return a result for step {i}.\");\n            statementResults.Add(stepResult);\n        }\n\n        return statementResults;","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs#L283-L319","documentation":"For a batch, the server must return exactly one step_results entry and one step_errors entry per submitted command. ExtractBatchStepResults threw because those arrays' lengths differ from the number of TursoBatchCommands sent, meaning the reply does not line up with the request.","triggerScenarios":"TursoBatch execution on a remote connection where batch.step_results.Count or batch.step_errors.Count differs from commands.Count -- for example 3 commands submitted but 2 step results returned.","commonSituations":"Servers that deduplicate or collapse identical statements in a batch; response truncation by a proxy; version drift changing batch result semantics; custom servers returning a single aggregate result instead of per-step results.","solutions":["Log the batch size you submitted and the counts in the message (the exception text includes results, errors, and expected counts) to see which side is off.","Reproduce the batch pipeline POST with curl and count the step arrays in the raw JSON.","Align server and Turso.Data binding versions; batch shape changes are common across protocol revisions.","Remove truncating or transforming proxies from the path.","If the server intentionally changed shape, upgrade the bindings to the release that understands it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await batch.ExecuteReaderAsync(cancellationToken); }\ncatch (TursoException ex) when (ex.Message.Contains(\"unexpected result shape\"))\n{\n    // message contains actual vs expected counts: log it verbatim\n    logger.LogError(ex, \"Batch step count mismatch for batch of {Count}\", batch.BatchCommands.Count);\n    throw;\n}","preventionTips":["Keep the submitted command count and the observed counts from the message when reporting -- they identify the skew direction.","Version-align server and bindings; batch result semantics changed across protocol revisions.","Keep truncating proxies away from large batch responses.","Prefer many small batches over one huge batch to reduce blast radius and ease diagnosis."],"tags":["turso","dotnet","remote","batch","protocol"],"backgroundTag":"response-schema-mismatch","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}