Skip to content

CrewAI memory callbacks retain session protection - #893

Merged
zlareb1 merged 2 commits into
mainfrom
feat/crewai-callback-protection
Nov 18, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
feat/crewai-callback-protection

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

CrewAI memory callbacks retain their conversation's protection contributors across client rebinding. Protected automatic recall and capture refuse before HTTP, while explicit native memory tools remain explicit.

Why

LoomCrewMemory loses constructor and earlier callback contributors when its client binding changes. Automatic callbacks can then dispatch after an originating contributor becomes protected. A marked recall must also reach retained contributors before the native memory callback returns content.

The adapter uses the shared callback protection helper to retain constructor and callback contributors, including the pure extract_memories producer. Each SDK dispatch joins automatic protection only when the application already owns an automatic scope; otherwise it observes response protection. The SDK retains those contributors across authentication awaits and observes marked responses before native matches return.

Scope and risk

Use one memory instance per conversation. Native user identifiers and the unsupported private flag do not select session protection. Explicit RememberTool and RecallMemoryTool calls outside an automatic scope keep their ownership. Query bodies, filtering, read-only behavior, and extraction contents retain their existing semantics.

The tests use native Crew.kickoff() and memory tools with the real SDK and an HTTPX mock transport. The existing scripted language model supplies the crew answer without a provider call. The fixture excludes inherited proxies before SDK construction through SDK close, and a separate assertion checks transport selection before any request.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: reverting restores callback behavior; no stored data or migrations change.

Tests

The test-only baseline produced the same 12 causal failures and 25 passes on both supported native CI legs: CrewAI 1.15.42 with Python 3.12 in 8.97 seconds, and CrewAI 1.15.0 with Python 3.11 in 5.67 seconds. The failures cover lost constructor and callback contributors, rebinding during authentication, marked recall, failed observation, and the real crew path dispatching two unwanted requests. Setup, imports, proxy isolation, and explicit-tool controls passed.

The fix preserves the entire 37-case test module byte-for-byte. Scoped Ruff format and lint checks, prose checks, and git diff --check pass. Local runtime checks remain blocked by the disk admission floor; no compatible task environment is available for a scoped type check. The corrected head passes all 37 cases on both supported native CI legs: CrewAI 1.15.42/Python 3.12 in 10.69 seconds and CrewAI 1.15.0/Python 3.11 in 4.33 seconds. Strict mypy passes four source files in both jobs. All 45 required checks are terminal: 43 pass and the two documentation publication checks are skipped. All four applicable workflows pass. Reproduce native checks with make test-sdk-adapter-crewai on both supported dependency resolutions.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: An agent wrote the change. Independent source review, both native dependency resolutions and all required CI checks pass.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Corrected-head native CI and strict type checks pass on both supported dependency resolutions.
  • Required full GitHub CI passes on the current head.
  • The original regression assertions and SDK dispatch payloads are unchanged.
  • No generated API, settings, schema, plugin or frontend artifacts require changes.
  • Docs describe conversation ownership and the operator and wire implications.
  • Public text follows the repository's copy rules.
  • Commits are signed off (git commit -s).

Automatic memory callbacks must retain their originating protection roots
when the bound client changes. Native explicit tools keep their own
ownership semantics. Add diagnostic cases before changing the adapter.

Signed-off-by: zlareb1 <[email protected]>
A client rebind must not remove a conversation's constructor or earlier
callback contributors. Join automatic protection at SDK dispatch only
inside an application-owned automatic scope, and observe explicit tools.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title Test CrewAI memory callback contributor retention CrewAI memory callbacks retain session protection Nov 18, 2026
@zlareb1
zlareb1 marked this pull request as ready for review November 18, 2026 17:49
@zlareb1
zlareb1 merged commit 6c009f4 into main Nov 18, 2026
45 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
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