Skip to content

fix(export): honor the target filesystem's NAME_MAX in export filenames - #5315

Closed
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/export-filesystem-name-max
Closed

Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/export-filesystem-name-max

Conversation

@Synvoya

@Synvoya Synvoya commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #2109. Re-submission of #2118, rebased onto current v8 (340268a), which supersedes it.

Export filename capping assumes the conventional 255-byte NAME_MAX. eCryptfs (Ubuntu's "encrypt my home folder") reports PC_NAME_MAX=143 because of its filename-encryption overhead, so a 150-200 byte label still produces a name the filesystem rejects, and graphify export obsidian / export wiki abort with ENAMETOOLONG.

stem_filename_budget() (#2655) already sizes every Obsidian note, community note, canvas reference and wiki article stem against the destination, but returned limit unchanged on POSIX. It now also caps the budget at the destination filesystem's PC_NAME_MAX, less the caller's reserve and .md. When the export directory does not exist yet, it asks the nearest existing ancestor. If pathconf is unavailable or fails, the budget is unchanged. The Windows MAX_PATH branch is untouched.

Type of change

  • Bug fix

Verification & Invariants

Invariant: every file an exporter writes has a name the destination filesystem accepts, and links keep pointing at the files actually written. On ordinary filesystems (NAME_MAX 255) output is byte-for-byte unchanged: the largest caller reserve is 16 (_COMMUNITY_ plus the dedup suffix), so 255 - 16 - 3 = 236 is still above the 200 limit. This touches path handling, so I checked that the only new input is the pathconf result for the export directory or its ancestors; no new path is built from graph data.

Limitations:

How was this tested?

Python 3.11.16 on macOS, environment from uv sync --all-extras, branch based on v8 340268a.

pytest tests/test_export_path_length.py tests/test_obsidian_filename_cap.py tests/test_wiki.py
    # with the fix: 68 passed, 3 skipped
    # with graphify/ reverted: 5 failed (the low-NAME_MAX and nearest-ancestor tests); the unchanged-at-255 and pathconf-unavailable tests pass either way
pytest tests -q                        # v8: 11548 passed, 165 skipped, 1 xfailed; this branch: 11555 passed, same skips, 0 failed
ruff check .                           # All checks passed
pyright                                # 759 errors on v8 and on this branch; same set, none new (compared ignoring line numbers)

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill sources touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

AI disclosure: drafted with help from Claude Code and reviewed before posting; the commit carries a Co-Authored-By trailer.

The 200-byte stem cap from Graphify-Labs#1094 assumes the conventional 255-byte
NAME_MAX. eCryptfs (Ubuntu's "encrypt my home folder") reports 143
because of its filename-encryption overhead, so a 150-200 byte label
still produced a name the filesystem rejects and `graphify export
obsidian` / `export wiki` aborted with ENAMETOOLONG.

stem_filename_budget() already sizes every Obsidian, canvas and wiki
stem against the destination (Graphify-Labs#2655), but returned the limit unchanged
on POSIX. It now also caps the budget at the destination filesystem's
PC_NAME_MAX less the caller's reserve and the ".md" extension, asking
the nearest existing ancestor when the export directory does not exist
yet. At the conventional 255 the budget is still 200, so output on
ordinary filesystems is byte-for-byte unchanged.

Closes Graphify-Labs#2109

Co-Authored-By: Claude <[email protected]>
@Synvoya
Synvoya requested a review from safishamsi as a code owner November 18, 2026 13:59
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Synvoya. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@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 code review View in Graphify

Review completed · 2d33fc737d94

Warning

Merge confidence: 3/5 · Review before merging · 🟠 High impact
2 P2 bugs · 1 preexisting

The filename budget now consults POSIX PC_NAME_MAX in addition to the existing Windows path-length calculation.

Full summary

The filename budget now consults POSIX PC_NAME_MAX in addition to the existing Windows path-length calculation. Obsidian, Canvas, and wiki exports use that budget to cap generated filenames.

Bugs (2)

P2 · Cap the stem budget at the space left after the suffix and .md: stem_filename_budget can exceed a very small PC_NAME_MAX, so _safe_filename may generate an unwritable filename. Inspect source

Detailed review · checked against the code

Exports can exceed very small POSIX filename limits

On a filesystem reporting NAME_MAX below the budget floor, long labels can still produce filenames that are too long, aborting the export.

Expected: The generated filename component, including its extension and any reserved suffix, fits within the filesystem's component limit.
Actually: The minimum budget can exceed the available space, allowing an overlong filename that can make the export write fail.

On POSIX, when PC_NAME_MAX is available, stem_filename_budget returns at least 16 even if name_max - reserve - len(".md") is smaller. For a limit of 14 and reserve of 5, that produces a 16-byte stem budget, although only 6 bytes remain for the stem. The wiki exporter passes that budget to _safe_filename, appends .md, and writes the resulting filename. A long ASCII label can therefore yield a 19-byte component on a filesystem limited to 14 bytes, causing the write to fail. The previous POSIX implementation returned limit without deriving a budget from PC_NAME_MAX; the faulty floor is introduced by this change.

  • Independent source review: The existing low-NAME_MAX test uses 143 bytes and verifies the budget fits there; it does not cover values below the 16-byte floor plus reserve and extension. The wiki caller uses the computed limit directly when slugging and writing article filenames; no smaller-component guard appears in the inspected route.

P2 · Truncate slugs by UTF-8 byte length in _safe_filename: stem_filename_budget is a byte allowance, but character slicing lets multibyte wiki article names exceed PC_NAME_MAX and fail on write. Inspect source

Detailed review · checked against the code

Non-ASCII wiki names can still exceed the filesystem limit

On filesystems with a low NAME_MAX, exporting a wiki with non-ASCII labels can still fail when article files are written.

Expected: Every article filename, including its extension and any collision suffix, fits within the filesystem's component-byte limit.
Actually: The POSIX byte budget is used as a character slice limit; multibyte characters can make the resulting filename exceed the limit and cause an article write to fail.

On POSIX, stem_filename_budget computes a byte allowance from PC_NAME_MAX and subtracts the reserved suffix and .md extension. to_wiki passes that number to _safe_filename, which slices by Python characters. With NAME_MAX=143, reserve 5, and a label whose slug has at least 135 three-byte UTF-8 characters, the resulting filename can exceed the byte limit and fail when written. The path reaches article writes for both community and god-node slugs. The behavior is a bounded wiki-export failure under low component limits and sufficiently long multibyte labels.

  • Independent source review: The multibyte wiki test uses CJK labels, but replaces the budget function with a fixed value and asserts character length and link resolution—not encoded filename byte length. It therefore does not prevent the reported overrun. Base source also returned a 200-character POSIX budget, so long multibyte labels on low-NAME_MAX filesystems could already exceed the byte limit before this change; the new calculation reduces but does not eliminate that case.

  • Also reported as: Wiki filenames can still exceed a low byte limit for Unicode labels

Code graph and static checks · 5068 functions depend on this change

Impact & health

Impact — 5068 functions depend on the 237 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: to_obsidian() — 44 callers, 14 callees
  • worse: to_wiki() — 58 callers, 8 callees
  • worse: to_canvas() — 21 callers, 5 callees

Formal checks — 5068 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

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

Advisory (not blocking):

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

Test selection

219 of 593 test file(s) selected (37%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact
  • tests/test_affected_cli.py — impact
  • tests/test_affected_overrides.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_affected_seed_reference_forms.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_alias_folding.py — impact
  • tests/test_analyze.py — impact
  • tests/test_atomic_canvas_export.py — impact
  • tests/test_atomic_version_stamp.py — impact
  • tests/test_atomic_writes.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_binary_media_words.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_ghost_fold_4955.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_callflow_html.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_claude_md.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cluster.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_community_labels_skill.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cpp_forward_declarations.py — impact
  • tests/test_cpp_member_declaration_identity.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_csharp_method_owner_labels.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dedup.py — impact
  • tests/test_dedup_prefix_derived_words.py — impact
  • tests/test_dedup_remaps_hyperedges.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • … and 169 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Every flagged function

  • to_wiki() in graphify/wiki.py:306 · 58 callers, 8 callees: fans out to 8 callees (efferent coupling); 58 callers depend on it (afferent coupling)
  • to_obsidian() in graphify/export.py:847 · 44 callers, 14 callees: fans out to 14 callees (efferent coupling); 44 callers depend on it (afferent coupling)
  • to_canvas() in graphify/export.py:1210 · 21 callers, 5 callees: 21 callers depend on it (afferent coupling)

safishamsi added a commit that referenced this pull request Nov 23, 2026
Maintainer tweaks on top of the #5299/#5394/#5315/#5374 batch:
- Move `import anyio` in serve.py to module top (was re-imported per call
  inside _warm_graph), a trivial cleanup on #5374.
- 0.9.117 changelog and version bump. No AST-cache schema change in this
  batch (query scoring, export filenames, serve reload, rcfile parsing).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.118 via an authorship-preserving cherry-pick. Export filenames now honor the target filesystem's NAME_MAX (probed via pathconf), so export no longer aborts with ENAMETOOLONG on filesystems like eCryptfs that report 143; long names are truncated with a hash suffix and internal links use the shortened names. Thanks @Synvoya!

@safishamsi safishamsi closed this Nov 23, 2026
Synvoya added a commit to Synvoya/graphify that referenced this pull request Nov 26, 2026
Follow-up to Graphify-Labs#5315. stem_filename_budget() returns a byte budget on
POSIX, but two paths still overran it:

- Where NAME_MAX leaves less room than the 16-byte floor after the
  reserve and ".md", the floor won and produced a name the filesystem
  rejects. The budget now drops to what fits, and _cap_filename keeps
  what fits when there is no room for its "_" + 8-hex digest instead of
  slicing with a negative index.
- wiki._safe_filename sliced characters, so a CJK label could exceed a
  byte-based NAME_MAX. It now caps UTF-8 bytes, as _cap_filename already
  does for Obsidian (Graphify-Labs#1094).

Co-Authored-By: Claude <[email protected]>
safishamsi pushed a commit that referenced this pull request Nov 28, 2026
Follow-up to #5315. stem_filename_budget() returns a byte budget on
POSIX, but two paths still overran it:

- Where NAME_MAX leaves less room than the 16-byte floor after the
  reserve and ".md", the floor won and produced a name the filesystem
  rejects. The budget now drops to what fits, and _cap_filename keeps
  what fits when there is no room for its "_" + 8-hex digest instead of
  slicing with a negative index.
- wiki._safe_filename sliced characters, so a CJK label could exceed a
  byte-based NAME_MAX. It now caps UTF-8 bytes, as _cap_filename already
  does for Obsidian (#1094).

Co-Authored-By: Claude <[email protected]>
(cherry picked from commit ffc921c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_cap_filename's hardcoded limit=200 assumes NAME_MAX=255; breaks on eCryptfs (real limit can be ~143 bytes)

2 participants