Skip to content

fix(go): always write the required value on CUSTOM events - #3184

Open
rudycelekli wants to merge 1 commit into
ag-ui-protocol:mainfrom
rudycelekli:fix/go-custom-event-null-value
Open

rudycelekli wants to merge 1 commit into
ag-ui-protocol:mainfrom
rudycelekli:fix/go-custom-event-null-value

Conversation

@rudycelekli

Copy link
Copy Markdown

What's wrong

CustomEvent.Value is tagged json:"value,omitempty". If you build a custom event without a value, or with a nil value, the value key is left out of the output:

data, _ := events.NewCustomEvent("app.ping").ToJSON()
// {"type":"CUSTOM","timestamp":...,"name":"app.ping"}

The 1.0 schema lists value as required on CustomEvent ("required": ["type", "name", "value"]) and says it may be any JSON value, including null (spec/1.0/fixtures/CustomEvent/valid/value-null.json). The TypeScript reference client's generated schema enforces the requirement with value: z.any().refine((value) => value !== undefined). So a Go server sending a bare CUSTOM signal such as NewCustomEvent("app.ping") makes the TS client fail validation on that event. A relay hits the same problem: a Go relay that decodes and re-encodes a value: null event drops the key.

The fix

omitempty is removed from Value, so a nil value is written as "value":null. Non-nil values serialize exactly as before.

Test

TestCustomEventAlwaysWritesValue (pkg/core/events/custom_value_test.go) checks that:

  • NewCustomEvent("app.ping") writes a value key with a null value.
  • NewCustomEvent(name, WithValue(nil)) does the same.
  • A non-nil value is unchanged.

The test fails on main with value key missing from {"type":"CUSTOM",...,"name":"app.ping"} and passes with the fix. Mutation check: I reverted only custom_events.go, and the named test failed.

Checks

  • cd sdks/community/go && go test ./... -v: all packages ok, 126 top-level tests passed.
  • cd example/server && go test ./...: ok.
  • gofmt -l is clean.

🤖 Generated with Claude Code

CustomEvent.Value was tagged omitempty, so NewCustomEvent(name) without
WithValue, or with a nil value, was serialized with no value key. The spec
makes value required (null is allowed), and the TypeScript client's schema
rejects a CUSTOM event without it, failing the run. Write value always.

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

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.

1 participant