Domain: Automation, Cowork, Operations Verification: Repeatedly Verified (3+ occurrences) First observed: 2026-03-24 Last verified: 2026-03-26 Knowledge items: kc-2026-03-26-027 (code fences), kc-2026-03-24-001 (BOM/CRLF)
Warning
Pattern 1: BOM / CRLF
Symptoms
Cause pattern
# Dangerous: adds BOM
Set-Content -Path "file.md" -Value $content -Encoding UTF8
# Safe: no BOM
[System.IO.File]::WriteAllText($path, $content, [System.Text.UTF8Encoding]::new($false))
Reading BOM files (Python side) — use utf-8-sig
# Dangerous: BOM included as first character, JSON parsing fails
with open("task_routing.json", "r", encoding="utf-8") as f:
data = json.load(f)
# Safe: utf-8-sig automatically strips BOM
with open("task_routing.json", "r", encoding="utf-8-sig") as f:
data = json.load(f)
This pattern was the root cause of an actual production bug (ops_fix fix_20260325_220604_6428) in task_event_emit.py's _load_routing(). Fixed on 2026-03-26 per Orchestra P-01 proposal.
Pattern 2: Code Fence Wrapping (kc-2026-03-26-027)
Symptoms
Root cause
# Dangerous: actual file content ends up like this
```yaml
---
task_id: knowledge-curator
schedule: ...
---
# Knowledge Curator
...
``` ← closing code fence also at end of file
# Safe: frontmatter must start at the first line
---
task_id: knowledge-curator
...
Remedy
- Explicitly instruct the LLM: "Save SKILL.md file content without code fences"
- Validate before saving: check that the first line is
--- - Fix script: automatic code fence removal
# Detect and remove code fence wrapping
$content = Get-Content $skillPath -Raw
if ($content -match '^\s*```(yaml|markdown)?\s*\r?\n') {
# Remove first-line code fence
$content = $content -replace '^\s*```(yaml|markdown)?\s*\r?\n', ''
# Remove last code fence
$content = $content -replace '\r?\n\s*```\s*$', ''
[System.IO.File]::WriteAllText($skillPath, $content, [System.Text.UTF8Encoding]::new($false))
Write-Host "Code fence wrapping removed"
}
Actual occurrences (2026-03-26)
- "Fix ProjectPocket director skill format" session: director SKILL.md was wrapped in code fences, causing schedule task registration failure
- "Fix schedule format issues" session: same pattern recurred, resolved after removing code fences
Standard Remedy
Correct encoding baseline
- Writing: UTF-8 No BOM + LF (Unix line endings)
- Python reading:
encoding='utf-8-sig'(safe regardless of BOM presence) - First line: must be
---(YAML frontmatter start) - Applies equally to all 14 SKILL.md files
Diagnostic commands
# BOM check: if first 3 bytes are EF-BB-BF, BOM is present
$bytes = [System.IO.File]::ReadAllBytes($path)
$hasBOM = ($bytes[0] -eq 0xEF) -and ($bytes[1] -eq 0xBB) -and ($bytes[2] -eq 0xBF)
# Line ending check: 0D-0A means CRLF
# Code fence wrapping check: dangerous if first line starts with ```
Bulk verify all SKILL.md files
Get-ChildItem "~\AppData\Roaming\Claude\*.md" -Recurse | ForEach-Object {
$bytes = [System.IO.File]::ReadAllBytes($_.FullName)
$bom = ($bytes.Length -ge 3) -and ($bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF)
$firstLine = (Get-Content $_.FullName -TotalCount 1)
$codeFence = $firstLine -match '^\s*```'
[PSCustomObject]@{ File = $_.Name; BOM = $bom; CodeFence = $codeFence }
}
Safe writing (safe_skill_rw.ps1)
Use .\safe_skill_rw.ps1:
# Read
.\safe_skill_rw.ps1 -Mode read -Path $skillPath
# Write (automatically ensures UTF-8 No BOM + LF)
.\safe_skill_rw.ps1 -Mode write -Path $skillPath -Content $newContent
# Bulk verify
.\safe_skill_rw.ps1 -Mode bulk-verify -Path $skillDir
Affected Systems
- Cowork schedule app parser
- All schedule tasks that read EMIT_PROTOCOL.md
- All 14 SKILL.md files including the newly registered knowledge-curator
- All Python scripts that read BOM-containing JSON files (especially task_event_emit.py)
- All SKILL.md files generated/modified by LLMs
Preventive Measures (built 2026-03-25)
- Added "Encoding Safety Rules" section to EMIT_PROTOCOL.md — document read by all tasks before execution
- safe_skill_rw.ps1 helper — standard tool for SKILL.md read/write
- operational_fixes.jsonl — tracks BOM issues at critical severity
- Schedule creation skill updated — encoding safety rules auto-included when creating new schedules
- Use utf-8-sig for Python file opens (added 2026-03-26)
- Standardized LLM instructions — explicitly prohibit code fence wrapping (added 2026-03-26)
Evidence
- 2026-03-25: "Fix terminal loop environment with cmux" session — full remediation of CRLF/BOM mix across 14 files
- 2026-03-26: "Refactor and register consolidated schedules" session — encoding re-corrupted after path fix, restored
- 2026-03-26: "Execute approved orchestra system updates" session — task_event_emit.py
_load_routing()utf-8 to utf-8-sig fix (resolved production bug ops_fix fix_20260325_220604_6428) - 2026-03-26: "Fix ProjectPocket director skill format" session — parsing failure due to code fence wrapping
- 2026-03-26: "Fix schedule format issues" session — code fence wrapping recurrence and fix
- 2026-03-27: "Fix bootstrap sync schedule format" session — bootstrap-sync SKILL.md had markdown code fence + CRLF simultaneously. Both fixed and restored to normal. (kc-2026-03-28-003)
- User quote: "BOM again..." (frustration over repeated occurrence)