Skip to content

fix: truncate markdown image name context to prevent OS filename limit - #236

Merged
EricNGOntos merged 1 commit into
Ontos-AI:mainfrom
gdccyuen:fix/gdccyuen/truncate-image-name-context
Aug 3, 2026
Merged

fix: truncate markdown image name context to prevent OS filename limit#236
EricNGOntos merged 1 commit into
Ontos-AI:mainfrom
gdccyuen:fix/gdccyuen/truncate-image-name-context

Conversation

@gdccyuen

Copy link
Copy Markdown
Contributor

What

When last_context (the markdown text preceding an image) is very long, the generated image filename exceeds the OS 255-byte limit, causing os.rename to fail with OSError: [Errno 36] File name too long.

Error

OSError: [Errno 36] File name too long:
'/tmp/.../images/a68d4c...jpg' ->
'/tmp/.../images/image-1-## 5. How to determine whether an application falls within or beyond the _$500,000 threshold For EE A, whose employment contract is terminated by 1-month notice ending on 30 April 2025, the relevant date of termination of employment falls on 30 April 2025...jpg'

Fix

Truncate image_name_context to 60 characters after sanitization in build_markdown_image_name(). The context is cosmetic (used in the filename for debuggability), so truncation has no functional impact.

Verification

Tested end-to-end with a 44-page PDF that triggered the original error — parsing succeeds after this fix.

When last_context (the preceding markdown text) is very long, the
generated image filename exceeds the OS 255-byte limit and os.rename
fails with OSError ENAMETOOLONG. Truncate to 60 chars after sanitization.

@EricNGOntos EricNGOntos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — real filename-too-long fix; context is cosmetic. Follow-up will unify the truncate length with table asset naming (80).

@EricNGOntos
EricNGOntos merged commit abcb0e3 into Ontos-AI:main Aug 3, 2026
6 checks passed
EricNGOntos added a commit that referenced this pull request Aug 3, 2026
* fix: share one 80-char cap for image and table asset filenames

Unify the post-#236 image context truncate with table header naming so
cosmetic asset stems use a single MAX_ASSET_FILE_NAME_CHARS constant.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: handle None from path_handle before truncating image titles

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants