nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] The reasoning/thinking trace re-processes its entire history on every flush, even while collapsed

Open addyCooks opened this issue 2 months ago • 1 comments

Description

StreamingReasoning re-wraps the FULL reasoning string on every token flush. StreamingMessage already has a bounded-tail helper (computeStreamingTail) for exactly this cost; StreamingReasoning never adopted it. Since reasoningExpanded defaults to false, this cost is paid on every flush for a panel that's collapsed and invisible by default.

Parent: #907

Recording

Not included this is a pure performance/CPU-cost finding with no visual symptom a screen recording could show; the UI looks identical whether the render is fast or slow. Evidence below is from a render-timing harness instead.

Evidence

30 flushes over ~150KB reasoning, expanded: 2890 ms (~96 ms/flush) 30 flushes over ~150KB reasoning, collapsed: 2356 ms (~79 ms/flush) <- renders nothing, still costs this StreamingMessage baseline, same size: 1187 ms (~40 ms/flush) Full-wrap cost per call at 640KB: 214.10 ms vs. a bounded 3.8KB tail: 2.16 ms

Expected Behavior

Reasoning-stream cost should stay bounded to a fixed tail, the same as StreamingMessage, and should be skipped entirely when the panel is collapsed.

Actual Behavior

Full-history re-wrap happens on every flush, expanded or not.

Root Cause

source/components/streaming-reasoning.tsx:35 calls wrapWithTrimmedContinuations(reasoning.trimEnd(), textWidth) on the complete accumulated string every flush, with no bound and no early-exit when expand === false.

Suggested Fix

Reuse computeStreamingTail in streaming-reasoning.tsx, and skip the wrap (and the calculateTokens call) entirely when expand === false.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently (measured via a render-timing harness against the real component)
  • [x] This issue occurs on the latest main

addyCooks avatar Sep 15 '26 19:09 addyCooks

Hi @akramcodez, would love to work on this could you assign this to me ?

addyCooks avatar Sep 15 '26 19:09 addyCooks