[PR #784] [MERGED] Fix raw gzip provider responses #4773

Closed
opened 2026-10-22 04:10:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/784
Author: @Promansis
Created: 5/13/2026
Status: ✅ Merged
Merged: 5/14/2026
Merged by: @Promansis

Base: main ← Head: fix/issue-781-openrouter-gzip


📝 Commits (3)

  • 220e125 fix(#781): decode raw gzip provider responses
  • e4e8613 Address gzip response review feedback
  • dd1f6e0 Merge branch 'main' into fix/issue-781-openrouter-gzip

📊 Changes

5 files changed (+131 additions, -6 deletions)

View changed files

📝 packages/server/src/services/llm/base-provider.ts (+6 -3)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+7 -2)
📝 packages/server/src/utils/security.ts (+20 -1)
📝 packages/server/test/openai-provider-reasoning.test.ts (+44 -0)
📝 packages/server/test/security-utils.test.ts (+54 -0)

📄 Description

Linked issue

Closes #781 and likely #771

Why this change

  • OpenRouter model fetch and non-stream chat responses can arrive as gzip-compressed JSON bytes without a Content-Encoding header, which made Marinara display garbled characters or fail JSON parsing.
  • The same raw gzip signature also appeared in the related Gemini provider report, so the server should defensively normalize this response shape before parsing JSON.

What changed

  • Added raw gzip detection/decompression for buffered outbound provider responses when Content-Encoding is missing.
  • Preserved safeFetch response-size limits by capping decompressed raw gzip output as well as compressed bytes.
  • Let LLM requests opt into buffered response handling for non-stream JSON paths while preserving streaming behavior for SSE.
  • Covered OpenRouter non-stream chat, shared safe fetch decoding, and decoded-size cap behavior with regression tests.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Ran pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/security-utils.test.ts test/openai-provider-reasoning.test.ts successfully.
  • Ran pnpm --filter @marinara-engine/server lint successfully.
  • Ran pnpm check successfully.
  • Not run: Docker/container validation.
  • Not run: real OpenRouter or Gemini API manual test with live API keys.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A - server/provider response handling only.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of streamed vs. buffered LLM responses to ensure correct parsing and consumption.
    • Added automatic detection and safe decompression of raw gzip response bodies when headers are missing, while preserving response size limits and error behavior.
  • Tests

    • Added tests covering gzipped responses without content-encoding and size-cap enforcement.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/784 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 5/13/2026 **Status:** ✅ Merged **Merged:** 5/14/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `main` ← **Head:** `fix/issue-781-openrouter-gzip` --- ### 📝 Commits (3) - [`220e125`](https://github.com/Pasta-Devs/Marinara-Engine/commit/220e125301899f5c8d868e6e4f5cbcaf6c84e024) fix(#781): decode raw gzip provider responses - [`e4e8613`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e4e86134a5f67bcab618fe0ed03241811a62c302) Address gzip response review feedback - [`dd1f6e0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dd1f6e0d9ccdcd931c4c9df42e2cd211b5733d0c) Merge branch 'main' into fix/issue-781-openrouter-gzip ### 📊 Changes **5 files changed** (+131 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/base-provider.ts` (+6 -3) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+7 -2) 📝 `packages/server/src/utils/security.ts` (+20 -1) 📝 `packages/server/test/openai-provider-reasoning.test.ts` (+44 -0) 📝 `packages/server/test/security-utils.test.ts` (+54 -0) </details> ### 📄 Description ## Linked issue Closes #781 and likely #771 ## Why this change - OpenRouter model fetch and non-stream chat responses can arrive as gzip-compressed JSON bytes without a `Content-Encoding` header, which made Marinara display garbled characters or fail JSON parsing. - The same raw gzip signature also appeared in the related Gemini provider report, so the server should defensively normalize this response shape before parsing JSON. ## What changed - Added raw gzip detection/decompression for buffered outbound provider responses when `Content-Encoding` is missing. - Preserved `safeFetch` response-size limits by capping decompressed raw gzip output as well as compressed bytes. - Let LLM requests opt into buffered response handling for non-stream JSON paths while preserving streaming behavior for SSE. - Covered OpenRouter non-stream chat, shared safe fetch decoding, and decoded-size cap behavior with regression tests. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Ran `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/security-utils.test.ts test/openai-provider-reasoning.test.ts` successfully. - Ran `pnpm --filter @marinara-engine/server lint` successfully. - Ran `pnpm check` successfully. - Not run: Docker/container validation. - Not run: real OpenRouter or Gemini API manual test with live API keys. ## Docs and release impact - [x] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A - server/provider response handling only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of streamed vs. buffered LLM responses to ensure correct parsing and consumption. * Added automatic detection and safe decompression of raw gzip response bodies when headers are missing, while preserving response size limits and error behavior. * **Tests** * Added tests covering gzipped responses without content-encoding and size-cap enforcement. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/784) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:31 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4773
No description provided.