[GH-ISSUE #6156] Continuing a cut off Game message runs an extra planning request and overrides the continue instruction #3429

Closed
opened 2026-10-21 06:03:00 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6156

Originally assigned to: @SpicyMarinara on GitHub.

When a Game chat has a separate connection set for its tool calls, asking the model to continue a cut off Game master message still runs a full tool planning pass on that second connection, even with tool use switched off, and the results of that pass are pasted into the prompt after the instruction that tells the model to continue where it stopped. The model's final instruction ends up being "Write the narration using these results" instead of "continue your cut off message", and one extra request is billed for a turn that was already being narrated.

This is currently only reachable through a direct call to the generate endpoint, because Game mode ships no Continue button and no /continue command. It is worth a small guard now so the behaviour is correct the day a Continue affordance is added to Game mode.

How to reproduce (try it yourself)

  1. Start the app on a scratch port with a scratch data folder so your real chats are untouched.
  2. Create a Game chat on any narrator connection. Add a second, tool capable connection (an OpenAI one works), then open Chat Settings, go to Function Calling, and pick that second connection as the Game tool connection. Leave "Enable tool use" OFF.
  3. Play one turn so the chat has a player message and a Game master message. Note the id of that Game master message (visible in the network tab, or in a chat export).
  4. From a terminal, POST to /api/generate/ with {"chatId":"<chat id>","streaming":true,"continueMessageId":"<the GM message id>","continueAddsNewline":true}.
  5. Watch the tool connection's usage or logs, then open Peek Prompt (or the debug prompt log) for the narrator request and read the end of the last user turn.

What you'll see: one planning request is billed on the tool connection for a turn that is already half narrated, it can return a fresh dice roll even though tool use is off, and the narrator prompt's last user turn ends with "The engine ran a separate tool-planning pass for this action... Write the narration using these results. Do not reroll these actions or claim a failed tool succeeded.", placed 233 characters after "Your last message got cut off! Please, continue!".

What should happen: a continuation should not trigger a new planning pass at all, and the continue instruction should stay the last thing the model reads. Control check: clear the Game tool connection and repeat the identical POST. No planning request is made, and the prompt ends exactly on the continue instruction.

Where it is

At staging ac14dd704, packages/server/src/routes/generate.routes.ts:

  • Lines 6962 to 6976: the plan runs whenever gameToolConnection && toolsAttached && toolDefs?.length, with no !input.continueMessageId guard (compare the !input.impersonate guard that does exist on the connection gate at lines 5136 to 5141).
  • Lines 7318 to 7329: the plan results are appended as a role: "user" message after initialProviderMessages, therefore after the continuation prompt.
  • Lines 4138 to 4146: where the continuation prompt is pushed onto the message list.
  • Line 5186 plus packages/server/src/services/generation/tool-resolution-runtime.ts:1062: roll_dice is auto attached for Game mode, so toolsAttached is true on every non impersonate Game generation and the plan fires even with tool use off.

What's happening

The planning pass has no idea the request is a continuation, so it treats a half finished turn as a brand new action and plans tools for it again. Its results are then appended to the end of the message list, which is built after the continuation prompt was already added, and the two get merged into the same user turn. Because the planner's wrapper text ends with a directive ("Write the narration using these results") rather than being plain tool data, it lands as the model's last instruction and competes with the instruction to continue from the exact cut off point.

Suggested fix

Simplest option: skip the planning pass when input.continueMessageId is set, alongside the existing impersonate guard. The turn's tools were already resolved when the message was first generated, so nothing needs replanning, and this also removes the extra billed request. If the plan should still run on continuations, then insert the tool results before the continuation prompt instead of after it, and reword the wrapper so it reads as material to use while continuing rather than a fresh instruction to write narration, for example "Use these results while continuing your cut off message; do not restart it." Either way the continue instruction must end up last. A regression covering a Game generation with continueMessageId set and a Game tool connection configured would pin whichever behaviour is chosen; scripts/regressions/game-tool-controls.regression.ts never sets continueMessageId today.

Context

Introduced by PR #5982 (the separate Game tool connection and planning pass), which closed issue #5957. Neither the issue nor the PR discusses continuations. PR #6137 did not touch this area: its diff contains no reference to continueMessageId, the continuation prompt, or the plan path. Unreleased on staging (latest release tag is v2.4.4). Related but different: #6130 covers Peek Prompt omitting the planner's billed request.

Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing.

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6156 Originally assigned to: @SpicyMarinara on GitHub. When a Game chat has a separate connection set for its tool calls, asking the model to continue a cut off Game master message still runs a full tool planning pass on that second connection, even with tool use switched off, and the results of that pass are pasted into the prompt after the instruction that tells the model to continue where it stopped. The model's final instruction ends up being "Write the narration using these results" instead of "continue your cut off message", and one extra request is billed for a turn that was already being narrated. This is currently only reachable through a direct call to the generate endpoint, because Game mode ships no Continue button and no /continue command. It is worth a small guard now so the behaviour is correct the day a Continue affordance is added to Game mode. ## How to reproduce (try it yourself) 1. Start the app on a scratch port with a scratch data folder so your real chats are untouched. 2. Create a Game chat on any narrator connection. Add a second, tool capable connection (an OpenAI one works), then open Chat Settings, go to Function Calling, and pick that second connection as the Game tool connection. Leave "Enable tool use" OFF. 3. Play one turn so the chat has a player message and a Game master message. Note the id of that Game master message (visible in the network tab, or in a chat export). 4. From a terminal, POST to `/api/generate/` with `{"chatId":"<chat id>","streaming":true,"continueMessageId":"<the GM message id>","continueAddsNewline":true}`. 5. Watch the tool connection's usage or logs, then open Peek Prompt (or the debug prompt log) for the narrator request and read the end of the last user turn. **What you'll see:** one planning request is billed on the tool connection for a turn that is already half narrated, it can return a fresh dice roll even though tool use is off, and the narrator prompt's last user turn ends with "The engine ran a separate tool-planning pass for this action... Write the narration using these results. Do not reroll these actions or claim a failed tool succeeded.", placed 233 characters after "Your last message got cut off! Please, continue!". **What should happen:** a continuation should not trigger a new planning pass at all, and the continue instruction should stay the last thing the model reads. Control check: clear the Game tool connection and repeat the identical POST. No planning request is made, and the prompt ends exactly on the continue instruction. ## Where it is At staging ac14dd704, `packages/server/src/routes/generate.routes.ts`: * Lines 6962 to 6976: the plan runs whenever `gameToolConnection && toolsAttached && toolDefs?.length`, with no `!input.continueMessageId` guard (compare the `!input.impersonate` guard that does exist on the connection gate at lines 5136 to 5141). * Lines 7318 to 7329: the plan results are appended as a `role: "user"` message after `initialProviderMessages`, therefore after the continuation prompt. * Lines 4138 to 4146: where the continuation prompt is pushed onto the message list. * Line 5186 plus `packages/server/src/services/generation/tool-resolution-runtime.ts:1062`: `roll_dice` is auto attached for Game mode, so `toolsAttached` is true on every non impersonate Game generation and the plan fires even with tool use off. ## What's happening The planning pass has no idea the request is a continuation, so it treats a half finished turn as a brand new action and plans tools for it again. Its results are then appended to the end of the message list, which is built after the continuation prompt was already added, and the two get merged into the same user turn. Because the planner's wrapper text ends with a directive ("Write the narration using these results") rather than being plain tool data, it lands as the model's last instruction and competes with the instruction to continue from the exact cut off point. ## Suggested fix Simplest option: skip the planning pass when `input.continueMessageId` is set, alongside the existing impersonate guard. The turn's tools were already resolved when the message was first generated, so nothing needs replanning, and this also removes the extra billed request. If the plan should still run on continuations, then insert the tool results before the continuation prompt instead of after it, and reword the wrapper so it reads as material to use while continuing rather than a fresh instruction to write narration, for example "Use these results while continuing your cut off message; do not restart it." Either way the continue instruction must end up last. A regression covering a Game generation with `continueMessageId` set and a Game tool connection configured would pin whichever behaviour is chosen; `scripts/regressions/game-tool-controls.regression.ts` never sets `continueMessageId` today. ## Context Introduced by PR #5982 (the separate Game tool connection and planning pass), which closed issue #5957. Neither the issue nor the PR discusses continuations. PR #6137 did not touch this area: its diff contains no reference to `continueMessageId`, the continuation prompt, or the plan path. Unreleased on staging (latest release tag is v2.4.4). Related but different: #6130 covers Peek Prompt omitting the planner's billed request. Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:03:00 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 13, 2026):

Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.

<!-- gh-comment-id:5654635812 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Codex is addressing this report on behalf of @SpicyMarinara in draft PR #6168 as part of the requested issue sweep. I will verify the reported path against staging and preserve existing behavior outside the narrow fix.
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#3429
No description provided.