Repository navigation
fix(export): budget export filenames against the destination path, not just NAME_MAX (#2655) - #2656
abhay-codes07 wants to merge 1 commit into
Conversation
…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
|
@
I only have Windows to test on, so the POSIX claim is "output is unchanged by construction" (the helper returns early on |
There was a problem hiding this comment.
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).
|
Landed in v0.9.44, just published to PyPI. I cherry-picked this onto |
Fixes #2655.
Problem
graphify export obsidianandgraphify export wikiabort on Windows with an unhandledFileNotFoundErroras 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, andwiki._safe_filename'ss[:200]) is sized against the per-componentNAME_MAXof 255 bytes. On Windows the binding constraint is the whole path:MAX_PATHis 260 characters including the terminating NUL, andLongPathsEnabledis0on a default install.graphify-out\obsidianalone spends 21 of those characters, so a 200-byte stem overruns the ceiling under any ordinary checkout path: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 wikiis the more damaging of the two:AGENTS.mdtells assistants to navigategraphify-out/wiki/index.mdin 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:Returns
limituntouched on POSIX. On Windows it returns the smaller oflimitand whatever still fits insideMAX_PATHonce the destination directory, the separator, the caller'sreserveand.mdare accounted for. Extended-length (\\?\) destinations opt out. A floor keeps the budget from going negative —_cap_filenamewould otherwise slice with a negative index and silently emit a garbage stem.reservecovers the pieces callers append after capping: the_COMMUNITY_prefix on community notes, and the_1/_2collision suffixes from_dedup_node_filenames/_unique_slug.graphify/export.py—_obsidian_safe_stemtakes alimit;to_obsidianandto_canvasthread the budget through.to_canvasderives it from its own directory (which is the vault directory), because the CLI calls it without thenode_filenamesmap — otherwise every canvas card would point at a note thatto_obsidianwrote under a different name.graphify/wiki.py—_safe_filenametakes alimit;to_wikibudgets 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:
NAME_MAXbelow 255 (eCryptfs) viaos.pathconf(PC_NAME_MAX), which does not exist on Windows, and explicitly preserve the 200-byte behaviour on conventional filesystems. Different number, different platform. If fix: honor target filesystem filename limits #2118 lands first,limithere is the natural place for its computed value to arrive — the helper already takes it as a parameter.export.py/wiki.py.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 fakingos.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.pyand 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 off26128ab.Full suite, before → after:
47 failed, 4247 passed→44 failed, 4265 passed. Exactly the three pre-existingtest_obsidian_filename_cap.pyfailures are fixed, no new failures. (The remaining 44 are the unrelated pre-existing Windows failures — symlink privileges,os.geteuid, and friends.)All five
tools.skillgenvalidators pass (--check,--audit-coverage,--schema-singleton,--monolith-roundtrip,--always-on-roundtrip).End-to-end CLI, same corpus, before → after:
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.