{"record":{"id":"e9bbf947d67c066d","repo":"sgl-project/sglang","slug":"condition-video-keep-must-be-first-or-last-go","errorCode":null,"errorMessage":"condition_video_keep must be 'first' or 'last', got {keep!r}","messagePattern":"condition_video_keep must be 'first' or 'last', got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py","lineNumber":208,"sourceCode":"                tensors.append(_pil_to_normalized_tensor(image))\n            batch.preprocessed_image = torch.stack(tensors, dim=0).contiguous()\n            self.log_info(\n                f\"Preprocessed {len(tensors)} conditioning image(s) to \"\n                f\"{target_w}x{target_h}\"\n            )\n            return batch\n\n        if isinstance(video_path, str) and video_path:\n            frames = load_video(video_path)\n            if not frames:\n                raise ValueError(f\"No frames decoded from video: {video_path!r}\")\n\n            keep = (\n                getattr(batch.sampling_params, \"condition_video_keep\", \"first\")\n                or \"first\"\n            )\n            if keep not in (\"first\", \"last\"):\n                raise ValueError(\n                    f\"condition_video_keep must be 'first' or 'last', got {keep!r}\"\n                )\n            cond_indexes = self._resolve_condition_indexes(batch)\n            # Encode the full output-length video so that the latent positions\n            # we lock match what the decoder will reconstruct at those frame\n            # indices. Encoding only the first ``max_idx*4+1`` frames produces\n            # an out-of-distribution latent for the locked slots and decodes\n            # to noise.\n            num_source_frames = max(cond_indexes) * 4 + 1\n            num_target_frames = batch.num_frames\n            if keep == \"last\":\n                frames = frames[-num_source_frames:]\n            else:\n                frames = frames[:num_source_frames]\n            if len(frames) < num_source_frames:\n                frames = frames + [frames[-1]] * (num_source_frames - len(frames))\n            if len(frames) < num_target_frames:\n                frames = frames + [frames[-1]] * (num_target_frames - len(frames))","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py#L190-L226","documentation":"When conditioning on a video, Cosmos3 keeps either the first or last frame(s) as the condition anchor, selected by sampling_params.condition_video_keep. Only \"first\" and \"last\" are valid; anything else (including a misspelled value) is rejected before latent locking.","triggerScenarios":"Setting batch.sampling_params.condition_video_keep to a value other than \"first\"/\"last\" in a V2V request — e.g. \"middle\", \"First\" (case-sensitive), or \"none\".","commonSituations":"Client configs ported from other pipelines that use different keep-modes; typos or casing mistakes; JSON configs where the field is silently misspelled and getattr falls through to the raw string.","solutions":["Set condition_video_keep to \"first\" or \"last\" (lowercase) in sampling_params, or omit it to default to \"first\"","Validate the value client-side before sending the request"],"exampleFix":"# before\nsampling_params = {\"condition_video_keep\": \"middle\"}\n# after\nsampling_params = {\"condition_video_keep\": \"first\"}","handlingStrategy":"validation","validationCode":"keep = sampling_params.get(\"condition_video_keep\", \"first\")\nassert keep in (\"first\", \"last\"), f\"bad condition_video_keep: {keep!r}\"","typeGuard":"def is_valid_keep(v) -> bool:\n    return v in (\"first\", \"last\")","tryCatchPattern":null,"preventionTips":["Omit the field to use the safe default 'first'"],"tags":["cosmos3","v2v","condition-video-keep","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}