Skip to content

fix(backend): raise compress threshold to fix empty zstd /api/health body - #685

Merged
laboef1900 merged 1 commit into
devfrom
fix/compress-threshold
May 21, 2026
Merged

fix(backend): raise compress threshold to fix empty zstd /api/health body#685
laboef1900 merged 1 commit into
devfrom
fix/compress-threshold

Conversation

@laboef1900

Copy link
Copy Markdown
Contributor

Summary

  • /api/health was returning an empty body with content-encoding: zstd and content-length: 0 to the browser in the deployed EE backend container — Settings → Diagnostics consequently fell back to "Edition: Community (CE)" and "Backend commit: …" because await response.json() parsed an empty body.
  • Larger payloads on the same backend (/api/pages/:id at 1614 bytes) compressed fine. The bug is deterministic on the deployed container but does not reproduce against @fastify/compress 8.3.1 in isolation on Node 26 with the same payload shape — almost certainly an interaction with the container's Node 24 zstd encoder or the EE build pipeline. Investigation hit diminishing returns.
  • Workaround: register compress with { threshold: 4096 }. Payloads in the bug-prone size range pass through uncompressed; payloads where compression actually saves meaningful bandwidth still get compressed.

Repro before the fix

curl -sH "Accept-Encoding: gzip, br, zstd" -i http://localhost:3052/api/health | head -30
# → 200 OK
# → content-encoding: zstd
# → content-length: 0
# → (empty body)

After the fix the same request returns the full 1042-byte JSON with no content-encoding header.

Test plan

  • Two new regression tests in app.test.ts:
    • sub-4KB synthetic payload → no content-encoding, body intact
    • 4KB synthetic payload → some content-encoding set, body non-empty (so the threshold doesn't accidentally disable compression entirely)

  • All existing app tests pass (11/11)
  • Typecheck clean
  • Manual verification after EE backend rebuild — Diagnostics should show "Edition: Enterprise (EE)" + real backend commit hash

Follow-up

The EE backend image needs to be rebuilt for this fix to take effect in the running stack. Tracking the underlying @fastify/compress / Node 24 zstd interaction in a separate issue.

🤖 Generated with Claude Code

…y-body bug

The shipped EE backend (Node 24.15-alpine, @fastify/compress 8.3.1)
deterministically returns an empty body with `content-encoding: zstd`
and `content-length: 0` for `/api/health` (1042-byte JSON) when the
browser sends `Accept-Encoding: gzip, br, zstd`. Larger payloads on the
same plugin (e.g. `/api/pages/:id` at 1614 bytes) compress correctly.

User-visible symptom: the Settings → Diagnostics page falls back to
"Edition: Community (CE)" and "Backend commit: …" because the
`useBackendBuildInfo()` `useQuery` parses `await response.json()` from
an empty body — the actual version/commit/builtAt metadata never reaches
the UI.

Reproduces only against the deployed container, not against
`@fastify/compress 8.3.1` in isolation on Node 26 with the same payload
shape — likely an interaction with the container's Node 24 zlib zstd
encoder or the EE build pipeline. Investigation hit diminishing returns;
the workaround is to push the threshold above the bug-prone size range.
Sub-4KB payloads barely benefit from compression anyway once you net out
the encoding-header overhead, so the bandwidth cost is negligible.

Two regression tests in `app.test.ts` pin the behaviour: a ~1KB synthetic
route must not be compressed; a ~5KB synthetic route must be (so the
plugin stays wired up rather than effectively disabled).

Once this lands on `main` (via the usual release branch), the EE backend
needs to be rebuilt for the Diagnostics page to start showing real
backend metadata. The CE fallback `/api/health` route is unaffected
since CE doesn't compose with `@fastify/compress` in the same way at
runtime (community mode runs the same code, but the production EE
container is where the bug was observed).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@laboef1900
laboef1900 merged commit f20a9dc into dev May 21, 2026
5 checks passed
@laboef1900
laboef1900 deleted the fix/compress-threshold branch May 21, 2026 15:11
@laboef1900 laboef1900 mentioned this pull request May 21, 2026
3 tasks
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