Skip to content

fix(io): sniff BOM before plain UTF-8 so SKILL.md files with a BOM load#869

Open
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/skill-bom
Open

fix(io): sniff BOM before plain UTF-8 so SKILL.md files with a BOM load#869
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/skill-bom

Conversation

@abhay-codes07

Copy link
Copy Markdown

Fixes #701

A SKILL.md saved with a UTF-8 BOM (common when editing on Windows, Notepad and some editors add it silently) is reported as invalid with "Missing or invalid YAML frontmatter" even though the file looks perfectly fine.

Root cause: decode_safe tries plain utf-8 before sniffing the BOM. A UTF-8 BOM file decodes successfully as utf-8, so the BOM survives as U+FEFF at the start of the returned text. The frontmatter splitter then sees --- instead of --- on the first line and rejects the file (str.strip() does not remove U+FEFF, it is not whitespace).

Fix: try the BOM-derived codec first. For these files the codec is now utf-8-sig, which strips the marker. Round-trip writes stay byte-identical because the edit path reuses the reported encoding, so the BOM is preserved on write. The utf-16/32 BOM cases behave exactly as before since plain utf-8 decoding already failed on those.

This also fixes the same silent failure for any other file read through read_safe, AGENTS.md included.

Testing:

  • New io test asserting utf-8-sig is reported and the BOM is stripped
  • New manager test loading a BOM SKILL.md end to end
  • Existing utf-16 encoding tests unchanged and passing, ruff and pyright clean

@michelTho tagging you for review when you have a moment.

A SKILL.md saved with a UTF-8 BOM decodes successfully as plain utf-8,
which leaves U+FEFF at the start of the returned text. The frontmatter
parser then rejects the file because the leading boundary no longer
matches, so the skill is reported as invalid. Trying the BOM-derived
codec first returns utf-8-sig for these files, stripping the marker
while keeping round-trip writes byte-identical via the reported
encoding.

Fixes mistralai#701
@abhay-codes07
abhay-codes07 requested a review from a team as a code owner July 2, 2026 19:34
Copilot AI review requested due to automatic review settings July 2, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: SKILL.md files encoded with utf BOM considered invalid

2 participants