fix: implement turn gate and handoff improvements #8
Reference in New Issue
Block a user
Delete Branch "fix/turn-gate-and-handoff"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes
1. Fix channelId priority
2. Add sessionAllowed state
3. Add sessionInjected Set
4. Add before_message_write hook
5. message_sent
Design Consensus with Orion
- Fix channelId extraction: ctx.channelId is platform name ('discord'), not the Discord channel snowflake. Now extracts from conversation_label field ('channel id:123456') and sessionKey fallback (':channel:123456'). - Fix extractDiscordChannelId: support 'discord:channel:xxx' format in addition to 'channel:xxx' for conversationId/event.to fields. - Fix sender identification in message_received: event.from returns channel target, not sender ID. Now uses event.metadata.senderId for humanList matching so human messages correctly reset turn order. - Fix per-channel turn order: was using all server-wide bot accounts from bindings, causing deadlock when turn landed on bots not in the channel. Now dynamically tracks which bot accounts are seen per channel via message_received and only includes those in turn order. - Always save sessionChannelId/sessionAccountId mappings in before_model_resolve regardless of turn check result, so downstream hooks can use them. - Add comprehensive debug logging to message_sent hook.