Skip to content

Fix streaming replies when switching chats - #34

Merged
anikchand461 merged 2 commits into
smollabs:mainfrom
priyanshiy1312-ui:fix/8-streaming-chat-switch
Nov 23, 2026
Merged

anikchand461 merged 2 commits into
smollabs:mainfrom
priyanshiy1312-ui:fix/8-streaming-chat-switch

Conversation

@priyanshiy1312-ui

Copy link
Copy Markdown
Contributor

Description

Fixes the issue where switching conversations while an assistant reply is streaming could cause generated text to be lost and break the Stop button in the newly opened chat.

Changes Made

  • Added a dedicated chatGeneration structure to track each generation's cancellation function, reply message, and save timestamp.
  • Updated StopGeneration() to cancel the active generation.
  • Modified generate() to keep generation state independent of the currently selected chat.
  • Updated runGeneration() to accumulate tokens and save streaming progress to the correct reply.
  • Updated finishReply() to persist completed or cancelled replies even after switching conversations.
  • Ensured an older generation cannot accidentally reset the streaming state of a newly opened chat.

Testing

  • Ran git diff --check successfully.
  • Reviewed the modified code and verified that no obsolete a.chat.cancel or a.chat.lastSaved references remain.
  • Go tests could not be run because Go is not installed in the local environment.

Related Issue

Closes #8

@anikchand461

Copy link
Copy Markdown
Member

Thanks, the fix looks good! One thing before merge: app/chat.go fails gofmt, because the changed code uses spaces instead of tabs. Please run gofmt -w app/chat.go and push again. It would also be nice to put back the removed inline comments ("fast answers unless thinking is on", "callback runs on this generation goroutine", "crash/kill safety"). Once that's done I'll approve CI and merge.

@priyanshiy1312-ui

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've run gofmt on app/chat.go and restored all three inline comments as requested. The updated changes have been pushed in commit 32faba6.

Thanks for approving CI and helping get this merged!

@anikchand461
anikchand461 merged commit 155787b into smollabs:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching chats while a reply is streaming loses text and breaks the new chat's Stop button

2 participants