Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40fb6367c1 | ||
|
|
1859e79491 | ||
|
|
5eeb036875 |
@@ -1042,7 +1042,6 @@
|
|||||||
],
|
],
|
||||||
"server/src/chat/transport/matrix/bot/messages/handle_message.rs": [
|
"server/src/chat/transport/matrix/bot/messages/handle_message.rs": [
|
||||||
"const DIGGING_IN_MESSAGE",
|
"const DIGGING_IN_MESSAGE",
|
||||||
"fn spawn_digging_in_watcher",
|
|
||||||
"fn handle_message"
|
"fn handle_message"
|
||||||
],
|
],
|
||||||
"server/src/chat/transport/matrix/bot/messages/mod.rs": [
|
"server/src/chat/transport/matrix/bot/messages/mod.rs": [
|
||||||
@@ -1103,7 +1102,6 @@
|
|||||||
"fn default_compact_seed_max_bytes",
|
"fn default_compact_seed_max_bytes",
|
||||||
"fn default_cache_read_suggest_threshold",
|
"fn default_cache_read_suggest_threshold",
|
||||||
"fn default_compact_suggest_cooldown_secs",
|
"fn default_compact_suggest_cooldown_secs",
|
||||||
"fn default_digging_in_threshold_secs",
|
|
||||||
"fn default_transport",
|
"fn default_transport",
|
||||||
"fn default_whatsapp_provider",
|
"fn default_whatsapp_provider",
|
||||||
"struct BotConfig"
|
"struct BotConfig"
|
||||||
|
|||||||
Generated
+1
-1
@@ -1925,7 +1925,7 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "huskies"
|
name = "huskies"
|
||||||
version = "0.14.3"
|
version = "0.14.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ammonia",
|
"ammonia",
|
||||||
"async-stream",
|
"async-stream",
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "huskies",
|
"name": "huskies",
|
||||||
"version": "0.14.3",
|
"version": "0.14.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "huskies",
|
"name": "huskies",
|
||||||
"version": "0.14.3",
|
"version": "0.14.4",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/react-syntax-highlighter": "^15.5.13",
|
"@types/react-syntax-highlighter": "^15.5.13",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "huskies",
|
"name": "huskies",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.14.3",
|
"version": "0.14.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "huskies"
|
name = "huskies"
|
||||||
version = "0.14.3"
|
version = "0.14.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
|||||||
@@ -130,10 +130,6 @@ pub struct BotContext {
|
|||||||
/// Minimum seconds between repeated `compact` suggestions for the same
|
/// Minimum seconds between repeated `compact` suggestions for the same
|
||||||
/// room. From `bot.toml`'s `compact_suggest_cooldown_secs`.
|
/// room. From `bot.toml`'s `compact_suggest_cooldown_secs`.
|
||||||
pub compact_suggest_cooldown_secs: i64,
|
pub compact_suggest_cooldown_secs: i64,
|
||||||
/// Seconds a turn may spend on tool calls before emitting any
|
|
||||||
/// user-facing text before the bot posts a "digging in" notice. From
|
|
||||||
/// `bot.toml`'s `digging_in_threshold_secs`.
|
|
||||||
pub digging_in_threshold_secs: u64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotContext {
|
impl BotContext {
|
||||||
@@ -365,7 +361,6 @@ mod tests {
|
|||||||
compact_seed_max_bytes: 8_000,
|
compact_seed_max_bytes: 8_000,
|
||||||
cache_read_suggest_threshold: 50_000,
|
cache_read_suggest_threshold: 50_000,
|
||||||
compact_suggest_cooldown_secs: 3_600,
|
compact_suggest_cooldown_secs: 3_600,
|
||||||
digging_in_threshold_secs: 15,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use matrix_sdk::ruma::{OwnedEventId, OwnedRoomId};
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
|
||||||
use tokio::sync::Mutex as TokioMutex;
|
use tokio::sync::Mutex as TokioMutex;
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
@@ -19,34 +18,10 @@ use super::super::history::{ConversationEntry, ConversationRole, save_history};
|
|||||||
|
|
||||||
use super::format_user_prompt;
|
use super::format_user_prompt;
|
||||||
|
|
||||||
/// Text posted to the room by [`spawn_digging_in_watcher`] when a turn runs
|
/// Text posted by `on_room_message` as an immediate acknowledgement when a
|
||||||
/// long without emitting any user-facing text, and by `on_room_message` as
|
/// message is first received (story 1239).
|
||||||
/// an immediate acknowledgement when a message is first received (story 1239).
|
|
||||||
pub(super) const DIGGING_IN_MESSAGE: &str = "Working...";
|
pub(super) const DIGGING_IN_MESSAGE: &str = "Working...";
|
||||||
|
|
||||||
/// Spawns a background watcher that posts a single "digging in" notice to
|
|
||||||
/// `room_id` if `threshold` elapses before `sent_any_text` becomes `true`.
|
|
||||||
///
|
|
||||||
/// Callers must abort the returned [`tokio::task::JoinHandle`] once the turn
|
|
||||||
/// completes so a turn that finishes under the threshold — with or without
|
|
||||||
/// text — never triggers the notice after the fact.
|
|
||||||
pub(in crate::chat::transport::matrix::bot) fn spawn_digging_in_watcher(
|
|
||||||
transport: Arc<dyn ChatTransport>,
|
|
||||||
room_id: String,
|
|
||||||
sent_any_text: Arc<AtomicBool>,
|
|
||||||
threshold: Duration,
|
|
||||||
) -> tokio::task::JoinHandle<()> {
|
|
||||||
tokio::spawn(async move {
|
|
||||||
tokio::time::sleep(threshold).await;
|
|
||||||
if !sent_any_text.load(Ordering::Relaxed) {
|
|
||||||
let html = markdown_to_html(DIGGING_IN_MESSAGE);
|
|
||||||
let _ = transport
|
|
||||||
.send_message(&room_id, DIGGING_IN_MESSAGE, &html)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One live-progress update to apply to the room's placeholder message
|
/// One live-progress update to apply to the room's placeholder message
|
||||||
/// while a turn runs (story 1240).
|
/// while a turn runs (story 1240).
|
||||||
enum ProgressUpdate {
|
enum ProgressUpdate {
|
||||||
@@ -248,21 +223,10 @@ pub(in crate::chat::transport::matrix::bot) async fn handle_message(
|
|||||||
);
|
);
|
||||||
tokio::pin!(chat_fut);
|
tokio::pin!(chat_fut);
|
||||||
|
|
||||||
// Notify the room if this turn spends longer than the configured
|
|
||||||
// threshold on tool calls before emitting any user-facing text, so a
|
|
||||||
// long silent turn doesn't look hung. Aborted below once the turn ends.
|
|
||||||
let digging_in_task = spawn_digging_in_watcher(
|
|
||||||
Arc::clone(&ctx.transport),
|
|
||||||
room_id_str.clone(),
|
|
||||||
Arc::clone(&sent_any_chunk),
|
|
||||||
Duration::from_secs(ctx.digging_in_threshold_secs),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Permission requests are handled by the persistent permission_listener
|
// Permission requests are handled by the persistent permission_listener
|
||||||
// task spawned at bot startup (story 884) — they no longer route through
|
// task spawned at bot startup (story 884) — they no longer route through
|
||||||
// per-message handlers. Just await chat_fut.
|
// per-message handlers. Just await chat_fut.
|
||||||
let result = (&mut chat_fut).await;
|
let result = (&mut chat_fut).await;
|
||||||
digging_in_task.abort();
|
|
||||||
|
|
||||||
// Flush any remaining text that didn't end with a paragraph boundary.
|
// Flush any remaining text that didn't end with a paragraph boundary.
|
||||||
let remaining = buffer.lock().unwrap().trim().to_string();
|
let remaining = buffer.lock().unwrap().trim().to_string();
|
||||||
@@ -503,107 +467,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AC 1: a turn that runs longer than the threshold without sending any
|
|
||||||
/// text gets exactly one "Working..." notice.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn digging_in_fires_after_threshold_when_no_text_sent() {
|
|
||||||
let transport = Arc::new(CapturingTransport::new());
|
|
||||||
let sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&sent_any_text),
|
|
||||||
Duration::from_millis(30),
|
|
||||||
);
|
|
||||||
handle.await.unwrap();
|
|
||||||
assert_eq!(transport.sent_count(), 1);
|
|
||||||
assert_eq!(transport.last_message().unwrap(), "Working...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AC 2: if text is sent before the threshold elapses, the watcher must
|
|
||||||
/// not post anything.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn digging_in_does_not_fire_when_text_sent_before_threshold() {
|
|
||||||
let transport = Arc::new(CapturingTransport::new());
|
|
||||||
let sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&sent_any_text),
|
|
||||||
Duration::from_millis(30),
|
|
||||||
);
|
|
||||||
sent_any_text.store(true, Ordering::Relaxed);
|
|
||||||
handle.await.unwrap();
|
|
||||||
assert_eq!(transport.sent_count(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AC 2: a fast turn that completes (and is aborted by its caller)
|
|
||||||
/// before the threshold elapses must not post anything, even if it
|
|
||||||
/// never sent any text either.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn digging_in_does_not_fire_when_aborted_before_threshold() {
|
|
||||||
let transport = Arc::new(CapturingTransport::new());
|
|
||||||
let sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&sent_any_text),
|
|
||||||
Duration::from_millis(200),
|
|
||||||
);
|
|
||||||
handle.abort();
|
|
||||||
tokio::time::sleep(Duration::from_millis(250)).await;
|
|
||||||
assert_eq!(transport.sent_count(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AC 3: the notice fires at most once per turn — even waiting well past
|
|
||||||
/// the threshold never produces a second message.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn digging_in_fires_at_most_once_even_after_extra_wait() {
|
|
||||||
let transport = Arc::new(CapturingTransport::new());
|
|
||||||
let sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&sent_any_text),
|
|
||||||
Duration::from_millis(20),
|
|
||||||
);
|
|
||||||
handle.await.unwrap();
|
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
||||||
assert_eq!(transport.sent_count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AC 5: state is fresh per call — spawning a second, independent
|
|
||||||
/// watcher (as a new turn would) does not inherit any state from a
|
|
||||||
/// prior watcher's `sent_any_text` flag.
|
|
||||||
#[tokio::test]
|
|
||||||
async fn digging_in_state_does_not_leak_across_turns() {
|
|
||||||
let transport = Arc::new(CapturingTransport::new());
|
|
||||||
|
|
||||||
// First "turn": text sent before threshold, so no notice.
|
|
||||||
let first_sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let first_handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&first_sent_any_text),
|
|
||||||
Duration::from_millis(30),
|
|
||||||
);
|
|
||||||
first_sent_any_text.store(true, Ordering::Relaxed);
|
|
||||||
first_handle.await.unwrap();
|
|
||||||
assert_eq!(transport.sent_count(), 0);
|
|
||||||
|
|
||||||
// Second "turn": fresh flag, no text sent — must fire independently
|
|
||||||
// of the first turn's outcome.
|
|
||||||
let second_sent_any_text = Arc::new(AtomicBool::new(false));
|
|
||||||
let second_handle = spawn_digging_in_watcher(
|
|
||||||
transport.clone() as Arc<dyn ChatTransport>,
|
|
||||||
"!room:example.com".to_string(),
|
|
||||||
Arc::clone(&second_sent_any_text),
|
|
||||||
Duration::from_millis(30),
|
|
||||||
);
|
|
||||||
second_handle.await.unwrap();
|
|
||||||
assert_eq!(transport.sent_count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── run_progress_updates (story 1240) ─────────────────────────────────
|
// ── run_progress_updates (story 1240) ─────────────────────────────────
|
||||||
|
|
||||||
fn spawn_progress(
|
fn spawn_progress(
|
||||||
|
|||||||
@@ -2092,7 +2092,6 @@ mod tests {
|
|||||||
compact_seed_max_bytes: 8_000,
|
compact_seed_max_bytes: 8_000,
|
||||||
cache_read_suggest_threshold: 50_000,
|
cache_read_suggest_threshold: 50_000,
|
||||||
compact_suggest_cooldown_secs: 3_600,
|
compact_suggest_cooldown_secs: 3_600,
|
||||||
digging_in_threshold_secs: 15,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,7 +343,6 @@ pub async fn run_bot(
|
|||||||
compact_seed_max_bytes: config.compact_seed_max_bytes,
|
compact_seed_max_bytes: config.compact_seed_max_bytes,
|
||||||
cache_read_suggest_threshold: config.cache_read_suggest_threshold,
|
cache_read_suggest_threshold: config.cache_read_suggest_threshold,
|
||||||
compact_suggest_cooldown_secs: config.compact_suggest_cooldown_secs,
|
compact_suggest_cooldown_secs: config.compact_suggest_cooldown_secs,
|
||||||
digging_in_threshold_secs: config.digging_in_threshold_secs,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
slog!(
|
slog!(
|
||||||
|
|||||||
@@ -172,49 +172,6 @@ history_size = 50
|
|||||||
assert_eq!(config.history_size, 50);
|
assert_eq!(config.history_size, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AC4: `digging_in_threshold_secs` defaults to 15 when unset in bot.toml.
|
|
||||||
#[test]
|
|
||||||
fn load_uses_default_digging_in_threshold_secs() {
|
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
|
||||||
let sk = tmp.path().join(".huskies");
|
|
||||||
fs::create_dir_all(&sk).unwrap();
|
|
||||||
fs::write(
|
|
||||||
sk.join("bot.toml"),
|
|
||||||
r#"
|
|
||||||
homeserver = "https://matrix.example.com"
|
|
||||||
username = "@bot:example.com"
|
|
||||||
password = "secret"
|
|
||||||
room_ids = ["!abc:example.com"]
|
|
||||||
enabled = true
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let config = BotConfig::load(tmp.path()).unwrap();
|
|
||||||
assert_eq!(config.digging_in_threshold_secs, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AC4: `digging_in_threshold_secs` can be overridden in bot.toml.
|
|
||||||
#[test]
|
|
||||||
fn load_respects_custom_digging_in_threshold_secs() {
|
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
|
||||||
let sk = tmp.path().join(".huskies");
|
|
||||||
fs::create_dir_all(&sk).unwrap();
|
|
||||||
fs::write(
|
|
||||||
sk.join("bot.toml"),
|
|
||||||
r#"
|
|
||||||
homeserver = "https://matrix.example.com"
|
|
||||||
username = "@bot:example.com"
|
|
||||||
password = "secret"
|
|
||||||
room_ids = ["!abc:example.com"]
|
|
||||||
enabled = true
|
|
||||||
digging_in_threshold_secs = 30
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let config = BotConfig::load(tmp.path()).unwrap();
|
|
||||||
assert_eq!(config.digging_in_threshold_secs, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn load_reads_display_name() {
|
fn load_reads_display_name() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
@@ -31,12 +31,6 @@ pub(super) fn default_compact_suggest_cooldown_secs() -> i64 {
|
|||||||
3_600
|
3_600
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default threshold (seconds) a turn may spend on tool calls before
|
|
||||||
/// emitting any user-facing text before the bot posts a "digging in" notice.
|
|
||||||
pub(super) fn default_digging_in_threshold_secs() -> u64 {
|
|
||||||
15
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn default_transport() -> String {
|
pub(super) fn default_transport() -> String {
|
||||||
"matrix".to_string()
|
"matrix".to_string()
|
||||||
}
|
}
|
||||||
@@ -229,10 +223,4 @@ pub struct BotConfig {
|
|||||||
/// room, so a busy room isn't spammed every turn. Defaults to 3600 (1h).
|
/// room, so a busy room isn't spammed every turn. Defaults to 3600 (1h).
|
||||||
#[serde(default = "default_compact_suggest_cooldown_secs")]
|
#[serde(default = "default_compact_suggest_cooldown_secs")]
|
||||||
pub compact_suggest_cooldown_secs: i64,
|
pub compact_suggest_cooldown_secs: i64,
|
||||||
|
|
||||||
/// Seconds a turn may spend on tool calls before emitting any
|
|
||||||
/// user-facing text before the bot posts a "digging in" notice to the
|
|
||||||
/// room, so a silent long-running turn doesn't look hung. Defaults to 15.
|
|
||||||
#[serde(default = "default_digging_in_threshold_secs")]
|
|
||||||
pub digging_in_threshold_secs: u64,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -959,7 +959,6 @@ mod tests {
|
|||||||
compact_seed_max_bytes: 8_000,
|
compact_seed_max_bytes: 8_000,
|
||||||
cache_read_suggest_threshold: 50_000,
|
cache_read_suggest_threshold: 50_000,
|
||||||
compact_suggest_cooldown_secs: 3_600,
|
compact_suggest_cooldown_secs: 3_600,
|
||||||
digging_in_threshold_secs: 15,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ mod tests {
|
|||||||
compact_seed_max_bytes: 8_000,
|
compact_seed_max_bytes: 8_000,
|
||||||
cache_read_suggest_threshold: 50_000,
|
cache_read_suggest_threshold: 50_000,
|
||||||
compact_suggest_cooldown_secs: 3_600,
|
compact_suggest_cooldown_secs: 3_600,
|
||||||
digging_in_threshold_secs: 15,
|
|
||||||
};
|
};
|
||||||
run_projects_list(&ctx).await
|
run_projects_list(&ctx).await
|
||||||
}
|
}
|
||||||
@@ -225,7 +224,6 @@ mod tests {
|
|||||||
compact_seed_max_bytes: 8_000,
|
compact_seed_max_bytes: 8_000,
|
||||||
cache_read_suggest_threshold: 50_000,
|
cache_read_suggest_threshold: 50_000,
|
||||||
compact_suggest_cooldown_secs: 3_600,
|
compact_suggest_cooldown_secs: 3_600,
|
||||||
digging_in_threshold_secs: 15,
|
|
||||||
};
|
};
|
||||||
let response = run_projects_list(&ctx).await;
|
let response = run_projects_list(&ctx).await;
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
Reference in New Issue
Block a user