{"record":{"id":"1a9438c0d7d996fa","repo":"zed-industries/zed","slug":"start-marker-must-come-before-end-marker","errorCode":null,"errorMessage":"start marker must come before end marker","messagePattern":"start marker must come before end marker","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeta_prompt/src/multi_region.rs","lineNumber":401,"sourceCode":"pub fn apply_marker_span(old_editable: &str, output: &str) -> Result<String> {\n    let (start_num, end_num, raw_new_span) = extract_marker_span(output)?;\n    let marker_offsets = compute_marker_offsets(old_editable);\n\n    let start_idx = start_num\n        .checked_sub(1)\n        .context(\"marker numbers are 1-indexed\")?;\n    let end_idx = end_num\n        .checked_sub(1)\n        .context(\"marker numbers are 1-indexed\")?;\n    let start_byte = *marker_offsets\n        .get(start_idx)\n        .context(\"start marker number out of range\")?;\n    let end_byte = *marker_offsets\n        .get(end_idx)\n        .context(\"end marker number out of range\")?;\n\n    if start_byte > end_byte {\n        return Err(anyhow!(\"start marker must come before end marker\"));\n    }\n\n    let old_span = &old_editable[start_byte..end_byte];\n    let mut new_span = raw_new_span;\n    if old_span.ends_with('\\n') && !new_span.ends_with('\\n') && !new_span.is_empty() {\n        new_span.push('\\n');\n    }\n    if !old_span.ends_with('\\n') && new_span.ends_with('\\n') {\n        new_span.pop();\n    }\n\n    let mut result = String::new();\n    result.push_str(&old_editable[..start_byte]);\n    result.push_str(&new_span);\n    result.push_str(&old_editable[end_byte..]);\n\n    Ok(result)\n}","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/zeta_prompt/src/multi_region.rs#L383-L419","documentation":"The model's marker-tag output referenced a start marker number greater than the end marker number, so the computed replacement span would be reversed (end byte before start byte) in apply_marker_span. It fires when the parsed tag pair from the model output is internally inconsistent with the marker numbering of the old editable region.","triggerScenarios":"Thrown at crates/zeta_prompt/src/multi_region.rs:401 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reject the model output and re-request the edit so the model emits a valid ordered marker pair","Validate marker ordering before applying and surface the rejection to the retry/feedback loop","Log the raw output to diagnose systematic marker-ordering mistakes from the model"],"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"}