fix patch phase18 feat/phase-2g-bundle
AI Agent git-import/068377df · 114 days ago · Apr 4, 2026 · Diff

fix(phase18): eliminate double-Lambda hop for image upload; gateway commits directly to GitHub

Root cause of the hosted 502: the gateway was forwarding the raw multipart body to the bridge Netlify function via an HTTP fetch. When Netlify Lambda receives a binary POST it base64-encodes the body; serverless-http re-buffers it, but multer's stream parser inside the bridge then receives a synthetic (non-streaming) IncomingMessage, which in some Netlify runtime combinations causes an uncaught error → plain-HTML 502 that the client can't JSON-parse → errData.error is always undefined → "Upload failed (HTTP 502)".

New architecture (no binary Lambda-to-Lambda hop): 1. Gateway receives the multipart upload. 2. Gateway calls GET /api/v1/vault/github-token on the bridge (tiny JSON round-trip, authenticated, server-to-server) to get the stored token + repo. 3. Gateway parses the file from the already-buffered multipart body using the new parseMultipartFile utility (hub/gateway/parse-multipart.mjs) — pure Buffer manipulation, no streaming, no multer, no esbuild issues. 4. Gateway validates extension / Content-Type / magic bytes. 5. Gateway calls commitImageToRepo() directly and returns the result.

bridge changes: - Add GET /api/v1/vault/github-token (requireBridgeAuth, returns decrypted token + repo for the authenticated user, never exposed to browser). - Keep POST upload-image and GET image-proxy routes (for self-hosted compat).

gateway changes: - Import commitImageToRepo, validateImageExtension, validateMagicBytes, parseMultipartFile. - Rewrite upload-image handler: 2-step token-fetch + direct GitHub commit.

new files: - hub/gateway/parse-multipart.mjs — exported parseMultipartFile utility. - test/parse-multipart.test.mjs — 6 unit tests (513 total, 0 fail).

sha256:04778920114dadfc61d2a0bf5101e0bfdd1f45f5011b71c5b8c2e5d7a79f8d05 sha
sha256:cc50a2d3a71a1b63ab88e765b13ffc709b3c85ef3bb6965a630d262c1e256da2 snapshot
← Older Oldest on feat/phase-2g-bundle
All commits
Newer → Latest on feat/phase-2g-bundle

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:04778920114dadfc61d2a0bf5101e0bfdd1f45f5011b71c5b8c2e5d7a79f8d05 --body "your comment"