Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

fix: decouple system signal events from Telemetry (fixes #4041)

Summary

This PR fixes issue #4041 where system signal events (SigTermEvent, SigIntEvent, etc.) were disabled when telemetry was disabled via CREWAI_DISABLE_TELEMETRY=true.

The root cause was that signal registration logic lived entirely inside the Telemetry class, which returns early in __init__ when telemetry is disabled. This meant @on_signal handlers would never fire for users who opted out of telemetry.

Changes:

  • Created new SystemSignalManager singleton class to handle OS signal registration independently of telemetry
  • Signal handlers are now registered at system_events.py module import time, ensuring they work regardless of telemetry settings
  • Telemetry now subscribes to signal events via the event bus for cleanup, rather than owning the signal handlers
  • Added subprocess-based tests that verify signal events work with telemetry disabled

Review & Testing Checklist for Human

  • Verify signal events fire with telemetry disabled: Run the reproduction script from issue [BUG] System signal events (SigTermEvent SigIntEvent) are disabled if Telemetry is disabled, and fragile to signal handler ordering #4041 with CREWAI_DISABLE_TELEMETRY=true and confirm @on_signal handlers execute
  • Check handler chaining: Register a signal handler before importing CrewAI, then verify both handlers fire when signal is received
  • Review the empty ensure_handlers_installed method at line 121 in signal_manager.py - it's defined but not implemented (just pass). Decide if this should be implemented or removed
  • Test in multi-threaded context: Signal handlers can only be registered from the main thread - verify the warning logging works correctly when called from other threads
  • Verify no import-time issues: The signal registration now happens at module import time - confirm this doesn't cause issues with test isolation or other import scenarios

Recommended test plan:

# Test script - save and run with CREWAI_DISABLE_TELEMETRY=true
import os
os.environ["CREWAI_DISABLE_TELEMETRY"] = "true"

from crewai.events.types.system_events import SignalEvent, on_signal

@on_signal
def my_handler(source, event):
    print(f"Signal received: {event.type}")

print(f"PID: {os.getpid()}")
# Then send SIGTERM from another terminal: kill -TERM <pid>

Notes

This fixes issue #4041 where system signal events (SigTermEvent, SigIntEvent,
etc.) were disabled when telemetry was disabled.

Changes:
- Create SystemSignalManager class to handle OS signal registration
  independently of telemetry settings
- Move signal registration from Telemetry to SystemSignalManager
- Register signal handlers at system_events.py module import time
- Update Telemetry to subscribe to signal events via event bus instead
  of owning the signal handlers
- Add comprehensive tests for signal events with telemetry disabled
  and signal handler chaining

The signal events now work regardless of CREWAI_DISABLE_TELEMETRY setting,
and properly chain to any handlers registered before CrewAI imports.

Co-Authored-By: João <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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] System signal events (SigTermEvent SigIntEvent) are disabled if Telemetry is disabled, and fragile to signal handler ordering

2 participants