Skip to content

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

Open
gdccyuen wants to merge 1 commit into
Ontos-AI:mainfrom
gdccyuen:fix/gdccyuen/truncate-image-name-context
Open

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

Conversation

@gdccyuen

Copy link
Copy Markdown

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.
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.

1 participant