zed-industries/zed · error

could not locate prefix lines

Error message

could not locate prefix lines

What it means

The prefix context lines echoed by the model could not be found at a line boundary in the original text, so the replacement start offset is unknown. Typically the model hallucinated or altered the prefix context.

Source

Thrown at crates/zeta_prompt/src/zeta_prompt.rs:4406

    ) -> Result<(Range<usize>, String)> {
        let (prefix_context, rest) = model_output
            .split_once("<|fim_middle|>\n")
            .or_else(|| model_output.split_once("<|fim_middle|>"))
            .ok_or_else(|| anyhow::anyhow!("missing <|fim_middle|> in model output"))?;

        let (new_text, suffix_context) = rest
            .split_once("<|fim_suffix|>\n")
            .or_else(|| rest.split_once("<|fim_suffix|>"))
            .unwrap_or((rest, ""));

        let suffix_context = if prefix_context.is_empty() && !suffix_context.is_empty() {
            suffix_context.strip_prefix('\n').unwrap_or(suffix_context)
        } else {
            suffix_context
        };

        let prefix_offset = find_substring_at_line_boundary(context, prefix_context)
            .ok_or_else(|| anyhow!("could not locate prefix lines"))?
            + prefix_context.len();
        let suffix_offset = if suffix_context.is_empty() {
            context.len()
        } else {
            find_substring_at_line_boundary(&context[prefix_offset..], suffix_context)
                .ok_or_else(|| anyhow!("could not locate suffix lines"))?
                + prefix_offset
        };

        let edit_range = prefix_offset..suffix_offset;
        return Ok((edit_range, new_text.to_string()));
    }

    fn find_substring_at_line_boundary(haystack: &str, needle: &str) -> Option<usize> {
        if needle.is_empty() {
            return Some(0);
        }

View on GitHub (pinned to f4178619ac)

Solutions

  1. Retry the request so the model reproduces the prefix context verbatim
  2. Fall back to fuzzy line matching on the prefix before failing
  3. Validate the prefix against the current buffer before applying
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/zeta_prompt/src/zeta_prompt.rs:4406 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/6abb6035063b1eb7. Report an issue: GitHub.