{"record":{"id":"526ca7b24b2c819b","repo":"twentyhq/twenty","slug":"response-length-did-not-match-query-length","errorCode":null,"errorMessage":"response length did not match query length","messagePattern":"response length did not match query length","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-client-sdk/src/generate/genql/runtime/batcher.ts","lineNumber":61,"sourceCode":"    let batchedQuery: any = queue.map((item) => item.request)\n\n    if (batchedQuery.length === 1) {\n        batchedQuery = batchedQuery[0]\n    }\n\n    client.fetcher(batchedQuery).then((responses: any) => {\n        if (queue.length === 1 && !Array.isArray(responses)) {\n            if (responses.errors && responses.errors.length) {\n                queue[0].reject(\n                    new GenqlError(responses.errors, responses.data),\n                )\n                return\n            }\n\n            queue[0].resolve(responses)\n            return\n        } else if (responses.length !== queue.length) {\n            throw new Error('response length did not match query length')\n        }\n\n        for (let i = 0; i < queue.length; i++) {\n            if (responses[i].errors && responses[i].errors.length) {\n                queue[i].reject(\n                    new GenqlError(responses[i].errors, responses[i].data),\n                )\n            } else {\n                queue[i].resolve(responses[i])\n            }\n        }\n    }).catch((error: any) => {\n        // Reject every queued request if the batched fetch fails (e.g. network\n        // error), otherwise callers hang forever and the rejection is unhandled.\n        for (const item of queue) {\n            item.reject(error)\n        }\n    })","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/generate/genql/runtime/batcher.ts#L43-L79","documentation":"Thrown by QueryBatcher.dispatchQueueBatch (batcher.ts:60-61) when the fetcher returns an Array response whose length does not match the number of queued requests. The batcher relies on positional correspondence between the sent batch and the returned array; a length mismatch makes it impossible to route results to the correct caller.","triggerScenarios":"Batching enabled and the server returns an array (Array.isArray(responses) === true in the batcher) but with fewer or more entries than the queue. This happens when the server partially processes a batch, dedupes queries, or a custom fetcher reshapes the response array.","commonSituations":"A custom fetcher passed via the `fetcher` option that wraps/truncates the array; server-side batching implementation that collapses identical queries; intermittent server errors that drop some entries; race conditions where the queue is mutated during dispatch.","solutions":["Disable batching (batch: false) so each query is dispatched individually.","If using a custom fetcher, ensure it returns one response entry per input query preserving order.","Reduce maxBatchSize to 1 to isolate which query breaks the contract.","Upgrade/align the Twenty server version with the client SDK so batch semantics match."],"exampleFix":"// before\nconst client = createClient({ url, headers, batch: { maxBatchSize: 10, batchInterval: 40 } });\n// after\nconst client = createClient({ url, headers, batch: false });","handlingStrategy":"validation","validationCode":"// Before enabling batching, verify the server handles batched queries\n// by sending a 2-query array and checking the response is a length-2 array.\nconst probe = await fetch(url, {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },\n  body: JSON.stringify([{ query: '{ currentUser { id } }' }, { query: '{ workspace { id } }' }]),\n});\nconst json = await probe.json();\nif (!Array.isArray(json) || json.length !== 2) {\n  // disable batching\n}","typeGuard":"const isLengthMatchedArray = (r: unknown, expected: number): r is unknown[] =>\n  Array.isArray(r) && r.length === expected;","tryCatchPattern":"try {\n  const data = await client.someQuery();\n} catch (err) {\n  if (err.message === 'response length did not match query length') {\n    // Switch the client to non-batched mode and retry.\n  }\n  throw err;\n}","preventionTips":["Default to batch: false unless you control the server.","Keep maxBatchSize conservative.","Ensure any custom fetcher returns one entry per query in order.","Monitor batcher queue mutations during dispatch."],"tags":["graphql","batching","client-sdk","contract-violation"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}