fix(react): detect job-attachment paths across all union branches#952
Draft
cotovanu-cristian wants to merge 1 commit into
Draft
fix(react): detect job-attachment paths across all union branches#952cotovanu-cristian wants to merge 1 commit into
cotovanu-cristian wants to merge 1 commit into
Conversation
get_json_paths_by_type collapsed every field annotation to the first non-None union member (via _unwrap_optional), so a target type reachable through any other branch of an anyOf/oneOf union was never searched. A field typed `str | Target`, `Union[A, B]`, `Optional[Union[...]]`, `list[Union[...]]`, or a union whose member nests the type returned no path, and downstream extract_values_by_paths silently dropped the value (e.g. a job attachment). Search every non-None union member (recursively, including list-inner unions) instead of collapsing to the first. _unwrap_optional is unchanged and still serves Optional-stripping in the RootModel root-peel and _coerce_field. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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
get_json_paths_by_typeis documented to return JSONPaths for all fields that reference agiven type. It silently misses every path when a field is a genuine multi-branch union and the
target type is not the first non-
Nonemember.The cause is in
_recursive_search: it called_unwrap_optional(annotation), which collapses anyUnionto its first non-Nonemember. SoUnion[str, Target],Union[A, Target],Optional[Union[A, Target]],list[Union[A, Target]], the PEP-604 formstr | Target | None, anda union whose member nests the target type all reduced to the first branch — the rest were never
searched, the function returned
[], and downstreamextract_values_by_pathssilently dropped thevalue (e.g. a job attachment).
This matters in normal operation: a JSON-schema field
{"anyOf": [{"type": "string"}, {"$ref": ".../job-attachment"}]}becomesUnion[str, <Attachment>, None], so a real attachment passed in astring-or-attachment field was never resolved.
The contract
The function's own docstring: "Get JSONPath expressions for all fields that reference a
specific type … recursively traverses nested Pydantic models to find all paths." A field
reachable via any union member references that type, so its path must be returned. Union/Optional
handling is intended and already tested (
test_optional_field,test_pipe_union_field).Root cause & fix
agent/react/json_utils.py— inside_recursive_search, search every non-Noneunion member(recursively, including a union nested as a list's inner type) instead of collapsing to the first.
A new
_union_membershelper returns the non-Nonemembers of a union, or[annotation]for anon-union — so non-union fields behave byte-identically to before.
_unwrap_optionalis leftunchanged; it still serves Optional-stripping in the
RootModelroot-peel and_coerce_field,which only ever see single-member optionals.
This is a single change in the shared producer through which all callers route
(
get_job_attachment_pathsis the only production caller), not a per-caller patch.Tests
Added
TestGetJsonPathsByTypeUnionscovering second-branch unions, optional unions, PEP-604three-member unions,
list[Union[...]], a union member that nests the type, multiple branchesreferencing the type, the first-branch baseline, and the dynamic
anyOf/$refcase. Each failson the current code and passes with the fix. Full
tests/agent/react+tests/agent/toolssuite:893 passed.