← Back to Pull requests

fix(crewai): stop leaking crew bookkeeping when LLM Observability is disabled #21649

Open
unknown opened this pull request with 293 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 10, 2026 16:37 UTC
Author

Description

Fixes #21647

CrewAIIntegration.trace() registers each crew in _crews_to_task_span_ids, _crews_to_tasks and _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 direct self._crews_to_tasks[crew_id] lookup in _llmobs_set_tags_task to .get(crew_id, {}) like the other accesses, so a crew that started before LLM Observability was enabled doesn't raise a KeyError there.

Testing

Added three tests to tests/contrib/crewai/test_crewai.py that 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) and test_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 the crewai.py change. Before the rebase they also passed against the crewai 0.157 lock, and scripts/lint style, 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 (one is_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's finally would cover them; happy to do that here or in a follow-up if you prefer.

Diff: 293 lines (+219 / -74) across 3 files Reviewer: mansur-akhmadi Review duration: 29849m
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
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 44.9% (MEDIUM) · Higher = larger blast radius
44.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 23.9% · Safe to merge
23.9%