[GH-ISSUE #6221] [Issue]: Tool-round and dice follow-up usage accumulators sum different fields #3470

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/6221

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The three places that accumulate usage across a turn's requests do not sum the same fields. The tool loop and the final follow-up add five fields; the dice outcome follow-up adds nine. A turn's reasoning-token total therefore depends on which path added the request.

Expected behavior

One accumulator, or three that sum the same set of fields, so the persisted reasoning, audio and prediction totals cover every request of the turn.

Actual behavior

packages/server/src/routes/generate.routes.ts:7131-7145 (tool rounds) and :7444-7456 (final follow-up) sum promptTokens, completionTokens, totalTokens, cachedPromptTokens and cacheWritePromptTokens only. The dice follow-up at :8049-8060 also sums completionReasoningTokens, completionAudioTokens, acceptedPredictionTokens and rejectedPredictionTokens. Because the first round's usage is copied whole and later rounds only add the five fields, tokensReasoning (:8484) ends up holding the first round's reasoning alone.

Steps to reproduce

  1. Use a thinking model with Enable Tool Use on and a tool the model will call twice in one turn.
  2. Send a turn and read the reasoning figure under Show token usage.
  3. Compare with the per-request reasoning counts in the provider debug log. Only the first request's reasoning is counted.

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 three accumulators are at the cited lines.

Additional context

Extracting one helper that both paths call, in the shape the dice follow-up already uses, is the smallest fix.

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/6221 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The three places that accumulate usage across a turn's requests do not sum the same fields. The tool loop and the final follow-up add five fields; the dice outcome follow-up adds nine. A turn's reasoning-token total therefore depends on which path added the request. ## Expected behavior One accumulator, or three that sum the same set of fields, so the persisted reasoning, audio and prediction totals cover every request of the turn. ## Actual behavior `packages/server/src/routes/generate.routes.ts:7131-7145` (tool rounds) and `:7444-7456` (final follow-up) sum `promptTokens`, `completionTokens`, `totalTokens`, `cachedPromptTokens` and `cacheWritePromptTokens` only. The dice follow-up at `:8049-8060` also sums `completionReasoningTokens`, `completionAudioTokens`, `acceptedPredictionTokens` and `rejectedPredictionTokens`. Because the first round's usage is copied whole and later rounds only add the five fields, `tokensReasoning` (`:8484`) ends up holding the first round's reasoning alone. ## Steps to reproduce 1. Use a thinking model with **Enable Tool Use** on and a tool the model will call twice in one turn. 2. Send a turn and read the reasoning figure under **Show token usage**. 3. Compare with the per-request reasoning counts in the provider debug log. Only the first request's reasoning is counted. ## 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 three accumulators are at the cited lines. ## Additional context Extracting one helper that both paths call, in the shape the dice follow-up already uses, is the smallest fix. ## 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:5677750199 --> @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).

Tool rounds, finalization and dice follow-ups now share the same usage accumulator, preserving reasoning, audio, prediction and cache counters as well as prompt/completion totals. Focused tool/finalization and dice regressions pass.

<!-- gh-comment-id:5679125354 --> @SpicyMarinara commented on GitHub (Sep 15, 2026): Merged in #6230 to staging (c6685f7034d474bee00db124c4dc6398c5fc2bed). Tool rounds, finalization and dice follow-ups now share the same usage accumulator, preserving reasoning, audio, prediction and cache counters as well as prompt/completion totals. Focused tool/finalization and dice regressions pass.
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#3470
No description provided.