fix(core): keep tool output custom_data structured in RunState serialization - #5015
Open
betacatsling wants to merge 1 commit into
Open
betacatsling wants to merge 1 commit into
betacatsling wants to merge 1 commit into
Conversation
…ization ToolCallOutputItem.custom_data is SDK-only metadata that persists through RunState. _serialize_item passed it straight to _ensure_json_compatible, which uses json.dumps(default=str) and degrades Pydantic models and dataclasses to repr strings. Route it through _serialize_output_value first, the same pipeline already used for the item's output field, so structured payloads persist as plain JSON data on save and restore.
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.
Summary
ToolCallOutputItem.custom_datais SDK-only metadata that persists throughRunState, but_serialize_itempassed it directly to_ensure_json_compatible, which usesjson.dumps(default=str)and degrades Pydantic models and dataclasses to repr strings such as"value=0.9 label='high'". The siblingoutputfield already routes through_serialize_output_valuefirst. This change applies the same pipeline tocustom_dataso structured payloads round-trip as plain JSON data on save and restore.The
custom_data_extractorcontract enforced bynormalize_custom_datais unchanged; this only makesRunStatepersistence faithful for values set directly on the public field, consistent with howoutputis handled.Found during a serialization audit; no existing issue covers this field.
Test plan
New regression test
test_tool_output_custom_data_preserves_structured_valuesfails before the fix ({'score': "value=0.9 label='high'"}repr strings) and passes after.Commands and results:
The full verification script (
.agents/skills/code-change-verification/scripts/run.sh) could not run in this environment because dev dependencyevdevfails to build (-pthreadcompile error). The focused test suites covering the changed module all pass (620 tests); the limitation is unrelated to this change.Issue number
Closes #5014
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR