huskies: merge 1063
This commit is contained in:
@@ -325,6 +325,38 @@ pub async fn run_bot(
|
||||
});
|
||||
}
|
||||
|
||||
// Subscribe to gateway-side status events and buffer compact audit lines for
|
||||
// the LLM context. A separate resubscribed receiver is used so both the
|
||||
// buffer task and the room-forwarder task receive every event independently.
|
||||
let pending_gateway_events: Arc<TokioMutex<Vec<String>>> =
|
||||
Arc::new(TokioMutex::new(Vec::new()));
|
||||
let gateway_event_rx_for_forwarder = if let Some(event_rx) = gateway_event_rx {
|
||||
// Buffer task: silently accumulate compact audit lines for Timmy's context.
|
||||
{
|
||||
use crate::service::gateway::polling::format_gateway_audit_line;
|
||||
let buf_rx = event_rx.resubscribe();
|
||||
let buf = Arc::clone(&pending_gateway_events);
|
||||
tokio::spawn(async move {
|
||||
let mut rx = buf_rx;
|
||||
loop {
|
||||
match rx.recv().await {
|
||||
Ok(event) => {
|
||||
let line = format_gateway_audit_line(&event.project, &event.event);
|
||||
buf.lock().await.push(line);
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(n)) => {
|
||||
slog!("[matrix-bot] gateway event buffer lagged by {n} events");
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => break,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Some(event_rx)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let ctx = BotContext {
|
||||
services,
|
||||
matrix_user_id: bot_user_id,
|
||||
@@ -340,6 +372,7 @@ pub async fn run_bot(
|
||||
gateway_projects,
|
||||
gateway_project_urls,
|
||||
pending_pipeline_events,
|
||||
pending_gateway_events,
|
||||
handled_incoming_event_ids: Arc::new(TokioMutex::new(super::context::SeenEventIds::new(
|
||||
super::context::SEEN_EVENT_IDS_CAP,
|
||||
))),
|
||||
@@ -379,13 +412,8 @@ pub async fn run_bot(
|
||||
);
|
||||
}
|
||||
|
||||
// In gateway mode, subscribe to the gateway-side status broadcaster and
|
||||
// forward events to the configured Matrix rooms with a `[project-name]` prefix.
|
||||
// This path delivers events pushed directly by project nodes over WebSocket
|
||||
// (via `/gateway/events/push`), complementing the HTTP-polling path above.
|
||||
// On broadcaster back-pressure (Lagged), the task re-subscribes automatically
|
||||
// so it never permanently stalls.
|
||||
if let Some(event_rx) = gateway_event_rx {
|
||||
// Forwarder task: post gateway events to Matrix rooms with `[project-name]` prefix.
|
||||
if let Some(event_rx) = gateway_event_rx_for_forwarder {
|
||||
let broadcast_room_ids: Vec<String> =
|
||||
announce_room_ids.iter().map(|r| r.to_string()).collect();
|
||||
crate::gateway::spawn_gateway_broadcaster_forwarder(
|
||||
|
||||
Reference in New Issue
Block a user