fix(crewai): stop leaking crew bookkeeping when LLM Observability is disabled #21649
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 293 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.340
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #21649"
general
weight: 0.35
mansur-akhmadi
Description
Fixes #21647
CrewAIIntegration.trace()registers each crew in_crews_to_task_span_ids,_crews_to_tasksand_planning_crew_ids. Only the LLM Observability tagging path reads and removes those entries, and it does not run when LLM Observability is disabled, so APM-only users leaked one entry per kickoff.The crew is now registered only when LLM Observability is enabled. Task registration already used
.get(crew_id, ...)and is a no-op for unregistered crews. I also switched the one directself._crews_to_tasks[crew_id]lookup in_llmobs_set_tags_taskto.get(crew_id, {})like the other accesses, so a crew that started before LLM Observability was enabled doesn't raise aKeyErrorthere.Testing
Added three tests to
tests/contrib/crewai/test_crewai.pythat run the existing basic, async-task and hierarchical (planning) crews against their cassettes and snapshots, and check that the class-level containers are the same size before and after. All three fail on main and pass with the change.Rebased on main after #21455 (crewai 1.x):
test_crewai.py(42 passed, snapshots included) andtest_crewai_llmobs.py(35 passed) pass with crewai 1.15.45 and vcrpy 8.3.0 on Python 3.12, and the three new tests still fail without thecrewai.pychange. Before the rebase they also passed against the crewai 0.157 lock, andscripts/lintstyle, typing, spelling, security and suitespec checks passed on the changed files; after the rebase I ran ruff check and ruff format on them.Benchmarks: none of the scenarios under
benchmarks/exercise the crewai integration, so this change has no benchmark coverage. With LLM Observability disabled the crew hook now does less work (oneis_enabled()check and an early return); with it enabled it adds that one check.Risks
Low. APM spans are unchanged (the new tests reuse the existing snapshots). With LLM Observability enabled the behavior is the same as before.
Additional Notes
The cleanup still lives in the LLM Observability tagging path, so a crew that starts with LLM Observability on and finishes after it is disabled, or whose crew tagging raises, still keeps its entry. Both cases existed before this change. Moving the cleanup into
traced_kickoff'sfinallywould cover them; happy to do that here or in a follow-up if you prefer.