[PR #8376] [MERGED] perf(mari): smaller write results and a cache-stable system prompt #8323

Closed
opened 2026-10-27 06:07:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8376
Author: @ylli-selmani
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ylli-selmani

Base: staging ← Head: perf/prompt-diet


📝 Commits (4)

  • 6a5a5da perf(mari): stop re-sending what a write's tool call already carried
  • 5373c27 perf(mari): put the per-turn context lines last in her system prompt
  • 6e60ebd perf(mari): keep the text tool block in the cached prompt prefix
  • 1277e0a fix(mari): find the per-turn prompt block by message, not by text

📊 Changes

5 files changed (+151 additions, -20 deletions)

View changed files

📝 packages/server/src/services/professor-mari/pi-runtime.ts (+20 -6)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+35 -12)
📝 packages/server/src/services/professor-mari/workspace-commands.ts (+1 -1)
📝 scripts/regressions/mari-write-readback.regression.ts (+56 -0)
📝 scripts/regressions/professor-mari/pi-runtime.regression.ts (+39 -1)

📄 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 #8375

Why this change

On a small-context model (12b, 16k), Professor Mari runs out of room partway through a task. The permanent prompt is large, but the faster drain is how much each tool turn adds: about 12k chars per turn in a measured Gemma 4 31b run. Much of that is text the model already has:

  • A write's result repeated its own input twice. One character.create result was 8,581 chars. Of those, 2,934 were the call's arguments echoed back in an <input> block, and 515 were the same arguments again as the command string.
  • An update echoed unchanged nested data. changedFieldsOnly compared fields only one level deep, so a description-only character.update returned the whole data.extensions object (where onboarding lives) whenever anything inside it differed. Mari hit the 32,000-char result cut this way.
  • Every new chat missed the prompt cache. The <workspace_context> block (with currentTime and this turn's message id) sat third in the system prompt, so everything after it, including the skill index and the memories, changed on every turn.

What changed

Write results (workspace-agent.service.ts, pi-runtime.ts)

  • changedFieldsOnly diffs nested records at any depth (capped at 8 levels). Arrays are still compared and shown whole.
  • Pi tool results drop the <input> block, since the native tool call already carries the arguments. The opening tag keeps the tool name and gains the action, e.g. <workspace_command_result name="app_data" action="character.create" success="true">. The classic JSON runtime is unchanged, because its model has no separate tool call to look back at.
  • The model-facing app_data mutation result drops its command string. mari CLI commands keep it. The raw result, which the change card, receipts and keep/undo read, is untouched.

Prompt order (workspace-agent.service.ts)

  • <workspace_context> is now the last of the prompt blocks, after the skill index, memories, permissions mode and understood-request record. Nothing in it is removed or reworded; decisionAuthoring stays JSON because it carries pending Decision questions and consent records.
  • On connections without native tool calls (pi-runtime.ts), the <text_tool_calls> block now goes just before <workspace_context> instead of after the whole prompt, so it stays in the cached part too.

Regressions (mari-write-readback, pi-runtime)

  • A nested onboarding change returns only extensions.onboarding, with no sibling keys and no unchanged data fields. Proven to bite: it fails with the old one-level diff.
  • app_data results have no command; a mari db patch result keeps it.
  • echoInput: false drops <input> and names the action; the default still echoes it.
  • In the real pi prompt, <workspace_context> follows the tool rules and the skill index, and only pi's own <cwd> line comes after it. Proven to bite: it fails with the old order.
  • On a textual connection, the real prompt puts <text_tool_calls> before <workspace_context>. Proven to bite: it fails with the old append.

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

Agent-run checks:

  • pnpm check exits 0.
  • node scripts/run-regressions.mjs --filter passes for mari-write-readback, professor-mari (23/23), mari- (18/18), scripts/regressions/mari/ (35/35) and pi-runtime.
  • Local CodeRabbit on the whole branch: 0 findings.

Still to check by hand:

  • Manually verify in the browser: ask Mari to create a character, then to change only its description. She should still confirm both correctly, and the request log should show tool results without an <input> block.
  • Before/after request logs on Gemma 31b and a 12b follow in the finetuning pass.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

UI evidence (if applicable)

No UI changes. The change is in what Mari's model receives.

🤖 Generated with Claude Code


🔄 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/8376 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `perf/prompt-diet` --- ### 📝 Commits (4) - [`6a5a5da`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6a5a5da2fe9e3cb837f61a48003bd27f1ced4ae2) perf(mari): stop re-sending what a write's tool call already carried - [`5373c27`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5373c278caeabb728a182edf3b38e7ea1c3706e7) perf(mari): put the per-turn context lines last in her system prompt - [`6e60ebd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6e60ebd697543df32f39b195afe1558b7380355b) perf(mari): keep the text tool block in the cached prompt prefix - [`1277e0a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1277e0acba90e73cbc89a3e166f460caf3e8486b) fix(mari): find the per-turn prompt block by message, not by text ### 📊 Changes **5 files changed** (+151 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/professor-mari/pi-runtime.ts` (+20 -6) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+35 -12) 📝 `packages/server/src/services/professor-mari/workspace-commands.ts` (+1 -1) 📝 `scripts/regressions/mari-write-readback.regression.ts` (+56 -0) 📝 `scripts/regressions/professor-mari/pi-runtime.regression.ts` (+39 -1) </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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8375 ## Why this change On a small-context model (12b, 16k), Professor Mari runs out of room partway through a task. The permanent prompt is large, but the faster drain is how much each tool turn adds: about 12k chars per turn in a measured Gemma 4 31b run. Much of that is text the model already has: - **A write's result repeated its own input twice.** One `character.create` result was 8,581 chars. Of those, 2,934 were the call's arguments echoed back in an `<input>` block, and 515 were the same arguments again as the `command` string. - **An update echoed unchanged nested data.** `changedFieldsOnly` compared fields only one level deep, so a description-only `character.update` returned the whole `data.extensions` object (where onboarding lives) whenever anything inside it differed. Mari hit the 32,000-char result cut this way. - **Every new chat missed the prompt cache.** The `<workspace_context>` block (with `currentTime` and this turn's message id) sat third in the system prompt, so everything after it, including the skill index and the memories, changed on every turn. ## What changed **Write results** (`workspace-agent.service.ts`, `pi-runtime.ts`) - `changedFieldsOnly` diffs nested records at any depth (capped at 8 levels). Arrays are still compared and shown whole. - Pi tool results drop the `<input>` block, since the native tool call already carries the arguments. The opening tag keeps the tool name and gains the action, e.g. `<workspace_command_result name="app_data" action="character.create" success="true">`. The classic JSON runtime is unchanged, because its model has no separate tool call to look back at. - The model-facing `app_data` mutation result drops its `command` string. `mari` CLI commands keep it. The raw result, which the change card, receipts and keep/undo read, is untouched. **Prompt order** (`workspace-agent.service.ts`) - `<workspace_context>` is now the last of the prompt blocks, after the skill index, memories, permissions mode and understood-request record. Nothing in it is removed or reworded; `decisionAuthoring` stays JSON because it carries pending Decision questions and consent records. - On connections without native tool calls (`pi-runtime.ts`), the `<text_tool_calls>` block now goes just before `<workspace_context>` instead of after the whole prompt, so it stays in the cached part too. **Regressions** (`mari-write-readback`, `pi-runtime`) - A nested onboarding change returns only `extensions.onboarding`, with no sibling keys and no unchanged `data` fields. Proven to bite: it fails with the old one-level diff. - `app_data` results have no `command`; a `mari db patch` result keeps it. - `echoInput: false` drops `<input>` and names the action; the default still echoes it. - In the real pi prompt, `<workspace_context>` follows the tool rules and the skill index, and only pi's own `<cwd>` line comes after it. Proven to bite: it fails with the old order. - On a textual connection, the real prompt puts `<text_tool_calls>` before `<workspace_context>`. Proven to bite: it fails with the old append. ## 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 Agent-run checks: - `pnpm check` exits 0. - `node scripts/run-regressions.mjs --filter` passes for `mari-write-readback`, `professor-mari` (23/23), `mari-` (18/18), `scripts/regressions/mari/` (35/35) and `pi-runtime`. - Local CodeRabbit on the whole branch: 0 findings. Still to check by hand: - Manually verify in the browser: ask Mari to create a character, then to change only its description. She should still confirm both correctly, and the request log should show tool results without an `<input>` block. - Before/after request logs on Gemma 31b and a 12b follow in the finetuning pass. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) ## UI evidence (if applicable) No UI changes. The change is in what Mari's model receives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #8376] perf(mari): smaller write results and a cache-stable system prompt to [PR #8376] [MERGED] perf(mari): smaller write results and a cache-stable system prompt 2026-11-07 16:45:37 +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#8323
No description provided.