Skip to content

fix(memory): preserve reusable scope configs - #7068

Open
tandede wants to merge 6 commits into
crewAIInc:mainfrom
tandede:fix/preserve-memory-scope-config
Open

fix(memory): preserve reusable scope configs#7068
tandede wants to merge 6 commits into
crewAIInc:mainfrom
tandede:fix/preserve-memory-scope-config

Conversation

@tandede

@tandede tandede commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • preserve caller-owned memory view mappings while inferring legacy discriminators
  • keep MemoryScope and MemorySlice configuration dictionaries reusable across validations
  • add regression coverage for dependency extraction, path normalization, and discriminator inference

Problem

The memory view validators modified their input mappings in place. Constructing a MemoryScope removed the runtime memory dependency from the caller's dictionary, so reusing the same configuration produced a second scope that was not bound to its memory. MemorySlice also rewrote the caller's scope paths, and legacy discriminator inference inserted memory_kind into the original mapping.

Implementation

Each validation path now makes a shallow copy immediately before it mutates the mapping. The validated values, normalized paths, serialization format, and public API remain unchanged.

Validation

  • regression tests before the fix: 3 failed
  • regression tests after the fix: 3 passed
  • uv run --python 3.12 pytest -q lib/crewai/tests/memory/: 150 passed
  • uv run --python 3.12 pre-commit run --files lib/crewai/src/crewai/memory/memory_scope.py lib/crewai/tests/memory/test_unified_memory.py: Ruff, formatting, and mypy passed

AI assistance

AI assistance was used to inspect the validator mutation paths and draft the regression tests. I reproduced the behavior before the change, reviewed every changed line, and ran the validations above locally.

The required llm-generated label could not be applied because GitHub does not grant external contributors permission to label upstream pull requests. Please apply it during triage.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b0bbed27-5c61-473d-b8dd-a4aabf39a256

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc5d29 and 62de334.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/memory/memory_scope.py
  • lib/crewai/tests/memory/test_unified_memory.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/crewai/src/crewai/memory/memory_scope.py
  • lib/crewai/tests/memory/test_unified_memory.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Memory normalization now copies incoming dictionaries before modifying them. Regression tests verify that repeated validation preserves caller-owned configuration, normalized paths, dependencies, and inferred memory_kind.

Changes

Memory Input Immutability

Layer / File(s) Summary
Copy inputs during memory normalization
lib/crewai/src/crewai/memory/memory_scope.py
Legacy dictionary inputs are copied before normalization adds or removes fields in _ensure_memory_kind, MemoryScope._accept_memory, and MemorySlice._accept_memory.
Validate reusable memory configurations
lib/crewai/tests/memory/test_unified_memory.py
Regression tests verify repeated validation, dependency preservation, scope-path normalization, and non-mutating memory_kind inference.

Merge Risk: ⚪ Minimal · up to 62de3

This localized change preserves caller-owned memory configuration mappings without changing validated values or public behavior. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving reusable memory scope configurations during validation.
Description check ✅ Passed The description directly explains the input-mutation problem, the copy-before-mutation fix, regression tests, and validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tandede
tandede marked this pull request as ready for review August 20, 2026 11:39
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant