Skip to content

Conversation

@sweetmantech
Copy link
Contributor

Summary

  • Integrates handleChatCompletion into handleChatStream and handleChatGenerate to properly save chat memories
  • The function was fully implemented but never called, causing memories to not be persisted to the database
  • Fixes the bug where conversations appear empty when users return to them

Root Cause

The handleChatCompletion function at lib/chat/handleChatCompletion.ts was implemented with:

  • Room creation for new conversations
  • Memory storage for user and assistant messages via upsertMemory
  • New conversation notifications

However, both handleChatStream.ts and handleChatGenerate.ts had TODO comments but never actually called the function:

// Note: Credit handling and chat completion handling will be added
// as part of the handleChatCredits and handleChatCompletion migrations

Changes

  • Added handleChatCompletion call in handleChatStream.ts after streaming completes
  • Added handleChatCompletion call in handleChatGenerate.ts after text generation
  • Added comprehensive tests for the integration (following red-green-refactor)

Test plan

  • All existing tests pass (215 tests)
  • New tests verify handleChatCompletion is called with correct parameters
  • Tests verify graceful error handling (completion failures don't break chat response)

🤖 Generated with Claude Code

The handleChatCompletion function was implemented but never called from
the chat handlers, causing memories to not be saved to the database.
This fix integrates handleChatCompletion into both handleChatStream and
handleChatGenerate to properly save user and assistant messages.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vercel
Copy link

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
recoup-api Ready Ready Preview Jan 16, 2026 8:59pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

generateText returns ResponseMessage[] which lacks id and parts properties.
Construct a proper UIMessage from the result.text to pass to handleChatCompletion.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
…essages

StreamTextResult does not have responseMessages property. Use result.text
to construct the UIMessage for handleChatCompletion.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@sweetmantech sweetmantech merged commit bc89c0c into test Jan 16, 2026
4 checks passed
@sweetmantech sweetmantech deleted the sweetmantech/myc-3950-api-apichat-fix-missing-memories branch January 16, 2026 21:07
sweetmantech added a commit that referenced this pull request Jan 16, 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.

2 participants