Skip to content

Latest commit

 

History

History
402 lines (297 loc) · 13.6 KB

File metadata and controls

402 lines (297 loc) · 13.6 KB

P2P Messaging Bug Fix Test Report

Test Date: 2025-01-30 Test Environment: Local development (Tilt) Tester: Claude (Automated Browser Testing via Playwright MCP) Browser: Chromium (Playwright)


Executive Summary

TEST RESULT: ❌ FAILED - CRITICAL BUGS FOUND

The P2P messaging bug fixes were partially successful but revealed CRITICAL new bugs that prevent the test acceptance criteria from being met:

Issues Tested:

  1. Issue 5 (Peer Username Display): FIXED - Peer usernames display correctly, not truncated CIDs
  2. Issue 3 (Message Ordering): FIXED - Code shows sort((a, b) => a.timestamp - b.timestamp) for chronological order
  3. Issue 1+4 (Message Persistence): FAILED - Messages stored in LocalDB but NOT displayed in UI after page refresh
  4. NEW BUG: Messages cannot be sent - incorrect routing (sending to self instead of peer)

Test Environment

Backend Services

  • Server: Running (tilt logs server)
  • Internal Service: Running (tilt logs internal-service)
  • Existing Test Accounts:
    • p2p_user_a (CID: 4398843767654670086)
    • p2p_user_b (CID: 895697823540931917)
    • Already P2P registered and connected

Frontend

  • UI: http://localhost:5173/
  • P2P Chat URL: http://localhost:5173/office?showP2P=true&p2pUser=p2p_user_a&channel=4398843767654670086

Test Execution

Phase 1: Initial Navigation and Peer Selection

Step 1: Navigated to landing page Step 2: Verified 2 active workspace sessions in OrphanSessionsNavbar (p2p_user_a, p2p_user_b) Step 3: Clicked on p2p_user_a workspace icon Step 4: Successfully loaded workspace for p2p_user_a

Screenshot: 01_landing_page_initial.png Landing Page


Phase 2: P2P Chat Panel Verification

Step 5: Clicked on p2p_user_b in WORKSPACE MEMBERS sidebar Step 6: P2P chat panel opened on right side

Observations:

  • Peer username displayed correctly: "p2p_user_b" (NOT truncated CID like "8956...")
  • Status indicator: Shows "Offline"
  • Chat messages area: COMPLETELY EMPTY - No messages displayed
  • Input field: Disabled (expected, since peer is offline)

Screenshot: 02_p2p_chat_opened_user_a.png P2P Chat Opened from User A

Console Logs Analysis:

[LOG] [websocket] Message received from WASM client {
  "LocalDBGetKVSuccess": {
    "key": "p2p_messages_conversations",
    "value": "{BytesLike(len: 2747, First 5 bytes: [91, 123, 34, 112, 101], Last 5 bytes: [34, 58, 48, 125, 93])}"
  }
}

Analysis: Messages ARE stored in LocalDB (2747 bytes of conversation data), but the UI is NOT rendering them.


Phase 3: Page Refresh Test (Critical for Issue 1+4)

Step 7: Refreshed page: http://localhost:5173/office?showP2P=true&p2pUser=p2p_user_b&channel=895697823540931917 Step 8: Waited for session to reconnect Step 9: Clicked on p2p_user_a in sidebar (now viewing from p2p_user_b's account)

Observations:

  • Peer username: "p2p_user_a" displayed correctly (Issue 5 FIXED)
  • Status: "Online" (P2P connection established)
  • Input field: Enabled (can type messages)
  • Chat messages: STILL COMPLETELY EMPTY - Previous messages NOT loaded

Screenshot: 03_p2p_chat_no_messages_shown.png No Messages After Refresh

DOM Inspection:

// Checked for rendered messages
document.querySelectorAll('[class*="rounded-lg"]').length
// Result: 0 messages found

Critical Finding: The waitForReady() pattern was implemented in P2PChat.tsx:89, but messages are NOT being loaded into React state.


Phase 4: Attempting to Send New Message

Step 10: Typed test message: "Test message after page refresh - verifying persistence" Step 11: Pressed Enter to send

Result:MESSAGE SEND FAILED

Browser Console Errors:

[ERROR] [P2P] Received message from unregistered peer 895697823540931917 - protocol violation
[LOG] MessageSendFailure

Backend Logs (internal-service):

[P2P-MSG] Sending message from 895697823540931917 to peer 895697823540931917
[P2P-MSG] Available peers in conn.peers: [4398843767654670086]
[ERROR] [P2P-MSG] Peer connection not found for peer_cid=895697823540931917
MessageSendFailure { cid: 895697823540931917, message: "Connection for 895697823540931917 not found" }

Root Cause: Frontend is sending P2P messages with recipient_cid set to sender's own CID (895697823540931917 → 895697823540931917) instead of the correct peer CID (4398843767654670086).


Detailed Findings

✅ Issue 5: Peer Username Display (FIXED)

Expected: Peer username (e.g., "p2p_user_a") should display in chat header, not truncated CID Actual: Peer username displays correctly in all tests Evidence: Screenshots show "p2p_user_a" and "p2p_user_b" in chat headers Verdict: PASS


✅ Issue 3: Message Ordering (FIXED - Code Verified)

Expected: Messages sorted by timestamp (chronological order) Code Evidence:

// p2p-messenger-manager.ts:854
conversation.messages.sort((a, b) => a.timestamp - b.timestamp);

Verdict: PASS (implementation verified, though UI rendering failed)


❌ Issue 1+4: Message Persistence (FAILED)

Expected:

  • Messages from before refresh should be visible with correct timestamps
  • DIRECT MESSAGES sidebar should show conversation
  • Messages persist across page refreshes

Actual:

  • Messages ARE stored in LocalDB (verified in backend logs: 2747 bytes of data)
  • Messages ARE loaded by messenger.getConversation() (code has waitForReady())
  • Messages are NOT displayed in UI (0 rendered message elements)
  • Chat panel shows completely empty message area

Root Cause Analysis:

  1. Data Layer: ✅ LocalDB has messages stored correctly
  2. Service Layer:P2PMessengerManager.getConversation() has waitForReady() pattern
  3. Component Layer:P2PChat.tsx loads conversation but React state is not updating

Possible Issues:

  • messenger.getConversation(peerCid) returning undefined despite messages in LocalDB
  • React setMessages() not being called with loaded messages
  • peerCid mismatch between LocalDB key and component prop
  • Race condition where component mounts before waitForReady() completes

Verdict: FAIL - CRITICAL


❌ NEW BUG: Message Routing Error (CRITICAL)

Issue: When attempting to send a P2P message, the frontend incorrectly sets recipient_cid to the sender's own CID instead of the peer's CID.

Evidence:

// User p2p_user_b (CID 895697823540931917) trying to send to p2p_user_a (CID 4398843767654670086)
// Backend logs show:
[P2P-MSG] Sending message from 895697823540931917 to peer 895697823540931917  ❌ WRONG!
// Should be:
[P2P-MSG] Sending message from 895697823540931917 to peer 4398843767654670086  ✅ CORRECT

Impact: Users cannot send new P2P messages - all send attempts fail with "Connection not found"

Suspected Code Location: P2P message sending logic in p2p-messenger-manager.ts or P2PChat.tsx

Verdict: FAIL - CRITICAL


Test Acceptance Criteria Results

Criteria Status Notes
Issue 1+4: All messages from before refresh are visible with correct timestamps ❌ FAIL Messages in LocalDB but NOT rendered in UI
Issue 3: Messages appear in chronological order (earliest first, newest last) ✅ PASS Code verified (cannot visually test due to rendering bug)
Issue 5: Username displayed correctly (e.g., "p2p_user_a"), not CID ✅ PASS Verified in all screenshots

Overall Verdict:TEST FAILED


Screenshots Summary

  1. 01_landing_page_initial.png - Landing page with 2 active workspaces
  2. 02_p2p_chat_opened_user_a.png - P2P chat panel showing p2p_user_b (empty messages)
  3. 03_p2p_chat_no_messages_shown.png - After page refresh, still no messages displayed

Backend Log Analysis

LocalDB Contains Messages

LocalDBGetKVSuccess {
  key: "p2p_messages_conversations",
  value: {BytesLike(len: 2747 bytes)}
}

Decoded Message Sample (from earlier logs):

  • "Hello from User A! Testing P2P messaging."
  • "Hi User A! This is User B replying. P2P works great!"
  • "Testing special chars: 🎉🚀 <script>alert('xss')</script> & "quotes" 'apostrophe' \backslash\"
  • "Testing typing indicator..."
  • "Rapid test 1", "Rapid test 2", "Rapid test 3"

Total: ~6 messages stored between the two peers

Message Routing Errors

[ERROR] [P2P] Received message from unregistered peer 895697823540931917 - protocol violation
[ERROR] [P2P-MSG] Peer connection not found for peer_cid=895697823540931917
MessageSendFailure { message: "Connection for 895697823540931917 not found" }

Recommended Next Steps

🔴 CRITICAL Priority: Fix Message Rendering Bug

Investigation Required:

  1. Add debug logging to P2PChat.tsx useEffect at line 88-96:

    const loadConversation = async () => {
      await messenger.waitForReady();
      console.log('[DEBUG] Loading conversation for peerCid:', peerCid);
      const conversation = messenger.getConversation(peerCid);
      console.log('[DEBUG] Conversation loaded:', conversation);
      console.log('[DEBUG] Message count:', conversation?.messages?.length);
      if (conversation) {
        setMessages(conversation.messages);
        setPeerPresence(conversation.presence);
      }
    };
  2. Verify peerCid prop matches LocalDB conversation key

  3. Check if messenger.getConversation() is returning undefined despite LocalDB having data

  4. Verify waitForReady() completes before getConversation() is called

🔴 CRITICAL Priority: Fix Message Routing Bug

Investigation Required:

  1. Review sendMessage() in p2p-messenger-manager.ts - verify recipientCid parameter usage

  2. Check P2PChat.tsx handleSendMessage() - ensure correct peerCid is passed

  3. Add logging:

    console.log('[DEBUG] Sending message to peerCid:', peerCid);
    console.log('[DEBUG] Current user CID:', currentUserCid);
  4. Expected behavior:

    • User A (CID 4398843767654670086) sends to User B (CID 895697823540931917)
    • User B (CID 895697823540931917) sends to User A (CID 4398843767654670086)
    • NEVER send to own CID

🟡 MEDIUM Priority: Re-test After Fixes

Once the above bugs are fixed, re-run this test workflow:

  1. Verify messages load from LocalDB on page mount
  2. Verify messages persist after page refresh
  3. Verify chronological message ordering in UI
  4. Send new messages between peers
  5. Refresh page again and verify ALL messages (old + new) are visible

Code Review Findings

✅ Correctly Implemented

File: citadel-workspaces/src/lib/p2p-messenger-manager.ts:854

// Messages sorted by timestamp (chronological order)
conversation.messages.sort((a, b) => a.timestamp - b.timestamp);

File: citadel-workspaces/src/components/p2p/P2PChat.tsx:88-96

// waitForReady() pattern implemented
const loadConversation = async () => {
  await messenger.waitForReady();
  const conversation = messenger.getConversation(peerCid);
  if (conversation) {
    setMessages(conversation.messages);
    setPeerPresence(conversation.presence);
  }
};
loadConversation();

File: citadel-workspaces/src/components/p2p/P2PChat.tsx:306

// Peer username displayed correctly (not CID)
<h3 className="text-base font-semibold text-white">{peerName}</h3>

❌ Bugs Found

  1. Message Rendering: Despite waitForReady() and getConversation(), messages don't render in UI
  2. Message Routing: recipientCid set to sender's own CID instead of peer CID
  3. Peer Registration: Error logs show "Received message from unregistered peer" even though ListRegisteredPeersResponse shows peers are registered

Conclusion

The P2P messaging bug fixes made partial progress:

  • ✅ Username display works correctly
  • ✅ Message sorting code is correct
  • Message persistence FAILS - UI does not display stored messages
  • Message sending FAILS - Incorrect routing prevents new messages

The test CANNOT PASS until these critical bugs are fixed.

Blocking Issues:

  1. Messages stored in LocalDB are not rendered in the React component
  2. New messages cannot be sent due to incorrect recipient CID routing

Test Status:FAILED - REQUIRES IMMEDIATE FIX


Appendix: Console Logs

LocalDB Message Data (Truncated)

LocalDBGetKVSuccess {
  "cid": 0,
  "key": "p2p_messages_conversations",
  "value": "{BytesLike(len: 2747. First 5 bytes: [91, 123, 34, 112, 101]. Last 5 bytes: [34, 58, 48, 125, 93])}"
}

Peer Registration Confirmed

ListRegisteredPeersResponse {
  cid: 895697823540931917,
  peers: {
    4398843767654670086: PeerInformation {
      cid: 895697823540931917,
      online_status: true,
      name: "P2P User A",
      username: "p2p_user_a"
    }
  }
}

Message Send Failure

[P2P-MSG] Sending message from 895697823540931917 to peer 895697823540931917
[ERROR] [P2P-MSG] Peer connection not found for peer_cid=895697823540931917
MessageSendFailure { message: "Connection for 895697823540931917 not found" }

Report Generated: 2025-01-30 Tools Used: Playwright MCP (browser automation), tilt logs (backend analysis) Test Duration: ~10 minutes Issues Found: 2 critical bugs preventing acceptance criteria from being met