zed-industries/zed · error

edit span ` `..` ` looks truncated: the replacement stops…

Error message

edit span `{start_id}`..`{end_id}` looks truncated: the replacement stops before the end marker, which would silently delete:
{dropped}

What it means

Safety check in build_patch_from_spans: the replacement text stops before the end marker, so applying it would silently delete the trailing original content (`dropped`); the patch is rejected instead of losing code.

Solutions

  1. Retry so the model reproduces the full span up to the end marker
  2. Manually apply the intended edit
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

        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') {
                new_span.pop();
            }
        }

        if !new_span.is_empty()
            && let Some(dropped) = detect_trailing_deletion(old_span, &new_span)
        {
            return Err(anyhow!(
                "edit span `{start_id}`..`{end_id}` looks truncated: the replacement \
                 stops before the end marker, which would silently delete:\n{dropped}"
            ));
        }

        // `cursor_in_span` was located in `raw_new_span` before the trailing
        // newline normalization above, which can drop a byte. Clamp it to the
        // finalized replacement so the offset never points past `new_span`
        // (downstream cursor mapping byte-slices `new_text` by this offset).
        let cursor_offset_in_new_text = cursor_in_span.map(|offset| offset.min(new_span.len()));
        edits.push(ParsedSpanEdit {
            snippet_ix: start_snippet,
            range: start_byte..end_byte,
            new_text: new_span,
            cursor_offset_in_new_text,
        });
    }

View on GitHub (pinned to f4178619ac)