Skip to content

Conversation

@Cprakhar
Copy link

@Cprakhar Cprakhar commented Nov 23, 2025

What

Skip adding reasoning-only assistant messages to chat state in Agent.parseUiStream.

Why

Fixes #705 - empty messages were being created when assistant only had reasoning/step-start parts, leading to "Agent failed: Bad Request [ce]" errors.

How

Added a guard that filters out assistant messages containing only reasoning or step-start parts before adding to karton state.

Testing

  • Manual testing: verify no empty messages appear in chat
  • Changeset included for version bump

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a Bad Request error that occurred when internal reasoning-only messages were added to the chat stream, preventing empty messages from causing failures.
    • Improved message clarity by automatically filtering out internal reasoning and processing step information from displayed messages, keeping the chat history focused on user-relevant content.

✏️ Tip: You can customize this high-level summary in your review settings.

@cla-bot
Copy link

cla-bot bot commented Nov 23, 2025

We require contributors to sign our Contributor License Agreement, and we don"t have @Cprakhar on file. In order for us to review and merge your code, please follow our CLA guidelines.

@vercel
Copy link

vercel bot commented Nov 23, 2025

@Cprakhar is attempting to deploy a commit to the stagewise Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

A new changeset entry documents a patch for @stagewise/agent-client, and filtering logic is added to the UI stream parser to skip assistant messages containing only non-user-visible reasoning or step-start parts, preventing empty messages from causing Bad Request errors.

Changes

Cohort / File(s) Summary
Changeset documentation
\.changeset/itchy-files-doubt.md
New changeset documenting patch release for @stagewise/agent-client with note about skipping reasoning-only messages to avoid empty message errors.
Message filtering logic
agent/client/src/Agent.ts
Adds filtering in UI stream parser to skip assistant messages where all parts are either 'reasoning' or 'step-start' type, preventing internal reasoning fragments from surfacing in user-visible chat history.

Sequence Diagram

sequenceDiagram
    participant Stream as UI Stream
    participant Parser as parseUiStream
    participant Filter as Message Filter
    participant History as Chat History

    Stream->>Parser: Emit assistant message with parts
    Parser->>Filter: Check message parts
    
    alt All parts are reasoning or step-start
        Filter-->>Parser: Skip message
        Note over Parser,History: Message filtered out
    else Contains user-visible content
        Filter->>History: Add message to chat
        Note over History: Message surfaced to user
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the filtering logic in Agent.ts to confirm it correctly identifies and skips reasoning-only messages
  • Verify the changeset accurately reflects the fix for issue #705

Possibly related PRs

Suggested labels

cla-signed

Poem

🐰 Through reasoning streams and steps untold,
We filter noise with logic bold,
No empty whispers shall pass through,
Only wisdom users view! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: skipping reasoning-only assistant messages to prevent empty messages, which directly addresses the linked issue #705.
Linked Issues check ✅ Passed The PR successfully implements filtering of assistant messages containing only reasoning or step-start parts, directly addressing the core requirement from issue #705 to prevent empty messages that cause Bad Request errors.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: the Agent.ts modification filters reasoning-only messages, and the changeset documents the patch release—both directly addressing issue #705.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
agent/client/src/Agent.ts (1)

680-690: LGTM! Logic correctly implements the fix for the reported issue.

The filtering logic properly prevents assistant messages containing only reasoning or step-start parts from being added to the chat state. The condition ordering is safe—parts?.length > 0 ensures parts is defined before calling .every().

Optional enhancement: Consider also filtering assistant messages with empty or undefined parts arrays to be more defensive:

 // Skip assistant messages that only contain non-user-visible reasoning or step-start parts
 if (
   uiMessage.role === 'assistant' &&
-  uiMessage.parts?.length > 0 &&
-  uiMessage.parts.every(
-    (part) =>
-      part.type === 'reasoning' || part.type === 'step-start',
-  )
+  (!uiMessage.parts ||
+    uiMessage.parts.length === 0 ||
+    uiMessage.parts.every(
+      (part) =>
+        part.type === 'reasoning' || part.type === 'step-start',
+    ))
 ) {
   continue;
 }

This would also catch any assistant messages with no content, though the current implementation correctly addresses the specific bug reported in #705.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 589104e and c41c9c4.

📒 Files selected for processing (2)
  • .changeset/itchy-files-doubt.md (1 hunks)
  • agent/client/src/Agent.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

NEVER use any. NEVER use unknown unless absolutely necessary.

Files:

  • agent/client/src/Agent.ts
🧠 Learnings (1)
📚 Learning: 2025-08-17T19:03:32.418Z
Learnt from: CR
Repo: stagewise-io/stagewise PR: 0
File: toolbar/core/CLAUDE.md:0-0
Timestamp: 2025-08-17T19:03:32.418Z
Learning: Applies to toolbar/core/src/hooks/agent/**/*.{ts,tsx} : Place agent connectivity hooks under `src/hooks/agent`, with individual interface capabilities covered by individual hooks

Applied to files:

  • agent/client/src/Agent.ts
🔇 Additional comments (1)
.changeset/itchy-files-doubt.md (1)

1-5: LGTM!

The changeset correctly documents the patch and provides a clear description of the fix that aligns with the PR objectives.

@glenntws
Copy link
Contributor

@Cprakhar thanks for your contribution! We would be ready to approve this once everything checks out and the CLA is signed!

@juliangoetze should be an easy merge i guess?

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.

bug: empty message is created somehow producing "Agent failed: Bad Request [ce]" error

2 participants