Skip to content

fix: avoid tracing-context AttributeError in service decorators#4566

Open
AlessioSpallino wants to merge 2 commits into
pipecat-ai:mainfrom
ellipsishealth:fix-tracing-none-context-guard
Open

fix: avoid tracing-context AttributeError in service decorators#4566
AlessioSpallino wants to merge 2 commits into
pipecat-ai:mainfrom
ellipsishealth:fix-tracing-none-context-guard

Conversation

@AlessioSpallino
Copy link
Copy Markdown

@AlessioSpallino AlessioSpallino commented May 26, 2026

Summary
This PR fixes a tracing-related crash in service decorators during function-call handling.

Problem
In some function-call paths, tracing context access could raise:
'NoneType' object has no attribute 'get_turn_context'
This can happen when _tracing_context is truthy at the call-site check, but the underlying getter path raises an AttributeError.

Root Cause
_get_turn_context() and _get_parent_service_context() used direct getter calls after a truthiness check.
That check does not protect against AttributeError raised inside get_turn_context() / get_conversation_context().

How to reproduce

  • Disable tracing (enable_tracing=False).
  • Trigger a tool/function call (runs through LLMService._run_function_call). Tracing decorator helpers can raise AttributeError: 'NoneType' object has no attribute 'get_turn_context' when tracing context isn’t available.

Changes
Updated _get_turn_context to return None on AttributeError.
Updated _get_parent_service_context to return None conversation context on AttributeError, then keep the existing fallback behaviour.

Tests
Added targeted regression tests in tests/test_service_tracing_decorators.py:

  • test_get_turn_context_handles_none_context
  • test_get_turn_context_handles_truthy_broken_proxy
  • test_get_parent_service_context_handles_none_context
  • test_get_parent_service_context_handles_truthy_broken_proxy

Validation run: uv run pytest tests/test_service_tracing_decorators.py

@AlessioSpallino AlessioSpallino marked this pull request as ready for review May 26, 2026 17:05
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