Skip to content

export obsidian: OSError ENAMETOOLONG on long node labels (to_obsidian lacks filename length cap that wiki.py has) #1094

Closed

Description

@felipeathayde

Summary

graphify export obsidian crashes with OSError: [Errno 63] File name too long when any node has a long label/identifier (~255+ bytes). Reproduced on v0.8.26 (latest) and v0.8.14.

Root cause

In graphify/export.py, to_obsidian writes each note with:

fname = node_filename[node_id] + ".md"
(out / fname).write_text("\n".join(lines), encoding="utf-8")  # export.py:927 in v0.8.26

node_filename[node_id] is derived from the node label without any length cap. When a node label is a long identifier (e.g. a generated symbol name, or a label sourced from a long string), fname exceeds the filesystem's 255-byte limit and write_text raises OSError [Errno 63].

By contrast, the wiki exporter already guards against this: graphify/wiki.py has _safe_filename(name) which returns s[:200] (caps length at 200 chars, see wiki.py:23). to_obsidian does not reuse this sanitizer.

Reproduce

  1. Create a source file containing a symbol with a ~300-char name (e.g. a very long function/class identifier).
  2. graphify update <dir>
  3. graphify export obsidian <out>
  4. Crash: OSError: [Errno 63] File name too long: '.../<300-char-name>().md'

Suggested fix

Reuse wiki.py's _safe_filename (or an equivalent length cap + de-dup) for the Obsidian filename, so to_obsidian truncates long names the same way the wiki exporter does.

Environment

  • graphify (PyPI graphifyy) v0.8.26 and v0.8.14
  • macOS (APFS, 255-byte filename limit)

Activity

  1. safishamsi commented on May 31, 2026

    @safishamsi
    Member

    Fixed in 690b4e5, shipping in the next release. Thanks for the precise diagnosis @felipeathayde - the wiki.py vs to_obsidian comparison made it easy to confirm.

    Fix

    Added a shared _cap_filename(s, limit=200) helper that both to_obsidian and to_canvas route their filenames through. Two things beyond a straight [:200] cap:

    1. Caps on UTF-8 bytes, not chars. The FS limit is 255 bytes, and a label of CJK/accented characters hits that well under 255 chars (200 CJK chars ≈ 600 bytes). A char cap would still crash on multibyte labels. The helper truncates on a byte boundary with decode(..., "ignore") so it never splits a multibyte char.

    2. Hash suffix on truncation. When a name is truncated it gets an 8-char sha1 of the full label appended, so two distinct labels sharing a long prefix produce distinct, deterministic filenames instead of silently overwriting each other.

    Two extra sites your report didn't mention (also fixed)

    • The _COMMUNITY_<name>.md overview notes were built with no dedup dict at all, so two long community names sharing a prefix could overwrite. The hash suffix fixes that too.
    • to_canvas has its own copy of the same safe_name builder with the same uncapped bug - now capped via the same helper.

    Wikilinks stay correct automatically because both the file write and the [[link]] read from the same node_filename dict.

    Tests

    Added tests/test_obsidian_filename_cap.py: 300-char ASCII, 300-char CJK (byte overflow), two distinct labels sharing a 200-char prefix (no collision), wikilink-resolves-after-truncation, and the canvas file-ref cap. Full suite green (1495 passed).

  2. added a commit that references this issue on May 31, 2026
    690b4e5
  3. added a commit that references this issue on Aug 13, 2026
    19ea76b
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