Visitar URL original
Python: [Bug]: make_json_safe() raises RecursionError on a plain Enum member · Issue #9194 · microsoft/agent-framework · GitHub
Skip to content

Python: [Bug]: make_json_safe() raises RecursionError on a plain Enum member #9194

Closed

Description

Description

agent_framework._serialization.make_json_safe() is documented to fall back to str() "so that json.dumps never raises". A plain Enum member breaks that. It is not a scalar and has no to_dict() or model_dump(), so it reaches the vars(obj) fallback. Among its attributes is __objclass__, the enum class itself, and walking the class leads back to its members, so the call recurses until RecursionError.

Members of enums with a str or int mixin are not affected, because they take the scalar branch.

It shows up wherever arbitrary values pass through make_json_safe(). In AG-UI, for example, _safe_serialize_session_continuation_state() catches the error and saves the snapshot with session_state=None, so the session state is dropped without an error reaching the caller. Marimo (@SuperMarimoBros) ran into it in discussion #9189.

Code Sample

from enum import Enum

from agent_framework._serialization import make_json_safe


class Color(Enum):
    RED = 1


make_json_safe({"color": Color.RED})

Error Messages / Stack Traces

  File ".../agent_framework/_serialization.py", line 779, in make_json_safe
    return {key: make_json_safe(value) for key, value in vars(obj).items()}
RecursionError: maximum recursion depth exceeded

Package Versions

agent-framework-core: 1.20.0 (main at 3d0bde5)

Python Version

Python 3.12

Additional Context

A fix that keeps every current output: an Enum branch right after the scalar check that returns make_json_safe(obj.value). Mixin enums still return through the scalar branch unchanged, and .value is what json.dumps already writes for IntEnum and StrEnum. I have it ready with tests and can open the PR.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 8, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 8, 2026
  3. github-actions commented on Oct 8, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: python/packages/core/agent_framework/_serialization.py::make_json_safe at lines 756 and 779 recursively traverses a plain Enum member until RecursionError. Minimal repro: define Color(Enum) with RED = 1, then call make_json_safe({"color": Color.RED}).

    • Failing test: python/packages/core/tests/core/test_observability.py
    • Files examined: python/packages/core/agent_framework/_serialization.py, python/packages/core/tests/core/test_observability.py, python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py, python/packages/core/pyproject.toml
    • Tests run: existing make_json_safe tests (3 passed), test_make_json_safe_plain_enum_member (failed)
    • Reported version: 1.20.0
    • Current version: 1.20.0
  4. added
    agentsUsage: [Issues, PRs], Target: Single agent
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 8, 2026
  5. added a commit that references this issue on Oct 13, 2026
    538da71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions