zed-industries/zed · error

start marker `{start_id}` must come before end marker `{end_

Error message

start marker `{start_id}` must come before end marker `{end_id}`

What it means

Raised in build_patch_from_spans when a start/end marker pair resolves to the same context snippet but the start marker's byte offset is not before the end marker's byte offset (reversed or identical positions). The resulting span would be invalid, so the patch is rejected.

Source

Thrown at crates/zeta_prompt/src/hashed_regions.rs:683

    }

    let mut edits: Vec<ParsedSpanEdit> = Vec::new();
    for (start_id, end_id, raw_new_span) in spans {
        let &(start_snippet, start_byte) = marker_index
            .get(start_id.as_str())
            .with_context(|| format!("unknown start marker `{start_id}`"))?;
        let &(end_snippet, end_byte) = marker_index
            .get(end_id.as_str())
            .with_context(|| format!("unknown end marker `{end_id}`"))?;

        if start_snippet != end_snippet {
            return Err(anyhow!(
                "markers `{start_id}` and `{end_id}` belong to different context snippets \
                 that are not contiguous excerpts of the same file"
            ));
        }
        if start_byte > end_byte {
            return Err(anyhow!(
                "start marker `{start_id}` must come before end marker `{end_id}`"
            ));
        }

        let old_text = snippets[start_snippet].text.as_ref();
        let old_span = &old_text[start_byte..end_byte];

        let cursor_in_span = raw_new_span.find(cursor_marker);
        let mut new_span = raw_new_span.replace(cursor_marker, "");
        if old_span.is_empty() {
            if !new_span.is_empty() && !new_span.ends_with('\n') {
                new_span.push('\n');
            }
        } else {
            if old_span.ends_with('\n') && !new_span.ends_with('\n') && !new_span.is_empty() {
                new_span.push('\n');
            }
            if !old_span.ends_with('\n') && new_span.ends_with('\n') {

View on GitHub (pinned to f4178619ac)

Solutions

  1. Retry the edit; the model emitted markers in the wrong order
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/zeta_prompt/src/hashed_regions.rs:683 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/d7d34473b4cc7324. Report an issue: GitHub.