Skip to content

fix(vision): the TrOCR and Florence-2 tiers get a Buffer image as a Blob - #229

Merged
jddunn merged 1 commit into
masterfrom
fix/vision-transformers-blob-input
Oct 10, 2026
Merged

jddunn merged 1 commit into
masterfrom
fix/vision-transformers-blob-input

Conversation

@jddunn

@jddunn jddunn commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

What this fixes

The handwriting (TrOCR) and document-layout (Florence-2) tiers failed on every image given as a Buffer.

VisionPipeline turned a Buffer into a data:image/png;base64,... string before handing it to the transformers.js image-to-text pipeline. In Node, transformers.js reads a string that is not an http:, https: or blob: URL as a file path. getFile in utils/hub.js takes the env.useFS branch, RawImage.fromURL gets a 404 and throws, and the tier fails.

This was reachable before, but it now hits every http(s) image the vision-pipeline pack handles. Since framerslab/agentos-extensions#105 the pack fetches the image itself through imageToBuffer(url, { untrusted: true }) and passes the bytes. The tool still returned success: true, with OCR-only text or a cloud tier's result in place of TrOCR's or Florence-2's.

A Buffer now goes in a Blob. The pipelines take string | RawImage | URL | Blob (pipelines.js, ImageInput), and RawImage.fromBlob decodes a Blob with sharp in Node (utils/image.js). A URL string goes as it is.

Found by a cold security read of #211 and agentos-extensions #105.

Tests

In VisionPipeline.test.ts, with the transformers.js pipeline factory mocked to record its input:

  • a handwritten image given as a Buffer reaches TrOCR as a non-empty Blob;
  • a document-layout image given as a Buffer reaches Florence-2 as a Blob, and one given as a URL reaches it as the same string.

A run against the real models would download them in CI, so the contract is pinned at the call into transformers.js.

Not in this change

The CLIP tier runs the text feature-extraction task, so it never sees an image. That limit is documented in VISION_PIPELINE.md and needs its own change: the image-feature-extraction task.

Summary by Sourcery

Ensure local image-to-text vision tiers receive image inputs in a format transformers.js can decode reliably.

Bug Fixes:

  • Fix TrOCR and Florence-2 vision tiers so Buffer images are processed successfully instead of being misinterpreted as file paths.
  • Preserve URL strings as URL inputs for the Florence-2 pipeline.

Enhancements:

  • Align vision pipeline image inputs with the supported transformers.js input types by converting Buffers to Blobs.

Tests:

  • Add coverage verifying that Buffer images reach TrOCR and Florence-2 as non-empty Blobs and URL images remain unchanged.

VisionPipeline handed transformers.js a Buffer as a data URL string. In
Node, transformers.js reads a string that is not an http(s) or blob: URL
as a file path (getFile in its utils/hub.js), so the handwriting and
document-layout tiers failed on every Buffer input. The vision-pipeline
pack now fetches http(s) images itself and passes the bytes, which made
those tiers fail for every image it handles. A Buffer now goes in a
Blob, which transformers.js decodes with sharp (RawImage.fromBlob); a
URL string goes as it is.
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 10, 2026 01:17
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 hours and 21 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes local TrOCR and Florence-2 failures for Buffer-backed images by passing Buffers as Blob objects, which transformers.js can decode in Node, while retaining URL strings unchanged; tests pin this boundary contract with mocked pipelines.

Sequence diagram for Blob-based vision pipeline inputs

sequenceDiagram
    participant VisionPipeline
    participant transformersImage
    participant TransformersJS

    VisionPipeline->>transformersImage: transformersImage(image)
    alt image is Buffer
        transformersImage->>transformersImage: bufferToBlobPart(image)
        transformersImage-->>VisionPipeline: Blob
    else image is URL string
        transformersImage-->>VisionPipeline: URL string
    end
    VisionPipeline->>TransformersJS: pipe(input)
    TransformersJS-->>VisionPipeline: generated output
Loading

File-Level Changes

Change Details Files
Convert in-memory image buffers to Blob inputs for transformers.js image-to-text pipelines while preserving URL strings.
  • Added a shared input-normalization helper that wraps Buffers in Blobs using the image buffer conversion utility.
  • Updated TrOCR and Florence-2 calls to use the normalized input instead of generating data URLs.
  • Kept string inputs unchanged so remote HTTP(S) URLs continue to be passed through directly.
src/io/vision/VisionPipeline.ts
Add regression coverage for the transformers.js input contract used by local vision tiers.
  • Verify TrOCR receives a non-empty Blob for Buffer images.
  • Verify Florence-2 receives a Blob for Buffer images and the original URL string for URL inputs.
  • Mock the pipeline factory to assert inputs without downloading or running real models.
src/io/vision/__tests__/VisionPipeline.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 38 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: e3e99fcf-3d52-415a-884c-6f2c8035b4c4

📥 Commits

Reviewing files that changed from the base of the PR and between c105869 and 1da4f0c.


📒 Files selected for processing (2)
  • src/io/vision/VisionPipeline.ts
  • src/io/vision/__tests__/VisionPipeline.test.ts


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Pass Buffer images as Blobs to TrOCR and Florence-2

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Fix TrOCR and Florence-2 failures caused by passing Buffer images as data URL strings.
• Preserve URL strings and test the inputs received by both transformers.js pipelines.
Diagram

graph TD
  A["Image input"] --> B{"Buffer input?"} -->|yes| C["Blob bytes"] --> G["Image-to-text pipeline"] -->|handwriting| E["TrOCR handwriting"]
  B -->|no| D["Original URL"] --> G
  G -->|document layout| F["Florence-2 layout"]
Loading
High-Level Assessment

Use the PR's shared Blob conversion: it matches the supported transformers.js input contract and fixes both tiers without changing URL handling. Constructing a RawImage directly would add model-library coupling without a clear benefit.

Files changed (2) +67 / -11

Bug fix (1) +15 / -11
VisionPipeline.tsConvert Buffer inputs to Blobs for image-to-text tiers +15/-11

Convert Buffer inputs to Blobs for image-to-text tiers

• Adds a shared input converter using the existing Buffer-to-Blob helper. TrOCR and Florence-2 now receive Blobs for Buffer images instead of data URL strings; URL strings remain unchanged.

src/io/vision/VisionPipeline.ts

Tests (1) +52 / -0
VisionPipeline.test.tsVerify TrOCR and Florence-2 receive supported image inputs +52/-0

Verify TrOCR and Florence-2 receive supported image inputs

• Adds mocked pipeline tests asserting that Buffer images reach both tiers as Blobs and that Florence-2 receives a URL string unchanged. The tests check the call contract without downloading models.

src/io/vision/tests/VisionPipeline.test.ts

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@jddunn
jddunn merged commit 7fe444a into master Oct 10, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 10, 2026
## [0.13.23](v0.13.22...v0.13.23) (2026-10-10)

### fix

* **gmi:** follow-ups from the reviews of #193 and #199 (#217) ([2bacb69](2bacb69))
* **gmi:** manager shutdown waits for creations in flight, bounds each GMI and runs once (#222) ([d99b126](d99b126))
* **images:** the untrusted fetch settles on a protocol upgrade, and four review follow-ups (#227) ([9efb4b5](9efb4b5))
* **vision:** the TrOCR and Florence-2 tiers get a Buffer image as a Blob (#229) ([7fe444a](7fe444a))
@jddunn
jddunn deleted the fix/vision-transformers-blob-input branch October 10, 2026 19:00
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