fix(self-host): apply the pglite-prisma-adapter Bytes patch on npm installs - #1719
Open
f-liva wants to merge 1 commit into
Open
fix(self-host): apply the pglite-prisma-adapter Bytes patch on npm installs#1719f-liva wants to merge 1 commit into
f-liva wants to merge 1 commit into
Conversation
The monorepo patches pglite-prisma-adapter from patches/fix-pglite-prisma-bytes.cjs via the root postinstall, which never runs for anyone installing happy-server-self-host from npm. Those installs get the unpatched adapter, so every Bytes column fails with P2023 and /v1/sessions and /v1/machines return 500 as soon as one encrypted session exists. Apply the same replacement from the package's own postinstall, against the adapter copy npm resolved for it.
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
happy-server-self-hostinstalled from npm ships an unpatchedpglite-prisma-adapter, so standalone PGlite self-hosting is broken as soon as the first encrypted session exists.The repo already has the fix —
patches/fix-pglite-prisma-bytes.cjs, added in 9e99583 — but it is wired into the rootscripts/postinstall.cjs:That root script only runs for a monorepo checkout. Someone doing
npm i -g happy-server-self-hostrunspackages/happy-server-self-host/scripts/postinstall.cjs, which today only doesprisma generate. npm then resolvespglite-prisma-adapter@^0.7.2fresh from the registry, unpatched — lucasthevenet/pglite-utils#50 is still open, so there is no fixed release to bump to.Symptom
parsePgBytesreturns aUint8Array, which serializes as{"0":104,"1":101,…}across the JS→WASM boundary; the query engine wantsnumber[]:Every
Bytescolumn is affected, which in practice means everydataEncryptionKey.GET /v1/sessionsandGET /v1/machinesreturn 500, the CLI reportsMachine registration failed: 500, and no session ever appears in the app. Rows with aNULLkey read fine, so a fresh server looks healthy right up to the first CLI session — then every listing containing that row fails, not just the row.Same underlying bug as #612 and #686; this PR is about the npm distribution path specifically, which those don't cover.
Fix
Apply the same replacement from the package's own
postinstall.cjs, against whichever adapter copy npm resolved for it.require.resolve('pglite-prisma-adapter', { paths: [root] })handles hoisted and nested layouts alike (the adapter exports no./package.json, so its entry point is resolved instead and both bundles are patched next to it).prisma/schema.prisma.patches/fix-pglite-prisma-bytes.cjsis left alone.Verified
Against the real
pglite-prisma-adapter@0.7.2tarball, in a layout mirroring an npm install:Two per file:
parsePgBytesandnormalizeByteaArray.Separately, this same replacement applied by hand to a live deployment (
happy-server-self-host1.1.11 behind Traefik, PGlite standalone) took/v1/sessionsand/v1/machinesfrom 500 to 200, with sessions listing on the phone and no P2023 in the logs.Note
This is a workaround for as long as lucasthevenet/pglite-utils#50 is unmerged. Once a fixed adapter ships, bumping the dependency and dropping both this and
patches/fix-pglite-prisma-bytes.cjswould be the real cleanup.