Repository navigation
fix(go): always write the required value on CUSTOM events - #3184
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
CustomEvent.Valueis taggedjson:"value,omitempty". If you build a custom event without a value, or with a nil value, thevaluekey is left out of the output:The 1.0 schema lists
valueas required onCustomEvent("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 withvalue: z.any().refine((value) => value !== undefined). So a Go server sending a bareCUSTOMsignal such asNewCustomEvent("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 avalue: nullevent drops the key.The fix
omitemptyis removed fromValue, 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 avaluekey with a null value.NewCustomEvent(name, WithValue(nil))does the same.The test fails on
mainwithvalue key missing from {"type":"CUSTOM",...,"name":"app.ping"}and passes with the fix. Mutation check: I reverted onlycustom_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 -lis clean.🤖 Generated with Claude Code