Skip to content

Commit 00a1400

Browse files
Joelclaude
andcommitted
Fix PersonaUser room subscription for new DM rooms
PersonaUser was only subscribing to data:rooms:updated events, missing data:rooms:created events. When a new DM room was created with a persona as a member, the persona never received the event and didn't subscribe to chat messages for that room. Fix: subscribeToRoomUpdates() now subscribes to BOTH events: - data:rooms:updated (existing room membership changes) - data:rooms:created (new rooms with persona as member) Tested: DM with Helper AI + Legal LoRA adapter - persona now responds to messages in newly created DM rooms. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 66aacd1 commit 00a1400

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/debug/jtag/system/user/shared/BaseUser.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,32 @@ export abstract class BaseUser {
231231
}
232232

233233
/**
234-
* Subscribe to room update events to handle dynamic membership changes
234+
* Subscribe to room update AND create events to handle dynamic membership changes
235235
* All user types need to track when they're added/removed from rooms
236+
*
237+
* CRITICAL: Must subscribe to BOTH events:
238+
* - data:rooms:updated - When existing room members change
239+
* - data:rooms:created - When NEW room is created with persona as member (e.g., DM)
236240
*/
237241
protected subscribeToRoomUpdates(handler: (room: RoomEntity) => Promise<void>): void {
238-
const eventName = DataEventNames.updated(COLLECTIONS.ROOMS);
239-
240242
if (!this.client) {
241243
// ❌ FAIL FAST: No client = broken user, crash instead of creating zombie
242244
throw new Error(`${this.constructor.name} ${this.displayName}: Cannot subscribe to room updates - no client available. User is broken and must be discarded.`);
243245
}
244246

245-
// ✅ Use Events.subscribe (works anywhere via sharedInstance)
246-
// Pass this.id as subscriberId to enable deduplication (prevents duplicate subscriptions)
247-
Events.subscribe(eventName, async (roomData: RoomEntity) => {
247+
// ✅ Subscribe to room UPDATED events (existing rooms with member changes)
248+
const updatedEventName = DataEventNames.updated(COLLECTIONS.ROOMS);
249+
Events.subscribe(updatedEventName, async (roomData: RoomEntity) => {
248250
await handler(roomData);
249-
}, undefined, this.id);
250-
this.log.info(`📢 ${this.constructor.name} ${this.displayName}: Subscribed to room updates via Events.subscribe`);
251+
}, undefined, `${this.id}_room_updated`);
252+
253+
// ✅ Subscribe to room CREATED events (new rooms with persona as member, e.g., DM)
254+
const createdEventName = DataEventNames.created(COLLECTIONS.ROOMS);
255+
Events.subscribe(createdEventName, async (roomData: RoomEntity) => {
256+
await handler(roomData);
257+
}, undefined, `${this.id}_room_created`);
258+
259+
this.log.info(`📢 ${this.constructor.name} ${this.displayName}: Subscribed to room created+updated events`);
251260
}
252261

253262
/**

0 commit comments

Comments
 (0)