Skip to content

fix(core): allow generating responses in empty threads#13164

Open
roaminro wants to merge 2 commits intomainfrom
roamin/issue-13045
Open

fix(core): allow generating responses in empty threads#13164
roaminro wants to merge 2 commits intomainfrom
roamin/issue-13045

Conversation

@roaminro
Copy link
Member

@roaminro roaminro commented Feb 17, 2026

Fixes #13045

ensureGeminiCompatibleMessages was throwing a MastraError when there were no user/assistant messages (only system messages). This blocked generating responses in empty threads (e.g. generate welcome messages via CopilotKit's useAgent hook).

The fix replaces the throw with a warning via the Mastra logger. Providers that handle system-only prompts natively (Anthropic, OpenAI) now work without issues. Providers that require a user message (Gemini) will return their own error, and users will see a helpful warning in their logs pointing them in the right direction.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an error that occurred when generating responses in threads containing only system messages. Providers supporting system-only prompts (Anthropic, OpenAI) now work correctly. Providers requiring user messages (Gemini) log a warning instead of throwing an error.

Replace throw with warning in ensureGeminiCompatibleMessages when no
user/assistant messages are present. Providers that support system-only
prompts (Anthropic, OpenAI) now work natively. Gemini users get a
warning and the provider's own error.

Fixes #13045
@vercel
Copy link

vercel bot commented Feb 17, 2026

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

Project Deployment Actions Updated (UTC)
mastra-docs Ready Ready Preview, Comment Feb 17, 2026 11:34pm
mastra-docs-1.x Building Building Preview, Comment Feb 17, 2026 11:34pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 81d3559

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@mastra/core Patch
@mastra/mcp-docs-server Patch
@internal/playground Patch
@mastra/client-js Patch
@mastra/react Patch
@mastra/opencode Patch
@mastra/longmemeval Patch
mastra Patch
@mastra/deployer-cloud Patch
@mastra/playground-ui Patch
@mastra/server Patch
@mastra/deployer Patch
create-mastra Patch
@mastra/express Patch
@mastra/fastify Patch
@mastra/hono Patch
@mastra/koa Patch
@mastra/deployer-cloudflare Patch
@mastra/deployer-netlify Patch
@mastra/deployer-vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

The PR addresses issue #13045 by replacing error-throwing behavior with optional logging when processing empty or system-only message lists. This allows providers supporting system-only prompts to function while providers requiring user messages log warnings instead of failing.

Changes

Cohort / File(s) Summary
Changelog Entry
.changeset/blue-times-shine.md
Documents patch release fixing empty thread response generation error for system-only prompts.
Core Message Handling
packages/core/src/agent/message-list/message-list.ts, packages/core/src/agent/message-list/utils/provider-compat.ts
Added optional logger parameter to MessageList constructor and ensureGeminiCompatibleMessages function. Replaced error-throwing on empty/system-only messages with optional warning-based logging.
Workflow Integration
packages/core/src/agent/workflows/prepare-stream/prepare-memory-step.ts
Updated MessageList instantiation to pass logger from capabilities context.
Test Updates
packages/core/src/agent/message-list/tests/message-list.test.ts, packages/core/src/agent/message-list/tests/message-list-gemini.test.ts, packages/core/src/agent/message-list/tests/message-list-v5.test.ts
Replaced error assertions with empty array and system-message array expectations. Added mock logger utility for warning assertions. Added test group for issue #13045 covering empty thread response generation across SDK versions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise, descriptive, follows imperative mood, and clearly summarizes the main change of fixing empty thread response generation.
Linked Issues check ✅ Passed The PR fully addresses issue #13045 by replacing the hard error in ensureGeminiCompatibleMessages with optional logger-based warnings, allowing system-only prompts to work for compatible providers.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the empty thread generation issue: updating message-list handling, adding logging support, adjusting provider compatibility logic, and updating comprehensive tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch roamin/issue-13045

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.

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.

Generate a response in an empty thread

1 participant

Comments