[GH-ISSUE #417] [Issue]: Context trimming not applied when preset has useMaxContext: false (v1.5.7) #175

Closed
opened 2026-10-20 17:25:55 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @cha1latte on GitHub (May 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/417

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Context trimming is not applied when a preset has useMaxContext: false with a manually-set Max Context Window value. Long chats grow unbounded past the configured limit and responses get cut off mid-sentence, despite v1.5.7 changelog claiming this was fixed.

Expected behavior

With Max Context Window set to 60000 in the preset, oversized prompts should be trimmed before generation so input stays at or below 60000 tokens. The v1.5.7 changelog states: "Connection max-context limits now trim oversized prompts before generation, and prompt inspection shows the fitted prompt that was actually sent upstream."

Actual behavior

The full message history is sent upstream with no trimming applied. Input climbs past 57000 tokens and grows ~500 per response. The model's reply gets cut off mid-sentence. Manually deleting older messages works temporarily until context climbs back up.

Steps to reproduce

  1. Create a preset with Max Context Window set manually (useMaxContext: false) — e.g. 60000 tokens.
  2. Have a chat exceed that limit (reproduced at 259 messages, ~57000+ tokens of input).
  3. Generate a response.
  4. Observe: full history sent upstream, no trimming applied, response cut off mid-sentence.

Environment

  • Marinara Engine version: v1.5.7
  • Install type: installer
  • OS + version: Windows
  • Browser or app shell: (not specified by reporter)

Logs, screenshots, or video

Reproduced with both Gemma 4 and DeepSeek — both stop the same way, ruling out a content filter.

Setup details:

  • Chat Summary agent active (triggers after 20 messages)
  • Memory Recall enabled
  • Max Output Tokens: 4096 (preset) / 8192 (connection)
  • Long character card (fixed cost, expected)

Additional context

Suspected cause (from a Discord investigation by Luka — please verify against current source, line numbers not confirmed):

In the dry-run preset assembly path, effectiveMaxContext is only set when useMaxContext is true:

const presetMaxContext = assembled.parameters.useMaxContext
  ? normalizeMaxContext(conn.maxContext)
  : undefined;
effectiveMaxContext = minContextLimit(effectiveMaxContext, presetMaxContext);

When the preset's Max Context Window is set manually with useMaxContext: false, presetMaxContext is undefined, so the trimmer has no ceiling to enforce.

Suggested fix:

const presetMaxContext = assembled.parameters.useMaxContext
  ? normalizeMaxContext(conn.maxContext)
  : normalizeMaxContext(assembled.parameters.maxContext);

Worth checking the regular /generate route for the same pattern — if it has the same conditional, patching dry-run alone will only fix prompt previews, not actual generation.

Workaround: Setting useMaxContext: true in the preset and letting the connection's Max Context Window drive the trim restores expected behavior.

Originally reported on Discord by user AKEF; this issue is being filed on their behalf.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @cha1latte on GitHub (May 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/417 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Context trimming is not applied when a preset has `useMaxContext: false` with a manually-set Max Context Window value. Long chats grow unbounded past the configured limit and responses get cut off mid-sentence, despite v1.5.7 changelog claiming this was fixed. ## Expected behavior With Max Context Window set to 60000 in the preset, oversized prompts should be trimmed before generation so input stays at or below 60000 tokens. The v1.5.7 changelog states: "Connection max-context limits now trim oversized prompts before generation, and prompt inspection shows the fitted prompt that was actually sent upstream." ## Actual behavior The full message history is sent upstream with no trimming applied. Input climbs past 57000 tokens and grows ~500 per response. The model's reply gets cut off mid-sentence. Manually deleting older messages works temporarily until context climbs back up. ## Steps to reproduce 1. Create a preset with Max Context Window set manually (`useMaxContext: false`) — e.g. 60000 tokens. 2. Have a chat exceed that limit (reproduced at 259 messages, ~57000+ tokens of input). 3. Generate a response. 4. Observe: full history sent upstream, no trimming applied, response cut off mid-sentence. ## Environment - Marinara Engine version: v1.5.7 - Install type: installer - OS + version: Windows - Browser or app shell: (not specified by reporter) ## Logs, screenshots, or video Reproduced with both Gemma 4 and DeepSeek — both stop the same way, ruling out a content filter. Setup details: - Chat Summary agent active (triggers after 20 messages) - Memory Recall enabled - Max Output Tokens: 4096 (preset) / 8192 (connection) - Long character card (fixed cost, expected) ## Additional context **Suspected cause** (from a [Discord investigation by Luka](https://discord.com/channels/1417099416812392641/1500943111982026902) — please verify against current source, line numbers not confirmed): In the dry-run preset assembly path, `effectiveMaxContext` is only set when `useMaxContext` is true: ```js const presetMaxContext = assembled.parameters.useMaxContext ? normalizeMaxContext(conn.maxContext) : undefined; effectiveMaxContext = minContextLimit(effectiveMaxContext, presetMaxContext); ``` When the preset's Max Context Window is set manually with `useMaxContext: false`, `presetMaxContext` is `undefined`, so the trimmer has no ceiling to enforce. **Suggested fix:** ```js const presetMaxContext = assembled.parameters.useMaxContext ? normalizeMaxContext(conn.maxContext) : normalizeMaxContext(assembled.parameters.maxContext); ``` Worth checking the regular `/generate` route for the same pattern — if it has the same conditional, patching dry-run alone will only fix prompt previews, not actual generation. **Workaround:** Setting `useMaxContext: true` in the preset and letting the connection's Max Context Window drive the trim restores expected behavior. **Originally reported on Discord** by user AKEF; this issue is being filed on their behalf. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:25:55 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (May 5, 2026):

Fixed.

<!-- gh-comment-id:4377828500 --> @SpicyMarinara commented on GitHub (May 5, 2026): Fixed.
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#175
No description provided.