[PR #6665] [MERGED] fix(generation): report a reply budget spent on the prompt #7277

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6665
Author: @SonaGat3
Created: 9/25/2026
Status: ✅ Merged
Merged: 9/25/2026
Merged by: @SonaGat3

Base: staging ← Head: fix/6614-log-reply-budget-reduction


📝 Commits (1)

  • 2f16b4c fix(generation): report a reply budget spent on the prompt

📊 Changes

4 files changed (+40 additions, -9 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/server/src/services/llm/base-provider.ts (+22 -9)
📝 packages/shared/src/types/generation-integration.ts (+2 -0)
📝 scripts/regressions/context-fit.regression.ts (+14 -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

Refs #6614

Why this change

  • When an assembled prompt does not fit the input budget, fitMessagesToContext can hand the reply budget to the prompt instead of dropping messages, down to a floor of 128 tokens. That is the right call — better than sending a request the backend will truncate — but it happens silently.
  • Dropping messages is reported ([LLM context] Trimmed prompt ...). Spending the reply budget is not, so a user whose configured Max Tokens never reaches the provider has nothing to go on.
  • In #6614 that is exactly what happened: Max Tokens was set to 1000, the provider received 128, the model spent all of it on reasoning and returned an empty reply. The logs showed no trim line, which read as "the Engine is doing nothing" when it had in fact made a large adjustment.

What changed

  • ContextFitResult carries requestedMaxTokens, the budget the caller asked for, alongside the one actually used.
  • logContextTrim reports both adjustments instead of returning early on the first. The existing trim message is unchanged, so anyone grepping for it still finds it.
  • A reduction that lands on the 128-token floor logs at warn; any smaller reduction logs at debug. Single-shot prompts (summarizers, Noodle refreshes) carry no removable history and give the reply budget back by design on every call, so warning on those would add noise to working setups.
  • Regression: the requested budget survives the fit, and a prompt that fills the window on its own leaves the reply at the floor — the shape of the reported failure.

No behaviour changes: what gets sent to the provider is identical, only what is reported differs.

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

  • pnpm check: passes (exit 0).
  • node scripts/run-regressions.mjs --filter context-fit: passes, including the two new cases.
  • The new floor case reproduces the reported failure in the repository: asking for 1000 reply tokens with a prompt that fills the window returns exactly 128.

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)

UI evidence (if applicable)

Not applicable: no UI change. Surfacing the reduced budget in the UI would help too, but that touches client and server and belongs in its own change.

Summary by CodeRabbit

  • Improvements
    • Generation reports when an oversized prompt reduces the reply-token budget, including when it reaches the 128-token minimum.
    • Reports distinguish between the requested reply budget and the reduced budget used.

🔄 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/6665 **Author:** [@SonaGat3](https://github.com/SonaGat3) **Created:** 9/25/2026 **Status:** ✅ Merged **Merged:** 9/25/2026 **Merged by:** [@SonaGat3](https://github.com/SonaGat3) **Base:** `staging` ← **Head:** `fix/6614-log-reply-budget-reduction` --- ### 📝 Commits (1) - [`2f16b4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f16b4ce5fffcdb89c475cc4046f162fdc2fba6b) fix(generation): report a reply budget spent on the prompt ### 📊 Changes **4 files changed** (+40 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/server/src/services/llm/base-provider.ts` (+22 -9) 📝 `packages/shared/src/types/generation-integration.ts` (+2 -0) 📝 `scripts/regressions/context-fit.regression.ts` (+14 -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`. ## Linked issue Refs #6614 ## Why this change - When an assembled prompt does not fit the input budget, `fitMessagesToContext` can hand the reply budget to the prompt instead of dropping messages, down to a floor of 128 tokens. That is the right call — better than sending a request the backend will truncate — but it happens silently. - Dropping messages is reported (`[LLM context] Trimmed prompt ...`). Spending the reply budget is not, so a user whose configured Max Tokens never reaches the provider has nothing to go on. - In #6614 that is exactly what happened: Max Tokens was set to 1000, the provider received 128, the model spent all of it on reasoning and returned an empty reply. The logs showed no trim line, which read as "the Engine is doing nothing" when it had in fact made a large adjustment. ## What changed - `ContextFitResult` carries `requestedMaxTokens`, the budget the caller asked for, alongside the one actually used. - `logContextTrim` reports both adjustments instead of returning early on the first. The existing trim message is unchanged, so anyone grepping for it still finds it. - A reduction that lands on the 128-token floor logs at `warn`; any smaller reduction logs at `debug`. Single-shot prompts (summarizers, Noodle refreshes) carry no removable history and give the reply budget back by design on every call, so warning on those would add noise to working setups. - Regression: the requested budget survives the fit, and a prompt that fills the window on its own leaves the reply at the floor — the shape of the reported failure. No behaviour changes: what gets sent to the provider is identical, only what is reported differs. ## Validation - [x] `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) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check`: passes (exit 0). - `node scripts/run-regressions.mjs --filter context-fit`: passes, including the two new cases. - The new floor case reproduces the reported failure in the repository: asking for 1000 reply tokens with a prompt that fills the window returns exactly 128. ## 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) ## UI evidence (if applicable) Not applicable: no UI change. Surfacing the reduced budget in the UI would help too, but that touches client and server and belongs in its own change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Generation reports when an oversized prompt reduces the reply-token budget, including when it reaches the 128-token minimum. * Reports distinguish between the requested reply budget and the reduced budget used. <!-- 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:11 +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#7277
No description provided.