mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7179] [MERGED] fix(termux): keep the server up when sharp's WebAssembly runtime is missing #7609
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7609
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7179
Author: @SpicyMarinara
Created: 10/6/2026
Status: ✅ Merged
Merged: 10/6/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/termux-sharp-crash-7173📝 Commits (1)
6eb7bd4fix(termux): keep the server up when sharp's WebAssembly runtime is missing📊 Changes
7 files changed (+116 additions, -0 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/package.json(+1 -0)📝
packages/server/src/index.ts(+8 -0)📝
packages/server/src/services/image/sharp-runtime.ts(+20 -0)📝
pnpm-lock.yaml(+3 -0)➕
scripts/regressions/sharp-wasm-runtime-missing.regression.ts(+58 -0)📝
scripts/regressions/termux-sharp.regression.mjs(+25 -0)📄 Description
Linked issue
Closes #7173
Why this change
On Android/Termux, a server updated in place from 2.4.6 to 2.5.0 shuts down as soon as a browser opens Engine. The chat list asks for background thumbnails (
/api/backgrounds/file/Black.jpg?w=320), which loads sharp, and the server exits.@img/sharp-wasm32as an optional dependency, so pnpm recorded@emnapi/runtimeas "skipped" innode_modules/.modules.yaml. 2.5.0 made sharp-wasm32 a regular dependency. But the frozen in-place install thatstart-termux.shruns (without--force) reaches@emnapi/runtimefirst through a parent that is always skipped:@huggingface/transformers -> sharp -> @img/sharp-freebsd-wasm32. So pnpm never removes the stale skipped entry, and@emnapi/runtimeis never installed. Fresh installs work, and the in-app updater's--forcerepairs it.async run()that nothing awaits. Whenrequire("@emnapi/runtime")fails there,getSharp()catches the import failure ("sharp.libvipsVersion is not a function"). A second, detachedMODULE_NOT_FOUNDrejection then reaches the server'sunhandledRejectionhandler, which exits with code 1. Image processing is optional, so this failure should switch image processing off, not stop the server.What changed
packages/server/package.json/pnpm-lock.yaml:@emnapi/runtime ^1.11.3is now a direct server dependency, adding 3 importer lines to the lockfile. pnpm now reaches it from a parent that can be installed, so it gets installed on fresh installs, on in-place updates from 2.4.6 and on 2.5.0 trees that are already broken.packages/server/src/services/image/sharp-runtime.ts: newisSharpLoaderRejection(reason). It matches only errors whose origin (requireStack[0], or else the first non-node:/wasm:stack frame) is a file in sharp's own@img/sharp-*loader packages.packages/server/src/index.ts: theunhandledRejectionhandler first checksisSharpLoaderRejection. If it matches, the handler logs a warning ("image processing stays off until dependencies are reinstalled") and returns. Every other rejection is still fatal, and the rest of the handler is unchanged.scripts/regressions/termux-sharp.regression.mjs: checks that the server importer depends directly on the same@emnapi/runtimeversion that the@img/sharp-wasm32snapshot needs. Its probe also now fails on any detached rejection.scripts/regressions/sharp-wasm-runtime-missing.regression.ts: sets the platform to Android and usesmodule.registerHooksto make@emnapi/runtimeunresolvable. It then checks thatresolveThumbPathserves the original image, that exactly one detachedMODULE_NOT_FOUNDrejection is classified as non-fatal, that an unrelatedErrorstays fatal, and thatindex.tschecks the classifier first.CHANGELOG.md: user-facing entry under[Unreleased].Known limit, marked with a
ponytail:comment: only sharp's own loader files are matched. The half-started WebAssembly heap (about 44 MB) stays in memory until restart. If needed, the upgrade path is to probe sharp in a child process before importing it in-process.Validation
pnpm checkpasses locallyCONTRIBUTING.mdAgent-run checks (macOS arm64, Node 24.16.0, pnpm 10.34.5):
node scripts/run-regressions.mjs --filter sharp-wasm-runtime-missing: passes with the fix. With staging'sindex.tsandsharp-runtime.tsit fails (isSharpLoaderRejection is not a function). With the classifier but staging's handler it fails on the handler-order assertion.node scripts/run-regressions.mjs --filter termux-sharp: passes with the fix. With staging'spnpm-lock.yamland serverpackage.jsonit fails: "the server must depend on @emnapi/runtime 1.11.3 directly so in-place updates install it".termux-postmortem(still exactly twonoteSessionExitKind("crash")calls) androbustness-shutdown-safetyregressions pass.pnpm check: result in the PR comments below.--prefer-offlineinstallstart-termux.shruns, with the CLI flags--os linux --cpu arm64 --cpu wasm32standing in for Termux'ssupportedArchitectures; install scripts skipped):git checkout --detachthis branch in the same tree:@emnapi/runtime@1.11.3leavesskippedand is linked. Frompackages/server,import("sharp")loads through WebAssembly (versions.emscriptenis set),metadata()on a 1x1 PNG works, and there is no unhandled rejection.@emnapi/runtimestays underskipped, the import fails, and one detachedMODULE_NOT_FOUNDrejection comes from@img/sharp-wasm32/lib/sharp-wasm32-0.35.5.node.js. Updating that same tree to this branch repairs it without--force, andcheck-workspace-installreports no problems for android.@emnapi/runtimemade unresolvable, thenGET /api/backgrounds/file/Black.jpg?w=320: staging exits with code 1 ([process] Unhandled rejection). This branch returns the original image with 200, logs one[image]warning and keeps answering/api/health.Manual verification notes
start-termux.sh, and confirm.pnpm/@emnapi+runtime@1.11.3exists in the repository root (.npmrcputs the virtual store in.pnpm/, notnode_modules/.pnpm/) and@emnapi/runtime@1.11.3is no longer underskippedinnode_modules/.modules.yaml.start-termux.shon this branch and confirm the frozen install adds@emnapi/runtimewithout--force.@emnapi/runtimeis removed by hand: the log shows one "[image] sharp's image runtime failed to start" warning, and backgrounds are served at full size.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Only
CHANGELOG.mdchanges; no files underdocs/are touched.UI evidence (if applicable)
Not applicable (server and dependency change only).
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.