Skip to content

fix(agent): filter SDK metadata from messages/partial events#102

Merged
blove merged 1 commit into
mainfrom
claude/condescending-sanderson
Apr 10, 2026
Merged

fix(agent): filter SDK metadata from messages/partial events#102
blove merged 1 commit into
mainfrom
claude/condescending-sanderson

Conversation

@blove
Copy link
Copy Markdown
Contributor

@blove blove commented Apr 10, 2026

Summary

  • Bug: LangGraph SDK messages/partial events include metadata objects (e.g. { langgraph_node, langgraph_triggers }) alongside real messages. normalizeMessages() had an unfiltered event['messages'] code path that let these through, causing metadata to accumulate in the messages array and crash the content classifier (undefined.length TypeError), breaking all streaming chat rendering.
  • Fix: Apply the existing isMessageLike filter to the event['messages'] code path, matching the behavior already used for the event['data'] path.
  • Tests: Added 3 new tests simulating post-normalizeSdkEvent event shapes (the production code path that MockAgentTransport bypasses), proving metadata is filtered and doesn't accumulate across partial events.

Root cause

normalizeMessages() in stream-manager.bridge.ts had two code paths:

  1. event['messages'] exists → returned unfiltered (production path via FetchStreamTransport)
  2. event['data'] exists → filtered by isMessageLike (test path via MockAgentTransport)

Tests only exercised path 2, so the bug in path 1 was invisible.

Test plan

  • nx test agent — 35/35 pass (includes 3 new tests)
  • nx test chat — 175/175 pass
  • Streaming dev server loads cleanly after fix

🤖 Generated with Claude Code

normalizeMessages() had two code paths: event['messages'] (returned
unfiltered) and event['data'] (filtered by isMessageLike). In
production, FetchStreamTransport's normalizeSdkEvent wraps the raw SDK
data array—which includes metadata objects like { langgraph_node,
langgraph_triggers }—into event.messages. These metadata objects lack
content/type/id fields, causing messageContent() to return undefined
and crashing the content classifier's detectType() on
undefined.length.

The fix applies the existing isMessageLike filter to the
event['messages'] path. Tests now simulate post-normalization event
shapes matching what FetchStreamTransport produces.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 10, 2026

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

Project Deployment Actions Updated (UTC)
cacheplane Ready Ready Preview, Comment Apr 10, 2026 7:11pm

Request Review

@blove blove merged commit d4c5243 into main Apr 10, 2026
14 checks passed
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.

1 participant