{"record":{"id":"9d7d9f40d21c9685","repo":"tursodatabase/turso","slug":"pipeline-response-has-len-results-results-for","errorCode":null,"errorMessage":"pipeline response has {len(results)} results for {len(reqs)} requests","messagePattern":"pipeline response has (.+?) results for (.+?) requests","errorType":"exception","errorClass":"ProtocolError","httpStatus":null,"severity":"error","filePath":"serverless/python/turso_serverless/session.py","lineNumber":244,"sourceCode":"        \"\"\"Execute a pipeline (section 5). When `track_autocommit` is set, a\n        `get_autocommit` request is appended and its answer refreshes the\n        cached transaction state; the returned results cover only the\n        caller's requests.\"\"\"\n        reqs = list(requests)\n        if track_autocommit:\n            reqs.append({\"type\": \"get_autocommit\"})\n        raw = self._post(\"/v3/pipeline\", {\"baton\": self._baton, \"requests\": reqs})\n        try:\n            resp: dict[str, Any] = json.loads(raw)\n        except ValueError as e:\n            self._reset_stream()\n            raise ProtocolError(f\"invalid pipeline response: {e}\") from None\n        self._update_stream(resp.get(\"baton\"), resp.get(\"base_url\"))\n        results = resp.get(\"results\") or []\n        # The protocol guarantees one result per request (section 5.2); a\n        # mismatch would misattribute results to the wrong requests.\n        if len(results) != len(reqs):\n            raise ProtocolError(\n                f\"pipeline response has {len(results)} results for {len(reqs)} requests\"\n            )\n        if track_autocommit:\n            result = results.pop()\n            if result.get(\"type\") == \"error\":\n                raise _server_error(result.get(\"error\"))\n            response = result.get(\"response\") or {}\n            if response.get(\"type\") != \"get_autocommit\" or not isinstance(\n                response.get(\"is_autocommit\"), bool\n            ):\n                raise ProtocolError(\n                    f\"expected get_autocommit result in pipeline response, got {response}\"\n                )\n            self._autocommit = response[\"is_autocommit\"]\n        return results\n\n    def _refresh_autocommit(self) -> None:\n        \"\"\"Refresh the cached transaction state with a standalone","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/serverless/python/turso_serverless/session.py#L226-L262","documentation":"ProtocolError raised by Session.execute_pipeline (session.py:243-246) when the results array length differs from the number of requests sent — the protocol (section 5.2) guarantees exactly one result per request, and a mismatch would silently misattribute results to the wrong requests, so the driver aborts instead of guessing. Note the baton/base_url were already applied from the response before this check.","triggerScenarios":"A response-mutating proxy drops or duplicates elements of the results array; a buggy server build returns results for a different request stream; version skew in pipeline semantics.","commonSituations":"Custom API gateways or caches in front of the database; preview/alternative server implementations that are not protocol-conformant.","solutions":["Connect the client directly to the database endpoint and retry","Align client and server versions","Report with the captured response — the driver cannot safely recover a misaligned result set"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from turso_serverless.protocol import ProtocolError\n\ntry:\n    conn.executescript(script)\nexcept ProtocolError as e:\n    if \"results for\" not in str(e) or \"requests\" not in str(e):\n        raise\n    # misaligned results cannot be attributed safely: stop, reconnect, surface\n    raise RuntimeError(\"pipeline result count mismatch — check proxies/server version\") from e","preventionTips":["Never put response-caching or -rewriting gateways on the database path","Smoke-test executescript pipelines against the exact server version in staging","Treat count mismatches as a hard stop — do not guess at result attribution"],"tags":["python","protocol","pipeline","response-mismatch"],"backgroundTag":"malformed-server-response","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}