[GH-ISSUE #6150] The Game tool planning instruction ends up inside the system prompt on Claude and Gemini connections #3425

Closed
opened 2026-10-21 06:02:57 +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/6150

Originally assigned to: @SpicyMarinara on GitHub.

When a Game chat uses a separate connection for tool planning, the engine sends that connection a short instruction telling it to plan tools and not write narration. On Anthropic and Google connections that instruction does not arrive where it was meant to: it gets folded into the system prompt, right after the Game Master prompt that says to output only scene text. The planner then tends to return fewer tool calls, no tool calls, or prose that is thrown away, and the turn quietly gets no tool work.

How to reproduce (try it yourself)

  1. Create an Anthropic or a Google connection that supports tools.
  2. Open a Game chat, go to Chat Settings, Function Calling, and set "Game tool connection" to that connection.
  3. Turn on debug logging.
  4. Play a turn that needs a roll, for example type I try to pick the lock.
  5. In the server log, find the line [game/tools] Planning prompt sent to <name>, then find the provider's own outbound request body, for example [debug/anthropic] final tool request.

What you'll see: the engine's own log shows the planning instruction as the last message, but the request that actually goes out has the text "You are planning tools for the Game narrator..." inside the top-level system field (Anthropic) or systemInstruction field (Google), concatenated after the Game Master prompt. The conversation itself ends with the player's line.

What should happen: the planning instruction should be the model's last input on every provider, the way it already is on an OpenAI-family connection. Repeat the same turn with an OpenAI tool connection to see the intended shape.

Where it is

packages/server/src/services/generation/game-tool-planning.ts, lines 36 to 45: the planning instruction is appended to the message array with role: "system", relying on being last.

packages/server/src/services/llm/providers/anthropic.provider.ts, chatComplete at lines 369 to 381: every system message is filtered out of the conversation and joined into the top-level system field, with no positional condition. packages/server/src/services/llm/providers/google.provider.ts at line 625 and lines 650 to 652 does the same into systemInstruction.

What's happening

The planning pass depends on message position, but two of the three provider families do not preserve position for system messages: they hoist all of them into a single system block. So the instruction that is supposed to be the last thing the model reads becomes an extra paragraph appended to the narration system prompt, competing with "output only the VN scene text" instead of overriding it. Only OpenAI-family connections keep it as the final message. Anthropic and Google connections are exactly the ones a user is most likely to pick as a tool-capable planner, so the failure hits the common case, and because it is soft (fewer tool calls, or discarded prose) it is easy to misread as "the planner just does not work well on Claude".

Suggested fix

Stop relying on trailing position for a system-role message. Send the planning instruction as the final role: "user" turn, which no provider relocates, or put it deliberately at the front of the system block and make the planner prompt self-contained there. Either way the planner should see the same instruction placement on every provider family.

A regression for this needs to assert on the array handed to the provider's own request builder, not at the planGameToolCalls boundary. The current game-tool-controls lane only checks the last message before the provider is called, so it cannot see the relocation.

Context

Left by merged PR #5982, which implemented feature request #5957 (running Game tool calls on a different connection than narration). It is unreleased on staging: the latest release tag is v2.4.4. PR #6137 did not touch game-tool-planning.ts or either provider file. Related: the separate defect on this same feature where the planner branch reformats the narrator prompt and appends the tool results after the assistant prefill.

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

Related issue from the same sweep: #6148 (the planner branch reformatting the narrator prompt and appending after the prefill).

Originally created by @kolacheee on GitHub (Sep 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6150 Originally assigned to: @SpicyMarinara on GitHub. When a Game chat uses a separate connection for tool planning, the engine sends that connection a short instruction telling it to plan tools and not write narration. On Anthropic and Google connections that instruction does not arrive where it was meant to: it gets folded into the system prompt, right after the Game Master prompt that says to output only scene text. The planner then tends to return fewer tool calls, no tool calls, or prose that is thrown away, and the turn quietly gets no tool work. ## How to reproduce (try it yourself) 1. Create an Anthropic or a Google connection that supports tools. 2. Open a Game chat, go to Chat Settings, Function Calling, and set "Game tool connection" to that connection. 3. Turn on debug logging. 4. Play a turn that needs a roll, for example type `I try to pick the lock.` 5. In the server log, find the line `[game/tools] Planning prompt sent to <name>`, then find the provider's own outbound request body, for example `[debug/anthropic] final tool request`. **What you'll see:** the engine's own log shows the planning instruction as the last message, but the request that actually goes out has the text "You are planning tools for the Game narrator..." inside the top-level `system` field (Anthropic) or `systemInstruction` field (Google), concatenated after the Game Master prompt. The conversation itself ends with the player's line. **What should happen:** the planning instruction should be the model's last input on every provider, the way it already is on an OpenAI-family connection. Repeat the same turn with an OpenAI tool connection to see the intended shape. ## Where it is `packages/server/src/services/generation/game-tool-planning.ts`, lines 36 to 45: the planning instruction is appended to the message array with `role: "system"`, relying on being last. `packages/server/src/services/llm/providers/anthropic.provider.ts`, `chatComplete` at lines 369 to 381: every system message is filtered out of the conversation and joined into the top-level `system` field, with no positional condition. `packages/server/src/services/llm/providers/google.provider.ts` at line 625 and lines 650 to 652 does the same into `systemInstruction`. ## What's happening The planning pass depends on message position, but two of the three provider families do not preserve position for system messages: they hoist all of them into a single system block. So the instruction that is supposed to be the last thing the model reads becomes an extra paragraph appended to the narration system prompt, competing with "output only the VN scene text" instead of overriding it. Only OpenAI-family connections keep it as the final message. Anthropic and Google connections are exactly the ones a user is most likely to pick as a tool-capable planner, so the failure hits the common case, and because it is soft (fewer tool calls, or discarded prose) it is easy to misread as "the planner just does not work well on Claude". ## Suggested fix Stop relying on trailing position for a system-role message. Send the planning instruction as the final `role: "user"` turn, which no provider relocates, or put it deliberately at the front of the system block and make the planner prompt self-contained there. Either way the planner should see the same instruction placement on every provider family. A regression for this needs to assert on the array handed to the provider's own request builder, not at the `planGameToolCalls` boundary. The current `game-tool-controls` lane only checks the last message before the provider is called, so it cannot see the relocation. ## Context Left by merged PR #5982, which implemented feature request #5957 (running Game tool calls on a different connection than narration). It is unreleased on staging: the latest release tag is v2.4.4. PR #6137 did not touch `game-tool-planning.ts` or either provider file. Related: the separate defect on this same feature where the planner branch reformats the narrator prompt and appends the tool results after the assistant prefill. Found by an AI-assisted sweep and re-verified against staging ac14dd704 on 2026-09-13. Please verify before fixing. Related issue from the same sweep: #6148 (the planner branch reformatting the narrator prompt and appending after the prefill).
bsakaguchi 2026-10-21 06:02:57 +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:5654636639 --> @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#3425
No description provided.