Repository navigation
Validate document-image bytes before uploading to IT Glue - #16
Merged
Merged
Conversation
A colleague's itglue_create_document_image call failed with IT Glue's opaque "Validation failed. Paperclip::Errors::NotIdentifiedByImageMagickError". The content_base64 carried a valid PNG signature and IHDR (1100x321) but the body never arrived — the base64 was cut off in transit (or reconstructed by the assistant), and IT Glue's ImageMagick could not decode it. Sniff the bytes first: recognise PNG/JPEG/GIF/WebP/BMP/TIFF/SVG by magic bytes, check the container's end-of-image marker (IEND, FFD9, 0x3B, RIFF length, </svg>), and fail fast with a message that names the cause and points at url/file_path so the server reads the bytes itself. Attachments are not gated (they may be PDFs, configs, etc.). The tool description now also tells the model never to write base64 by hand. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A colleague's
itglue_create_document_imagecall (document 25040194,routing-diagram.png,content_base64) failed with IT Glue's opaque:Decoding the base64 from the screenshot: valid PNG signature and IHDR (1100×321, 8-bit palette), PLTE chunk starts — and then the body is missing. The base64 was cut off in transit (or reconstructed by the assistant), so IT Glue's ImageMagick could not decode it. Nothing in the error tells the model that.
Fix
sniffImage()insrc/tools/binary-input.tsidentifies PNG/JPEG/GIF/WebP/BMP/TIFF/SVG by magic bytes and checks each container's end-of-image marker (IEND,FF D9,0x3B, RIFF length,</svg>).assertRenderableImage()turns that into a clearUploadInputError: "truncated — header valid, end-of-image marker missing… use url / file_path" or "not a recognizable image… if the assistant wrote the base64 it is not a real image".itglue_create_document_imageruns it before calling IT Glue. Attachments are not gated (they may legitimately be PDFs, config exports, …).url/file_path.No behaviour change for valid uploads.
🤖 Generated with Claude Code