Serialize undefined tool output to null in UI message chunks - #15855
Merged
Conversation
1 task
gr2m
approved these changes
Jun 17, 2026
gr2m
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Signed, full CI green, correct undefined→null coercion with regression test.
Contributor
|
|
gr2m
added a commit
that referenced
this pull request
Jun 17, 2026
On v6.0 the tool-output-available chunk is produced in stream-text.ts (to-ui-message-chunk.ts does not exist here). Apply the undefined->null coercion there and drop the cherry-picked v7-only files. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5 tasks
gr2m
added a commit
that referenced
this pull request
Jun 17, 2026
## Background Adding the `backport` label to a **merged fork PR** fires the `labeled` event. For `pull_request` events originating from a fork, GitHub forces `GITHUB_TOKEN` to read-only regardless of the job's declared `pull-requests: write`. The fork-guidance `gh pr comment` then fails with `GraphQL: Resource not accessible by integration (addComment)`, and under `set -euo pipefail` the step aborts before the intended `skip` (exit 0) — failing the whole job. Example failure: https://github.com/vercel/ai/actions/runs/27725203720/job/82019805216 (firing on #15855). ## Summary Make the fork-guidance comment best-effort (`|| echo ::warning::…`) so the job still exits cleanly via `skip`. The actual backport path (`workflow_dispatch`) is unaffected. ## Manual Verification The change is shell-only. The failing run above hit the `gh pr comment` line and aborted; with `|| echo`, the script proceeds to `skip` and exits 0. ## Checklist - [x] All commits are signed - [ ] Tests have been added / updated - [ ] Documentation has been added / updated - [ ] A _patch_ changeset for relevant packages has been added - [x] I have reviewed this pull request (self-review) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gr2m
added a commit
that referenced
this pull request
Jun 17, 2026
#16240) This is an automated backport of #15855 to the release-v6.0 branch. FYI @nwalters512 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@gr2m thanks for merging this! Did you take a look at the "future work" section I had above? Obviously I won't be able to do any of that in this PR now that it's merged, but I'd be happy to open a follow-up if you'd be on board with those changes. On second thought: I'll just open the PR so this doesn't get lost. If you don't like the changes, let me know or feel free to close it outright! |
5 tasks
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.
Background
See #15854.
Summary
toUIMessageChunk(...)now coercesundefinedtool output tonullso that the property survives being round-tripped through JSON.Manual Verification
I made the change in my own application's
node_modulesand verified that the issue I described in the linked issue was resolved.Checklist
pnpm changesetin the project root)Future Work
This prevents invalid data from being produced in streams, but doesn't do anything to handle bad data that was already produced. If maintainers would be onboard, I'd like to make a few more changes to make this work seamlessly for people:
'tool-output-available'schema inuiMessageChunkSchemato have a.default(null)on theoutputschema.'output-available'schemas invalidateUIMessagesto have a.default(null)on theoutputschemaconvertToModelMessagesto pre-normalizeundefinedtool output tonullbeforecreateToolModelOutputis called.I'd be happy to increase the scope of this PR to include this, or move it to its own PR.
As it stands, I've already stored the "bad" data in my application's database, so even if this PR is merged, I'd need application-level compatibility with old messages. It'd be great to be able to shift this into
aiitself, and I bet others could benefit from this too. If nothing else, it'd help ensure a seamless upgrade path for others looking to move from Zod 3 to Zod 4.Related Issues
Fixes #15854