Skip to content

Windows PowerShell 5.1: Out-File -Encoding utf8 BOM in .graphify_python/.graphify_root breaks post-commit hook rebuild (WinError 123) #3028

Closed

Description

@card0re

Environment

  • OS: Windows 11 Pro
  • Shell: Windows PowerShell 5.1 (the shell the skill's own code blocks are written for)
  • graphify: 0.9.49 (CLI via pip install graphifyy, skill installed via graphify install)
  • Python: 3.14, plain pip-into-active-env install (not uv/pipx)

What happened

After running the full /graphify . pipeline once, I ran graphify hook install (post-commit + post-checkout) so the graph would auto-rebuild after future commits, per references/hooks.md.

The next git commit correctly triggered the hook ([graphify hook] launching background rebuild (log: ~/.cache/graphify-rebuild.log)), but the rebuild silently failed every time:

[graphify hook] 3 file(s) changed - rebuilding graph...
[graphify hook] Rebuild failed: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\ufeffC:\Users\<user>\...\graphify-out'

Note the \ufeff (UTF-8 BOM) prepended to the path — that's what WinError 123 is complaining about.

Root cause

SKILL.md Step 1 (the block every fresh /graphify <path> run executes) writes the two sidecar files the hook later reads:

$GRAPHIFY_PYTHON | Out-File -FilePath graphify-out\.graphify_python -Encoding utf8 -NoNewline
(Resolve-Path INPUT_PATH).Path | Out-File -FilePath graphify-out\.graphify_root -Encoding utf8 -NoNewline

(SKILL.md lines 120 and 122 in 0.9.49.)

Out-File -Encoding utf8 in Windows PowerShell 5.1 always emits a UTF-8 BOM (EF BB BF) — there is no BOM-less utf8 codepage on 5.1 (that only exists as utf8NoBOM starting in PowerShell 6+). -NoNewline suppresses the trailing newline but does nothing about the BOM.

So graphify-out/.graphify_python and graphify-out/.graphify_root end up as e.g. b'\xef\xbb\xbfC:\Python314\python.exe' instead of b'C:\Python314\python.exe'.

Whatever code path the hook uses to read .graphify_root (and hand it to Python's path/subprocess machinery) doesn't strip the BOM, so the leading \ufeff character rides along into a Windows path API and blows up with WinError 123.

This is nasty because it's silent from the user's perspective in the normal flow: graphify hook install reports success, hook status reports "installed", the hook visibly fires on every commit — but the rebuild itself fails every single time, so the graph silently goes stale forever unless someone thinks to check ~/.cache/graphify-rebuild.log. Anyone on plain Windows PowerShell 5.1 (i.e. anyone who didn't proactively install PowerShell 7) who follows the skill's own documented bootstrap hits this on the very first commit after hook install.

Fix I applied locally (works)

Rewrite both sidecar files without a BOM:

$pythonPath = (Get-Content graphify-out\.graphify_python -Raw).Trim()
$rootPath = (Get-Content graphify-out\.graphify_root -Raw).Trim()
[System.IO.File]::WriteAllText("graphify-out\.graphify_python", $pythonPath, [System.Text.UTF8Encoding]::new($false))
[System.IO.File]::WriteAllText("graphify-out\.graphify_root", $rootPath, [System.Text.UTF8Encoding]::new($false))

After that, graphify update . and the post-commit hook both rebuild cleanly.

Suggested upstream fix

Two independent, non-exclusive fixes — either alone closes this:

  1. Write without a BOM in the first place. In SKILL.md Step 1 (and anywhere else in the skill/CLI that writes .graphify_python / .graphify_root via PowerShell), swap Out-File -Encoding utf8 for either -Encoding utf8NoBOM (PS7+) with a version-gated fallback to [System.IO.File]::WriteAllText(path, content, [System.Text.UTF8Encoding]::new($false)) on 5.1, or just always use the [System.IO.File]::WriteAllText form directly — it's BOM-less on every PowerShell version and sidesteps the whole -Encoding footgun.
  2. Defense in depth on read. Wherever the Python side reads these two sidecar files (hook rebuild path resolution, graphify update's interpreter/root detection, etc.), .lstrip('\ufeff') the contents before using them as a path/interpreter string. Costs nothing and guards against any other BOM-writing code path (existing files from other editors, future regressions) that hits the same failure mode.

Happy to open a PR for #1 if useful — the fix is small and I already have it working locally.

Activity

  1. rohit-jsfreaky commented on Aug 25, 2026

    @rohit-jsfreaky
    Contributor

    Confirmed on Windows PowerShell 5.1.26100.9168. Ran both forms against the same interpreter path and diffed the bytes: Out-File -Encoding utf8 -NoNewline writes EF BB BF ahead of it (26 bytes), while WriteAllText with New-Object System.Text.UTF8Encoding $false writes 23 — no BOM, and still no trailing newline. The POSIX fragment already writes those same bytes with echo >.

    The read side is worth fixing too. All five readers (hooks.py ×2, watch.py, reflect.py, build.py) decode with utf-8, which keeps the BOM as U+FEFF, and str.strip() does not remove it — ''.isspace() is False. Rewriting the markers alone only helps fresh runs; decoding with utf-8-sig also repairs installs already in this state on their next commit, and is a no-op on a clean file.

    There is a quieter failure than WinError 123, too. In _infer_merge_root the BOM makes the recorded path stop being drive-qualified, so Path(recorded).resolve() treats it as relative and silently joins it onto the cwd — a wrong scan root with no error at all.

    Opening a PR that does both sides.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions