{"record":{"id":"62ddc528c5b1693c","repo":"sgl-project/sglang","slug":"delta-payload-size-mismatch-expected-expectedsi","errorCode":null,"errorMessage":"delta payload size mismatch: expected ${expectedSize}, got ${restored.length}","messagePattern":"delta payload size mismatch: expected (.+?), got (.+?)","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/realtime_webui/app.js","lineNumber":1075,"sourceCode":"  }\n  return items;\n}\n\nasync function gunzipBytes(payload) {\n  if (typeof DecompressionStream === \"undefined\") {\n    throw new Error(\"This browser does not support gzip stream decoding\");\n  }\n  const stream = new Blob([payload]).stream().pipeThrough(new DecompressionStream(\"gzip\"));\n  return new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\nasync function restoreDeltaGzipRawRgb(header, payload) {\n  const frameBytes = Number(header.bytes_per_frame);\n  const count = Number(header.num_frames);\n  const expectedSize = frameBytes * count;\n  const restored = await gunzipBytes(payload);\n  if (restored.length !== expectedSize) {\n    throw new Error(`delta payload size mismatch: expected ${expectedSize}, got ${restored.length}`);\n  }\n  let previous = header.delta_reference === \"previous-frame\" ? lastRawRgbFrame : null;\n  if (header.delta_reference === \"previous-frame\" && !previous) {\n    throw new Error(\"Missing previous frame for delta payload\");\n  }\n  for (let f = 0; f < count; f++) {\n    const current = f * frameBytes;\n    if (previous) {\n      for (let i = 0; i < frameBytes; i++) {\n        restored[current + i] ^= previous[i];\n      }\n    }\n    previous = restored.slice(current, current + frameBytes);\n  }\n  return restored;\n}\n\nasync function framePayloadToImageData(header, payload) {","sourceCodeStart":1057,"sourceCodeEnd":1093,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/realtime_webui/app.js#L1057-L1093","documentation":"Thrown by ngram_corpus Param::parse when two configured ranges overlap: the parser marks each position it fills, and filling an already-marked position means the config assigns a value to the same token position twice. Ranges must be disjoint.","triggerScenarios":"resetBatchReturnTokenNum with overlapping segments such as '2-4|8 3-5|3' — position 3 and 4 are covered by both ranges, so mark[L] is already true on the second pass.","commonSituations":"Appending a new range to an existing config without checking for overlap, or ranges like '2-4|8 4-6|3' that share an endpoint (inclusive ranges).","solutions":["Make all ranges in the config disjoint, e.g. '2-4|8 5-8|3' instead of '2-4|8 3-5|3'","Remember ranges are inclusive on both ends — adjacent ranges must not share an endpoint","Write a quick Python check that merges/validates interval overlap before passing the string to C++"],"exampleFix":"# before\nparam.resetBatchReturnTokenNum(\"2-4|8 3-5|3\")\n\n# after\nparam.resetBatchReturnTokenNum(\"2-4|8 5-8|3\")","handlingStrategy":"validation","validationCode":"ivs = sorted(tuple(map(int, s.split(\"|\")[0].split(\"-\"))) for s in cfg.split())\nfor (a1, b1), (a2, b2) in zip(ivs, ivs[1:]):\n    assert b1 < a2, f\"overlapping ranges {a1}-{b1} and {a2}-{b2}\"","typeGuard":"def ranges_disjoint(cfg: str) -> bool:\n    ivs = sorted(tuple(map(int, s.split(\"|\")[0].split(\"-\"))) for s in cfg.split())\n    return all(b1 < a2 for (_, b1), (a2, _) in zip(ivs, ivs[1:]))","tryCatchPattern":"try:\n    param.resetBatchReturnTokenNum(cfg)\nexcept RuntimeError as e:\n    if \"repeated position\" in str(e):\n        raise ValueError(f\"overlapping ranges in {cfg!r}; make them disjoint\") from e\n    raise","preventionTips":["Treat ranges as inclusive on both ends — adjacent ranges must not share endpoints","Auto-merge overlapping intervals before serializing the config","Add a config round-trip test that parses and re-serializes"],"tags":["ngram","config","overlap","parsing"],"backgroundTag":"config-value-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}