{"record":{"id":"e561a2ffb6bfde53","repo":"zed-industries/zed","slug":"missing-fim-middle-in-model-output","errorCode":null,"errorMessage":"missing <|fim_middle|> in model output","messagePattern":"missing <\\|fim_middle\\|> in model output","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeta_prompt/src/zeta_prompt.rs","lineNumber":4392,"sourceCode":"    ///\n    /// The model output has the form:\n    ///\n    /// - prefix context lines\n    /// - `<|fim_middle|>`\n    /// - new text\n    /// - `<|fim_suffix|>`\n    /// - suffix context lines\n    ///\n    /// We locate the prefix/suffix context lines in the original text and replace\n    /// everything between them with the new text.\n    pub fn apply_variable_edit(\n        context: &str,\n        model_output: &str,\n    ) -> Result<(Range<usize>, String)> {\n        let (prefix_context, rest) = model_output\n            .split_once(\"<|fim_middle|>\\n\")\n            .or_else(|| model_output.split_once(\"<|fim_middle|>\"))\n            .ok_or_else(|| anyhow::anyhow!(\"missing <|fim_middle|> in model output\"))?;\n\n        let (new_text, suffix_context) = rest\n            .split_once(\"<|fim_suffix|>\\n\")\n            .or_else(|| rest.split_once(\"<|fim_suffix|>\"))\n            .unwrap_or((rest, \"\"));\n\n        let suffix_context = if prefix_context.is_empty() && !suffix_context.is_empty() {\n            suffix_context.strip_prefix('\\n').unwrap_or(suffix_context)\n        } else {\n            suffix_context\n        };\n\n        let prefix_offset = find_substring_at_line_boundary(context, prefix_context)\n            .ok_or_else(|| anyhow!(\"could not locate prefix lines\"))?\n            + prefix_context.len();\n        let suffix_offset = if suffix_context.is_empty() {\n            context.len()\n        } else {","sourceCodeStart":4374,"sourceCodeEnd":4410,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/zeta_prompt/src/zeta_prompt.rs#L4374-L4410","documentation":"apply_variable_edit splits the model output on the <|fim_middle|> token; its absence means the output is not in the expected prefix/middle/suffix FIM shape, so there is no boundary between context lines and new text.","triggerScenarios":"Thrown at crates/zeta_prompt/src/zeta_prompt.rs:4392 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reject the output and re-request the edit in proper FIM variable-edit format","Check for token-stripping post-processing that removed the fim_middle marker before parsing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}