[PR #2419] [MERGED] generation: honor model context window #5597

Closed
opened 2026-10-22 04:17:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2419
Author: @Xelvanis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/use-max-context-window


📝 Commits (2)

  • 7a9407c generation: honor model context window
  • 9e27a14 generation: cover context window precedence

📊 Changes

4 files changed (+104 additions, -6 deletions)

View changed files

➕ src/engine/generation/context-window.test.ts (+50 -0)
📝 src/engine/generation/context-window.ts (+49 -3)
📝 src/engine/generation/prompt-assembly.ts (+3 -1)
📝 src/engine/generation/start-generation.ts (+2 -2)

📄 Description

Linked issue

Closes #2288

Why this change

  • Presets with useMaxContext enabled still sized prompt fitting and memory recall against the manual maxContext, so known models with different context windows could be under-budgeted or over-budgeted.

What changed

  • Added shared engine logic to resolve the effective context window from connection limits, known model metadata, and preset/manual parameters.
  • Updated final request prompt fitting to use the effective context window.
  • Updated memory recall packing to use the same effective context window instead of raw connection.maxContext.
  • Added a focused regression test for effective context precedence, unknown-model fallback, smallest-limit clamping, and invalid limit handling.

Refactor impact

Primary owner:

engine generation

Impact areas reviewed:

  • Shared generation prompt fitting for chat, roleplay, and game mode sends.
  • Memory recall prompt packing in shared prompt assembly.
  • Legacy origin/main context-window parity for useMaxContext and smallest-limit clamping.

Boundary notes:

  • React-free engine change only.
  • No feature UI, shared API wrapper, Tauri command, Rust capability, or remote-runtime route changes.
  • Engine imports engine contract model metadata; no React, Zustand, Tauri, or feature imports added.

Pressure points touched:

  • None. ModeSurface, GameSurface, shared mode UI, command registration, and import modules were not touched.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Focused local jiti harness verified effective context selection for known model, manual max context, connection clamping, unknown model fallback, and prompt-trim behavior.
  • pnpm test -- src/engine/generation/context-window.test.ts
  • pnpm typecheck
  • pnpm check:architecture
  • pnpm check
  • No native Tauri/manual generation run; this is a shared engine sizing fix with command-level proof.

Durable test rationale:

  • Regression/risky invariant: effectiveMaxContext now controls both prompt trimming and memory recall sizing for useMaxContext.
  • Existing proof gap: command output proved the current behavior, but reviewer feedback requested a committed guard for precedence and fallback cases.
  • Test scope: one narrow engine helper test file covering known-model lookup, unknown-model fallback, smallest-limit clamping, and invalid limit handling.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Bugfix for existing useMaxContext behavior; no new user-discoverable surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No UI evidence. This change affects engine prompt sizing, not visible UI layout.


🔄 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/2419 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/use-max-context-window` --- ### 📝 Commits (2) - [`7a9407c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7a9407cdb260f2204ebf3fd56c6b14d5dd2c3231) generation: honor model context window - [`9e27a14`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9e27a14374fca3888af86d66422134b2e34847c6) generation: cover context window precedence ### 📊 Changes **4 files changed** (+104 additions, -6 deletions) <details> <summary>View changed files</summary> ➕ `src/engine/generation/context-window.test.ts` (+50 -0) 📝 `src/engine/generation/context-window.ts` (+49 -3) 📝 `src/engine/generation/prompt-assembly.ts` (+3 -1) 📝 `src/engine/generation/start-generation.ts` (+2 -2) </details> ### 📄 Description ## Linked issue Closes #2288 ## Why this change - Presets with `useMaxContext` enabled still sized prompt fitting and memory recall against the manual `maxContext`, so known models with different context windows could be under-budgeted or over-budgeted. ## What changed - Added shared engine logic to resolve the effective context window from connection limits, known model metadata, and preset/manual parameters. - Updated final request prompt fitting to use the effective context window. - Updated memory recall packing to use the same effective context window instead of raw `connection.maxContext`. - Added a focused regression test for effective context precedence, unknown-model fallback, smallest-limit clamping, and invalid limit handling. ## Refactor impact Primary owner: engine generation Impact areas reviewed: - Shared generation prompt fitting for chat, roleplay, and game mode sends. - Memory recall prompt packing in shared prompt assembly. - Legacy `origin/main` context-window parity for `useMaxContext` and smallest-limit clamping. Boundary notes: - React-free engine change only. - No feature UI, shared API wrapper, Tauri command, Rust capability, or remote-runtime route changes. - Engine imports engine contract model metadata; no React, Zustand, Tauri, or feature imports added. Pressure points touched: - None. `ModeSurface`, `GameSurface`, shared mode UI, command registration, and import modules were not touched. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Focused local `jiti` harness verified effective context selection for known model, manual max context, connection clamping, unknown model fallback, and prompt-trim behavior. - `pnpm test -- src/engine/generation/context-window.test.ts` - `pnpm typecheck` - `pnpm check:architecture` - `pnpm check` - No native Tauri/manual generation run; this is a shared engine sizing fix with command-level proof. Durable test rationale: - Regression/risky invariant: `effectiveMaxContext` now controls both prompt trimming and memory recall sizing for `useMaxContext`. - Existing proof gap: command output proved the current behavior, but reviewer feedback requested a committed guard for precedence and fallback cases. - Test scope: one narrow engine helper test file covering known-model lookup, unknown-model fallback, smallest-limit clamping, and invalid limit handling. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Bugfix for existing `useMaxContext` behavior; no new user-discoverable surface. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No UI evidence. This change affects engine prompt sizing, not visible UI layout. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:42 +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#5597
No description provided.