Skip to content

Conversation

@rajan-chari
Copy link
Contributor

Summary

Fixes issue #154 where DevTools was only displaying incoming messages but not outgoing messages, making it difficult to debug bot conversations during development.

Problem

The DevTools UI was correctly showing incoming messages but outgoing messages were not being captured or displayed. This significantly impacted the developer experience when debugging bots.

Root Cause

The event routing logic in AppEvents.cs used .Equals() to determine which plugins to skip when broadcasting events. The intention was to skip the plugin that sent the message (to avoid notifying it of its own action), but this comparison was incorrectly causing DevToolsPlugin to be skipped as well.

Changes Made

Core Fix

Replaced .Equals() with ReferenceEquals() in three event handlers in Libraries/Microsoft.Teams.Apps/AppEvents.cs:

  • OnErrorEvent (line 32)
  • OnActivitySentEvent (line 55)
  • OnActivityResponseEvent (line 72)

ReferenceEquals() explicitly checks if two references point to the exact same object instance, ensuring only the actual sender plugin is skipped, not observer plugins like DevToolsPlugin.

Debugging Enhancements

Added detailed debug logging to help diagnose similar issues in the future:

  • AppEvents.cs: Added logging to track sender, plugin iterations, equality checks, and skip decisions
  • DevToolsPlugin.cs: Added logging to confirm when OnActivitySent is called and how many WebSocket connections receive the event

Testing

✅ All 559 existing tests pass
✅ Build succeeds with no errors or warnings
✅ No breaking changes to public APIs

Verification Steps for Reviewers

  1. Run a sample bot with DevTools enabled
  2. Send a message from the bot
  3. Verify that outgoing messages now appear in the DevTools UI alongside incoming messages

Closes #154

🤖 Generated with Claude Code

## Problem
DevTools was only displaying incoming messages but not outgoing messages,
making it difficult to debug bot conversations.

## Root Cause
The event routing logic in AppEvents.cs used .Equals() to skip notifying
plugins of their own events. However, this comparison had issues that
caused DevToolsPlugin to be incorrectly skipped even though it should
always be notified as an observer plugin.

## Solution
Replaced .Equals() with ReferenceEquals() in three event handlers:
- OnErrorEvent
- OnActivitySentEvent
- OnActivityResponseEvent

ReferenceEquals() explicitly checks if two references point to the same
object instance, ensuring only the actual sender plugin is skipped, not
observer plugins like DevToolsPlugin.

## Testing
- All 559 existing tests pass
- Build succeeds with no errors
- Added debug logging to help diagnose similar issues in the future

Fixes #154

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #154 where DevTools was not displaying outgoing messages from bots, only incoming messages. The root cause was incorrect use of .Equals() for plugin identity checks, which caused DevToolsPlugin to be incorrectly skipped when broadcasting activity sent events.

Key Changes

  • Replaced .Equals() with ReferenceEquals() in plugin skip logic to correctly identify the actual sender plugin
  • Added extensive debug logging to track event routing behavior (should be removed)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
Libraries/Microsoft.Teams.Apps/AppEvents.cs Fixed plugin comparison in three event handlers (OnErrorEvent, OnActivitySentEvent, OnActivityResponseEvent) by replacing .Equals() with ReferenceEquals(), plus added temporary debug logging
Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore.DevTools/DevToolsPlugin.cs Added temporary debug logging to OnActivitySent to track when the method is called and how many WebSocket connections receive events

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Removed temporary debug logging from AppEvents.cs and DevToolsPlugin.cs
- Refactored foreach loops to use .Where() for explicit filtering instead of continue
- Cleaner, more idiomatic code following existing codebase patterns
- All 559 tests still pass

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@rajan-chari
Copy link
Contributor Author

Addressed Review Feedback

Thank you for the review. I have addressed all the feedback:

Changes Made

  1. Removed debug logging: Removed all temporary debug log statements from both AppEvents.cs and DevToolsPlugin.cs. Only the original Logger.Debug() calls remain, following the existing codebase patterns.

  2. Refactored filtering logic: Updated all three event handlers to use .Where() for explicit filtering instead of continue statements inside the loops:

    • OnErrorEvent
    • OnActivitySentEvent
    • OnActivityResponseEvent

Testing

✅ All 559 tests pass
✅ Build succeeds with no errors
✅ Code now follows the existing codebase patterns more closely

The core fix (using ReferenceEquals() instead of .Equals()) remains unchanged and resolves the issue where DevToolsPlugin was being incorrectly skipped during event notification.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Devtools does not log outgoing messages for C#

2 participants