Skip to content

fix(export): budget export filenames against the destination path, not just NAME_MAX (#2655) - #2656

Closed
abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/export-filename-max-path
Closed

abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/export-filename-max-path

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

Fixes #2655.

Problem

graphify export obsidian and graphify export wiki abort on Windows with an unhandled FileNotFoundError as soon as one node label is long enough to reach the filename cap. The export dies partway through and leaves a half-written vault.

The 200-byte cap from #1094 (export._cap_filename, and wiki._safe_filename's s[:200]) is sized against the per-component NAME_MAX of 255 bytes. On Windows the binding constraint is the whole path: MAX_PATH is 260 characters including the terminating NUL, and LongPathsEnabled is 0 on a default install. graphify-out\obsidian alone spends 21 of those characters, so a 200-byte stem overruns the ceiling under any ordinary checkout path:

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

Labels in this range are expected by design — security.sanitize_label() caps at 256 characters, and the semantic pass over docs/PDFs produces them routinely.

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 is simply never written for any graph containing one long label.

Change

graphify/paths.py — new shared helper:

stem_filename_budget(output_dir, *, reserve=0, limit=200) -> int

Returns limit untouched on POSIX. On Windows it returns the smaller of limit and whatever still fits inside MAX_PATH once the destination directory, the separator, the caller's reserve and .md are accounted for. Extended-length (\\?\) destinations opt out. A floor keeps the budget from going negative — _cap_filename would otherwise slice with a negative index and silently emit a garbage stem.

reserve covers the pieces callers append after capping: the _COMMUNITY_ prefix on community notes, and the _1/_2 collision suffixes from _dedup_node_filenames / _unique_slug.

graphify/export.py — _obsidian_safe_stem takes a limit; to_obsidian and to_canvas thread the budget through. to_canvas derives it from its own directory (which is the vault directory), because the CLI calls it without the node_filenames map — otherwise every canvas card would point at a note that to_obsidian wrote under a different name.

graphify/wiki.py — _safe_filename takes a limit; to_wiki budgets against the wiki directory.

Capping rather than writing through \\?\ extended-length paths is deliberate: 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 tool the user actually opens the vault with.

Scope

This is complementary to, and does not collide with, the other path-length work in flight:

Regression coverage

tests/test_export_path_length.py, 15 tests. CI runs Ubuntu only, so the suite is written to have teeth there rather than skipping: the budget math is exercised by faking os.name, and the exporters' wiring is exercised by forcing a small budget and asserting that wikilinks and canvas card refs still resolve to files that exist. Three end-to-end tests are Windows-gated.

Reverting graphify/export.py + graphify/wiki.py and keeping the tests fails 9 of the 15, 6 of which run on the Linux runners.

Validation

Windows 11 (LongPathsEnabled=0), Python 3.12, branched off 26128ab.

Full suite, before → after: 47 failed, 4247 passed → 44 failed, 4265 passed. Exactly the three pre-existing test_obsidian_filename_cap.py failures are fixed, no new failures. (The remaining 44 are the unrelated pre-existing Windows failures — symlink privileges, os.geteuid, and friends.)

=== FIXED by this change ===
tests/test_obsidian_filename_cap.py::test_obsidian_distinct_long_labels_sharing_prefix_do_not_collide
tests/test_obsidian_filename_cap.py::test_obsidian_long_ascii_label_does_not_crash
tests/test_obsidian_filename_cap.py::test_obsidian_wikilink_resolves_after_truncation
=== NEW failures introduced ===
(none)

All five tools.skillgen validators pass (--check, --audit-coverage, --schema-singleton, --monolith-roundtrip, --always-on-roundtrip).

End-to-end CLI, same corpus, before → after:

> graphify export obsidian .
FileNotFoundError: [Errno 2] No such file or directory: 'graphify-out\obsidian\Consolidating the payment...di_89c6113a.md'
> graphify export wiki .
FileNotFoundError: [Errno 2] No such file or directory: 'graphify-out\wiki\Consolidating_the_payment...dispute_res.md'
> graphify export obsidian .
Obsidian vault: 4 notes in graphify-out\obsidian/
Canvas: graphify-out\obsidian/graph.canvas
> graphify export wiki .
Wiki: 2 articles written to graphify-out/wiki/

with no dangling wikilinks and no canvas cards pointing at missing notes.

No churn on normal graphs. Exported graphify's own package (2249 nodes, 4497 edges, 151 communities → 2400 notes + 161 wiki articles) with and without the patch: the exported filename sets are identical, and the canvas resolves cleanly both times. The budget only bites when a label would otherwise have overrun.

…t just NAME_MAX

`graphify export obsidian` and `graphify export wiki` abort on Windows with
an unhandled FileNotFoundError as soon as one node label reaches the filename
cap, leaving a half-written vault.

The 200-byte cap from Graphify-Labs#1094 is sized against the per-component NAME_MAX of
255 bytes. On Windows the binding constraint is the WHOLE path: MAX_PATH is
260 characters including the terminating NUL, and LongPathsEnabled is 0 by
default. `graphify-out\obsidian` alone spends 21 of those characters, so a
200-byte stem overruns the ceiling under any ordinary checkout path.

Add paths.stem_filename_budget(output_dir, *, reserve, limit=200), which
returns `limit` untouched on POSIX and otherwise shrinks it to what still
fits inside MAX_PATH once the destination directory, the separator, the
caller reserve (the `_COMMUNITY_` prefix and `_1`/`_2` collision suffixes
appended after capping) and `.md` are accounted for. Thread it through
to_obsidian, to_canvas and to_wiki; to_canvas derives the same budget from
its own directory so cards keep resolving to the notes to_obsidian wrote.

Capping rather than writing through `\\?\` extended-length paths is
deliberate: the output is opened by Obsidian and other editors, so emitting
a 300-character path would just move the failure to the tool the user
actually opens the vault with.

POSIX output is unchanged. On a real 2249-node graph the exported filename
set is identical before and after.

Fixes Graphify-Labs#2655
Copilot AI lite review requested due to automatic review settings August 11, 2026 21:38

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.

@abhay-codes07

Copy link
Copy Markdown
Contributor Author

@
@safishamsi whenever you have a moment. Two things worth flagging so this does not step on anything:

  • It does not overlap fix: honor target filesystem filename limits #2118. That one lowers the cap when NAME_MAX is below 255 on POSIX; this one lowers it when the destination directory eats the Windows MAX_PATH window. The two limits compose — stem_filename_budget already takes limit as a parameter, so if fix: honor target filesystem filename limits #2118 lands first its computed value drops straight in and I will rebase.
  • I kept wiki.py in the same PR because it fails identically and the fix is the same three lines, but happy to split it out if you would rather review them separately.

I only have Windows to test on, so the POSIX claim is "output is unchanged by construction" (the helper returns early on os.name != "nt") plus the identical-filename check on a 2249-node export, rather than something I ran on Linux myself. Worth a second pair of eyes there.
@

@graphify-labs graphify-labs Bot 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.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. 3 change(s) tested, no difference found (not proven).


Graphify review — findings

This PR introduces a new stem_filename_budget helper in graphify/paths.py intended to compute a filename-stem length cap based on the destination directory path rather than only the per-component NAME_MAX limit, with the stated goal of avoiding Windows MAX_PATH overruns (#2655). The change threads a configurable limit parameter into the filename-sanitizing functions across the Obsidian, canvas, and wiki exporters (_obsidian_safe_stem, _safe_filename, and related dedup/community paths), so each export computes its budget against its own output directory. It also adds a new test file, tests/test_export_path_length.py, exercising the wiki, obsidian, and canvas export path-length behavior. Reviewers should focus on the exporter call sites in export.py/wiki.py and the new paths.py helper as the primary surface area.

Worth a look

  • _MIN_STEM_BUDGET floor can violate MAX_PATH for deep directories — graphify/paths.py:386 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1450 functions depend on the 102 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: to_obsidian() — 29 callers, 12 callees
  • worse: to_wiki() — 36 callers, 7 callees
  • worse: to_canvas() — 17 callers, 4 callees

Verification — 1450 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 970 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_obsidian\_safe\_stem (not a proof).

The verifier ran both versions of \_obsidian\_safe\_stem on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in to\_canvas (not a proof).

The verifier ran both versions of to\_canvas on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify to\_obsidian.

The verifier did not have enough to check to\_obsidian, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

No difference found (not proven): No behavior difference found in \_safe\_filename (not a proof).

The verifier ran both versions of \_safe\_filename on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify to\_wiki.

The verifier did not have enough to check to\_wiki, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `output_dir` is annotated `str | Path` — outside the synthesizable primitive/collection set

· 3 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.44, just published to PyPI. I cherry-picked this onto v8 with your authorship preserved in the commit, so both the change and the credit are in the history. Thanks @abhay-codes07 for the fix. Closing since it is now released.

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.

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

3 participants