Skip to content

fix(tui): bound the reasoning stream to a tail and skip it when collapsed - #1375

Merged
will-lamerton merged 1 commit into
Nano-Collective:mainfrom
addyCooks:fix/reasoning-tail-1329
Sep 21, 2026
Merged

will-lamerton merged 1 commit into
Nano-Collective:mainfrom
addyCooks:fix/reasoning-tail-1329

Conversation

@addyCooks

Copy link
Copy Markdown
Contributor

Closes #1329

Description

StreamingReasoning called wrapWithTrimmedContinuations(reasoning.trimEnd(), textWidth) on the entire accumulated reasoning string on every token flush, with no bound and no early exit. StreamingMessage already solved this with computeStreamingTail; the reasoning component never adopted it. Worse, reasoningExpanded defaults to false, so the full re-wrap plus calculateTokens ran on every flush for a panel that renders nothing.

Fix:

  • Reuse computeStreamingTail (already exported from streaming-message.tsx) so each flush is O(tail) rather than O(history).
  • Skip the wrap and the token count entirely when expand === false.

No new helper and no new file the bounded-tail logic stays in one place.

Measured, 30 flushes over a ~150KB trace (same shape as the harness in the issue):

before after
collapsed 2757ms total 91.9ms/flush 348ms 11.6ms/flush
expanded 2977ms total 99.2ms/flush 757ms 25.2ms/flush

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging

…psed

StreamingReasoning re-wrapped the entire accumulated reasoning string on every token flush, and paid that cost plus calculateTokens even while collapsed - the default - where nothing below the header renders. It now reuses computeStreamingTail, the bounded-tail helper StreamingMessage already had, and skips the wrap and the token count entirely when collapsed. Measured over 30 flushes of a ~150KB trace: 91.9ms to 11.6ms per flush collapsed, 99.2ms to 25.2ms expanded. Closes Nano-Collective#1329.
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: nothing to raise

@addyCooks — nothing to raise from the automated review.

The PR ports the bounded-tail wrap pattern from StreamingMessage into StreamingReasoning and short-circuits the wrap and token count when expand === false. The reuse is direct — same helper, same MAX_LINES, same sliced || lines.length > MAX_LINES truncated-or-not logic — so the symmetry is preserved and no new file is added. The three new tests target the actual behaviours that regressed under the old code (tail across flushes, collapsed-default rendering nothing) and the changeset is present with the right workspace package name. Ready to merge.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:clean nc-review had nothing to raise label Sep 17, 2026
@will-lamerton

Copy link
Copy Markdown
Member

Great work @addyCooks :)

@will-lamerton
will-lamerton merged commit a68d463 into Nano-Collective:main Sep 21, 2026
17 checks passed
@addyCooks

Copy link
Copy Markdown
Contributor Author

Thanks @will-lamerton : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:clean nc-review had nothing to raise area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants