nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Streaming tail is still unbounded when a huge line comes after an earlier newline (follow-up to #1555)

Open addyCooks opened this issue 1 month ago • 1 comments

Description

#1560 fixed computeStreamingTail for a message with no newline at all. But the code still moves the start of the tail back to the nearest earlier newline, however far back that is. If the message has a short line first and then one huge line (a fenced minified bundle, a big JSON blob), the tail becomes the whole message. Every streaming update then re-wraps all of it.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 6eaff7af)
  • Provider / Model: not relevant (reproduced by calling computeStreamingTail directly)

Steps to Reproduce

  1. Call computeStreamingTail(message, 80, 20) from source/components/streaming-message.tsx with three messages: 2,000,000 x characters; 'Intro\n' followed by 2,000,000 x; and 'Here is the output:\n```json\n' followed by 2,000,000 x.
  2. Time computeStreamingTail plus wrapWithTrimmedContinuations(tail, 80), which is what the component does on each update.

Expected Behavior

The tail stays near textWidth × maxLines × 4 (6,400 characters here) in all three cases.

Actual Behavior

Only the first message is bounded:

2 MB, no newline (fixed by #1560)            tail=    6400 chars        5.8 ms per update
2 MB, one earlier newline (still slow)       tail= 2000000 chars     1310.5 ms per update
200 KB, one earlier newline                  tail=  200000 chars       71.7 ms per update

Suggested Fix

  • source/components/streaming-message.tsx (computeStreamingTail, about lines 21-45): only snap back to the previous newline when it is close, for example prevNewline >= rawTailStart - textWidth. Otherwise keep rawTailStart.
  • Add the "short line, then a huge line" and "fenced block, then a huge line" cases to streaming-message.spec.tsx. Those two cases fail today; the no-newline case passes.

Additional Context

  • Related: #1555 (closed), PR #1560.
  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

addyCooks avatar Oct 09 '26 18:10 addyCooks

Thanks @Zaygal for the fix in #1693, gonna review it this time. For next time: please comment on an issue and wait to be assigned before opening a PR, even for a small fix. It keeps two people from working on the same thing.

addyCooks avatar Oct 12 '26 08:10 addyCooks