[PR #8090] [MERGED] fix(mari): recover when a reply hits the model's output limit #8092

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

📋 Pull Request Information

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

Base: staging ← Head: claude/mari-output-limit-recovery-002a30


📝 Commits (2)

  • 6d2c266 fix(mari): recover when a reply hits the model's output limit
  • 76e122c fix(mari): audit a failed stream; name a closed textual call cut before prose

📊 Changes

8 files changed (+322 additions, -38 deletions)

View changed files

📝 packages/server/src/services/llm/base-provider.ts (+9 -0)
📝 packages/server/src/services/llm/providers/anthropic.provider.ts (+3 -2)
📝 packages/server/src/services/llm/providers/google.provider.ts (+3 -4)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+12 -16)
📝 packages/server/src/services/professor-mari/pi-runtime.ts (+107 -11)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+1 -0)
📝 scripts/regressions/professor-mari/pi-runtime.regression.ts (+135 -5)
📝 scripts/regressions/provider-compat.regression.ts (+52 -0)

📄 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

Part of #8096 (umbrella). This PR is part 1 of 2; the handbook follow-up (PR B) closes it.

Why this change

  • When a reply hits the connection's output limit (Max Output Tokens), Professor Mari stops and the user has to type "continue". She usually retries the same oversized call and is cut again. Small local models (e.g. Gemma 3 12b) hit this on any large write.
  • On native tool-calling connections the cut was hidden: OpenAI (chat + Responses), Anthropic and Google reported a cut tool call as tool_calls, not length. Mari ran it with {} arguments, got a generic "invalid arguments" error and never learned why.

What changed

Providers (no visible change for the user)

  • base-provider.ts: new toolCallFinishReason(). A reply with tool calls reports tool_calls unless it was cut (length / max_tokens / max_output_tokens). It is used at every finish-reason site in the OpenAI, Anthropic and Google providers. Nothing in the server compares against "tool_calls", so no caller changes.

Professor Mari, pi runtime (visible to the user)

  • When a round is cut, Mari gets a steered engine note ([Engine note, not from the user]). It names what was cut (tool, action, size) and asks for smaller calls: one per reply, each under about 1.5× the token limit in characters, with no redoing of steps that already succeeded. Thinking-only and prose-only cuts get their own wording.
  • Up to 2 recoveries per run. Each shows a status line: "The reply was too long for this model's output limit, so Professor Mari is redoing it in smaller steps."
  • After that she stops with "…kept hitting this model's output limit… Raise Max Output Tokens on the connection, or ask for a smaller piece." The Continue chip appears when a mutating call was dropped.
  • The cut check runs before the claim audit, so a cut answer gets "write it shorter", not a "you claimed…" repair.
  • She stays quiet about the limit while working; her final answer may mention it in one light sentence.
  • The classic runtime is unchanged.

Regressions

  • pi-runtime.regression.ts: two cuts then a finish, budget exhausted, thinking cut, a cut while claiming, plus unit checks for the description and prompt.
  • provider-compat.regression.ts: a local server sends a partial tool call with finish_reason: "length", streamed and non-streamed. It fails without the provider fix.

Slices

  • A1: provider fix + pi recovery turn + regressions (6d2c26608)
  • Local CodeRabbit: 1 finding, fixed (a call cut before any arguments reported "about 2 characters")
  • Dottore round 1: 2 defects fixed (76e122c53). A failed stream (not a limit cut) goes through the claim audit again and keeps the old stop note. A closed textual call dropped with cut prose is named as the call. The 1.5 characters-per-token target is a named constant.

Follow-up (PR B, not in this PR): an up-front hint when Max Output Tokens is small, and "small models" lines in the built-in handbooks. Themes may need a partial-CSS Engine action.

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

Agent-run results: pnpm check passed (one existing client lint warning, client untouched). node ./scripts/run-regressions.mjs --filter regressions/professor-mari/ and --filter regressions/mari/ passed. No live run against a small-output model yet.

Manual verification notes

  • Manually verify: with Max Output Tokens around 1024, ask Mari for a big write (a full theme or character) and check she redoes it in smaller calls with the "too long for this model's output limit" status line.
  • Manually verify: with a very small limit (e.g. 256), she stops after two recoveries with the "kept hitting this model's output limit" note and a Continue chip.
  • Manually verify: intermediate turns say nothing about the limit, and the final answer mentions it in one short sentence at most.
  • Manually verify: normal tool-calling runs (no cut) behave as before on OpenAI, Anthropic and Google connections.

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)

No user docs touched: the new status strings are server-built, like every other Mari status.

UI evidence (if applicable)

None yet: the visible change is two status lines in Mari's chat. A screenshot will follow from the manual run.

@SpicyMarinara

🤖 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/8090 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `claude/mari-output-limit-recovery-002a30` --- ### 📝 Commits (2) - [`6d2c266`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6d2c2660867079fdd789e0e2f3f783856e9c2a7b) fix(mari): recover when a reply hits the model's output limit - [`76e122c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76e122c53ab2913a11b3b885b7fb4ef7bd7d1910) fix(mari): audit a failed stream; name a closed textual call cut before prose ### 📊 Changes **8 files changed** (+322 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/base-provider.ts` (+9 -0) 📝 `packages/server/src/services/llm/providers/anthropic.provider.ts` (+3 -2) 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+3 -4) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+12 -16) 📝 `packages/server/src/services/professor-mari/pi-runtime.ts` (+107 -11) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+1 -0) 📝 `scripts/regressions/professor-mari/pi-runtime.regression.ts` (+135 -5) 📝 `scripts/regressions/provider-compat.regression.ts` (+52 -0) </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 Part of #8096 (umbrella). This PR is part 1 of 2; the handbook follow-up (PR B) closes it. ## Why this change - When a reply hits the connection's output limit (Max Output Tokens), Professor Mari stops and the user has to type "continue". She usually retries the same oversized call and is cut again. Small local models (e.g. Gemma 3 12b) hit this on any large write. - On native tool-calling connections the cut was hidden: OpenAI (chat + Responses), Anthropic and Google reported a cut tool call as `tool_calls`, not `length`. Mari ran it with `{}` arguments, got a generic "invalid arguments" error and never learned why. ## What changed **Providers (no visible change for the user)** - `base-provider.ts`: new `toolCallFinishReason()`. A reply with tool calls reports `tool_calls` unless it was cut (`length` / `max_tokens` / `max_output_tokens`). It is used at every finish-reason site in the OpenAI, Anthropic and Google providers. Nothing in the server compares against `"tool_calls"`, so no caller changes. **Professor Mari, pi runtime (visible to the user)** - When a round is cut, Mari gets a steered engine note (`[Engine note, not from the user]`). It names what was cut (tool, action, size) and asks for smaller calls: one per reply, each under about 1.5× the token limit in characters, with no redoing of steps that already succeeded. Thinking-only and prose-only cuts get their own wording. - Up to **2** recoveries per run. Each shows a status line: "The reply was too long for this model's output limit, so Professor Mari is redoing it in smaller steps." - After that she stops with "…kept hitting this model's output limit… Raise Max Output Tokens on the connection, or ask for a smaller piece." The Continue chip appears when a mutating call was dropped. - The cut check runs before the claim audit, so a cut answer gets "write it shorter", not a "you claimed…" repair. - She stays quiet about the limit while working; her final answer may mention it in one light sentence. - The classic runtime is unchanged. **Regressions** - `pi-runtime.regression.ts`: two cuts then a finish, budget exhausted, thinking cut, a cut while claiming, plus unit checks for the description and prompt. - `provider-compat.regression.ts`: a local server sends a partial tool call with `finish_reason: "length"`, streamed and non-streamed. It fails without the provider fix. **Slices** - [x] A1: provider fix + pi recovery turn + regressions (`6d2c26608`) - [x] Local CodeRabbit: 1 finding, fixed (a call cut before any arguments reported "about 2 characters") - [x] Dottore round 1: 2 defects fixed (`76e122c53`). A failed stream (not a limit cut) goes through the claim audit again and keeps the old stop note. A closed textual call dropped with cut prose is named as the call. The 1.5 characters-per-token target is a named constant. **Follow-up (PR B, not in this PR):** an up-front hint when Max Output Tokens is small, and "small models" lines in the built-in handbooks. Themes may need a partial-CSS Engine action. ## 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` Agent-run results: `pnpm check` passed (one existing client lint warning, client untouched). `node ./scripts/run-regressions.mjs --filter regressions/professor-mari/` and `--filter regressions/mari/` passed. No live run against a small-output model yet. ### Manual verification notes - Manually verify: with Max Output Tokens around 1024, ask Mari for a big write (a full theme or character) and check she redoes it in smaller calls with the "too long for this model's output limit" status line. - Manually verify: with a very small limit (e.g. 256), she stops after two recoveries with the "kept hitting this model's output limit" note and a Continue chip. - Manually verify: intermediate turns say nothing about the limit, and the final answer mentions it in one short sentence at most. - Manually verify: normal tool-calling runs (no cut) behave as before on OpenAI, Anthropic and Google connections. ## 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) No user docs touched: the new status strings are server-built, like every other Mari status. ## UI evidence (if applicable) None yet: the visible change is two status lines in Mari's chat. A screenshot will follow from the manual run. @SpicyMarinara 🤖 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 2026-10-24 04:10:18 +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#8092
No description provided.