{"record":{"id":"15c2bbcb139beb11","repo":"gitbutlerapp/gitbutler","slug":"found-only-the-gitbutler-managed-block-end-marker-refusing","errorCode":null,"errorMessage":"Found only the GitButler managed block end marker. Refusing to edit a partial managed block.","messagePattern":"Found only the GitButler managed block end marker\\. Refusing to edit a partial managed block\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/agent/files.rs","lineNumber":106,"sourceCode":"fn match_line_endings(existing: &str, block: &str) -> String {\n    if existing.contains(\"\\r\\n\") {\n        block.replace(\"\\r\\n\", \"\\n\").replace('\\n', \"\\r\\n\")\n    } else {\n        block.to_string()\n    }\n}\n\npub(super) fn upsert_managed_block(existing: &str, block: &str) -> Result<String> {\n    let start = find_line_anchored(existing, MANAGED_BLOCK_START, 0);\n    let end = find_line_anchored(existing, MANAGED_BLOCK_END, 0);\n\n    match (start, end) {\n        // No managed block yet: append a fresh one.\n        (None, None) => return Ok(append_managed_block(existing, block)),\n        (Some(_), None) => anyhow::bail!(\n            \"Found only the GitButler managed block start marker. Refusing to edit a partial managed block.\"\n        ),\n        (None, Some(_)) => anyhow::bail!(\n            \"Found only the GitButler managed block end marker. Refusing to edit a partial managed block.\"\n        ),\n        (Some(start), Some(end)) if end < start => anyhow::bail!(\n            \"Found GitButler managed block markers in the wrong order (end before start). Refusing to edit a malformed managed block.\"\n        ),\n        // Well-formed: a start marker with an end after it. Fall through to replace.\n        (Some(_), Some(_)) => {}\n    }\n\n    // Replace the first block with the fresh one and drop any extra blocks\n    // (e.g. left over from an earlier buggy run), so the file converges to\n    // exactly one block.\n    let mut spans = Vec::new();\n    for span in managed_block_spans(existing)? {\n        let mut block_end = span.end;\n        if existing[block_end..].starts_with(\"\\r\\n\") {\n            block_end += 2;\n        } else if existing[block_end..].starts_with('\\n') {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/agent/files.rs#L88-L124","documentation":"The mirror case of the partial-start-marker error: only the end marker of the GitButler managed block was found. Since a well-formed block requires start-then-end, the tool refuses to upsert to avoid corrupting surrounding user content.","triggerScenarios":"upsert_managed_block finds MANAGED_BLOCK_END with no preceding MANAGED_BLOCK_START — e.g. the user deleted the start marker line, or an automated edit truncated the block header.","commonSituations":"Manual cleanup of instruction files that removed the header comment; linters/formatters stripping the start marker line; merge conflict resolution keeping only the tail.","solutions":["Re-add the GitButler managed block start marker above the end marker.","Or remove the orphaned end marker so a complete fresh block can be appended.","Re-run the upsert once the markers are balanced."],"exampleFix":"// before\n...content...\n<!-- GITBUTLER-MANAGED-BLOCK:END -->\n// after\n<!-- GITBUTLER-MANAGED-BLOCK:START -->\n...content...\n<!-- GITBUTLER-MANAGED-BLOCK:END -->","handlingStrategy":"validation","validationCode":"const content = fs.readFileSync(file, 'utf8');\nconst startIdx = content.indexOf('GITBUTLER-MANAGED-BLOCK:START');\nconst endIdx = content.indexOf('GITBUTLER-MANAGED-BLOCK:END');\nif (endIdx !== -1 && startIdx === -1) throw new Error(`Orphaned end marker in ${file}; re-add the start marker`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Delete the entire managed block (both markers) rather than individual lines.","Verify marker balance after any automated rewrite of the file.","Keep managed-block edits flowing through `but agent` commands only."],"tags":["gitbutler","managed-block","file-editing","cli"],"backgroundTag":"invalid-state-transition","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}