[PR #6326] [MERGED] fix: send per-chat session headers to OpenCode endpoints #7136

Closed
opened 2026-10-23 04:16:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6326
Author: @SpicyMarinara
Created: 9/18/2026
Status: ✅ Merged
Merged: 9/18/2026
Merged by: @SpicyMarinara

Base: staging ← Head: codex/opencode-session


📝 Commits (5)

  • b60f746 chore: start OpenCode session header support
  • 55600c8 fix: send chat-scoped sessions to OpenCode API endpoints
  • 5273bd4 Merge staging before final OpenCode session validation
  • 493477a fix: drop OpenCode session headers when redirects leave the API
  • 85207ef Merge branch 'staging' into codex/opencode-session

📊 Changes

9 files changed (+224 additions, -1 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 e2e/chat-sweep.e2e.ts (+2 -0)
📝 packages/client/src/hooks/use-translate.ts (+1 -0)
📝 packages/client/src/lib/translate-text.ts (+1 -0)
📝 packages/server/src/app.ts (+4 -0)
📝 packages/server/src/routes/translate.routes.ts (+1 -0)
➕ packages/server/src/utils/opencode-session.ts (+50 -0)
📝 packages/server/src/utils/security.ts (+11 -1)
➕ scripts/regressions/opencode-session.regression.ts (+152 -0)

📄 Description

Linked issue

Closes #6325.

Why this change

OpenCode Go requires a stable session header for each conversation. A fixed Custom Request Headers value sends every chat through the same session; without it, requests can be rejected. Existing OpenAI-compatible connections now derive the session from the originating chat and identify the client as Marinara Engine. No new provider option or connection setting is added.

What changed

  • Reuse the server's request-context pattern so nested generation, auxiliary calls and retries share a stable, hashed chat ID. Resume and later turns derive the same ID; standalone requests get separate temporary sessions.
  • Attach x-opencode-session and User-Agent: Marinara-Engine/<version> only to HTTPS OpenCode Go/Zen API destinations. Re-evaluate the destination on every redirect and strip configured session headers when leaving the API, including same-origin redirects to non-API paths.
  • Pass the originating chat ID in both translation helpers, including automatic translation after navigation.
  • Preserve other custom headers and connection-managed authentication. Automatic chat identity replaces any old fixed OpenCode session header on those endpoints.

The upstream contract is documented in OpenCode Go: Where can I use it?.

Validation performed

  • pnpm check passes, including localization, formatting, lint/types and production builds.
  • Request-capture regression: the previous path retains the same fixed session for different chats; the change passes concurrent-chat isolation, repeated turns, resumed chats, route/body chat IDs, auxiliary generation, streaming/non-streaming, standalone requests, same-origin redirects, cross-origin stripping, and unrelated/lookalike-host controls.
  • Existing provider-compatibility and image-result redirect/security regressions pass.
  • After integrating staging, all 21 desktop Chromium, mobile Chromium and mobile WebKit translation cases pass, including originating chat IDs, navigation, evicted settings and overlapping regenerations. pnpm check and the focused provider/session regressions also pass on the combined code.
  • Local CodeRabbit's test-import suggestion was addressed using the repository's existing createRequire pattern to resolve Fastify from its owning server package. The final initial review covered all nine files and returned zero findings. GitHub review found a same-origin API-to-docs redirect edge case; its new regression fails before the fix and passes after it, and local review of the three changed files returned zero findings.

Before/after logs and validation

Claim boundaries and manual verification

The regression exercises the real OpenAI-compatible provider and safe-fetch code with synthetic DNS/fetch responses. It makes no paid API calls. This verifies header transport, not live account access or upstream client approval; requests identify Marinara honestly.

  • Manually verify a configured OpenCode connection can generate across multiple turns and separate chats.
  • Manually verify resumed chats keep their session identity.

Docs and release impact

Added an Unreleased entry. Existing OpenAI-compatible connection setup is unchanged, so no user-facing documentation or localization keys changed. No version bump.

Summary by CodeRabbit

  • New Features

    • OpenAI-compatible connections to OpenCode Go and Zen now automatically include stable per-chat session identification.
    • Requests identify Marinara Engine and maintain session context across nested generations, retries, streaming, and chat translations.
    • Translation requests now carry the associated chat ID for improved conversation continuity.
  • Bug Fixes

    • OpenCode session information is preserved for supported service redirects while being removed when requests move to unrelated domains.

🔄 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/6326 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 9/18/2026 **Status:** ✅ Merged **Merged:** 9/18/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `codex/opencode-session` --- ### 📝 Commits (5) - [`b60f746`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b60f7467f4eff91f3a13c5f3f980804f2820eaf2) chore: start OpenCode session header support - [`55600c8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/55600c8566b44023b47b5ac960823ea17b2f11a1) fix: send chat-scoped sessions to OpenCode API endpoints - [`5273bd4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5273bd46b1779c110c5e6b2cb3c23b129964b802) Merge staging before final OpenCode session validation - [`493477a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/493477a5a7a9ca28f0d452a78aae9c2fac8071c1) fix: drop OpenCode session headers when redirects leave the API - [`85207ef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/85207ef5962ddd5f0e956d3976809ae4a8575029) Merge branch 'staging' into codex/opencode-session ### 📊 Changes **9 files changed** (+224 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `e2e/chat-sweep.e2e.ts` (+2 -0) 📝 `packages/client/src/hooks/use-translate.ts` (+1 -0) 📝 `packages/client/src/lib/translate-text.ts` (+1 -0) 📝 `packages/server/src/app.ts` (+4 -0) 📝 `packages/server/src/routes/translate.routes.ts` (+1 -0) ➕ `packages/server/src/utils/opencode-session.ts` (+50 -0) 📝 `packages/server/src/utils/security.ts` (+11 -1) ➕ `scripts/regressions/opencode-session.regression.ts` (+152 -0) </details> ### 📄 Description ## Linked issue Closes #6325. ## Why this change OpenCode Go requires a stable session header for each conversation. A fixed Custom Request Headers value sends every chat through the same session; without it, requests can be rejected. Existing OpenAI-compatible connections now derive the session from the originating chat and identify the client as Marinara Engine. No new provider option or connection setting is added. ## What changed - Reuse the server's request-context pattern so nested generation, auxiliary calls and retries share a stable, hashed chat ID. Resume and later turns derive the same ID; standalone requests get separate temporary sessions. - Attach `x-opencode-session` and `User-Agent: Marinara-Engine/<version>` only to HTTPS OpenCode Go/Zen API destinations. Re-evaluate the destination on every redirect and strip configured session headers when leaving the API, including same-origin redirects to non-API paths. - Pass the originating chat ID in both translation helpers, including automatic translation after navigation. - Preserve other custom headers and connection-managed authentication. Automatic chat identity replaces any old fixed OpenCode session header on those endpoints. The upstream contract is documented in [OpenCode Go: Where can I use it?](https://opencode.ai/docs/go/#where-can-i-use-it). ## Validation performed - `pnpm check` passes, including localization, formatting, lint/types and production builds. - Request-capture regression: the previous path retains the same fixed session for different chats; the change passes concurrent-chat isolation, repeated turns, resumed chats, route/body chat IDs, auxiliary generation, streaming/non-streaming, standalone requests, same-origin redirects, cross-origin stripping, and unrelated/lookalike-host controls. - Existing provider-compatibility and image-result redirect/security regressions pass. - After integrating staging, all 21 desktop Chromium, mobile Chromium and mobile WebKit translation cases pass, including originating chat IDs, navigation, evicted settings and overlapping regenerations. `pnpm check` and the focused provider/session regressions also pass on the combined code. - Local CodeRabbit's test-import suggestion was addressed using the repository's existing `createRequire` pattern to resolve Fastify from its owning server package. The final initial review covered all nine files and returned zero findings. GitHub review found a same-origin API-to-docs redirect edge case; its new regression fails before the fix and passes after it, and local review of the three changed files returned zero findings. [Before/after logs and validation](https://gist.github.com/SpicyMarinara/99e2b5aaea7b9c7bd8a67376a005b300) ## Claim boundaries and manual verification The regression exercises the real OpenAI-compatible provider and safe-fetch code with synthetic DNS/fetch responses. It makes no paid API calls. This verifies header transport, not live account access or upstream client approval; requests identify Marinara honestly. - [ ] Manually verify a configured OpenCode connection can generate across multiple turns and separate chats. - [ ] Manually verify resumed chats keep their session identity. ## Docs and release impact Added an Unreleased entry. Existing OpenAI-compatible connection setup is unchanged, so no user-facing documentation or localization keys changed. No version bump. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - OpenAI-compatible connections to OpenCode Go and Zen now automatically include stable per-chat session identification. - Requests identify Marinara Engine and maintain session context across nested generations, retries, streaming, and chat translations. - Translation requests now carry the associated chat ID for improved conversation continuity. - **Bug Fixes** - OpenCode session information is preserved for supported service redirects while being removed when requests move to unrelated domains. <!-- 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-23 04:16:52 +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#7136
No description provided.