Repository navigation
fix: pin sharp to 0.35.4 in ai-image-generator [AIS-610] - #11310
Open
Jared Jolton (jjolton-contentful) wants to merge 2 commits into
Open
Jared Jolton (jjolton-contentful) wants to merge 2 commits into
Jared Jolton (jjolton-contentful) wants to merge 2 commits into
Conversation
The AI Image Generator pipes caller-supplied image and mask URLs into sharp, so it needs libheif 1.23.2 (GHSA-rgj7-g3m4-5g8c). Upgrade sharp to 0.35.4, which bundles libvips 1.3.3 / libheif 1.23.2. The build force-installs the Linux binaries separately from the declared range, which previously resolved @img/sharp-linux-x64 and @img/sharp-libvips-linux-x64 to latest while sharp itself stayed within ^0.33.0. npm then nested the matching 0.33.5 / 1.0.4 pair under sharp/node_modules, and Node resolved those first, so the deployed bundle ran libheif 1.18.2 and shipped both copies of libvips. Pin all three to exact, matching versions. 0.35 replaced sharp's color* dependency chain with @img/colour, which bundle-sharp.js did not copy: bumping the range alone produces a bundle that fails to load with "Cannot find module '@img/colour'". Drive the copy from an explicit module list that fails loudly when an expected module is absent. 0.35 also removed the sharp.RGBA type export and no longer tolerates piping into an already-ended stream-backed instance. Replace RGBA with a local interface, and drop the pipe into this.maskImage, which re-decoded already-raw pixels through the instance the fetch stream had ended. Verified on linux/amd64: the built bundle reports sharp 0.35.4 / vips 8.18.6 / heif 1.23.2 with no nested duplicate, all three actions load, tsc is clean, and the backend suite matches its pre-change baseline (12 passing; the 7 remaining failures reproduce on 0.33.5). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Jared Jolton (jjolton-contentful)
requested review from
a team
as code owners
September 18, 2026 20:13
1 task
Mitch Goudy (mgoudy91)
approved these changes
Sep 22, 2026
Pinning sharp in the two manifests leaves a third copy of the version inside the install-linux-sharp script, which force-installs the Linux binaries outside the dependency graph. Renovate's npm manager only reads dependency blocks, so it would bump both manifests and leave the script behind, recreating the skew this branch fixes with different numbers. Add a regex customManager over that script and group the three packages so they always move in one PR. Verified with renovate 44.107.2: config-validator passes with no migration warning, and a local dry-run=extract reports the regex manager finding sharp@0.35.4, @img/sharp-linux-x64@0.35.4 and @img/sharp-libvips-linux-x64@1.3.3 alongside the npm manager's own sharp entry. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Jared Jolton (jjolton-contentful)
enabled auto-merge (squash)
October 9, 2026 22:44
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.
Purpose
The AI Image Generator app action accepts caller-supplied image and mask URLs, fetches them, and pipes both into
sharp. The current libheif advisory (GHSA-rgj7-g3m4-5g8c) requiressharp >= 0.35.4, which bundles patched libheif 1.23.2.The deployed bundle was not running what any manifest claimed. The committed lockfile resolves sharp 0.33.4 / libvips 1.0.2, but neither the lockfile nor the installed tree reflected what actually ran:
install-linux-sharpforce-installed@img/sharp-linux-x64and@img/sharp-libvips-linux-x64unpinned, so both resolved to latest (0.35.4 / libvips 1.3.3).sharpitself stayed within the declared^0.33.0and resolved to 0.33.5.sharp/node_modules/, and Node resolution finds the nested copy first.Verified on linux/amd64, the built bundle reported
sharp=0.33.5 vips=8.15.3 heif=1.18.2— the force-installed binaries sat unused at top level, and both copies of libvips shipped (35 MB). So the real exposure was libheif 1.18.2, neither the lockfile's 1.17.6 nor a patched 1.23.2.Approach
Pin all three to exact, mutually consistent versions (sharp 0.35.4,
@img/sharp-linux-x640.35.4,@img/sharp-libvips-linux-x641.3.3) in the root and backend manifests and ininstall-linux-sharp, so the declared range and the force-installed binaries can no longer drift apart.sharp is marked
esbuild --external, so it is resolved at runtime from the closure thatbundle-sharp.jshand-copies. Three things had to change alongside the version bump:bundle-sharp.jsmodule list. sharp 0.35 replaced thecolor/color-convert/color-name/color-string/is-arrayish/simple-swizzlechain with a single@img/colour, which the old copy list does not include. The script now iterates an explicit list and throws when an expected module is absent, so an incomplete bundle fails the build instead of shipping.sharp.RGBAremoved. Its replacements (Colour/Color) alias a looseColorLikeunion that will not typecheck structural.r/.g/.baccess, so these helpers now use a localRGBAinterface.replaceColorWithTransparentpiped.raw()output back intothis.maskImage— the same stream-backed instance the fetch stream had already ended. 0.33 tolerated it; 0.35 throwswrite after end. Piping already-raw pixels through another sharp was a no-op decode, so the pipe is gone. (Piping into a freshsharp()instead does not work: raw pixels carry no dimensions and fail withInput buffer contains unsupported image format.)Bundle size drops from 35 MB to 20 MB, since only one libvips now ships.
Keeping the three pins in sync. Two of them live in
package.jsonand Renovate maintains those already (rangeStrategy: bumpupdates an exact pin in place, as it has forlodash,luxonandvitest). The third is embedded in theinstall-linux-sharpscript, which the npm manager cannot see because it only reads dependency blocks, so Renovate would bump the manifests and silently leave the script behind.renovate.jsonnow adds a regexcustomManagerover that script plus agroupNameso all three packages move in a single PR. Verified with renovate 44.107.2:renovate-config-validatorpasses with no migration warning, and a local--dry-run=extractshows the regex manager picking up all three versions alongside the npm manager's ownsharpentry.Testing steps
All verification ran in a
linux/amd64container, since the bundle targets Lambda and a host arm64 build proves nothing about it.sharp=0.35.4 vips=8.18.6 heif=1.23.2@img/*duplicate undersharp/node_modules/; exactly onelibvips-cpp.soin the bundleaiig-select-edit,aiig-static,aiig-generate-image)require()cleanly against the bundled sharptsc --noEmitand the productiontscbuild are cleanrenovate-config-validatorclean on the newrenovate.json; local--dry-run=extractconfirms the regex manager matches all three pinned versions and nothing elseTo reproduce the bundle check:
On the remaining test failures: the suite reports 7 failing both before and after this change. I captured a 0.33.5 baseline to confirm none of them are new — 3 are sinon double-wrap (
Attempted to wrap fromOpenAiApiKey which is already wrapped) and 4 are mocha 2000 ms timeouts that pass in isolation (--grep PrepareImageForEditis 4/4 green on both versions). Thewrite after endfailures this upgrade initially introduced are gone. Worth a separate cleanup ticket, but out of scope here.Breaking Changes
None to the app's external contract. All changes are internal: the pinned versions, the bundle copy list, a type that was never exported from this package, and the Renovate config.
Worth flagging for reviewers: because sharp is external and hand-copied, a green CI run does not prove the bundle loads. Bumping the sharp range without the
bundle-sharp.jschange produces a bundle that dies at startup withCannot find module '@img/colour'— reproduced while validating this. That is the main reason this is not a one-line dependency bump.Dependencies and/or References
^0.35.0but touches onlypackage.jsonand lockfiles. Merging it as-is ships the broken bundle described above. Suggest closing it in favour of this PR.🤖 Generated with Claude Code