Skip to content

Migration unpickler blocks builtins.getattr on py311 + crewai extras, silently dropping v0 EventActions during migration #6636

Closed

Description

@loponly

** Please make sure you read the contribution guide and file the issues in the right place. **

Describe the bug

The v0→v1 session migration tool's restricted unpickler (added in 9db48ce9, "fix(migration): restrict unpickling of v0 actions blobs") blocks builtins.getattr, and on Python 3.11 — specifically an environment with the full test extras installed, where crewai[tools] applies per the pyproject marker python_version>='3.11' and python_version<'3.12' — the pickled EventActions graph contains a getattr global. The unpickler rejects it, _safe_unpickle_actions logs a WARNING and falls back to empty actions, and migrated events silently lose requested_auth_configs and compaction.

Observable today as a deterministic unit-test failure on the py311 tox environment:

FAILED tests/unittests/sessions/migration/test_migration.py::test_migrate_from_sqlalchemy_pickle_preserves_nested_safe_actions_pickle
AssertionError: assert 'fc-auth' in {}

with this in the captured log:

WARNING ... Failed to unpickle actions for event event1: Blocked global during migration unpickle: builtins.getattr

To Reproduce

Steps to reproduce (repo at current main):

  1. uv venv --python "python3.11" .venv && source .venv/bin/activate && uv sync --all-extras
  2. pytest "tests/unittests/sessions/migration/test_migration.py::test_migrate_from_sqlalchemy_pickle_preserves_nested_safe_actions_pickle"
  3. Test fails as above. The same test passes on py310, py312, py313, and py314 tox environments (tox run: py310 OK, py311 FAIL, py312 OK, py313 OK, py314 OK).

Ruling out version skew: pydantic (2.12.5), fastapi (0.141.1), and google-genai (2.17.0) are identical across the py310/py311/py312 environments — the only material difference in the failing environment is the presence of crewai and its transitive dependencies, which only install on 3.11. A plausible mechanism is a pydantic plugin registered via entry points by one of those transitive dependencies altering how pydantic model instances pickle (introducing a getattr reduction), but I have not bisected the exact package.

Expected behavior

Either the migration unpickler accepts the pickle streams that pydantic models actually produce in every supported environment (so nested EventActions content survives migration), or — if builtins.getattr must stay blocked for hardening reasons — the migration should not silently degrade to {} for blobs a supported environment wrote. Silent data loss during migration is the worst outcome of the current behavior; the test correctly catches it.

Desktop:

  • OS: macOS (Darwin 24.6.0)
  • Python version: 3.11 (failing); 3.10/3.12/3.13/3.14 (passing)
  • ADK version: current main (c5672030)

Additional context

🤖 Generated with Claude Code

Activity

  1. vup903 commented on Aug 8, 2026

    @vup903
    Contributor

    Hi, I’m a Python contributor focusing on agent runtime reliability. I reproduced this on Windows 11 with CPython 3.11 and traced the pickle payload directly.

    The trigger is not a Pydantic plugin: CPython 3.11 serializes enum members such as SecuritySchemeType.http through builtins.getattr(EnumClass, member_name), while newer Python versions use the enum value constructor.

    I have a narrow fix in progress that substitutes a restricted enum-member resolver instead of allowlisting arbitrary getattr. It only accepts already-allowlisted enum classes and names present in __members__; non-enum and dunder lookups remain blocked. I’ve also added cross-version regression coverage and negative security tests.

    Would this direction be acceptable, and could I be assigned to the issue?

  2. added
    core
    on Aug 10, 2026
  3. llalitkumarrr commented on Aug 12, 2026

    @llalitkumarrr
    Collaborator

    Hello @loponly,

    We tried to reproduce this issue using the current main (a56f6e13) but we were unable to reproduce it on our end. Could you please test this on your end and share your observations?

  4. added
    request clarification
    on Aug 12, 2026
  5. a2105z commented on Aug 13, 2026

    @a2105z
    Contributor

    I tried to reproduce this on current main (18903cad) as well.

    Environment

    • macOS (arm64)
    • CPython 3.11.15
    • uv sync --all-extras (crewai 1.6.1 is installed)
    • pydantic 2.13.4, fastapi 0.141.1, google-genai 2.16.0

    Result
    Could not reproduce the failure:

    UV_PROJECT_ENVIRONMENT=.venv-py311 uv run --python 3.11 pytest \
      tests/unittests/sessions/migration/test_migration.py::test_migrate_from_sqlalchemy_pickle_preserves_nested_safe_actions_pickle -vv
    # 1 passed

    I also pickled the same nested EventActions(AuthConfig(HTTPBearer()), …) graph and inspected the stream: on this 3.11.15 build, SecuritySchemeType.http pickles via STACK_GLOBAL + REDUCE (no builtins.getattr), and _restricted_pickle_loads succeeds with fc-auth preserved.

    That lines up with @llalitkumarrr’s non-repro on a56f6e13.

    Notes / ask

    • Issue report used pydantic 2.12.5 / google-genai 2.17.0; my tree differs there, which may matter.
    • @vup903’s enum/getattr theory is plausible for some 3.11 pickle layouts, but I’m not seeing that opcode in the current dependency set.

    @loponly if you still hit this, could you share:

    1. exact python -V patch (e.g. 3.11.x),
    2. pip show pydantic fastapi google-genai crewai,
    3. (ideal) a hex/base64 dump of the failing actions pickle blob?

    Happy to help land a safe enum-member resolver if we can get a failing payload; I’ve opened a local branch ready for that once we have a deterministic repro.

  6. llalitkumarrr commented on Sep 10, 2026

    @llalitkumarrr
    Collaborator

    Closing this issue since this is not reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

corerequest clarification

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions