[PR #4502] [CLOSED] [GUI] The engine reports its reasoning tokens, and the row shows them exactly #5070

Closed
opened 2026-11-07 16:32:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4502
Author: @xvcezrqpbxtpzblrt
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: gui/reasoning-exact-027


📝 Commits (2)

  • fec4741 [GUI] The thinking row shows live time and tokens, and counts only the thinking
  • c19c886 [GUI] Report the engine's reasoning tokens and show them exactly when they arrive

📊 Changes

17 files changed (+140 additions, -26 deletions)

View changed files

📝 apps/host/server/agent/events.mjs (+5 -1)
📝 apps/host/src/components/ReasoningBlock.tsx (+32 -9)
📝 apps/host/src/lib/reasoning.ts (+33 -0)
📝 apps/host/src/lib/store.ts (+10 -6)
📝 apps/host/src/lib/types.ts (+2 -0)
📝 apps/host/src/locales/de.json (+2 -1)
📝 apps/host/src/locales/en.json (+2 -1)
📝 apps/host/src/locales/es.json (+2 -1)
📝 apps/host/src/locales/fr.json (+2 -1)
📝 apps/host/src/locales/ja.json (+2 -1)
📝 apps/host/src/locales/ko.json (+2 -1)
📝 apps/host/src/locales/pt.json (+2 -1)
📝 apps/host/src/locales/ru.json (+2 -1)
📝 apps/host/src/locales/zh.json (+2 -1)
📝 apps/host/tests/agent-events.test.mjs (+19 -0)
📝 apps/host/tests/live-chat.test.mjs (+17 -0)
📝 serve/server.py (+4 -1)

📄 Description

Problem

The thinking row had to estimate its token count (marked ≈) because the chat usage the engine returns carries only prompt/completion/total. The engine already counts the thinking tokens internally for the Responses API (reasoning_tokens in its done event) but the OpenAI-compatible usage object had no completion_tokens_details.reasoning_tokens.

Result

  • The engine's chat usage now carries the standard field, for streamed and non-streamed replies: "completion_tokens_details": {"reasoning_tokens": N}.
  • The app reads it (host usage frame, message, thinking row) and shows the exact number without ≈ when it is present; the estimate remains the fallback when a provider does not send it.
  • The count is summed over the turn's requests, like the reasoning text itself.

Validation

  • Direct call to the running engine, non-streamed: "completion_tokens_details": {"reasoning_tokens": 16} next to prompt 54 / completion 16.
  • Same call streamed with stream_options.include_usage: the final usage carries "completion_tokens_details": {"reasoning_tokens": 19}.
  • node --test tests/agent-events.test.mjs → the count is summed over two usage frames (3 + 4 = 7) and the terminal frame has none when the provider sends none.
  • npm run typecheck clean.

Limits

  • On this computer the app still shows ≈: the pinned Harness (0.2.1-alpha.3) builds its usage frame in dsh-llm-pi-ai's mapUsage, which copies input/output/total/cache only and drops the provider's reasoning count before the app sees it. Its own TokenUsage type has the field, but this version never fills it. The engine and app sides are ready; the exact number appears once the Harness forwards it.
  • The estimate stays for API models whose providers do not send completion_tokens_details.
  • Based on #4471 (the live thinking row); that one should merge first.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4502 **Author:** [@xvcezrqpbxtpzblrt](https://github.com/xvcezrqpbxtpzblrt) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `gui/reasoning-exact-027` --- ### 📝 Commits (2) - [`fec4741`](https://github.com/Niko1221/Strata/commit/fec47415a3bf1b0ea2dd2069dd3acef1a7fd360d) [GUI] The thinking row shows live time and tokens, and counts only the thinking - [`c19c886`](https://github.com/Niko1221/Strata/commit/c19c886b3bd1f0165f17621423707c460473bec5) [GUI] Report the engine's reasoning tokens and show them exactly when they arrive ### 📊 Changes **17 files changed** (+140 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/agent/events.mjs` (+5 -1) 📝 `apps/host/src/components/ReasoningBlock.tsx` (+32 -9) 📝 `apps/host/src/lib/reasoning.ts` (+33 -0) 📝 `apps/host/src/lib/store.ts` (+10 -6) 📝 `apps/host/src/lib/types.ts` (+2 -0) 📝 `apps/host/src/locales/de.json` (+2 -1) 📝 `apps/host/src/locales/en.json` (+2 -1) 📝 `apps/host/src/locales/es.json` (+2 -1) 📝 `apps/host/src/locales/fr.json` (+2 -1) 📝 `apps/host/src/locales/ja.json` (+2 -1) 📝 `apps/host/src/locales/ko.json` (+2 -1) 📝 `apps/host/src/locales/pt.json` (+2 -1) 📝 `apps/host/src/locales/ru.json` (+2 -1) 📝 `apps/host/src/locales/zh.json` (+2 -1) 📝 `apps/host/tests/agent-events.test.mjs` (+19 -0) 📝 `apps/host/tests/live-chat.test.mjs` (+17 -0) 📝 `serve/server.py` (+4 -1) </details> ### 📄 Description ## Problem The thinking row had to estimate its token count (marked `≈`) because the chat usage the engine returns carries only prompt/completion/total. The engine already counts the thinking tokens internally for the Responses API (`reasoning_tokens` in its done event) but the OpenAI-compatible `usage` object had no `completion_tokens_details.reasoning_tokens`. ## Result - The engine's chat usage now carries the standard field, for streamed and non-streamed replies: `"completion_tokens_details": {"reasoning_tokens": N}`. - The app reads it (host usage frame, message, thinking row) and shows the exact number without `≈` when it is present; the estimate remains the fallback when a provider does not send it. - The count is summed over the turn's requests, like the reasoning text itself. ## Validation - Direct call to the running engine, non-streamed: `"completion_tokens_details": {"reasoning_tokens": 16}` next to prompt 54 / completion 16. - Same call streamed with `stream_options.include_usage`: the final usage carries `"completion_tokens_details": {"reasoning_tokens": 19}`. - `node --test tests/agent-events.test.mjs` → the count is summed over two usage frames (3 + 4 = 7) and the terminal frame has none when the provider sends none. - `npm run typecheck` clean. ## Limits - On this computer the app still shows `≈`: the pinned Harness (0.2.1-alpha.3) builds its usage frame in `dsh-llm-pi-ai`'s `mapUsage`, which copies input/output/total/cache only and drops the provider's reasoning count before the app sees it. Its own `TokenUsage` type has the field, but this version never fills it. The engine and app sides are ready; the exact number appears once the Harness forwards it. - The estimate stays for API models whose providers do not send `completion_tokens_details`. - Based on #4471 (the live thinking row); that one should merge first. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:27 +07:00
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
Niko1221/Strata#5070
No description provided.