[GH-ISSUE #6220] [Issue]: Context usage bar over-reports on turns that made more than one request #3469

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The context usage bar treats prompt tokens as the size of the prompt the model saw, but the persisted prompt figure is a sum across every request the turn made. A turn that resent the prompt for a tool round or for the dice outcome rewrite shows roughly twice the real context.

Expected behavior

The bar reflects how full the context window is, not the turn's billing total.

Actual behavior

packages/client/src/lib/professor-mari-context-budget.ts:31-38 computes usedTokens = promptTokens + cachedPromptTokens + cacheWritePromptTokens + completionTokens from the persisted per-turn figures. The route accumulates one usage object across tool rounds (packages/server/src/routes/generate.routes.ts:7131-7145), the final follow-up (:7444-7456) and the dice follow-up (:8049-8060), and persists that sum. There is no per-request breakdown stored anywhere.

Steps to reproduce

  1. In a Game chat, turn on Enable Tool Use with a tool the Game Master will call, or write a text skill check with Narrate dice outcomes immediately on.
  2. Send a turn and note the prompt tokens under Show token usage.
  3. Compare the context bar with a turn of the same chat that made no follow-up request. The multi-request turn reports about twice the prompt size.

Environment

  • Marinara Engine version: 2.4.5 (staging at 29ee24fc2)
  • Install type: source
  • OS + version: Fedora 44
  • Browser or app shell: not browser-specific; verified by reading the code at the cited lines

Logs, screenshots, or video

Not applicable; the arithmetic is at the cited lines.

Additional context

A requestCount on generationInfo, or a small per-request array of prompt, cached and cache-write tokens, would fix the bar and would also make a zero cache read on the second request visible instead of buried in the turn total.

Template check

Please uncheck (untick) 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 @kolacheee on GitHub (Sep 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6220 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The context usage bar treats prompt tokens as the size of the prompt the model saw, but the persisted prompt figure is a sum across every request the turn made. A turn that resent the prompt for a tool round or for the dice outcome rewrite shows roughly twice the real context. ## Expected behavior The bar reflects how full the context window is, not the turn's billing total. ## Actual behavior `packages/client/src/lib/professor-mari-context-budget.ts:31-38` computes `usedTokens = promptTokens + cachedPromptTokens + cacheWritePromptTokens + completionTokens` from the persisted per-turn figures. The route accumulates one `usage` object across tool rounds (`packages/server/src/routes/generate.routes.ts:7131-7145`), the final follow-up (`:7444-7456`) and the dice follow-up (`:8049-8060`), and persists that sum. There is no per-request breakdown stored anywhere. ## Steps to reproduce 1. In a Game chat, turn on **Enable Tool Use** with a tool the Game Master will call, or write a text skill check with **Narrate dice outcomes immediately** on. 2. Send a turn and note the prompt tokens under **Show token usage**. 3. Compare the context bar with a turn of the same chat that made no follow-up request. The multi-request turn reports about twice the prompt size. ## Environment - Marinara Engine version: 2.4.5 (staging at 29ee24fc2) - Install type: source - OS + version: Fedora 44 - Browser or app shell: not browser-specific; verified by reading the code at the cited lines ## Logs, screenshots, or video Not applicable; the arithmetic is at the cited lines. ## Additional context A `requestCount` on `generationInfo`, or a small per-request array of prompt, cached and cache-write tokens, would fix the bar and would also make a zero cache read on the second request visible instead of buried in the turn total. ## Template check Please **uncheck (untick)** 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.
bsakaguchi 2026-10-21 06:03:26 +07:00
Author
Owner

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

Owner: @SpicyMarinara, with Codex implementing this issue as part of the requested sweep in draft PR #6230 against staging. I checked the open PRs and issue-linked work before starting; no competing open PR was found.

<!-- gh-comment-id:5677750479 --> @SpicyMarinara commented on GitHub (Sep 15, 2026): Owner: @SpicyMarinara, with Codex implementing this issue as part of the requested sweep in draft PR #6230 against `staging`. I checked the open PRs and issue-linked work before starting; no competing open PR was found.
Author
Owner

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

Merged in #6230 to staging (c6685f7034).

New generations record the latest request’s context size separately from the turn’s cumulative billed tokens. The context bar uses that value and does not infer a total if the latest report is missing. Native Anthropic cache counts are included once. Historical records without per-request metadata retain their legacy estimate until another generation.

<!-- gh-comment-id:5679124850 --> @SpicyMarinara commented on GitHub (Sep 15, 2026): Merged in #6230 to staging (c6685f7034d474bee00db124c4dc6398c5fc2bed). New generations record the latest request’s context size separately from the turn’s cumulative billed tokens. The context bar uses that value and does not infer a total if the latest report is missing. Native Anthropic cache counts are included once. Historical records without per-request metadata retain their legacy estimate until another generation.
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#3469
No description provided.