|
| 1 | +# Fix: Empty Assistant Messages in Sessions |
| 2 | + |
| 3 | +**Related Issues:** [#7](https://github.com/waynesutton/opensync/issues/7), [#8](https://github.com/waynesutton/opensync/issues/8) |
| 4 | + |
| 5 | +**Status:** Fixed (2025-01-22) |
| 6 | + |
| 7 | +## Problem |
| 8 | + |
| 9 | +Users reported empty assistant message bubbles in Claude Code sessions, particularly with long tool-calling chains. Messages showed timestamps but no content. The issue affected: |
| 10 | + |
| 11 | +- Dashboard session viewer |
| 12 | +- SessionViewer component |
| 13 | +- Context page slide-over |
| 14 | +- Public session pages |
| 15 | + |
| 16 | +## Root Cause |
| 17 | + |
| 18 | +The `hasDisplayableParts` / `hasPartsContent` check only verified if a part TYPE existed (tool-call or tool-result), not whether the part had actual extractable content. |
| 19 | + |
| 20 | +**Before (buggy):** |
| 21 | +```typescript |
| 22 | +const hasDisplayableParts = message.parts?.some((part: any) => { |
| 23 | + if (part.type === "text") { |
| 24 | + const text = getPartTextContent(part.content); |
| 25 | + return text && text.trim().length > 0; // Correctly checks content |
| 26 | + } |
| 27 | + return part.type === "tool-call" || part.type === "tool-result"; // BUG: Only checks type! |
| 28 | +}); |
| 29 | +``` |
| 30 | + |
| 31 | +This caused: |
| 32 | +1. `hasDisplayableParts` = `true` (because part type existed) |
| 33 | +2. `showFallback` = `false` (skipped textContent fallback) |
| 34 | +3. Empty bubbles rendered because part.content was null/undefined/malformed |
| 35 | + |
| 36 | +## Fix |
| 37 | + |
| 38 | +Added content validation for tool-call and tool-result parts: |
| 39 | + |
| 40 | +**After (fixed):** |
| 41 | +```typescript |
| 42 | +const hasDisplayableParts = message.parts?.some((part: any) => { |
| 43 | + if (part.type === "text") { |
| 44 | + const text = getPartTextContent(part.content); |
| 45 | + return text && text.trim().length > 0; |
| 46 | + } |
| 47 | + if (part.type === "tool-call") { |
| 48 | + // Check if tool-call has extractable name |
| 49 | + return part.content && (part.content.name || part.content.toolName); |
| 50 | + } |
| 51 | + if (part.type === "tool-result") { |
| 52 | + // Check if tool-result has extractable result |
| 53 | + const result = part.content?.result || part.content?.output || part.content; |
| 54 | + return result !== null && result !== undefined; |
| 55 | + } |
| 56 | + return false; |
| 57 | +}); |
| 58 | +``` |
| 59 | + |
| 60 | +## Files Modified |
| 61 | + |
| 62 | +1. `src/pages/Dashboard.tsx` - MessageBubble component |
| 63 | +2. `src/components/SessionViewer.tsx` - MessageBlock component |
| 64 | +3. `src/pages/Context.tsx` - SlideOverMessageBlock component |
| 65 | +4. `src/pages/PublicSession.tsx` - MessageBlock component |
| 66 | + |
| 67 | +## Testing |
| 68 | + |
| 69 | +After fix: |
| 70 | +- Messages with empty/null parts but valid `textContent` now show the textContent |
| 71 | +- Tool-call parts with actual names render correctly |
| 72 | +- Tool-result parts with actual results render correctly |
| 73 | +- Messages with no extractable content from parts OR textContent show empty (correct behavior) |
| 74 | + |
| 75 | +## Previous Related Fixes |
| 76 | + |
| 77 | +This is the second fix for content extraction issues: |
| 78 | + |
| 79 | +1. **First fix (Issue #7 initial):** Added content normalization helpers (`getPartTextContent`, `getTextContent`) to handle object formats like `{ text: "..." }` or `{ content: "..." }` from Claude Code. |
| 80 | + |
| 81 | +2. **Second fix (Issue #7, #8):** Fixed the displayable content detection to properly check tool-call/tool-result content, not just type existence. |
0 commit comments