[PR #6727] [MERGED] feat(decision): answer decisions with a chat model on the user's own server #7300

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6727
Author: @kolacheee
Created: 9/26/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @kolacheee

Base: staging ← Head: claude/busy-davinci-5wlp15


📝 Commits (3)

  • af101a1 feat(decision): answer decisions with a chat model on the user's own server
  • 43e7bf6 Merge remote-tracking branch 'origin/staging' into claude/busy-davinci-5wlp15
  • 0a89705 docs(decision): name the 4 s default of a chat model Decision connection

📊 Changes

21 files changed (+769 additions, -143 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/agents/custom-agents.md (+1 -1)
📝 docs/connections/decision-models.md (+18 -6)
📝 docs/connections/local-self-hosted.md (+3 -0)
📝 docs/prompts/conditional-prompts.md (+1 -1)
➕ e2e/decision-chat-connection.e2e.ts (+106 -0)
📝 packages/client/src/components/connections/ConnectionEditor.tsx (+24 -12)
📝 packages/client/src/hooks/use-connections.ts (+8 -2)
📝 packages/client/src/lib/decision-test-message.ts (+13 -5)
📝 packages/client/src/localization/locales/en.json (+6 -1)
📝 packages/server/src/routes/connections.routes.ts (+26 -2)
📝 packages/server/src/routes/decision.routes.ts (+1 -0)
📝 packages/server/src/services/decision/decision-connection.ts (+38 -6)
📝 packages/server/src/services/decision/decision-default.ts (+74 -48)
📝 packages/server/src/services/decision/sidecar-decision.backend.ts (+83 -22)
📝 packages/server/src/services/decision/system-one.client.ts (+48 -30)
📝 packages/server/src/services/sidecar/decision-process.service.ts (+7 -1)
📝 packages/shared/src/types/connection.ts (+17 -2)
📝 packages/shared/src/types/decision.ts (+11 -3)
➕ scripts/regressions/decision-chat-connection.regression.ts (+282 -0)

...and 1 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6714

Why this change

  • A general chat model can already answer decisions, but only when Marinara's own sidecar runs it (Primary or Utility local model). Someone who already runs the model in Ollama, LM Studio or llama.cpp had to load it a second time, which costs VRAM and disk.
  • The only Decision connection that takes a URL, Custom System One endpoint, speaks System One (/v1/systemone). Pointed at Ollama it gets a 404, every gate fails open, and Test reported it as "could not be reached".
  • The issue asks to pick a regular connection for decisions. This PR lets an existing Custom (OpenAI-compatible) chat connection become the Decision model in one click, using the same method the local slots already use. Following the active chat or agent connection automatically is not included: most hosted chat models return no log-probabilities, and each statement would be a billed request.

What changed

  • New Decision source, OpenAI-compatible chat model. It is asked exactly the way the Primary and Utility slots are: one yes/no token per statement, with the answer read from its log-probabilities, and Thinking on Auto. It reuses the same backend (sidecar-decision.backend.ts). The request goes to the user's URL under the provider URL policy (PROVIDER_LOCAL_URLS_ENABLED for LAN addresses, loopback always allowed) and carries the connection's key, time limit and token budget.
  • Defaults for the new source: 4 s per statement (the local slots' budget; a thinking model gets at least 20 s), a 3,500-token budget, and a required model name (a chat server is never sent jev-latest). Statements go to the server one at a time, since its parallelism is unknown, so each statement's limit starts when the server takes it.
  • Base URL handling: the same base URL as the Custom chat connection (http://host:11434/v1), which gets /chat/completions appended. A bare host gets /v1/chat/completions, and a full endpoint is kept as entered. A key can be borrowed from a Custom connection only on the same origin, reusing the existing link check.
  • One-click shortcut: a Custom connection shows Use this model for decisions, next to the existing OpenRouter "Use this key for decisions (Jev)" shortcut. It creates the linked Decision connection with the same server, model and key.
  • Test: for the new source it runs the same probe as a local model's Test, so it also reports when the server returned no log-probabilities or the model had to think. A 404 now reads "The server has no such endpoint… a chat model server such as Ollama or LM Studio needs OpenAI-compatible chat model" instead of "could not be reached".
  • Refactors:
    • postDecisionRequest (the policy-bound, abort-bounded POST) is extracted from the System One client and shared by both protocols.
    • The local-slot chat backend in decision-default.ts becomes chatBackend(), shared by local slots and the new connections.
    • DecisionConnection carries its protocol.

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

Automated runs by the agent that prepared this PR, in a Linux container with no GPU and no real Ollama (ollama.com is not reachable there):

  • pnpm check exited 0.
  • node scripts/run-regressions.mjs --filter decision: all 11 decision regressions pass, including the new decision-chat-connection.regression.ts. That regression uses a stand-in Ollama (OpenAI-compatible chat completions with log-probabilities, plain 404 everywhere else) and covers:
    • a Custom System One connection pointed at it gets http_404, which is the report;
    • the new source answers gates, prompt statements and Choice questions, one request at a time, with the key and model sent;
    • Test reports log-probabilities;
    • same-origin key linking works, and a different host needs relinking;
    • a missing model is refused;
    • a private-network URL is refused without PROVIDER_LOCAL_URLS_ENABLED, and no request is sent.
  • decision-time-limits.regression.ts needed its source-slice end marker updated for the refactor; its assertions are unchanged.
  • New e2e/decision-chat-connection.e2e.ts passes on desktop-chromium and mobile-chromium (dark theme). It opens a Custom connection, clicks Use this model for decisions, checks the new Decision connection's source, URL, model and 4 s limit, and runs Test against the stand-in server.
  • Local CodeRabbit review has not run: the CLI is not available in the agent's container. This PR stays a draft until that review has run.

Still to verify by hand:

  • Real Ollama with Gemma 4 E2B or E4B: create the Decision connection with the shortcut, select it under Decision model, click Test, then run a chat with an activation question and a {{#if decision:"..."}} statement and confirm they answer (Debug Mode logs [decision] Chat connection request/result).
  • Real Ollama: confirm it returns logprobs on /v1/chat/completions. If it does not, Test shows "No log-probabilities, so answers are only yes or no".
  • Real Ollama or LM Studio with a thinking model (for example Qwen3): confirm the llama.cpp-only reasoning_format / chat_template_kwargs fields are ignored rather than rejected, and that Auto switches to thinking after two failed one-token answers.
  • LM Studio: Test and a chat turn.
  • A server on another machine: blocked without PROVIDER_LOCAL_URLS_ENABLED, works with it.
  • Light mode: the shortcut link and Decision source help text (the e2e run covered dark mode only).
  • Existing TypeSafe, OpenRouter and Custom System One connections, and the Primary, Utility and decision-sidecar slots, still Test and answer as before.

Docs and release impact

  • No docs changes needed

  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed

  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)

  • Version/release files updated (only if this PR includes a version bump)

  • CHANGELOG.md: new [Unreleased] entry.

  • docs/connections/decision-models.md: new section "On a server you already run", a row in the options table, the new source in the setup steps, the threshold and time-limit tables, and a troubleshooting entry for the 404.

  • docs/connections/local-self-hosted.md: a pointer to the decision option.

  • docs-i18n: both files exist in all 10 language packs. A [docs-i18n] docs/connections/decision-models.md, docs/connections/local-self-hosted.md follow-up issue is still to be opened (#6667 already tracks earlier decision-models.md changes).

UI evidence (if applicable)

Screenshots from the e2e run (desktop and mobile, dark), to attach:

  • the Custom connection with Use this model for decisions;
  • the new Decision connection's source section;
  • a successful Test ("Probability of yes: 0.800 · answered in 0.01 s (time limit 4 s)").

Summary by CodeRabbit

  • New Features
    • Use chat models hosted on Ollama, LM Studio, llama.cpp, or other OpenAI-compatible servers for Decision connections. Create a Decision connection from a Custom chat connection and reuse its server and model settings.
    • Decision connection tests report probability results and note when the model lacks probability support or answers directly.
    • OpenAI-compatible Decision connections default to a 4-second request limit, with more time when the model needs to think first.
  • Bug Fixes
    • Tests distinguish an unsupported endpoint from an unreachable server.

🔄 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/6727 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/26/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `claude/busy-davinci-5wlp15` --- ### 📝 Commits (3) - [`af101a1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/af101a15d6b2f096003fcb170f3a1195d36ecc1b) feat(decision): answer decisions with a chat model on the user's own server - [`43e7bf6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43e7bf670b27f248f234a656f78875612b9c40bb) Merge remote-tracking branch 'origin/staging' into claude/busy-davinci-5wlp15 - [`0a89705`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0a89705edbec6285e90cf2f137c8cf1d0a463010) docs(decision): name the 4 s default of a chat model Decision connection ### 📊 Changes **21 files changed** (+769 additions, -143 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/agents/custom-agents.md` (+1 -1) 📝 `docs/connections/decision-models.md` (+18 -6) 📝 `docs/connections/local-self-hosted.md` (+3 -0) 📝 `docs/prompts/conditional-prompts.md` (+1 -1) ➕ `e2e/decision-chat-connection.e2e.ts` (+106 -0) 📝 `packages/client/src/components/connections/ConnectionEditor.tsx` (+24 -12) 📝 `packages/client/src/hooks/use-connections.ts` (+8 -2) 📝 `packages/client/src/lib/decision-test-message.ts` (+13 -5) 📝 `packages/client/src/localization/locales/en.json` (+6 -1) 📝 `packages/server/src/routes/connections.routes.ts` (+26 -2) 📝 `packages/server/src/routes/decision.routes.ts` (+1 -0) 📝 `packages/server/src/services/decision/decision-connection.ts` (+38 -6) 📝 `packages/server/src/services/decision/decision-default.ts` (+74 -48) 📝 `packages/server/src/services/decision/sidecar-decision.backend.ts` (+83 -22) 📝 `packages/server/src/services/decision/system-one.client.ts` (+48 -30) 📝 `packages/server/src/services/sidecar/decision-process.service.ts` (+7 -1) 📝 `packages/shared/src/types/connection.ts` (+17 -2) 📝 `packages/shared/src/types/decision.ts` (+11 -3) ➕ `scripts/regressions/decision-chat-connection.regression.ts` (+282 -0) _...and 1 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6714 ## Why this change - A general chat model can already answer decisions, but only when Marinara's own sidecar runs it (Primary or Utility local model). Someone who already runs the model in Ollama, LM Studio or llama.cpp had to load it a second time, which costs VRAM and disk. - The only Decision connection that takes a URL, **Custom System One endpoint**, speaks System One (`/v1/systemone`). Pointed at Ollama it gets a 404, every gate fails open, and Test reported it as "could not be reached". - The issue asks to pick a regular connection for decisions. This PR lets an existing Custom (OpenAI-compatible) chat connection become the Decision model in one click, using the same method the local slots already use. Following the active chat or agent connection automatically is not included: most hosted chat models return no log-probabilities, and each statement would be a billed request. ## What changed - **New Decision source, OpenAI-compatible chat model.** It is asked exactly the way the Primary and Utility slots are: one yes/no token per statement, with the answer read from its log-probabilities, and Thinking on Auto. It reuses the same backend (`sidecar-decision.backend.ts`). The request goes to the user's URL under the provider URL policy (`PROVIDER_LOCAL_URLS_ENABLED` for LAN addresses, loopback always allowed) and carries the connection's key, time limit and token budget. - **Defaults for the new source:** 4 s per statement (the local slots' budget; a thinking model gets at least 20 s), a 3,500-token budget, and a required model name (a chat server is never sent `jev-latest`). Statements go to the server one at a time, since its parallelism is unknown, so each statement's limit starts when the server takes it. - **Base URL handling:** the same base URL as the Custom chat connection (`http://host:11434/v1`), which gets `/chat/completions` appended. A bare host gets `/v1/chat/completions`, and a full endpoint is kept as entered. A key can be borrowed from a Custom connection only on the same origin, reusing the existing link check. - **One-click shortcut:** a Custom connection shows **Use this model for decisions**, next to the existing OpenRouter "Use this key for decisions (Jev)" shortcut. It creates the linked Decision connection with the same server, model and key. - **Test:** for the new source it runs the same probe as a local model's Test, so it also reports when the server returned no log-probabilities or the model had to think. A 404 now reads "The server has no such endpoint… a chat model server such as Ollama or LM Studio needs OpenAI-compatible chat model" instead of "could not be reached". - **Refactors:** - `postDecisionRequest` (the policy-bound, abort-bounded POST) is extracted from the System One client and shared by both protocols. - The local-slot chat backend in `decision-default.ts` becomes `chatBackend()`, shared by local slots and the new connections. - `DecisionConnection` carries its `protocol`. ## 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 Automated runs by the agent that prepared this PR, in a Linux container with no GPU and no real Ollama (ollama.com is not reachable there): - `pnpm check` exited 0. - `node scripts/run-regressions.mjs --filter decision`: all 11 decision regressions pass, including the new `decision-chat-connection.regression.ts`. That regression uses a stand-in Ollama (OpenAI-compatible chat completions with log-probabilities, plain 404 everywhere else) and covers: - a Custom System One connection pointed at it gets `http_404`, which is the report; - the new source answers gates, prompt statements and Choice questions, one request at a time, with the key and model sent; - Test reports log-probabilities; - same-origin key linking works, and a different host needs relinking; - a missing model is refused; - a private-network URL is refused without `PROVIDER_LOCAL_URLS_ENABLED`, and no request is sent. - `decision-time-limits.regression.ts` needed its source-slice end marker updated for the refactor; its assertions are unchanged. - New `e2e/decision-chat-connection.e2e.ts` passes on desktop-chromium and mobile-chromium (dark theme). It opens a Custom connection, clicks **Use this model for decisions**, checks the new Decision connection's source, URL, model and 4 s limit, and runs Test against the stand-in server. - Local CodeRabbit review has **not** run: the CLI is not available in the agent's container. This PR stays a draft until that review has run. Still to verify by hand: - [ ] Real Ollama with Gemma 4 E2B or E4B: create the Decision connection with the shortcut, select it under **Decision model**, click Test, then run a chat with an activation question and a `{{#if decision:"..."}}` statement and confirm they answer (Debug Mode logs `[decision] Chat connection request/result`). - [ ] Real Ollama: confirm it returns `logprobs` on `/v1/chat/completions`. If it does not, Test shows "No log-probabilities, so answers are only yes or no". - [ ] Real Ollama or LM Studio with a thinking model (for example Qwen3): confirm the llama.cpp-only `reasoning_format` / `chat_template_kwargs` fields are ignored rather than rejected, and that Auto switches to thinking after two failed one-token answers. - [ ] LM Studio: Test and a chat turn. - [ ] A server on another machine: blocked without `PROVIDER_LOCAL_URLS_ENABLED`, works with it. - [ ] Light mode: the shortcut link and Decision source help text (the e2e run covered dark mode only). - [ ] Existing TypeSafe, OpenRouter and Custom System One connections, and the Primary, Utility and decision-sidecar slots, still Test and answer as before. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) - `CHANGELOG.md`: new `[Unreleased]` entry. - `docs/connections/decision-models.md`: new section "On a server you already run", a row in the options table, the new source in the setup steps, the threshold and time-limit tables, and a troubleshooting entry for the 404. - `docs/connections/local-self-hosted.md`: a pointer to the decision option. - `docs-i18n`: both files exist in all 10 language packs. A `[docs-i18n] docs/connections/decision-models.md, docs/connections/local-self-hosted.md` follow-up issue is still to be opened (#6667 already tracks earlier `decision-models.md` changes). ## UI evidence (if applicable) Screenshots from the e2e run (desktop and mobile, dark), to attach: - the Custom connection with **Use this model for decisions**; - the new Decision connection's source section; - a successful Test ("Probability of yes: 0.800 · answered in 0.01 s (time limit 4 s)"). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Use chat models hosted on Ollama, LM Studio, llama.cpp, or other OpenAI-compatible servers for Decision connections. Create a Decision connection from a Custom chat connection and reuse its server and model settings. - Decision connection tests report probability results and note when the model lacks probability support or answers directly. - OpenAI-compatible Decision connections default to a 4-second request limit, with more time when the model needs to think first. - **Bug Fixes** - Tests distinguish an unsupported endpoint from an unreachable server. <!-- 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:18:24 +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#7300
No description provided.