Fix telemetry crash when crew.memory is a Memory instance#4870
Open
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
Open
Fix telemetry crash when crew.memory is a Memory instance#4870gambletan wants to merge 1 commit intocrewAIInc:mainfrom
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
When crew.memory is a Memory instance instead of a boolean, OpenTelemetry's set_attribute() crashes because it cannot serialize complex objects. This converts non-bool memory values to bool before passing them to the telemetry span attribute. Fixes crewAIInc#4703
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| self._add_attribute( | ||
| span, | ||
| "crew_memory", | ||
| crew.memory if isinstance(crew.memory, bool) else bool(crew.memory), |
There was a problem hiding this comment.
Redundant isinstance check; bool() suffices alone
Low Severity
The ternary crew.memory if isinstance(crew.memory, bool) else bool(crew.memory) is equivalent to just bool(crew.memory), since bool(True) is True and bool(False) is False. The isinstance guard adds unnecessary complexity without changing behavior for any input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Fixes #4703
When
crew.memoryis set to aMemoryinstance (e.g., with a custom LanceDB storage backend) instead of a plain boolean, the telemetry module crashes with:This happens because
span.set_attribute()in OpenTelemetry only accepts primitive types, and theMemoryobject is passed directly.Fix
In
crew_creation(), thecrew_memoryattribute is now coerced toboolwhen it is not already a boolean. This preserves the originalTrue/Falsevalue for standard usage, while convertingMemoryinstances toTrue(since a non-None Memory object is truthy and indicates memory is enabled).Before:
After:
Test plan
memory=True— telemetry recordscrew_memory=True(unchanged behavior)memory=False— telemetry recordscrew_memory=False(unchanged behavior)memory=Memory(storage=LanceDBStorage(...))— telemetry recordscrew_memory=Trueinstead of crashingNote
Low Risk
Low risk: a small telemetry-only change that coerces
crew.memoryto a primitiveboolto satisfy OpenTelemetry attribute type requirements and avoid runtime crashes.Overview
Prevents telemetry from crashing when
crew.memoryis a non-boolean (e.g., aMemoryinstance) by coercing thecrew_memoryspan attribute to aboolinTelemetry.crew_creation()while preserving existingTrue/Falsebehavior for boolean inputs.Written by Cursor Bugbot for commit 0d52284. This will update automatically on new commits. Configure here.