[GH-ISSUE #6130] The Peek Prompt panel leaves out the extra planning request a Game chat just billed you for #3407

Closed
opened 2026-10-21 06:02:46 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

When a Game chat is set to use a separate connection for tool calls, every turn makes two paid requests: a planning request on the connection you picked, then the narration request. The Peek Prompt panel only reports the narration request's token count, so the number you see is smaller than what the turn actually cost, and the planner's model is never named.

How to reproduce (try it yourself)

You need two configured connections whose providers support native tool calls (the dropdown greys out ones that don't). Make the second one a visibly different, cheap model so you can tell them apart.

  1. Open or create a chat and set its mode to Game.
  2. Open the chat settings drawer (sliders icon in the chat header) and scroll to the "Function Calling" section.
  3. Change "Game tool connection" from "Same as narrator" to your second, cheap connection. The help line under it says: "A separate model chooses tools before narration. Adds one request per turn on this connection."
  4. In that same section, turn on at least one tool (or the "Lore search" toggle), so tools actually attach to the turn - the planner only runs when tools are attached.
  5. Close the drawer. Type exactly: I search the room for anything valuable and write down what I find. and press Send.
  6. When the narration finishes, click the small magnifier "Peek prompt" button on the GM narration.

What you'll see: the grey strip at the top of the Peek Prompt window reads something like openai / gpt-4o ~3184 est tokens · 3184 actual prompt tokens. Only the narrator's request is accounted for. The cheap planning model is not named and none of its tokens appear - even though the planning request was just sent and billed to your second connection.

What should happen: the same strip should also carry a separate, separately labelled planner figure, e.g. · planner gpt-4o-mini 1902→18 tok, so the panel accounts for both requests the turn made.

To confirm the number really is stored and just isn't drawn: curl -s http://127.0.0.1:7860/api/chats/<chatId>/messages | python3 -m json.tool | grep -A6 gameToolPlanning - you'll find extra.gameToolPlanning fully populated on the very message whose Peek panel showed none of it.

Note: don't look for a token line under the message itself, and don't bother with Settings -> "Show token usage on messages". That readout lives in ChatMessage.tsx, which Game mode never renders - Game chats go through GameSurface/GameNarration, which have no per-message token line. Peek Prompt is the only cost figure a Game chat shows.

Where it is

At staging 52799569c:

  • packages/server/src/routes/generate.routes.ts:8399-8407 - the only place gameToolPlanning is ever written: gameToolPlanning: { connectionId, model, provider, usage: gameToolPlan.usage ?? null }, alongside generationInfo.
  • packages/server/src/routes/chats.routes.ts:2760-2764 - the peek payload forwards extra.generationInfo only; gameToolPlanning is dropped here.
  • packages/client/src/components/chat/PeekPromptModal.tsx:510 (const gen = data.generationInfo;) and :596-620 - the generation-info strip, which reads gen.model and gen.tokensPrompt only.
  • packages/client/src/hooks/use-chats.ts:1544-1566 - the client-side peek payload type, which has no gameToolPlanning field.

grep -rn gameToolPlanning packages/client/src packages/shared returns zero hits. Repo-wide, the string appears exactly once in shipped code - the server write.

What's happening

The server captures the planner's token usage correctly and deliberately stores it in its own key so it never gets folded into the narrator's counters (the two requests hit different models at different prices). Nothing on the client ever reads that key, and the peek endpoint doesn't send it down, so the stored number has no path to the screen. It's a render gap, not lost data.

Suggested fix

Thread gameToolPlanning through the peek payload - add it to the server's peek response next to generationInfo (chats.routes.ts:2763), to the client payload type (use-chats.ts:1553-1565, PeekPromptModal.tsx:38-53), and render it as a second, separately labelled segment in the generation-info strip (PeekPromptModal.tsx:596-620) whenever it's present.

Do not sum it into generationInfo.tokensPrompt. That will fail scripts/regressions/game-tool-controls.regression.ts:182, whose assertion message is "planner usage cannot be charged to the narrator model" - that pin is intentional, because the two requests are different models at different prices. The fix is purely additive: a second figure, labelled as the planner's.

Worth deciding at the same time whether this should be a general "auxiliary requests for this turn" line rather than a Game-planner special case. The custom emoji/sticker tool-call pass (packages/server/src/routes/generate/conversation-custom-assets.ts:95-140) runs the same shape of extra request on its own connection and doesn't capture usage at all, and the lore-search toggle's own help text warns that "Lookups can add embedding and model requests" - also unshown.

Context

Shipped by PR #5982 ("give Game chats explicit tool and lore-search controls", closing #5955, #5957, #5958), which merged at ea02c44e6, after the v2.4.4 tag - so this is unreleased on staging. The separate-connection feature itself comes from #5957. The PR body states that "planner usage is saved separately from narrator usage in message extras", and docs/game/getting-started.md:91 plus the in-app help both tell the user an extra request happens and is charged to the connection they picked - so this is a disclosed cost that is never quantified on screen, which puts it closer to a small enhancement than a malfunction. Severity is low: nothing is lost or corrupted, the server-side isolation is correct and regression-pinned, and it takes a non-default Game tool connection to hit. One scale caveat for sizing the work: the planner prompt is refitted to the planner connection's own access policy with a 2048-token cap (packages/server/src/services/generation/game-tool-planning.ts:33-45), so the hidden amount is bounded, not a mirror of the narrator prompt.

Found by an AI-assisted sweep of merged PR #5982 against issue #5957, then re-verified against staging 52799569c 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/6130 Originally assigned to: @SpicyMarinara on GitHub. When a Game chat is set to use a separate connection for tool calls, every turn makes two paid requests: a planning request on the connection you picked, then the narration request. The Peek Prompt panel only reports the narration request's token count, so the number you see is smaller than what the turn actually cost, and the planner's model is never named. ## How to reproduce (try it yourself) You need two configured connections whose providers support native tool calls (the dropdown greys out ones that don't). Make the second one a visibly different, cheap model so you can tell them apart. 1. Open or create a chat and set its mode to Game. 2. Open the chat settings drawer (sliders icon in the chat header) and scroll to the "Function Calling" section. 3. Change "Game tool connection" from "Same as narrator" to your second, cheap connection. The help line under it says: "A separate model chooses tools before narration. Adds one request per turn on this connection." 4. In that same section, turn on at least one tool (or the "Lore search" toggle), so tools actually attach to the turn - the planner only runs when tools are attached. 5. Close the drawer. Type exactly: `I search the room for anything valuable and write down what I find.` and press Send. 6. When the narration finishes, click the small magnifier "Peek prompt" button on the GM narration. **What you'll see:** the grey strip at the top of the Peek Prompt window reads something like `openai / gpt-4o ~3184 est tokens · 3184 actual prompt tokens`. Only the narrator's request is accounted for. The cheap planning model is not named and none of its tokens appear - even though the planning request was just sent and billed to your second connection. **What should happen:** the same strip should also carry a separate, separately labelled planner figure, e.g. `· planner gpt-4o-mini 1902→18 tok`, so the panel accounts for both requests the turn made. To confirm the number really is stored and just isn't drawn: `curl -s http://127.0.0.1:7860/api/chats/<chatId>/messages | python3 -m json.tool | grep -A6 gameToolPlanning` - you'll find `extra.gameToolPlanning` fully populated on the very message whose Peek panel showed none of it. Note: don't look for a token line under the message itself, and don't bother with Settings -> "Show token usage on messages". That readout lives in `ChatMessage.tsx`, which Game mode never renders - Game chats go through `GameSurface`/`GameNarration`, which have no per-message token line. Peek Prompt is the only cost figure a Game chat shows. ## Where it is At staging 52799569c: - `packages/server/src/routes/generate.routes.ts:8399-8407` - the only place `gameToolPlanning` is ever written: `gameToolPlanning: { connectionId, model, provider, usage: gameToolPlan.usage ?? null }`, alongside `generationInfo`. - `packages/server/src/routes/chats.routes.ts:2760-2764` - the peek payload forwards `extra.generationInfo` only; `gameToolPlanning` is dropped here. - `packages/client/src/components/chat/PeekPromptModal.tsx:510` (`const gen = data.generationInfo;`) and `:596-620` - the generation-info strip, which reads `gen.model` and `gen.tokensPrompt` only. - `packages/client/src/hooks/use-chats.ts:1544-1566` - the client-side peek payload type, which has no `gameToolPlanning` field. `grep -rn gameToolPlanning packages/client/src packages/shared` returns zero hits. Repo-wide, the string appears exactly once in shipped code - the server write. ## What's happening The server captures the planner's token usage correctly and deliberately stores it in its own key so it never gets folded into the narrator's counters (the two requests hit different models at different prices). Nothing on the client ever reads that key, and the peek endpoint doesn't send it down, so the stored number has no path to the screen. It's a render gap, not lost data. ## Suggested fix Thread `gameToolPlanning` through the peek payload - add it to the server's peek response next to `generationInfo` (`chats.routes.ts:2763`), to the client payload type (`use-chats.ts:1553-1565`, `PeekPromptModal.tsx:38-53`), and render it as a second, separately labelled segment in the generation-info strip (`PeekPromptModal.tsx:596-620`) whenever it's present. Do not sum it into `generationInfo.tokensPrompt`. That will fail `scripts/regressions/game-tool-controls.regression.ts:182`, whose assertion message is "planner usage cannot be charged to the narrator model" - that pin is intentional, because the two requests are different models at different prices. The fix is purely additive: a second figure, labelled as the planner's. Worth deciding at the same time whether this should be a general "auxiliary requests for this turn" line rather than a Game-planner special case. The custom emoji/sticker tool-call pass (`packages/server/src/routes/generate/conversation-custom-assets.ts:95-140`) runs the same shape of extra request on its own connection and doesn't capture usage at all, and the lore-search toggle's own help text warns that "Lookups can add embedding and model requests" - also unshown. ## Context Shipped by PR #5982 ("give Game chats explicit tool and lore-search controls", closing #5955, #5957, #5958), which merged at ea02c44e6, after the v2.4.4 tag - so this is unreleased on staging. The separate-connection feature itself comes from #5957. The PR body states that "planner usage is saved separately from narrator usage in message extras", and `docs/game/getting-started.md:91` plus the in-app help both tell the user an extra request happens and is charged to the connection they picked - so this is a disclosed cost that is never quantified on screen, which puts it closer to a small enhancement than a malfunction. Severity is low: nothing is lost or corrupted, the server-side isolation is correct and regression-pinned, and it takes a non-default Game tool connection to hit. One scale caveat for sizing the work: the planner prompt is refitted to the planner connection's own access policy with a 2048-token cap (`packages/server/src/services/generation/game-tool-planning.ts:33-45`), so the hidden amount is bounded, not a mirror of the narrator prompt. Found by an AI-assisted sweep of merged PR #5982 against issue #5957, then re-verified against staging 52799569c on 2026-09-13. Please verify before fixing.
bsakaguchi 2026-10-21 06:02:46 +07:00
Author
Owner

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

@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.

<!-- gh-comment-id:5651923996 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): @SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
Author
Owner

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

Fixed in #6137, now merged to staging (e044997a2). Peek Prompt displays planning model, provider, and usage separately from narration.

<!-- gh-comment-id:5652784894 --> @SpicyMarinara commented on GitHub (Sep 13, 2026): Fixed in #6137, now merged to staging (`e044997a2`). Peek Prompt displays planning model, provider, and usage separately from narration.
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#3407
No description provided.