{"record":{"id":"11d9e23f53f00b45","repo":"sgl-project/sglang","slug":"debug-name-non-sequential-write-current-start","errorCode":null,"errorMessage":"{debug_name}: non-sequential write current_start={current_chunk_start} global_end={self._global_end} cur={None if self._cur is None else self._cur.g0}","messagePattern":"(.+?): non-sequential write current_start=(.+?) global_end=(.+?) cur=(.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/kvcache/qvg_packed_cache.py","lineNumber":311,"sourceCode":"            # rewrite current chunk in place (denoise step)\n            if cend != self._cur.g1:\n                raise NotImplementedError(\n                    f\"{debug_name}: current-chunk rewrite size changed\"\n                )\n            self._write(self._cur, key, value, head_slice)\n        elif current_chunk_start == self._global_end:\n            # advance: finalize current chunk, start a new one\n            if self._cur is not None:\n                self._segments.append(self._cur)\n            is_sink = current_chunk_start < self.sink_tokens\n            if self._chunk_tokens == 0:\n                self._chunk_tokens = num_new\n            self._cur = self._new_bf16_segment(current_chunk_start, cend, is_sink)\n            self._write(self._cur, key, value, head_slice)\n            self._global_end = cend\n            self._pack_and_evict()\n        else:\n            raise NotImplementedError(\n                f\"{debug_name}: non-sequential write current_start=\"\n                f\"{current_chunk_start} global_end={self._global_end} \"\n                f\"cur={None if self._cur is None else self._cur.g0}\"\n            )\n\n        local_end = min(self._global_end, self.cache_size)\n        if self.global_end_index_int is not None:\n            self.global_end_index_int = self._global_end\n            self.local_end_index_int = local_end\n        else:\n            self.global_end_index.fill_(self._global_end)\n            self.local_end_index.fill_(local_end)\n\n        vk, vv = self._reconstruct(current_chunk_start, recent_window_tokens)\n        return CausalAttentionKVView(\n            k=vk,\n            v=vv,\n            local_start_index=0,","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/kvcache/qvg_packed_cache.py#L293-L329","documentation":"The packed cache only supports two write modes: rewriting the current chunk, or appending at exactly self._global_end. Any other current_chunk_start is a non-sequential write and raises NotImplementedError with diagnostics of the expected vs. given positions.","triggerScenarios":"update_and_get_attention_kv with current_chunk_start not equal to self._cur.g0 (rewrite) nor self._global_end (append) — e.g. writing into the middle of history or rewinding past the current chunk.","commonSituations":"Rollback/replay logic in realtime pipelines attempting to overwrite an older chunk; multiple writers interleaving out of order; incorrect global position bookkeeping after an eviction/pack pass.","solutions":["Align current_chunk_start with cache._global_end for appends","To overwrite history, drain/reset the cache back to that position first","Serialize writers so chunks are produced strictly in order"],"exampleFix":"# before\ncache.update_and_get_attention_kv(k, v, current_chunk_start=older_start)\n# after\ncache.update_and_get_attention_kv(k, v, current_chunk_start=cache._global_end)","handlingStrategy":"validation","validationCode":"assert current_chunk_start == cache._global_end or (cache._cur and current_chunk_start == cache._cur.g0), 'non-sequential write'","typeGuard":null,"tryCatchPattern":"try:\\n    cache.update_and_get_attention_kv(k, v, current_chunk_start=s)\\nexcept NotImplementedError as e:\\n    if 'non-sequential write' in str(e):\\n        cache.rewind_to(s)","preventionTips":["Serialize writers to a single sequential producer","Reset/rewind the cache before replaying history"],"tags":["kv-cache","sequential-write","not-implemented","chunking"],"backgroundTag":"kv-cache-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}