Skip to content

Fix telemetry crash when crew.memory is a Memory instance#4870

Open
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
gambletan:fix/telemetry-memory-serialization
Open

Fix telemetry crash when crew.memory is a Memory instance#4870
gambletan wants to merge 1 commit intocrewAIInc:mainfrom
gambletan:fix/telemetry-memory-serialization

Conversation

@gambletan
Copy link

@gambletan gambletan commented Mar 14, 2026

Summary

Fixes #4703

When crew.memory is set to a Memory instance (e.g., with a custom LanceDB storage backend) instead of a plain boolean, the telemetry module crashes with:

Invalid type Memory for attribute 'crew_memory' value.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

This happens because span.set_attribute() in OpenTelemetry only accepts primitive types, and the Memory object is passed directly.

Fix

In crew_creation(), the crew_memory attribute is now coerced to bool when it is not already a boolean. This preserves the original True/False value for standard usage, while converting Memory instances to True (since a non-None Memory object is truthy and indicates memory is enabled).

Before:

self._add_attribute(span, "crew_memory", crew.memory)

After:

self._add_attribute(
    span,
    "crew_memory",
    crew.memory if isinstance(crew.memory, bool) else bool(crew.memory),
)

Test plan

  • Pass memory=True — telemetry records crew_memory=True (unchanged behavior)
  • Pass memory=False — telemetry records crew_memory=False (unchanged behavior)
  • Pass memory=Memory(storage=LanceDBStorage(...)) — telemetry records crew_memory=True instead of crashing

Note

Low Risk
Low risk: a small telemetry-only change that coerces crew.memory to a primitive bool to satisfy OpenTelemetry attribute type requirements and avoid runtime crashes.

Overview
Prevents telemetry from crashing when crew.memory is a non-boolean (e.g., a Memory instance) by coercing the crew_memory span attribute to a bool in Telemetry.crew_creation() while preserving existing True/False behavior for boolean inputs.

Written by Cursor Bugbot for commit 0d52284. This will update automatically on new commits. Configure here.

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
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

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.

[BUG]Telemetry Fails When Using Custom Memory Storage Backends

1 participant