{"record":{"id":"bea340ef22774128","repo":"sgl-project/sglang","slug":"sana-wm-realtime-denoising-requires-a-realtime-ses","errorCode":null,"errorMessage":"SANA-WM realtime denoising requires a realtime session","messagePattern":"SANA-WM realtime denoising requires a realtime session","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/streaming.py","lineNumber":257,"sourceCode":"        SanaWMSelfForcingSampler.evict_stale_kv_cache(\n            kv_cache, chunk_idx, valid, num_cached_blocks, num_blocks\n        )\n\n    # Realtime per-chunk path (sessions): per-session state in RealtimeCausalDiTState.\n    @torch.no_grad()\n    def _forward_realtime_chunk(self, batch: Req, server_args: ServerArgs) -> Req:\n        if batch.latents is None or batch.latents.ndim != 5:\n            raise ValueError(\n                \"SANA-WM realtime denoising expects this tick's pre-noised chunk \"\n                \"latents (B, C, n, H, W) from the latent-preparation stage.\"\n            )\n        pcfg = server_args.pipeline_config\n        device = get_local_torch_device()\n        target_dtype = PRECISION_TO_TYPE.get(\n            getattr(pcfg, \"dit_precision\", \"bf16\"), torch.bfloat16\n        )\n        if batch.session is None:\n            raise ValueError(\"SANA-WM realtime denoising requires a realtime session\")\n        state = get_realtime_causal_dit_state(batch.session)\n        if batch.block_idx == 0 and state.latents is not None:\n            state.dispose()  # session restart on chunk 0 (mirrors the base stage)\n\n        sc = self._resolve_stream_conditioning(\n            batch, server_args, device=device, target_dtype=target_dtype\n        )\n        sampler_cfg = sc.sampler_cfg\n        incoming = batch.latents.to(device=device, dtype=target_dtype).clone()\n        plan = list(batch.extra.get(\"sana_wm_chunk_plan\") or [incoming.shape[2]])\n        if sum(plan) != incoming.shape[2]:\n            raise ValueError(\n                f\"chunk plan {plan} does not cover the incoming {incoming.shape[2]} frames\"\n            )\n        if state.scheduler is None:\n            state.scheduler = FlowMatchEulerDiscreteScheduler(shift=1.0)\n        kv_cache = state.kv_cache\n        if kv_cache is None:","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/streaming.py#L239-L275","documentation":"The realtime per-chunk path stores autoregressive state (latents, scheduler, KV cache) in a per-session RealtimeCausalDiTState. If batch.session is None there is no session to key the state on, so realtime denoising cannot proceed.","triggerScenarios":"Sending a realtime chunk through the streaming stage with batch.session unset — e.g. an offline-style Req routed into the realtime path, or a session that was closed/never created before the first tick.","commonSituations":"Misrouted requests (offline vs realtime dispatch based on session presence); a gateway/proxy stripping the session field; racing session teardown with in-flight chunks.","solutions":["Create the realtime session before sending chunks and attach it to each tick's Req","Fix request routing so only session-backed Reqs take the realtime path","If the session was disposed, re-establish it and resend from chunk 0"],"exampleFix":"# before\nbatch.session = None\nstreaming_stage.forward(batch, server_args)\n# after\nbatch.session = get_or_create_session(session_id)\nstreaming_stage.forward(batch, server_args)","handlingStrategy":"validation","validationCode":"if batch.session is None:\n    batch.session = get_or_create_session(session_id)","typeGuard":"null","tryCatchPattern":"try:\n    resp = stage.forward(batch, server_args)\nexcept ValueError as e:\n    if \"realtime session\" in str(e):\n        raise SessionLost(session_id) from e\n    raise","preventionTips":["Create sessions before streaming chunks","Route requests by session presence (realtime vs offline)","Handle session-expiry by restarting from chunk 0"],"tags":["sana-wm","streaming","session","realtime","valueerror"],"backgroundTag":"missing-session-state","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}