[GH-ISSUE #2443] [Issue]: 12-PROMPT-CONTRACT-message-shaping-provider-ready merges incompatible same-role prompt messages #1197

Closed
opened 2026-10-21 05:28:51 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2443

Originally assigned to: @Promansis on GitHub.

Summary

12-PROMPT-CONTRACT-message-shaping-provider-ready has a parity gap: refactor prompt merging collapses adjacent messages by role only, while legacy preserved separate messages when characterId differed or prompt/history/injection context kinds were incompatible.

Linked target: #2442

Expected behavior

Legacy behavior:

  • Prompt message shaping merges adjacent messages only when the role matches, characterId matches, and context kinds are compatible.
  • Final provider-neutral messages still support squash-system, strict role formatting, single-user-message mode, and images.

Actual behavior

Refactor behavior:

  • mergeAdjacentMessages merges any adjacent same-role messages.
  • It does not check characterId.
  • It allows prompt/history/injection context kind boundaries to collapse, except for assigning a merged context kind afterward.

Steps to reproduce

  1. Assemble or directly shape adjacent prompt messages with the same role but different characterId values, or incompatible contextKind values such as prompt followed by history.
  2. Run refactor message shaping through src/engine/generation-core/prompt/merger.ts.
  3. Observe the messages collapse where legacy kept them separate.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: refactor@c92bbcfc
  • Run mode: not relevant
  • OS + version: not relevant
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: provider-neutral prompt shaping before Target 11 transport

Logs, screenshots, or video

Proof:

  • Legacy merge checks role, characterId, and context kind compatibility before collapsing messages: main:packages/server/src/services/prompt/merger.ts:29.
  • Refactor merge checks only role: src/engine/generation-core/prompt/merger.ts:29.
  • Refactor assembler calls final shaping before returning provider-neutral messages: src/engine/generation/prompt-assembly.ts:3446.
  • Refactor attaches images before LLM handoff, so the gap is isolated to merge boundaries, not attachment plumbing: src/engine/generation/start-generation.ts:3244.

Files inspected:

  • src/engine/generation-core/prompt/merger.ts:15
  • src/engine/generation/prompt-assembly.ts:3446
  • src/engine/generation/start-generation.ts:3244
  • main:packages/server/src/services/prompt/merger.ts:29
  • main:packages/server/src/services/prompt/assembler.ts:422
  • main:packages/server/src/routes/generate.routes.ts:7259

Regression notes

Legacy main preserved speaker/context boundaries during prompt message merging. Refactor currently collapses those boundaries by role only.

Additional context

Acceptance criteria:

  • 12-PROMPT-CONTRACT-message-shaping-provider-ready preserves legacy merge boundaries for differing characterId values.
  • 12-PROMPT-CONTRACT-message-shaping-provider-ready preserves legacy merge boundaries for incompatible prompt/history/injection context kinds.
  • Existing strict role formatting, squash-system, single-user-message, image attachment, and provider-neutral handoff behavior still works.
  • Add a focused proof or test for same-role messages with distinct characterId and incompatible contextKind.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2443 Originally assigned to: @Promansis on GitHub. ## Summary `12-PROMPT-CONTRACT-message-shaping-provider-ready` has a parity gap: refactor prompt merging collapses adjacent messages by role only, while legacy preserved separate messages when `characterId` differed or prompt/history/injection context kinds were incompatible. Linked target: #2442 ## Expected behavior Legacy behavior: - Prompt message shaping merges adjacent messages only when the role matches, `characterId` matches, and context kinds are compatible. - Final provider-neutral messages still support squash-system, strict role formatting, single-user-message mode, and images. ## Actual behavior Refactor behavior: - `mergeAdjacentMessages` merges any adjacent same-role messages. - It does not check `characterId`. - It allows prompt/history/injection context kind boundaries to collapse, except for assigning a merged context kind afterward. ## Steps to reproduce 1. Assemble or directly shape adjacent prompt messages with the same role but different `characterId` values, or incompatible `contextKind` values such as `prompt` followed by `history`. 2. Run refactor message shaping through `src/engine/generation-core/prompt/merger.ts`. 3. Observe the messages collapse where legacy kept them separate. ## Impact area - [ ] App shell, navigation, startup, or providers - [ ] Catalog resources - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] React-free engine behavior, contracts, agents, or capability ports - [ ] Shared API wrapper or remote runtime routing - [ ] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: refactor@c92bbcfc - Run mode: not relevant - OS + version: not relevant - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: provider-neutral prompt shaping before Target 11 transport ## Logs, screenshots, or video Proof: - Legacy merge checks role, `characterId`, and context kind compatibility before collapsing messages: `main:packages/server/src/services/prompt/merger.ts:29`. - Refactor merge checks only role: `src/engine/generation-core/prompt/merger.ts:29`. - Refactor assembler calls final shaping before returning provider-neutral messages: `src/engine/generation/prompt-assembly.ts:3446`. - Refactor attaches images before LLM handoff, so the gap is isolated to merge boundaries, not attachment plumbing: `src/engine/generation/start-generation.ts:3244`. Files inspected: - `src/engine/generation-core/prompt/merger.ts:15` - `src/engine/generation/prompt-assembly.ts:3446` - `src/engine/generation/start-generation.ts:3244` - `main:packages/server/src/services/prompt/merger.ts:29` - `main:packages/server/src/services/prompt/assembler.ts:422` - `main:packages/server/src/routes/generate.routes.ts:7259` ## Regression notes Legacy `main` preserved speaker/context boundaries during prompt message merging. Refactor currently collapses those boundaries by role only. ## Additional context Acceptance criteria: - `12-PROMPT-CONTRACT-message-shaping-provider-ready` preserves legacy merge boundaries for differing `characterId` values. - `12-PROMPT-CONTRACT-message-shaping-provider-ready` preserves legacy merge boundaries for incompatible prompt/history/injection context kinds. - Existing strict role formatting, squash-system, single-user-message, image attachment, and provider-neutral handoff behavior still works. - Add a focused proof or test for same-role messages with distinct `characterId` and incompatible `contextKind`. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
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#1197
No description provided.