feat(884): persistent perm_rx lock-holder for Matrix bot
Before: handle_message.rs acquired services.perm_rx only while processing one chat message and dropped it on chat_fut completion. The moment the bot wasn't actively responding, prompt_permission auto-denied any spawned coder bash call as "no interactive session" — making unattended coder work impossible. Now: a permission_listener task is spawned at bot startup and holds perm_rx for the bot's lifetime. Permission requests are forwarded to the first configured Matrix room, replies resolved by the existing on_room_message handler via pending_perm_replies. Per-message acquire is gone from handle_message.rs (chat_fut just awaits cleanly). - New module: chat/transport/matrix/bot/permission_listener.rs. - Wired into run_bot before BotContext construction; bot_sent_event_ids is hoisted out so the listener and the rest of the bot share it. - handle_message.rs no longer touches perm_rx. - diagnostics/permission.rs comment updated to reflect the new reality. - Regression test asserts the listener forwards a PermissionForward to the target room and records the pending reply key — exactly the path that was broken when no chat_fut was in flight. Discord/Slack/WhatsApp transports still acquire perm_rx per message (commands.rs:368 / commands/llm.rs:83 / commands/llm.rs:82). They are not the active transport in this deployment so their per-message acquire remains dormant; the same listener pattern should be applied to them as follow-up work in 884 phase 2.
This commit is contained in:
@@ -275,6 +275,26 @@ pub async fn run_bot(
|
||||
}
|
||||
}
|
||||
|
||||
// Hoist bot_sent_event_ids out of BotContext so the permission listener
|
||||
// can share it (the listener tracks which permission-prompt messages it
|
||||
// posted so the bot doesn't echo them back as user input).
|
||||
let bot_sent_event_ids: Arc<TokioMutex<HashSet<matrix_sdk::ruma::OwnedEventId>>> =
|
||||
Arc::new(TokioMutex::new(HashSet::new()));
|
||||
|
||||
// Spawn the permission listener: holds `perm_rx` for the bot's lifetime
|
||||
// and forwards permission requests to the first configured room. Story
|
||||
// 884 — replaces the per-message lock acquire previously done in
|
||||
// handle_message.rs, so spawned coders' bash calls reach chat even when
|
||||
// the bot isn't actively responding.
|
||||
if let Some(target_room) = target_room_ids.first() {
|
||||
super::permission_listener::spawn_permission_listener(
|
||||
Arc::clone(&services),
|
||||
Arc::clone(&transport),
|
||||
target_room.clone(),
|
||||
Arc::clone(&bot_sent_event_ids),
|
||||
);
|
||||
}
|
||||
|
||||
let ctx = BotContext {
|
||||
services,
|
||||
matrix_user_id: bot_user_id,
|
||||
@@ -282,7 +302,7 @@ pub async fn run_bot(
|
||||
allowed_users: config.allowed_users,
|
||||
history: Arc::new(TokioMutex::new(persisted)),
|
||||
history_size: config.history_size,
|
||||
bot_sent_event_ids: Arc::new(TokioMutex::new(HashSet::new())),
|
||||
bot_sent_event_ids,
|
||||
htop_sessions: Arc::new(TokioMutex::new(HashMap::new())),
|
||||
transport: Arc::clone(&transport),
|
||||
timer_store,
|
||||
|
||||
Reference in New Issue
Block a user