Aggressive multi-pattern sed -i '/X/d; /Y/d; /Z/d' scrub on script/config files deletes adjacent code that legitimately contains pattern strings (in comments, variable names, log messages). bash -n syntax check passes (false-positive); runtime fails with unbound variable or similar semantic error. Cumulative deletion can cascade across section boundaries — variable initializations and section_start lines disappear silently.

Diagnosis

Line-level sed delete is content-blind. When multiple patterns match within a contiguous code section (e.g., section header comment + variable init line both contain “paperclip” — header explicitly, init via “exclude paperclip” comment), all matching lines get nuked, severing dependencies. bash -n only validates syntax, not runtime semantics. Markdown/prose tolerates this pattern; code does not.

Fix

NEVER use multi-pattern sed -i '/PATTERN/d' on scripts/configs/code. (1) Restore from git: git checkout HEAD -- file. (2) Replace with surgical Python regex using bounded multi-line matches: re.sub(r'# ═{50,}\n# 3\. SECTION_NAME[^\n]*\n# ═{50,}\nsection_start "..."\n.*?section_done "..."\n\n', '', content, count=1, flags=re.DOTALL). (3) Run BOTH bash -n (syntax) AND bash <script> (runtime semantic check). Both must pass. For markdown/prose, sed-line-delete remains acceptable.