Skip to content

fix(go): decode TOOL_CALL_CHUNK, thinking and subagent events in the events package - #3180

Open
rudycelekli wants to merge 1 commit into
ag-ui-protocol:mainfrom
rudycelekli:fix/go-events-decoder-missing-types
Open

rudycelekli wants to merge 1 commit into
ag-ui-protocol:mainfrom
rudycelekli:fix/go-events-decoder-missing-types

Conversation

@rudycelekli

Copy link
Copy Markdown

What's wrong

pkg/core/events has two decoders, and neither covers every type in validEventTypes:

  • EventFromJSON (events.go) has no case for TOOL_CALL_CHUNK or the five deprecated THINKING_* events, so it returns unknown event type: TOOL_CALL_CHUNK. TOOL_CALL_CHUNK is a normal protocol event (spec/1.0/fixtures/ToolCallChunkEvent/valid/minimal.json). The Go SDK has a ToolCallChunkEvent struct and a NewToolCallChunkEvent constructor, and its own Validate accepts the type.
  • EventDecoder.DecodeEvent (decoder.go) has no case for TOOL_CALL_CHUNK, SUBAGENT_STARTED, SUBAGENT_FINISHED or SUBAGENT_ERROR. These fall through to default and come back as a *RawEvent that wraps the payload. If a consumer switches on *ToolCallChunkEvent or *SubagentStartedEvent, those events never reach that branch, and nothing reports an error. The example client (example/client/internal/event/parse.go) decodes through this function.

The fix

The missing cases are added to both switches. Each one uses the struct the package already defines.

Test

pkg/core/events/decoder_coverage_test.go loops over validEventTypes. For each type it checks two things:

  • EventFromJSON returns an event of that type.
  • DecodeEvent doesn't fall back to *RawEvent, except for RAW itself.

Because it walks the map, the test also catches the next event type that gets added to the map without a decoder case.

On main the test fails with 10 errors: 6 EventFromJSON ... unknown event type and 4 DecodeEvent ... fell back to *RawEvent. It passes with the fix. Mutation check: I reverted only events.go and decoder.go, and the named test failed with the same 10 errors.

Checks

  • cd sdks/community/go && go test ./... -v: all packages ok, 126 top-level tests passed.
  • gofmt is clean for the added lines. events.go has formatting differences that predate this change, and they aren't touched here.

🤖 Generated with Claude Code

…events package

EventFromJSON had no case for TOOL_CALL_CHUNK or the five THINKING_* events
and rejected them as "unknown event type", although validEventTypes accepts
them. EventDecoder.DecodeEvent had no case for TOOL_CALL_CHUNK or the three
SUBAGENT_* events and returned them as a *RawEvent, so a consumer switching
on the concrete type silently dropped them. Add the missing cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@contextablemark

Copy link
Copy Markdown
Contributor

Looks good as-is. A few optional regression tests would strengthen the coverage:

  • Assert the exact concrete event type for each added branch.
  • Use populated chunk, thinking, and subagent payloads and check that modeled fields survive a round trip, including metadata and rawEvent.
  • Check that malformed JSON, wrongly typed fields, and unknown event names return errors.

I wouldn’t block this PR on those tests. We’ll wait to hear back from you before merging.

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ag-ui/a2a-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a-middleware@3180

@ag-ui/a2ui-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-middleware@3180

@ag-ui/event-throttle-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/event-throttle-middleware@3180

@ag-ui/mcp-apps-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-apps-middleware@3180

@ag-ui/mcp-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-middleware@3180

@ag-ui/a2a

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a@3180

@ag-ui/adk-js

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/adk-js@3180

@ag-ui/adk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/adk@3180

@ag-ui/ag2

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/ag2@3180

@ag-ui/agno

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/agno@3180

@ag-ui/antigravity

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/antigravity@3180

@ag-ui/aws-strands

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/aws-strands@3180

@ag-ui/claude-agent-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/claude-agent-sdk@3180

@ag-ui/claude-managed-agents

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/claude-managed-agents@3180

@ag-ui/crewai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/crewai@3180

@ag-ui/langchain

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langchain@3180

@ag-ui/langgraph

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langgraph@3180

@ag-ui/llamaindex

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/llamaindex@3180

@ag-ui/mastra

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mastra@3180

@ag-ui/pydantic-ai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/pydantic-ai@3180

@ag-ui/vercel-ai-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/vercel-ai-sdk@3180

@ag-ui/watsonx

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/watsonx@3180

@ag-ui/a2ui-toolkit

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-toolkit@3180

create-ag-ui-app

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/create-ag-ui-app@3180

@ag-ui/client

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/client@3180

@ag-ui/core

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/core@3180

@ag-ui/encoder

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/encoder@3180

@ag-ui/proto

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/proto@3180

commit: 696cab7

This branch has not been deployed

No deployments
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