{"record":{"id":"4e6d53569f3c6777","repo":"thanos-io/thanos","slug":"unexpected-result-size-d","errorCode":null,"errorMessage":"unexpected result size %d","messagePattern":"unexpected result size (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/prometheus.go","lineNumber":422,"sourceCode":"\tsb := p.getBuffer()\n\tvar decomp []byte\n\ttracing.DoInSpan(ctx, \"decompress_response\", func(ctx context.Context) {\n\t\tdecomp, err = snappy.Decode(*sb, buf.Bytes())\n\t})\n\tdefer p.putBuffer(sb)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"decompress response\")\n\t}\n\n\tvar data prompb.ReadResponse\n\ttracing.DoInSpan(ctx, \"unmarshal_response\", func(ctx context.Context) {\n\t\terr = proto.Unmarshal(decomp, &data)\n\t})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unmarshal response\")\n\t}\n\tif len(data.Results) != 1 {\n\t\treturn nil, errors.Errorf(\"unexpected result size %d\", len(data.Results))\n\t}\n\n\tfor _, ts := range data.Results[0].Timeseries {\n\t\tlabelpb.ReAllocZLabelsStrings(&ts.Labels)\n\t}\n\n\treturn &data, nil\n}\n\nfunc (p *PrometheusStore) chunkSamples(series *prompb.TimeSeries, maxSamplesPerChunk int, calculateChecksums bool) (chks []storepb.AggrChunk, err error) {\n\tsamples := series.Samples\n\thasher := hashPool.Get().(hash.Hash64)\n\tdefer hashPool.Put(hasher)\n\n\tfor len(samples) > 0 {\n\t\tchunkSize := min(len(samples), maxSamplesPerChunk)\n\n\t\tenc, cb, err := p.encodeChunk(samples[:chunkSize])","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/prometheus.go#L404-L440","documentation":"After successfully unmarshaling the remote-read response, fetchSampledResponse requires exactly one query result (it sent exactly one prompb.Query). If data.Results has any length other than 1, errors.Errorf(\"unexpected result size %d\") is returned. This is an invariant check against a remote endpoint that returned a different number of results than requested.","triggerScenarios":"The upstream Prometheus returns a ReadResponse containing zero results or multiple results — e.g. a non-standard/older Prometheus implementation, a compatible remote-read server (Thanos, Cortex) that responds differently, or a proxy returning a cached/mismatched response.","commonSituations":"Pointing the store at Thanos/Cortex/other remote-read implementations with divergent result semantics; version drift where the server batch-responses differently; misrouted requests returning another query's cached result.","solutions":["Verify the remote endpoint is a standard Prometheus with remote read returning exactly one result per query","Check server version compatibility; upgrade Prometheus or pin a known-good version","Inspect response with curl to confirm result count matches the single query sent","If using a proxy/cache, bypass it to rule out stale or aggregated responses"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm endpoint honors one-query-per-request remote read\nresp, _ := http.Post(baseURL+\"/api/v1/read\", \"application/x-protobuf\", body)\n// decode and assert len(results)==1 before production use","typeGuard":null,"tryCatchPattern":"series, err := store.Series(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"unexpected result size\") {\n    // upstream returned wrong shape: fall back to another store or fail the query\n}","preventionTips":["Test new Prometheus/compatible remote-read endpoints before pointing stores at them","Keep server and client (Thanos) versions aligned","Bypass caches/proxies for remote-read traffic"],"tags":["prometheus","remote-read","response-validation"],"backgroundTag":"unexpected-response-shape","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}