twentyhq/twenty · error · Error
response length did not match query length
Error message
response length did not match query length
What it means
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.
Source
Thrown at packages/twenty-client-sdk/src/generate/genql/runtime/batcher.ts:61
let batchedQuery: any = queue.map((item) => item.request)
if (batchedQuery.length === 1) {
batchedQuery = batchedQuery[0]
}
client.fetcher(batchedQuery).then((responses: any) => {
if (queue.length === 1 && !Array.isArray(responses)) {
if (responses.errors && responses.errors.length) {
queue[0].reject(
new GenqlError(responses.errors, responses.data),
)
return
}
queue[0].resolve(responses)
return
} else if (responses.length !== queue.length) {
throw new Error('response length did not match query length')
}
for (let i = 0; i < queue.length; i++) {
if (responses[i].errors && responses[i].errors.length) {
queue[i].reject(
new GenqlError(responses[i].errors, responses[i].data),
)
} else {
queue[i].resolve(responses[i])
}
}
}).catch((error: any) => {
// Reject every queued request if the batched fetch fails (e.g. network
// error), otherwise callers hang forever and the rejection is unhandled.
for (const item of queue) {
item.reject(error)
}
})View on GitHub (pinned to 1f5dd2bbd2)
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.
Example fix
// before
const client = createClient({ url, headers, batch: { maxBatchSize: 10, batchInterval: 40 } });
// after
const client = createClient({ url, headers, batch: false }); Defensive patterns
Strategy: validation
Validate before calling
// Before enabling batching, verify the server handles batched queries
// by sending a 2-query array and checking the response is a length-2 array.
const probe = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify([{ query: '{ currentUser { id } }' }, { query: '{ workspace { id } }' }]),
});
const json = await probe.json();
if (!Array.isArray(json) || json.length !== 2) {
// disable batching
} Type guard
const isLengthMatchedArray = (r: unknown, expected: number): r is unknown[] => Array.isArray(r) && r.length === expected;
Try / catch
try {
const data = await client.someQuery();
} catch (err) {
if (err.message === 'response length did not match query length') {
// Switch the client to non-batched mode and retry.
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Genql batch fetcher returned unexpected result + JSON.strin
- ${res.statusText}: ${await res.text()}
- ${response.statusText}: ${response.rawBody}
- Invalid JSON response
- createCompany did not return an id
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/526ca7b24b2c819b.
Report an issue: GitHub.