Skip to content

export obsidian / export wiki abort on Windows: the filename cap is sized for NAME_MAX and ignores MAX_PATH, so one long label kills the whole export #2655

Closed

Description

@abhay-codes07

Summary

graphify export obsidian and graphify export wiki abort with an unhandled FileNotFoundError on Windows as soon as one node label is long enough to reach the filename cap. The export dies partway through, leaving a half-written vault (some notes present, the rest missing) and a non-zero exit with a raw traceback.

The cap added in #1094 (export._cap_filename, 200 bytes) is sized against the per-component NAME_MAX of 255 bytes. That is the correct constraint on POSIX and the wrong one on Windows, where the limit applies to the whole path: legacy MAX_PATH is 260 characters including the terminating NUL, and HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled is 0 on a default install. So a 200-byte stem under a perfectly ordinary output directory overruns the ceiling before the filesystem's per-component limit is anywhere near.

sanitize_label() caps labels at 256 characters (security._MAX_LABEL_LEN), so labels in this range are expected by design — they come out of the semantic pass over docs/PDFs routinely.

Reproduction

Windows 11, Python 3.12, v8 @ 26128ab, default LongPathsEnabled=0.

The project lives at C:\Users\abhay\AppData\Local\Temp\gx\payments-api (49 chars — shorter than a typical real checkout), and graph.json contains one document node whose label is 207 characters:

> graphify export obsidian .
Traceback (most recent call last):
  ...
  File "C:\graphify\graphify\cli.py", line 2667, in dispatch_command
    n = _to_obsidian(G, communities, str(obsidian_dir),
  File "C:\graphify\graphify\export.py", line 642, in to_obsidian
    if _owned_write(fname, "\n".join(lines)):
  File "C:\graphify\graphify\export.py", line 560, in _owned_write
    target.write_text(content, encoding="utf-8")
FileNotFoundError: [Errno 2] No such file or directory: 'graphify-out\\obsidian\\Consolidating the payment reconciliation ledger into a single append-only settlement journal so that replayed provider webhooks always keep their original ordering for downstream audit and di_89c6113a.md'

export wiki fails the same way, and sooner — graphify-out\wiki\ is written by wiki._safe_filename, which caps at 200 characters with no hash suffix:

> graphify export wiki .
  File "C:\graphify\graphify\wiki.py", line 328, in to_wiki
    (out / f"{slug}.md").write_text(article, encoding="utf-8")
FileNotFoundError: [Errno 2] No such file or directory: 'graphify-out\\wiki\\Consolidating_the_payment_reconciliation_ledger_into_a_single_append-only_settlement_journal_so_that_replayed_provider_webhooks_always_keep_their_original_ordering_for_downstream_audit_and_dispute_res.md'

This also reproduces without any corpus at all — three of the repo's own regression tests fail on Windows for exactly this reason on a clean v8 checkout:

> uv run --frozen pytest tests/test_obsidian_filename_cap.py -q
FAILED tests/test_obsidian_filename_cap.py::test_obsidian_long_ascii_label_does_not_crash
FAILED tests/test_obsidian_filename_cap.py::test_obsidian_distinct_long_labels_sharing_prefix_do_not_collide
FAILED tests/test_obsidian_filename_cap.py::test_obsidian_wikilink_resolves_after_truncation
3 failed, 2 passed

Root cause

export._cap_filename(s, limit=200) and wiki._safe_filename(name) both treat 200 as a constant. Neither knows where the file is about to be written, so the destination directory contributes an unbounded amount to a bounded budget:

len("C:\\Users\\me\\projects\\payments-api\\graphify-out\\obsidian")  #  55
+ len("\\")                                                          #   1
+ 200                                                                # stem
+ len("_1")                                                          # dedup suffix
+ len(".md")                                                         #   3
= 261  >  259 usable MAX_PATH characters

The graphify-out\obsidian / graphify-out\wiki suffix alone is 21/17 characters, so the headroom left for the user's own checkout path is about 34 characters. C:\Users\<name>\Documents\<repo> exhausts that on its own.

export wiki is the more damaging of the two: AGENTS.md tells assistants to navigate graphify-out/wiki/index.md in preference to raw files, so on Windows that entry point simply never gets written for any graph containing one long label.

Why the open issues don't already cover this

Suggested fix

Derive the stem cap from the destination directory instead of hardcoding it, and reserve room for the pieces callers append after the cap (_COMMUNITY_ prefix, _1/_2 collision suffixes, .md). POSIX keeps returning 200 unchanged, so existing vaults stay byte-for-byte stable and #2109's separate NAME_MAX question is untouched.

Capping is preferable to writing through \\?\ extended-length paths here: the output is meant to be opened by Obsidian, Explorer and other editors, and handing those a 300-character path just moves the failure downstream to the tools the user actually opens the vault with.

I have this working locally with regression coverage and will open a PR against v8 shortly.

Environment

OS Windows 11 Home Single Language 26200, LongPathsEnabled=0 (default)
Python 3.12 (and 3.10)
graphify v8 @ 26128ab (0.9.40)

Activity

  1. abhay-codes07 commented on Aug 11, 2026

    @abhay-codes07
    ContributorAuthor

    Opened #2656 with the fix and regression coverage.

  2. safishamsi commented on Aug 15, 2026

    @safishamsi
    Member

    Fixed in v0.9.44 (on PyPI now) via #2656, thanks @abhay-codes07. Closing.

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