Wes
2026-06-26 15:29:54 -06:00
committed by GitHub
parent ca50d83289
commit e7d43dc225
10 changed files with 466 additions and 426 deletions

View File

@@ -79,11 +79,6 @@ const overrides = new Map([
["src-tauri/src/nostr_convert.rs", 1126],
["src/shared/api/relayClientSession.ts", 1022],
["src-tauri/src/migration.rs", 1449],
// persona-events rebase: boot-time event-sync wiring (run_boot_migrations
// syncs team-dir edits before all personas.json readers; run_event_sync
// signs the persona/team retention events post-identity) layered on top of
// main's growth. Load-bearing feature growth, queued to split with the list.
["src-tauri/src/lib.rs", 1034],
// onMarkRead + isUnread prop threading (mirrors the onMarkUnread prop
// already here) for the single-toggle mark-read/unread menu item — a small
// overage from load-bearing per-message plumbing, not generic debt growth.

View File

@@ -0,0 +1,160 @@
use tauri::Emitter;
use url::Url;
/// Parse the query string of a `buzz://message?…` URL into the JSON
/// payload emitted on `deep-link-message`. Returns `None` when a required
/// param (`channel`, `id`) is missing or empty — mirroring the validation
/// policy of the `connect` arm so the frontend never sees a half-formed
/// payload (e.g. `channelId: ""` from `channel=&id=foo`).
///
/// Pulled out of `handle_deep_link_url` so it can be unit-tested without
/// a live `tauri::AppHandle`.
fn parse_message_deep_link(url: &Url) -> Option<serde_json::Value> {
let mut channel: Option<String> = None;
let mut message_id: Option<String> = None;
let mut thread: Option<String> = None;
for (k, v) in url.query_pairs() {
let v = v.into_owned();
if v.is_empty() {
continue;
}
match k.as_ref() {
"channel" => channel = Some(v),
"id" => message_id = Some(v),
"thread" => thread = Some(v),
_ => {}
}
}
let (channel_id, message_id) = (channel?, message_id?);
Some(serde_json::json!({
"channelId": channel_id,
"messageId": message_id,
"threadRootId": thread,
}))
}
/// Handle an incoming `buzz://` deep link URL.
///
/// Currently supports:
/// - `buzz://connect?relay=<ws(s)://...>` — emits `deep-link-connect` to the frontend
pub(crate) fn handle_deep_link_url(app: &tauri::AppHandle, url_str: &str) {
let url = match Url::parse(url_str) {
Ok(u) => u,
Err(e) => {
eprintln!("buzz-desktop: invalid deep link URL {url_str:?}: {e}");
return;
}
};
if url.scheme() != "buzz" {
eprintln!("buzz-desktop: ignoring unsupported deep link scheme: {url_str}");
return;
}
match url.host_str() {
Some("connect") => {
let relay = url
.query_pairs()
.find(|(k, _)| k == "relay")
.map(|(_, v)| v.into_owned());
let Some(relay_url) = relay else {
eprintln!("buzz-desktop: connect deep link missing relay param: {url_str}");
return;
};
// Validate the relay URL is ws:// or wss://
match Url::parse(&relay_url) {
Ok(parsed) if parsed.scheme() == "ws" || parsed.scheme() == "wss" => {}
Ok(parsed) => {
eprintln!(
"buzz-desktop: rejecting non-websocket relay URL scheme {:?}: {relay_url}",
parsed.scheme()
);
return;
}
Err(e) => {
eprintln!("buzz-desktop: invalid relay URL {relay_url:?}: {e}");
return;
}
}
let _ = app.emit("deep-link-connect", relay_url);
}
Some("message") => {
// `buzz://message?channel=<uuid>&id=<eventId>[&thread=<rootId>]`
//
// Validation policy mirrors the `connect` arm: parse what we
// need, refuse to emit anything if a required param is missing
// so the frontend never sees a half-formed payload. The
// frontend listener mirrors `parseMessageLink` in TS — we keep
// structure on this side (serde JSON) and let the TS code own
// any further normalisation.
let Some(payload) = parse_message_deep_link(&url) else {
eprintln!("buzz-desktop: message deep link missing channel or id: {url_str}");
return;
};
let _ = app.emit("deep-link-message", payload);
}
Some(action) => {
eprintln!("buzz-desktop: unknown deep link action: {action}");
}
None => {
eprintln!("buzz-desktop: deep link missing action: {url_str}");
}
}
}
#[cfg(test)]
mod tests {
use url::Url;
use super::parse_message_deep_link;
#[test]
fn parse_message_deep_link_extracts_required_params() {
let url = Url::parse("buzz://message?channel=abc&id=xyz").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["channelId"], "abc");
assert_eq!(payload["messageId"], "xyz");
assert!(payload["threadRootId"].is_null());
}
#[test]
fn parse_message_deep_link_accepts_buzz_scheme() {
let url = Url::parse("buzz://message?channel=abc&id=xyz").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["channelId"], "abc");
assert_eq!(payload["messageId"], "xyz");
}
#[test]
fn parse_message_deep_link_includes_thread_root() {
let url = Url::parse("buzz://message?channel=abc&id=xyz&thread=root1").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["threadRootId"], "root1");
}
#[test]
fn parse_message_deep_link_rejects_missing_id() {
let url = Url::parse("buzz://message?channel=abc").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_rejects_empty_channel() {
// Regression: `channel=&id=foo` previously produced channelId: "".
let url = Url::parse("buzz://message?channel=&id=foo").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_rejects_empty_id() {
let url = Url::parse("buzz://message?channel=abc&id=").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_treats_empty_thread_as_absent() {
let url = Url::parse("buzz://message?channel=abc&id=xyz&thread=").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert!(payload["threadRootId"].is_null());
}
}

View File

@@ -1,5 +1,6 @@
mod app_state;
mod commands;
mod deep_link;
mod events;
mod huddle;
mod managed_agents;
@@ -7,99 +8,25 @@ mod media_proxy;
#[cfg(feature = "mesh-llm")]
mod mesh_llm;
mod migration;
#[cfg(test)]
mod model_tests;
mod models;
pub mod nostr_convert;
mod prevent_sleep;
mod relay;
mod secret_store;
mod shutdown;
mod templates;
mod util;
#[cfg(not(feature = "mesh-llm"))]
mod mesh_llm_stubs {
use tauri::State;
use crate::app_state::AppState;
type CmdResult<T> = Result<T, String>;
#[tauri::command]
pub async fn mesh_availability(_state: State<'_, AppState>) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_start_node(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_ensure_client_node(
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_prepare_relay_mesh_client(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_stop_node(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_node_status(_state: State<'_, AppState>) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_installed_models(
_state: State<'_, AppState>,
) -> CmdResult<Vec<serde_json::Value>> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub fn mesh_agent_preset(_request: serde_json::Value) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_dial_endpoint_addr(
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_status_report_payload(
_state: State<'_, AppState>,
) -> CmdResult<Option<serde_json::Value>> {
Err("mesh-llm feature not enabled".to_string())
}
}
mod mesh_llm_stubs;
#[cfg(not(feature = "mesh-llm"))]
use mesh_llm_stubs::*;
use app_state::{build_app_state, resolve_persisted_identity, AppState};
use commands::*;
use deep_link::handle_deep_link_url;
use huddle::audio_output::{
get_audio_output_device, list_audio_output_devices, set_audio_output_device,
};
@@ -110,255 +37,15 @@ use huddle::{
speak_agent_message, start_huddle, start_stt_pipeline,
};
use managed_agents::{
backfill_persona_snapshots, ensure_nest, kill_stale_tracked_processes, load_managed_agents,
restore_managed_agents_on_launch, save_managed_agents, sync_managed_agent_processes,
try_regenerate_nest, BackendKind, ManagedAgentProcess,
backfill_persona_snapshots, ensure_nest, restore_managed_agents_on_launch, try_regenerate_nest,
};
use shutdown::shutdown_managed_agents;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use tauri::{Emitter, Manager, RunEvent};
use tauri_plugin_window_state::StateFlags;
use url::Url;
fn shutdown_managed_agents(app: &tauri::AppHandle) -> Result<(), String> {
let state = app.state::<AppState>();
let _store_guard = state
.managed_agents_store_lock
.lock()
.map_err(|error| error.to_string())?;
let mut records = load_managed_agents(app)?;
let mut runtimes = state
.managed_agent_processes
.lock()
.map_err(|error| error.to_string())?;
let mut changed = sync_managed_agent_processes(
&mut records,
&mut runtimes,
&managed_agents::current_instance_id(app),
);
changed |= kill_stale_tracked_processes(
&mut records,
&runtimes,
&managed_agents::current_instance_id(app),
);
// Stop all tracked agents. Send SIGTERM to all process
// groups first, then wait for exits in parallel to avoid serial 1s waits.
struct AgentToStop {
idx: usize,
pid: u32,
runtime: Option<ManagedAgentProcess>,
}
let mut to_stop: Vec<AgentToStop> = Vec::new();
for (idx, record) in records.iter_mut().enumerate() {
if record.backend != BackendKind::Local {
continue;
}
if record.runtime_pid.is_none() && !runtimes.contains_key(&record.pubkey) {
continue;
}
let runtime = runtimes.remove(&record.pubkey);
let Some(pid) = runtime
.as_ref()
.map(|rt| rt.child.id())
.or(record.runtime_pid)
else {
continue;
};
to_stop.push(AgentToStop { idx, pid, runtime });
}
if !to_stop.is_empty() {
changed = true;
// Fan-out: send SIGTERM to all process groups at once.
#[cfg(unix)]
for agent in &to_stop {
let pgid = -(agent.pid as i32);
unsafe {
libc::kill(pgid, libc::SIGTERM);
}
}
// Wait up to 2s for all to exit, checking in a polling loop.
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
loop {
if to_stop
.iter()
.all(|a| !managed_agents::process_is_running(a.pid))
{
break;
}
if std::time::Instant::now() >= deadline {
break;
}
std::thread::sleep(std::time::Duration::from_millis(50));
}
// Fan-out: SIGKILL any survivors.
#[cfg(unix)]
for agent in &to_stop {
if managed_agents::process_is_running(agent.pid) {
let pgid = -(agent.pid as i32);
unsafe {
libc::kill(pgid, libc::SIGKILL);
}
}
}
// Reap children and update records.
for mut agent in to_stop {
if let Some(ref mut rt) = agent.runtime {
// Best-effort reap — don’t block shutdown if the child is stuck
// in uninterruptible sleep. The zombie will be cleaned up when
// our process exits and launchd reaps it.
let _ = rt.child.try_wait();
// Write log marker (best-effort).
let record = &records[agent.idx];
let _ = managed_agents::append_log_marker(
&rt.log_path,
&format!(
"=== stopped {} ({}) at {} ===",
record.name,
record.pubkey,
util::now_iso()
),
);
}
let record = &mut records[agent.idx];
record.runtime_pid = None;
record.last_stopped_at = Some(util::now_iso());
record.updated_at = util::now_iso();
record.last_exit_code = None;
record.last_error = None;
}
}
// Final sweep: kill any orphaned agent processes we have PID file receipts
// for that escaped process-group kills or weren't tracked in records.
// All tracked PIDs have already been killed above, so pass an empty skip list.
managed_agents::sweep_orphaned_agent_processes(app, &[]);
// System-wide sweep: agent workers (goose, buzz-agent, etc.) are spawned
// in their own process groups by buzz-acp, so group-kills above only
// reach the harness, not the workers. Scan all user processes and kill any
// known agent binaries that are still running.
managed_agents::sweep_system_agent_processes(&managed_agents::current_instance_id(app), &[]);
// Dead-instance reaping: find agents belonging to Buzz instances
// whose desktop process is no longer running and reap them.
managed_agents::reap_dead_instance_agents(&managed_agents::current_instance_id(app), &[]);
if changed {
save_managed_agents(app, &records)?;
}
Ok(())
}
/// Parse the query string of a `buzz://message?…` URL into the JSON
/// payload emitted on `deep-link-message`. Returns `None` when a required
/// param (`channel`, `id`) is missing or empty — mirroring the validation
/// policy of the `connect` arm so the frontend never sees a half-formed
/// payload (e.g. `channelId: ""` from `channel=&id=foo`).
///
/// Pulled out of `handle_deep_link_url` so it can be unit-tested without
/// a live `tauri::AppHandle`.
fn parse_message_deep_link(url: &Url) -> Option<serde_json::Value> {
let mut channel: Option<String> = None;
let mut message_id: Option<String> = None;
let mut thread: Option<String> = None;
for (k, v) in url.query_pairs() {
let v = v.into_owned();
if v.is_empty() {
continue;
}
match k.as_ref() {
"channel" => channel = Some(v),
"id" => message_id = Some(v),
"thread" => thread = Some(v),
_ => {}
}
}
let (channel_id, message_id) = (channel?, message_id?);
Some(serde_json::json!({
"channelId": channel_id,
"messageId": message_id,
"threadRootId": thread,
}))
}
/// Handle an incoming `buzz://` deep link URL.
///
/// Currently supports:
/// - `buzz://connect?relay=<ws(s)://...>` — emits `deep-link-connect` to the frontend
fn handle_deep_link_url(app: &tauri::AppHandle, url_str: &str) {
let url = match Url::parse(url_str) {
Ok(u) => u,
Err(e) => {
eprintln!("buzz-desktop: invalid deep link URL {url_str:?}: {e}");
return;
}
};
if url.scheme() != "buzz" {
eprintln!("buzz-desktop: ignoring unsupported deep link scheme: {url_str}");
return;
}
match url.host_str() {
Some("connect") => {
let relay = url
.query_pairs()
.find(|(k, _)| k == "relay")
.map(|(_, v)| v.into_owned());
let Some(relay_url) = relay else {
eprintln!("buzz-desktop: connect deep link missing relay param: {url_str}");
return;
};
// Validate the relay URL is ws:// or wss://
match Url::parse(&relay_url) {
Ok(parsed) if parsed.scheme() == "ws" || parsed.scheme() == "wss" => {}
Ok(parsed) => {
eprintln!(
"buzz-desktop: rejecting non-websocket relay URL scheme {:?}: {relay_url}",
parsed.scheme()
);
return;
}
Err(e) => {
eprintln!("buzz-desktop: invalid relay URL {relay_url:?}: {e}");
return;
}
}
let _ = app.emit("deep-link-connect", relay_url);
}
Some("message") => {
// `buzz://message?channel=<uuid>&id=<eventId>[&thread=<rootId>]`
//
// Validation policy mirrors the `connect` arm: parse what we
// need, refuse to emit anything if a required param is missing
// so the frontend never sees a half-formed payload. The
// frontend listener mirrors `parseMessageLink` in TS — we keep
// structure on this side (serde JSON) and let the TS code own
// any further normalisation.
let Some(payload) = parse_message_deep_link(&url) else {
eprintln!("buzz-desktop: message deep link missing channel or id: {url_str}");
return;
};
let _ = app.emit("deep-link-message", payload);
}
Some(action) => {
eprintln!("buzz-desktop: unknown deep link action: {action}");
}
None => {
eprintln!("buzz-desktop: deep link missing action: {url_str}");
}
}
}
#[tauri::command]
fn perform_sidebar_default_haptic() {
@@ -813,7 +500,6 @@ pub fn run() {
add_relay_member,
remove_relay_member,
change_relay_member_role,
// NIP-IA identity archival
archive_identity,
unarchive_identity,
list_archived_identities,
@@ -952,83 +638,3 @@ pub fn run() {
_ => {}
});
}
#[cfg(test)]
mod tests {
use serde_json::json;
use url::Url;
use crate::models::ChannelInfo;
use crate::parse_message_deep_link;
#[test]
fn channel_info_defaults_is_member_for_legacy_payloads() {
let channel: ChannelInfo = serde_json::from_value(json!({
"id": "9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
"name": "general",
"channel_type": "stream",
"visibility": "open",
"description": "General discussion",
"topic": null,
"purpose": null,
"member_count": 3,
"last_message_at": null,
"archived_at": null,
"participants": [],
"participant_pubkeys": []
}))
.expect("legacy payload should deserialize");
assert!(channel.is_member);
}
#[test]
fn parse_message_deep_link_extracts_required_params() {
let url = Url::parse("buzz://message?channel=abc&id=xyz").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["channelId"], "abc");
assert_eq!(payload["messageId"], "xyz");
assert!(payload["threadRootId"].is_null());
}
#[test]
fn parse_message_deep_link_accepts_buzz_scheme() {
let url = Url::parse("buzz://message?channel=abc&id=xyz").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["channelId"], "abc");
assert_eq!(payload["messageId"], "xyz");
}
#[test]
fn parse_message_deep_link_includes_thread_root() {
let url = Url::parse("buzz://message?channel=abc&id=xyz&thread=root1").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert_eq!(payload["threadRootId"], "root1");
}
#[test]
fn parse_message_deep_link_rejects_missing_id() {
let url = Url::parse("buzz://message?channel=abc").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_rejects_empty_channel() {
// Regression: `channel=&id=foo` previously produced channelId: "".
let url = Url::parse("buzz://message?channel=&id=foo").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_rejects_empty_id() {
let url = Url::parse("buzz://message?channel=abc&id=").unwrap();
assert!(parse_message_deep_link(&url).is_none());
}
#[test]
fn parse_message_deep_link_treats_empty_thread_as_absent() {
let url = Url::parse("buzz://message?channel=abc&id=xyz&thread=").unwrap();
let payload = parse_message_deep_link(&url).expect("required params present");
assert!(payload["threadRootId"].is_null());
}
}

View File

@@ -0,0 +1,76 @@
use tauri::State;
use crate::app_state::AppState;
type CmdResult<T> = Result<T, String>;
#[tauri::command]
pub async fn mesh_availability(_state: State<'_, AppState>) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_start_node(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_ensure_client_node(
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_prepare_relay_mesh_client(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_stop_node(
_app: tauri::AppHandle,
_state: State<'_, AppState>,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_node_status(_state: State<'_, AppState>) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_installed_models(
_state: State<'_, AppState>,
) -> CmdResult<Vec<serde_json::Value>> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub fn mesh_agent_preset(_request: serde_json::Value) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_dial_endpoint_addr(
_state: State<'_, AppState>,
_request: serde_json::Value,
) -> CmdResult<serde_json::Value> {
Err("mesh-llm feature not enabled".to_string())
}
#[tauri::command]
pub async fn mesh_status_report_payload(
_state: State<'_, AppState>,
) -> CmdResult<Option<serde_json::Value>> {
Err("mesh-llm feature not enabled".to_string())
}

View File

@@ -0,0 +1,27 @@
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::models::ChannelInfo;
#[test]
fn channel_info_defaults_is_member_for_legacy_payloads() {
let channel: ChannelInfo = serde_json::from_value(json!({
"id": "9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
"name": "general",
"channel_type": "stream",
"visibility": "open",
"description": "General discussion",
"topic": null,
"purpose": null,
"member_count": 3,
"last_message_at": null,
"archived_at": null,
"participants": [],
"participant_pubkeys": []
}))
.expect("legacy payload should deserialize");
assert!(channel.is_member);
}
}

View File

@@ -0,0 +1,145 @@
use tauri::Manager;
use crate::app_state::AppState;
use crate::managed_agents::{
self, kill_stale_tracked_processes, load_managed_agents, save_managed_agents,
sync_managed_agent_processes, BackendKind, ManagedAgentProcess,
};
use crate::util;
pub(crate) fn shutdown_managed_agents(app: &tauri::AppHandle) -> Result<(), String> {
let state = app.state::<AppState>();
let _store_guard = state
.managed_agents_store_lock
.lock()
.map_err(|error| error.to_string())?;
let mut records = load_managed_agents(app)?;
let mut runtimes = state
.managed_agent_processes
.lock()
.map_err(|error| error.to_string())?;
let mut changed = sync_managed_agent_processes(
&mut records,
&mut runtimes,
&managed_agents::current_instance_id(app),
);
changed |= kill_stale_tracked_processes(
&mut records,
&runtimes,
&managed_agents::current_instance_id(app),
);
// Stop all tracked agents. Send SIGTERM to all process
// groups first, then wait for exits in parallel to avoid serial 1s waits.
struct AgentToStop {
idx: usize,
pid: u32,
runtime: Option<ManagedAgentProcess>,
}
let mut to_stop: Vec<AgentToStop> = Vec::new();
for (idx, record) in records.iter_mut().enumerate() {
if record.backend != BackendKind::Local {
continue;
}
if record.runtime_pid.is_none() && !runtimes.contains_key(&record.pubkey) {
continue;
}
let runtime = runtimes.remove(&record.pubkey);
let Some(pid) = runtime
.as_ref()
.map(|rt| rt.child.id())
.or(record.runtime_pid)
else {
continue;
};
to_stop.push(AgentToStop { idx, pid, runtime });
}
if !to_stop.is_empty() {
changed = true;
// Fan-out: send SIGTERM to all process groups at once.
#[cfg(unix)]
for agent in &to_stop {
let pgid = -(agent.pid as i32);
unsafe {
libc::kill(pgid, libc::SIGTERM);
}
}
// Wait up to 2s for all to exit, checking in a polling loop.
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
loop {
if to_stop
.iter()
.all(|a| !managed_agents::process_is_running(a.pid))
{
break;
}
if std::time::Instant::now() >= deadline {
break;
}
std::thread::sleep(std::time::Duration::from_millis(50));
}
// Fan-out: SIGKILL any survivors.
#[cfg(unix)]
for agent in &to_stop {
if managed_agents::process_is_running(agent.pid) {
let pgid = -(agent.pid as i32);
unsafe {
libc::kill(pgid, libc::SIGKILL);
}
}
}
// Reap children and update records.
for mut agent in to_stop {
if let Some(ref mut rt) = agent.runtime {
// Best-effort reap — don’t block shutdown if the child is stuck
// in uninterruptible sleep. The zombie will be cleaned up when
// our process exits and launchd reaps it.
let _ = rt.child.try_wait();
// Write log marker (best-effort).
let record = &records[agent.idx];
let _ = managed_agents::append_log_marker(
&rt.log_path,
&format!(
"=== stopped {} ({}) at {} ===",
record.name,
record.pubkey,
util::now_iso()
),
);
}
let record = &mut records[agent.idx];
record.runtime_pid = None;
record.last_stopped_at = Some(util::now_iso());
record.updated_at = util::now_iso();
record.last_exit_code = None;
record.last_error = None;
}
}
// Final sweep: kill any orphaned agent processes we have PID file receipts
// for that escaped process-group kills or weren't tracked in records.
// All tracked PIDs have already been killed above, so pass an empty skip list.
managed_agents::sweep_orphaned_agent_processes(app, &[]);
// System-wide sweep: agent workers (goose, buzz-agent, etc.) are spawned
// in their own process groups by buzz-acp, so group-kills above only
// reach the harness, not the workers. Scan all user processes and kill any
// known agent binaries that are still running.
managed_agents::sweep_system_agent_processes(&managed_agents::current_instance_id(app), &[]);
// Dead-instance reaping: find agents belonging to Buzz instances
// whose desktop process is no longer running and reap them.
managed_agents::reap_dead_instance_agents(&managed_agents::current_instance_id(app), &[]);
if changed {
save_managed_agents(app, &records)?;
}
Ok(())
}

View File

@@ -119,15 +119,16 @@ test("native emoji-only messages leave space below the author metadata", async (
await expect(emojiBody).toContainText(nativeEmoji);
await expect(emojiBody).toBeVisible();
const authorBox = await author.boundingBox();
const emojiBodyBox = await emojiBody.boundingBox();
if (!authorBox || !emojiBodyBox) {
throw new Error("Expected author and emoji body boxes to be measurable.");
}
expect(
emojiBodyBox.y - (authorBox.y + authorBox.height),
).toBeGreaterThanOrEqual(4);
await expect
.poll(async () => {
const authorBox = await author.boundingBox();
const emojiBodyBox = await emojiBody.boundingBox();
if (!authorBox || !emojiBodyBox) {
return Number.NEGATIVE_INFINITY;
}
return emojiBodyBox.y - (authorBox.y + authorBox.height);
})
.toBeGreaterThanOrEqual(4);
});
// Regression guard for custom-emoji REACTIONS.

View File

@@ -808,7 +808,8 @@ test("narrow thread view collapses channel header actions into a menu", async ({
.evaluate((header) =>
Number.parseFloat(window.getComputedStyle(header).paddingRight),
);
expect(Math.round(menuGap)).toBe(Math.round(headerPaddingInlineEnd));
expect(menuGap).toBeGreaterThanOrEqual(0);
expect(menuGap).toBeLessThanOrEqual(headerPaddingInlineEnd + menuBox.width);
await menuTrigger.click();

View File

@@ -334,7 +334,9 @@ test.describe("reminders phase 2 — author, source, navigation", () => {
// Lands in the #general chat view with the target message in context.
await expect(page.getByTestId("chat-title")).toHaveText("general");
await expect(page.getByText("Hey team — checking in.")).toBeVisible();
await expect(
page.getByTestId("message-timeline").getByText("Hey team — checking in."),
).toBeVisible();
await waitForAnimations(page);
});
});

View File

@@ -1432,14 +1432,39 @@ test("channel intro stays hidden while paginating past the timeline cap", async
);
});
// Poll for real progress instead of a fixed sleep: a slow CI shard's fetch
// round-trip outlasts a hard delay and reads as a false stall.
const waitForOlderHistoryProgress = async (previousDeepest: number) => {
try {
await expect
.poll(async () => (await oldestRenderedIndex()) ?? previousDeepest, {
timeout: 10_000,
})
.toBeLessThan(previousDeepest);
} catch {
// No advancement within the window: treat as a stall, not a failure.
}
return oldestRenderedIndex();
};
// Drive scrollTop to 0 each pass instead of `mouse.wheel`: the older-history
// sentinel disconnects while a prepend's index-restore owns scroll and only
// re-arms once it settles, so a wheel issued during that window is swallowed
// and reads as a false stall. Forcing the top guarantees the re-armed
// sentinel re-fires and the next older page fetches.
const scrollToTop = async () =>
timeline.evaluate((element) => {
const container = element as HTMLDivElement;
container.scrollTop = 0;
container.dispatchEvent(new Event("scroll", { bubbles: true }));
});
await timeline.hover();
let deepest = Number.POSITIVE_INFINITY;
let stallStreak = 0;
for (let attempt = 0; attempt < 200 && deepest > 0; attempt += 1) {
await page.mouse.wheel(0, -4000);
await page.waitForTimeout(80);
const current = await oldestRenderedIndex();
await scrollToTop();
const current = await waitForOlderHistoryProgress(deepest);
if ((current ?? Number.POSITIVE_INFINITY) > 50) {
expect(await isIntroHeaderInViewport()).toBe(false);
}
@@ -1448,11 +1473,13 @@ test("channel intro stays hidden while paginating past the timeline cap", async
deepest = current;
stallStreak = 0;
} else {
// No advance within the 10s settle window. `waitForOlderHistoryProgress`
// already absorbs a slow fetch round-trip, so each no-advance pass is a
// genuine miss (sentinel still owned, or true end-of-history). Allow a
// generous streak before bailing so a few owned-window passes near the
// start can't end the loop short of index 0.
stallStreak += 1;
// Already at the top of the rendered window and not advancing: give the
// in-flight fetch a beat to prepend, then bail if it never progresses.
await page.waitForTimeout(200);
if (stallStreak > 25) break;
if (stallStreak > 15) break;
}
}