[Bug] Streaming tail is still unbounded when a huge line comes after an earlier newline (follow-up to #1555)
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
computeStreamingTaildirectly)
Steps to Reproduce
- Call
computeStreamingTail(message, 80, 20)fromsource/components/streaming-message.tsxwith three messages: 2,000,000xcharacters;'Intro\n'followed by 2,000,000x; and'Here is the output:\n```json\n'followed by 2,000,000x. - Time
computeStreamingTailpluswrapWithTrimmedContinuations(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 exampleprevNewline >= rawTailStart - textWidth. Otherwise keeprawTailStart.- 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
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.