[PR #6540] [MERGED] feat(agents): answer activation questions with a local model #7219

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

📋 Pull Request Information

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

Base: staging ← Head: feat/decision-local-models


📝 Commits (5)

  • ae2a34f feat(agents): answer activation questions with a local model
  • 2068007 fix(agents): start the chosen local slot for decisions on demand
  • 9658216 fix(agents): keep decision gating consistent with what is actually slow
  • 47fee5c fix(agents): refuse decision models the dropdown greys out, and keep health cheap
  • 45ee629 docs(agents): say why /thinking accepts a slot with no model yet

📊 Changes

30 files changed (+2677 additions, -90 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 docs/agents/custom-agents.md (+30 -1)
📝 e2e/agent-activation-questions.e2e.ts (+12 -1)
📝 packages/client/src/components/agents/AgentEditor.tsx (+7 -7)
📝 packages/client/src/components/connections/DecisionDefaultControl.tsx (+213 -59)
📝 packages/client/src/components/panels/ConnectionsPanel.tsx (+1 -1)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+6 -0)
➕ packages/client/src/hooks/use-decision-model.ts (+89 -0)
📝 packages/client/src/lib/support-diagnostics.ts (+99 -0)
📝 packages/client/src/localization/locales/en.json (+25 -0)
📝 packages/server/src/app.ts (+15 -0)
➕ packages/server/src/routes/decision.routes.ts (+250 -0)
📝 packages/server/src/routes/generate.routes.ts (+19 -21)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/services/decision/decision-default.ts (+118 -0)
➕ packages/server/src/services/decision/decision-slots.ts (+158 -0)
➕ packages/server/src/services/decision/decision-thinking-cache.ts (+80 -0)
➕ packages/server/src/services/decision/logprob-answer.ts (+104 -0)
➕ packages/server/src/services/decision/sidecar-decision.backend.ts (+232 -0)
➕ packages/server/src/services/sidecar/sidecar-footprint.ts (+292 -0)

...and 10 more files

📄 Description

Linked issue

Closes #6539

Why this change

Activation questions shipped in #6531 needed a Decision connection, which means a hosted API key. A user who runs Marinara with a local model and no paid API could not gate a custom agent at all, even though the model they already run answers the question well. Measured on the pinned llama.cpp build with a Gemma 4 E4B: 0.0000 for a turn that stays in one room, 0.9996 for one that leaves it.

Issue #6530 scoped this out on purpose as a separate phase needing its own hardware validation. This is that phase. The managed Open-Jev installer is the next one and is not in this PR.

The diagnostics half is useful on its own, before anyone touches an activation question. Support diagnostics report the browser's GPU, which says nothing about the machine running the local model when the client is a phone or another PC.

What changed

  • A local slot answers a decision with one chat completion at max_tokens: 1, reading the probability from the first token's top_logprobs. No grammar or json_schema, because a constraint can change what top_logprobs reports. The shared state is the prompt prefix so llama-server reuses its cache across a group's questions.
  • The Decision model setting is now one list with three groups: None, Local models, Connections. Entries that cannot serve are greyed out with the reason instead of hidden. A selected entry that later becomes unusable stays selected, gates fail open, and the reason is shown.
  • A Thinking setting per local slot. Auto tries the one-word method and gives a model permission to think after two failures; Off never lets it think; Allowed never asks it to skip. The verdict lives in a cache keyed by the loaded model, so swapping models returns to the fast path and the user's own setting is never rewritten.
  • A thinking model gates post-processing agents only by default, since those run after the reply is on screen. Pre-generation and parallel gating is opt-in with a warning that every reply will wait.
  • Per-source timeouts: 1.5 s for a Decision connection, 4 s for a local slot, 20 s when the model has to think. All fail open.
  • sidecar-footprint.ts: an nvidia-smi probe, per-slot memory figures, and the verdict logic, with the command output injected so a regression covers every verdict row on a machine with no GPU.
  • /api/health gains a sidecar section from a cached probe, and Copy Diagnostics gains the server's GPU, one line per slot, and a combined load verdict. The health endpoint never waits on nvidia-smi; a probe that has not finished reports itself as pending.

A running slot's memory is read from the process rather than estimated from the model file. That matters: a Gemma 4 E4B measured 5.2 GB on the card from an 8.2 GB file, so the size-based estimate overstates it by half. The KV-cache allowance for the not-running case is measured too, at 64.7 KiB per token, from the same GGUF loaded at 4,096 and at 32,768 tokens.

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

pnpm check green. pnpm regression:node 351/351, including a new decision-local-models.regression.ts covering a clean yes, a clean no, a reasoning marker as the first token, unrelated prose, missing log-probabilities, the two-failure Auto switch, per-model cache isolation, and every footprint verdict row from recorded nvidia-smi output.

Manual verification notes

Run on Linux with an NVIDIA RTX 5090 Laptop (24463 MiB, driver 615.71.09), against a decoupled install on port 7820 with its own DATA_DIR, so the live install was untouched.

  1. The build returns log-probabilities. The proposal flagged this as the open question the whole method depends on. Pinned llama.cpp b10188, max_tokens: 1, logprobs: true, top_logprobs: 10: for "the location, time or cast of the scene changed", a turn leaving the inn at dawn returned yes at p=0.724 with 99.9% of the listed mass on yes/no variants; a turn about the ale returned no at p=0.0001 with 100%.
  2. The gate skips and runs. Driving the same two functions the generate route's gate calls, against the real model: the turn that stays put answered p=0.0000 and the agent was skipped; the turn that moves answered p=0.9996 and it ran. 201 ms and 157 ms. The assertion requires a real numeric probability, because "not skipped" is also what a failed request produces and an earlier version of this check passed on a fail-open.
  3. The slot starts on demand. With useForTrackers and useForGameScene both off, selecting the primary local model and pressing Test started llama-server and answered p=0.9997. This is the fix in the second commit; the first commit called ensureReady() without forceStart, so that user's chosen decision model would never have started.
  4. The dropdown is honest about what it cannot do. With no utility model installed and no decision runtime, /api/decision/options returned the primary slot selectable with its real model name, the utility slot greyed with "No model downloaded", and the decision sidecar greyed with "Not installed".
  5. Diagnostics. /api/health reported the main slot as measured 7.37 GB, matching nvidia-smi's 7030 MiB exactly, with a "recommended" verdict and 18.3 GB headroom. The first call after boot correctly returned pending: true without blocking.
  6. Failing open is real, not theoretical. While two stale llama-servers were holding memory from an earlier run, cold decision requests exceeded the 4 s budget and the agents ran. No generation failed.

Not done: no container build, and no second machine, so the multi-GPU path where the slots' device cannot be resolved by name is covered by the regression rather than by hardware.

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)

docs/agents/custom-agents.md gains a "Use a model you already run" section and corrects the timeout text, which said 1.5 seconds for everything. Translated docs are batched as a separate [docs-i18n] follow-up.

UI evidence (if applicable)

The existing activation-question e2e covers the dropdown and takes light and dark screenshots; it is extended here to assert that the Local models group is present and that unavailable entries are visible, disabled, and carry their reason.

Summary by CodeRabbit

  • New Features
    • Agent activation questions can use an already-running primary or utility local model without downloading data or sending it off-device.
    • Choose local or connection-based decision models, configure Thinking modes, and control pre-generation thinking.
    • Test local models and view availability, answer-style, and calibration details.
  • Diagnostics
    • Support diagnostics now include server GPU usage, local-model slot status, memory estimates, and capacity assessments.
    • Browser and server GPU information are clearly distinguished.
  • Documentation
    • Expanded guidance covers local models, Thinking settings, model suitability, privacy, and resource budgeting.

🔄 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/6540 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/22/2026 **Status:** ✅ Merged **Merged:** 9/22/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/decision-local-models` --- ### 📝 Commits (5) - [`ae2a34f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ae2a34ff2db03481a1148a4e875bdb365f5064ca) feat(agents): answer activation questions with a local model - [`2068007`](https://github.com/Pasta-Devs/Marinara-Engine/commit/20680078018ddb3b938fb70390142f800c6dd256) fix(agents): start the chosen local slot for decisions on demand - [`9658216`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9658216d05826dfc1f16cfc911a0a38c3be72c2c) fix(agents): keep decision gating consistent with what is actually slow - [`47fee5c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/47fee5c89800f7b271f34e00f888515d7ff094f4) fix(agents): refuse decision models the dropdown greys out, and keep health cheap - [`45ee629`](https://github.com/Pasta-Devs/Marinara-Engine/commit/45ee629250e650dd57d75fa9f269e0b762bb9eca) docs(agents): say why /thinking accepts a slot with no model yet ### 📊 Changes **30 files changed** (+2677 additions, -90 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `docs/agents/custom-agents.md` (+30 -1) 📝 `e2e/agent-activation-questions.e2e.ts` (+12 -1) 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+7 -7) 📝 `packages/client/src/components/connections/DecisionDefaultControl.tsx` (+213 -59) 📝 `packages/client/src/components/panels/ConnectionsPanel.tsx` (+1 -1) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+6 -0) ➕ `packages/client/src/hooks/use-decision-model.ts` (+89 -0) 📝 `packages/client/src/lib/support-diagnostics.ts` (+99 -0) 📝 `packages/client/src/localization/locales/en.json` (+25 -0) 📝 `packages/server/src/app.ts` (+15 -0) ➕ `packages/server/src/routes/decision.routes.ts` (+250 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+19 -21) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/services/decision/decision-default.ts` (+118 -0) ➕ `packages/server/src/services/decision/decision-slots.ts` (+158 -0) ➕ `packages/server/src/services/decision/decision-thinking-cache.ts` (+80 -0) ➕ `packages/server/src/services/decision/logprob-answer.ts` (+104 -0) ➕ `packages/server/src/services/decision/sidecar-decision.backend.ts` (+232 -0) ➕ `packages/server/src/services/sidecar/sidecar-footprint.ts` (+292 -0) _...and 10 more files_ </details> ### 📄 Description ## Linked issue Closes #6539 ## Why this change Activation questions shipped in #6531 needed a Decision connection, which means a hosted API key. A user who runs Marinara with a local model and no paid API could not gate a custom agent at all, even though the model they already run answers the question well. Measured on the pinned llama.cpp build with a Gemma 4 E4B: 0.0000 for a turn that stays in one room, 0.9996 for one that leaves it. Issue #6530 scoped this out on purpose as a separate phase needing its own hardware validation. This is that phase. The managed Open-Jev installer is the next one and is not in this PR. The diagnostics half is useful on its own, before anyone touches an activation question. Support diagnostics report the browser's GPU, which says nothing about the machine running the local model when the client is a phone or another PC. ## What changed - A local slot answers a decision with one chat completion at `max_tokens: 1`, reading the probability from the first token's `top_logprobs`. No grammar or `json_schema`, because a constraint can change what `top_logprobs` reports. The shared state is the prompt prefix so llama-server reuses its cache across a group's questions. - The Decision model setting is now one list with three groups: None, Local models, Connections. Entries that cannot serve are greyed out with the reason instead of hidden. A selected entry that later becomes unusable stays selected, gates fail open, and the reason is shown. - A **Thinking** setting per local slot. Auto tries the one-word method and gives a model permission to think after two failures; Off never lets it think; Allowed never asks it to skip. The verdict lives in a cache keyed by the loaded model, so swapping models returns to the fast path and the user's own setting is never rewritten. - A thinking model gates post-processing agents only by default, since those run after the reply is on screen. Pre-generation and parallel gating is opt-in with a warning that every reply will wait. - Per-source timeouts: 1.5 s for a Decision connection, 4 s for a local slot, 20 s when the model has to think. All fail open. - `sidecar-footprint.ts`: an `nvidia-smi` probe, per-slot memory figures, and the verdict logic, with the command output injected so a regression covers every verdict row on a machine with no GPU. - `/api/health` gains a sidecar section from a cached probe, and Copy Diagnostics gains the server's GPU, one line per slot, and a combined load verdict. The health endpoint never waits on `nvidia-smi`; a probe that has not finished reports itself as pending. A running slot's memory is read from the process rather than estimated from the model file. That matters: a Gemma 4 E4B measured 5.2 GB on the card from an 8.2 GB file, so the size-based estimate overstates it by half. The KV-cache allowance for the not-running case is measured too, at 64.7 KiB per token, from the same GGUF loaded at 4,096 and at 32,768 tokens. ## Validation - [x] `pnpm check` passes locally - [ ] 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` `pnpm check` green. `pnpm regression:node` 351/351, including a new `decision-local-models.regression.ts` covering a clean yes, a clean no, a reasoning marker as the first token, unrelated prose, missing log-probabilities, the two-failure Auto switch, per-model cache isolation, and every footprint verdict row from recorded `nvidia-smi` output. ### Manual verification notes Run on Linux with an NVIDIA RTX 5090 Laptop (24463 MiB, driver 615.71.09), against a decoupled install on port 7820 with its own `DATA_DIR`, so the live install was untouched. 1. **The build returns log-probabilities.** The proposal flagged this as the open question the whole method depends on. Pinned llama.cpp b10188, `max_tokens: 1, logprobs: true, top_logprobs: 10`: for "the location, time or cast of the scene changed", a turn leaving the inn at dawn returned `yes` at p=0.724 with 99.9% of the listed mass on yes/no variants; a turn about the ale returned `no` at p=0.0001 with 100%. 2. **The gate skips and runs.** Driving the same two functions the generate route's gate calls, against the real model: the turn that stays put answered p=0.0000 and the agent was skipped; the turn that moves answered p=0.9996 and it ran. 201 ms and 157 ms. The assertion requires a real numeric probability, because "not skipped" is also what a failed request produces and an earlier version of this check passed on a fail-open. 3. **The slot starts on demand.** With `useForTrackers` and `useForGameScene` both off, selecting the primary local model and pressing Test started llama-server and answered p=0.9997. This is the fix in the second commit; the first commit called `ensureReady()` without `forceStart`, so that user's chosen decision model would never have started. 4. **The dropdown is honest about what it cannot do.** With no utility model installed and no decision runtime, `/api/decision/options` returned the primary slot selectable with its real model name, the utility slot greyed with "No model downloaded", and the decision sidecar greyed with "Not installed". 5. **Diagnostics.** `/api/health` reported the main slot as `measured 7.37 GB`, matching `nvidia-smi`'s 7030 MiB exactly, with a "recommended" verdict and 18.3 GB headroom. The first call after boot correctly returned `pending: true` without blocking. 6. **Failing open is real, not theoretical.** While two stale llama-servers were holding memory from an earlier run, cold decision requests exceeded the 4 s budget and the agents ran. No generation failed. Not done: no container build, and no second machine, so the multi-GPU path where the slots' device cannot be resolved by name is covered by the regression rather than by hardware. ## Docs and release impact - [ ] No docs changes needed - [x] 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) `docs/agents/custom-agents.md` gains a "Use a model you already run" section and corrects the timeout text, which said 1.5 seconds for everything. Translated docs are batched as a separate `[docs-i18n]` follow-up. ## UI evidence (if applicable) The existing activation-question e2e covers the dropdown and takes light and dark screenshots; it is extended here to assert that the Local models group is present and that unavailable entries are visible, disabled, and carry their reason. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Agent activation questions can use an already-running primary or utility local model without downloading data or sending it off-device. - Choose local or connection-based decision models, configure Thinking modes, and control pre-generation thinking. - Test local models and view availability, answer-style, and calibration details. - **Diagnostics** - Support diagnostics now include server GPU usage, local-model slot status, memory estimates, and capacity assessments. - Browser and server GPU information are clearly distinguished. - **Documentation** - Expanded guidance covers local models, Thinking settings, model suitability, privacy, and resource budgeting. <!-- 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:17:38 +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#7219
No description provided.