[PR #5678] [MERGED] feat(sidecar): add a second, independent local model slot for agents #6880

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5678
Author: @GetBeholder
Created: 8/30/2026
Status: ✅ Merged
Merged: 8/30/2026
Merged by: @GetBeholder

Base: staging ← Head: feat/utility-sidecar


📝 Commits (10+)

  • 052d61e feat(sidecar): add a second, independent local model slot for agents
  • 544eda9 fix(sidecar): start the utility slot on demand and stop misnaming the connection
  • 201df77 chore: drop an accidentally committed node_modules symlink
  • d704538 fix(i18n): keep en.json key order alphabetical
  • 83f12ff fix(test): import shared from source in the utility-sidecar regression
  • 53a0851 fix(sidecar): rate-limit the utility slot routes
  • 4077751 feat(sidecar): put the utility model on the GPU by default
  • e9e3eb2 fix(sidecar): reject bad model ids, keep the process in step, name the real connection
  • d9bf5b3 Merge branch 'staging' into feat/utility-sidecar
  • 937778a fix(sidecar): wait for the process to exit, and recheck identity after a shared start

📊 Changes

13 files changed (+1469 additions, -18 deletions)

View changed files

📝 packages/client/src/components/agents/AgentEditor.tsx (+47 -1)
📝 packages/client/src/localization/locales/en.json (+2 -0)
📝 packages/server/src/middleware/rate-limit.ts (+12 -0)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+78 -9)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/routes/utility-sidecar.routes.ts (+178 -0)
📝 packages/server/src/services/generation/agent-resolution.ts (+51 -8)
➕ packages/server/src/services/utility-sidecar/utility-sidecar.provider.ts (+98 -0)
➕ packages/server/src/services/utility-sidecar/utility-sidecar.service.ts (+588 -0)
📝 packages/shared/src/constants/defaults.ts (+8 -0)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/types/utility-sidecar.ts (+111 -0)
➕ scripts/regressions/utility-sidecar.regression.ts (+293 -0)

📄 Description

Linked issue

Closes #

Why this change

Some agents are built around a small purpose-trained model rather than a general one — an extractor whose output is graded against a schema, where a 0.8B model tuned for the job beats a large general one and costs nothing to run.

There is nowhere to put such a model. The sidecar holds exactly one, and that one is the model the operator chose for generation, scene analysis and trackers. Installing an agent's model into it displaces their choice, so in practice those agents have no local path at all and must be pointed at a paid connection.

What changed

A second, parallel slot. Everything in it is additive; nothing about the existing sidecar changes.

Isolation. Its own config file, its own model directory under data/models/utility, its own llama-server on its own dynamically allocated port. The one thing it shares is the installed llama.cpp runtime, read-only: it uses sidecarRuntimeService.getCurrentInstall() and refuses to start when the runtime is absent, rather than ensureInstalled(), which would download and rewrite shared state the main slot depends on. It never reads or writes sidecar-config.json, never touches models outside its own subdirectory, and never stops or restarts the main process.

Routing. When the slot is up and holding a model whose id matches an agent, it answers for that agent; otherwise the agent's configured connection is used exactly as before. The rule is one pure function (utilitySlotServesAgent) shared by both agent resolution paths rather than duplicated in each. A configured-but-down slot falls back rather than failing the run.

Saying which model answered. GET /api/utility-sidecar/routing/:agentType returns the verdict and the reason for it, so a UI can name the model that will actually run instead of inferring it from the connection list. This matters more than it looks: an agent answered by the wrong model fails in ways that read as a bad model rather than a wrong setting.

Explicit selection. The agent editor offers the slot as a connection, but only once a model for that agent is installed — an option that cannot answer is worse than no option. Chosen-but-not-serving is reported as unavailable rather than quietly answered by a different model, because the two need different prompts.

Updates by version, not size. A requantization can land on the same byte count, and the operator is being asked to spend a download, so comparison is by blob id. When the ids cannot be compared the answer is indeterminate rather than an implied "current".

Settings expose hardware only — context size, GPU layers, parallel slots, each clamped before it reaches llama-server. Sampling is deliberately absent: an extractor is graded against a schema, and a temperature dial on it turns a working install into a subtly broken one. Defaults are CPU-only so a first run cannot quietly contend with the main sidecar for VRAM.

All writes sit behind requirePrivilegedAccess.

Validation

  • scripts/regressions/utility-sidecar.regression.ts added and passing
  • Full node regression suite: 166/168. The two failures (extension-security, mari/db-execution-security) reproduce identically on the unmodified base commit and are environmental
  • tsc --noEmit clean for packages/server and packages/client
  • prettier --check "packages/**/*.{ts,tsx}" clean
  • Ran a real engine against an isolated DATA_DIR and drove the whole feature end to end (below)
  • Container (Docker / Podman) built and ran without issue
  • Client UI clicked through in a browser (the agent-editor connection option)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Driven against a real engine on an isolated DATA_DIR, seeded with a main sidecar holding a different model so displacement would show up:

  • Install — real download from HuggingFace through the route: 811 MB, blob id recorded, landed only at data/models/utility/beholder/.
  • Input validation over HTTP — malformed repo, ../../escape.gguf, an absolute path, and a non-.gguf file each rejected with 400, and nothing was written outside the utility directory.
  • Update check — against the live repo: ids matched, updateAvailable: false, indeterminate: false.
  • Start — own llama-server on its own allocated port, launched with -ngl 0, so it does not contend with the main sidecar for VRAM by default.
  • A real Beholder agent run through /api/generate/retry-agents — all five lane passes answered by the local model. The debug stream shows utility-sidecar as the only model used.
  • Cold start — engine restarted with the slot selected but stopped; the next agent run started it on demand and again used only the local model.
  • The invariant — the main sidecar's sidecar-config.json, its model file and its runtime record are byte-for-byte identical (sha256) after install, start, an agent run and a restart.

Three faults were found this way and are fixed in the second commit: the slot did not survive a restart (routing required an already-running process, so a restart silently returned the agent to its paid connection); the run warned that it was billing the default gpt-5.5 connection while the local model was actually answering; and the main generation path's built-in agent loop had no override at all. The first two are exactly the kind of thing the code reads correctly and the running system does not.

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

Server-side feature; the client change is one conditional <option> in the agent editor, shown only when a model for that agent is installed.

Summary by CodeRabbit

  • New Features
    • Added an independently managed utility sidecar for local agent models.
    • Added model installation, removal, activation, update checks, hardware settings, and start/stop controls.
    • Eligible agents can automatically use the utility sidecar when a compatible model is available.
    • Added utility-sidecar status and routing information.
  • Improvements
    • The agent editor displays eligible utility models and clearly labels unavailable selections.
    • Improved isolation between utility-sidecar and main local-sidecar settings and models.
    • Added installation progress, model validation, safeguards, and request limits.

🔄 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/5678 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 8/30/2026 **Status:** ✅ Merged **Merged:** 8/30/2026 **Merged by:** [@GetBeholder](https://github.com/GetBeholder) **Base:** `staging` ← **Head:** `feat/utility-sidecar` --- ### 📝 Commits (10+) - [`052d61e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/052d61ec09d5813377f32493ee4a3c264b82de05) feat(sidecar): add a second, independent local model slot for agents - [`544eda9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/544eda9fecdf0e7b2dd9c51d213506fe8064a2c5) fix(sidecar): start the utility slot on demand and stop misnaming the connection - [`201df77`](https://github.com/Pasta-Devs/Marinara-Engine/commit/201df77aece6fbea6241b07288c306ab77b5f9af) chore: drop an accidentally committed node_modules symlink - [`d704538`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d7045387f73de23a60d5b5bc5c599c839e2b4e14) fix(i18n): keep en.json key order alphabetical - [`83f12ff`](https://github.com/Pasta-Devs/Marinara-Engine/commit/83f12ff68469f4bc5780ca74c9dc098874f791d9) fix(test): import shared from source in the utility-sidecar regression - [`53a0851`](https://github.com/Pasta-Devs/Marinara-Engine/commit/53a08511d0eff8ebffa2313f40ce848ce4f42bfe) fix(sidecar): rate-limit the utility slot routes - [`4077751`](https://github.com/Pasta-Devs/Marinara-Engine/commit/407775157aa954e7ec069fb3f31f7c8d11b1c966) feat(sidecar): put the utility model on the GPU by default - [`e9e3eb2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e9e3eb20f709ed5b8b7a6eef475362d78d16b017) fix(sidecar): reject bad model ids, keep the process in step, name the real connection - [`d9bf5b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d9bf5b3504dfe1702beba9f36721cfdc8d7aebde) Merge branch 'staging' into feat/utility-sidecar - [`937778a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/937778ac53a0901ad56aecf87160189bd5f67136) fix(sidecar): wait for the process to exit, and recheck identity after a shared start ### 📊 Changes **13 files changed** (+1469 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+47 -1) 📝 `packages/client/src/localization/locales/en.json` (+2 -0) 📝 `packages/server/src/middleware/rate-limit.ts` (+12 -0) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+78 -9) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/routes/utility-sidecar.routes.ts` (+178 -0) 📝 `packages/server/src/services/generation/agent-resolution.ts` (+51 -8) ➕ `packages/server/src/services/utility-sidecar/utility-sidecar.provider.ts` (+98 -0) ➕ `packages/server/src/services/utility-sidecar/utility-sidecar.service.ts` (+588 -0) 📝 `packages/shared/src/constants/defaults.ts` (+8 -0) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/types/utility-sidecar.ts` (+111 -0) ➕ `scripts/regressions/utility-sidecar.regression.ts` (+293 -0) </details> ### 📄 Description ## Linked issue Closes # ## Why this change Some agents are built around a small purpose-trained model rather than a general one — an extractor whose output is graded against a schema, where a 0.8B model tuned for the job beats a large general one and costs nothing to run. There is nowhere to put such a model. The sidecar holds exactly one, and that one is the model the operator chose for generation, scene analysis and trackers. Installing an agent's model into it displaces their choice, so in practice those agents have no local path at all and must be pointed at a paid connection. ## What changed A second, parallel slot. Everything in it is additive; nothing about the existing sidecar changes. **Isolation.** Its own config file, its own model directory under `data/models/utility`, its own `llama-server` on its own dynamically allocated port. The one thing it shares is the installed llama.cpp runtime, read-only: it uses `sidecarRuntimeService.getCurrentInstall()` and refuses to start when the runtime is absent, rather than `ensureInstalled()`, which would download and rewrite shared state the main slot depends on. It never reads or writes `sidecar-config.json`, never touches models outside its own subdirectory, and never stops or restarts the main process. **Routing.** When the slot is up and holding a model whose id matches an agent, it answers for that agent; otherwise the agent's configured connection is used exactly as before. The rule is one pure function (`utilitySlotServesAgent`) shared by both agent resolution paths rather than duplicated in each. A configured-but-down slot falls back rather than failing the run. **Saying which model answered.** `GET /api/utility-sidecar/routing/:agentType` returns the verdict *and the reason for it*, so a UI can name the model that will actually run instead of inferring it from the connection list. This matters more than it looks: an agent answered by the wrong model fails in ways that read as a bad model rather than a wrong setting. **Explicit selection.** The agent editor offers the slot as a connection, but only once a model for that agent is installed — an option that cannot answer is worse than no option. Chosen-but-not-serving is reported as unavailable rather than quietly answered by a different model, because the two need different prompts. **Updates by version, not size.** A requantization can land on the same byte count, and the operator is being asked to spend a download, so comparison is by blob id. When the ids cannot be compared the answer is `indeterminate` rather than an implied "current". **Settings expose hardware only** — context size, GPU layers, parallel slots, each clamped before it reaches `llama-server`. Sampling is deliberately absent: an extractor is graded against a schema, and a temperature dial on it turns a working install into a subtly broken one. Defaults are CPU-only so a first run cannot quietly contend with the main sidecar for VRAM. All writes sit behind `requirePrivilegedAccess`. ## Validation - [x] `scripts/regressions/utility-sidecar.regression.ts` added and passing - [x] Full node regression suite: 166/168. The two failures (`extension-security`, `mari/db-execution-security`) reproduce identically on the unmodified base commit and are environmental - [x] `tsc --noEmit` clean for `packages/server` and `packages/client` - [x] `prettier --check "packages/**/*.{ts,tsx}"` clean - [x] Ran a real engine against an isolated `DATA_DIR` and drove the whole feature end to end (below) - [ ] Container (Docker / Podman) built and ran without issue - [ ] Client UI clicked through in a browser (the agent-editor connection option) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Driven against a real engine on an isolated `DATA_DIR`, seeded with a main sidecar holding a *different* model so displacement would show up: - **Install** — real download from HuggingFace through the route: 811 MB, blob id recorded, landed only at `data/models/utility/beholder/`. - **Input validation over HTTP** — malformed repo, `../../escape.gguf`, an absolute path, and a non-`.gguf` file each rejected with 400, and nothing was written outside the utility directory. - **Update check** — against the live repo: ids matched, `updateAvailable: false`, `indeterminate: false`. - **Start** — own `llama-server` on its own allocated port, launched with `-ngl 0`, so it does not contend with the main sidecar for VRAM by default. - **A real Beholder agent run through `/api/generate/retry-agents`** — all five lane passes answered by the local model. The debug stream shows `utility-sidecar` as the only model used. - **Cold start** — engine restarted with the slot selected but stopped; the next agent run started it on demand and again used only the local model. - **The invariant** — the main sidecar's `sidecar-config.json`, its model file and its runtime record are byte-for-byte identical (sha256) after install, start, an agent run and a restart. Three faults were found this way and are fixed in the second commit: the slot did not survive a restart (routing required an already-running process, so a restart silently returned the agent to its paid connection); the run warned that it was billing the default gpt-5.5 connection while the local model was actually answering; and the main generation path's built-in agent loop had no override at all. The first two are exactly the kind of thing the code reads correctly and the running system does not. ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) Server-side feature; the client change is one conditional `<option>` in the agent editor, shown only when a model for that agent is installed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an independently managed utility sidecar for local agent models. * Added model installation, removal, activation, update checks, hardware settings, and start/stop controls. * Eligible agents can automatically use the utility sidecar when a compatible model is available. * Added utility-sidecar status and routing information. * **Improvements** * The agent editor displays eligible utility models and clearly labels unavailable selections. * Improved isolation between utility-sidecar and main local-sidecar settings and models. * Added installation progress, model validation, safeguards, and request limits. <!-- 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:14:32 +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#6880
No description provided.