Skip to content

Commit a87de0f

Browse files
committed
Merge remote-tracking branch 'origin/main' into gitbuzz-explorations
# Conflicts: # desktop/src/features/workspaces/ui/WorkspaceSwitcher.tsx
2 parents 3adfccd + 5bfd5ca commit a87de0f

37 files changed

Lines changed: 1802 additions & 265 deletions

‎NOSTR.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ the sender to be authenticated (NIP-42) as the relay owner or an admin.
262262
| 9030 | Add member | `["p", "<hex-pubkey>"]`, optional `["role", "member\|admin"]` |
263263
| 9031 | Remove member | `["p", "<hex-pubkey>"]`, optional `["role", "member\|admin"]` |
264264
| 9032 | Change role | `["p", "<hex-pubkey>"]`, `["role", "member\|admin"]` |
265+
| 9033 | Set workspace profile (icon) | `["icon", "<https-url or data:image/* URL>"]` (empty clears) |
265266

266267
Example using `nak`:
267268

@@ -295,6 +296,13 @@ After each add/remove/role-change, the relay publishes a kind:13534 membership l
295296
nak req -k 13534 --auth --sec <privkey> ws://localhost:3000
296297
```
297298

299+
A kind:9033 command similarly makes the relay store the workspace icon (per
300+
community) and serve it in the standard NIP-11 `icon` field of its relay
301+
information document. Clients render it in the workspace rail/switcher; anyone
302+
can read it (`curl -H 'Accept: application/nostr+json' http://localhost:3000`),
303+
but only admins/owners can set it. Full spec:
304+
[docs/nips/NIP-WP.md](docs/nips/NIP-WP.md).
305+
298306
### Known Limitations
299307

300308
1. **CLI intentionally does not emit kind 8000/8001 deltas** — `publish_nip43_delta` is

‎crates/buzz-acp/src/lib.rs‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,7 @@ async fn tokio_main() -> Result<()> {
21112111
&respawn_tx,
21122112
&mut respawn_tasks,
21132113
observer.clone(),
2114+
Some(&ctx.rest_client),
21142115
) == LoopAction::Exit
21152116
{
21162117
break;
@@ -2662,6 +2663,7 @@ fn handle_prompt_result(
26622663
respawn_tx: &mpsc::Sender<RespawnResult>,
26632664
respawn_tasks: &mut tokio::task::JoinSet<()>,
26642665
observer: Option<observer::ObserverHandle>,
2666+
rest_client: Option<&relay::RestClient>,
26652667
) -> LoopAction {
26662668
let before = pool.task_map().len();
26672669
let agent_index = result.agent.index;
@@ -2674,7 +2676,7 @@ fn handle_prompt_result(
26742676
// retry_counts. If mark_complete runs first, retry_counts is cleared and
26752677
// every retry starts at attempt 1 — defeating exponential backoff and
26762678
// dead-letter protection.
2677-
if let Some(batch) = result.batch {
2679+
if let Some(batch) = result.batch.take() {
26782680
// Don't requeue batches for channels the agent was removed from —
26792681
// those events are stale and should be silently dropped.
26802682
if !removed_channels.contains(&batch.channel_id) {
@@ -2689,8 +2691,31 @@ fn handle_prompt_result(
26892691
// system default — rather than telling the agent to supersede.
26902692
let reason = batch.cancel_reason.unwrap_or(CancelReason::Steer);
26912693
queue.requeue_as_cancelled(batch, reason);
2692-
} else {
2693-
queue.requeue(batch);
2694+
} else if let Some(dead) = queue.requeue(batch) {
2695+
// Dead-lettered: retries exhausted and the events are gone.
2696+
// Post a visible notice so the channel isn't left waiting on
2697+
// a turn that will never happen.
2698+
if let Some(rest) = rest_client {
2699+
let thread_tags = dead
2700+
.events
2701+
.last()
2702+
.map(|be| queue::parse_thread_tags(&be.event))
2703+
.unwrap_or_default();
2704+
let reason = match &result.outcome {
2705+
PromptOutcome::Timeout => "the turn timed out".to_string(),
2706+
PromptOutcome::AgentExited => "the agent process exited".to_string(),
2707+
PromptOutcome::Error(e) => format!("{e}"),
2708+
_ => "repeated failures".to_string(),
2709+
};
2710+
let content = format!(
2711+
"⚠️ I couldn't process the last request after multiple retries ({reason}). Please re-send if it's still needed."
2712+
);
2713+
let rest = rest.clone();
2714+
let channel_id = dead.channel_id;
2715+
tokio::spawn(async move {
2716+
pool::post_failure_notice(&rest, channel_id, &thread_tags, &content).await;
2717+
});
2718+
}
26942719
}
26952720
} else {
26962721
tracing::debug!(
@@ -2875,7 +2900,9 @@ fn recover_panicked_agent(
28752900
if let Some(batch) = meta.recoverable_batch {
28762901
if let Some(ch) = meta.channel_id {
28772902
if !removed_channels.contains(&ch) {
2878-
queue.requeue(batch);
2903+
// Dead-letter on exhaustion is logged inside requeue(); a
2904+
// panic path has no outcome to report, so no notice here.
2905+
let _ = queue.requeue(batch);
28792906
tracing::warn!("requeued batch for panicked agent {i}");
28802907
} else {
28812908
tracing::debug!(
@@ -4020,6 +4047,7 @@ mod error_outcome_emission_tests {
40204047
&respawn_tx,
40214048
&mut respawn_tasks,
40224049
Some(observer.clone()),
4050+
None,
40234051
);
40244052

40254053
observer

‎crates/buzz-acp/src/pool.rs‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::config::{DedupMode, PermissionMode};
3636
use crate::observer;
3737
use crate::queue::{
3838
CancelReason, ContextMessage, ConversationContext, FlushBatch, PromptChannelInfo,
39-
PromptProfile, PromptProfileLookup,
39+
PromptProfile, PromptProfileLookup, ThreadTags,
4040
};
4141
use crate::relay::{ChannelInfo, RestClient};
4242

@@ -2615,6 +2615,50 @@ pub(crate) async fn reaction_add(rest: &crate::relay::RestClient, event_id: &str
26152615
}
26162616
}
26172617

2618+
/// Best-effort: post a visible failure notice (kind:9) to a channel after a
2619+
/// batch is dead-lettered. Replies into the thread of `thread_tags` when the
2620+
/// triggering event was threaded. Errors are logged and swallowed — the
2621+
/// notice must never take down the main loop.
2622+
pub(crate) async fn post_failure_notice(
2623+
rest: &crate::relay::RestClient,
2624+
channel_id: Uuid,
2625+
thread_tags: &ThreadTags,
2626+
content: &str,
2627+
) {
2628+
let thread_ref = thread_tags.root_event_id.as_deref().and_then(|root| {
2629+
let root_id = nostr::EventId::from_hex(root).ok()?;
2630+
let parent_id = thread_tags
2631+
.parent_event_id
2632+
.as_deref()
2633+
.and_then(|p| nostr::EventId::from_hex(p).ok())
2634+
.unwrap_or(root_id);
2635+
Some(buzz_sdk::ThreadRef {
2636+
root_event_id: root_id,
2637+
parent_event_id: parent_id,
2638+
})
2639+
});
2640+
let builder =
2641+
match buzz_sdk::build_message(channel_id, content, thread_ref.as_ref(), &[], false, &[]) {
2642+
Ok(b) => b,
2643+
Err(e) => {
2644+
tracing::warn!(channel = %channel_id, "failure notice: build failed: {e}");
2645+
return;
2646+
}
2647+
};
2648+
let event = match builder.sign_with_keys(&rest.keys) {
2649+
Ok(e) => e,
2650+
Err(e) => {
2651+
tracing::warn!(channel = %channel_id, "failure notice: sign failed: {e}");
2652+
return;
2653+
}
2654+
};
2655+
match tokio::time::timeout(Duration::from_secs(5), rest.submit_event(&event)).await {
2656+
Ok(Ok(_)) => {}
2657+
Ok(Err(e)) => tracing::warn!(channel = %channel_id, "failure notice failed: {e}"),
2658+
Err(_) => tracing::warn!(channel = %channel_id, "failure notice timed out"),
2659+
}
2660+
}
2661+
26182662
/// Best-effort: remove a reaction via a signed kind:5 (NIP-09) deletion event.
26192663
///
26202664
/// Queries kind:7 reactions by our pubkey targeting the event, finds the matching

‎crates/buzz-acp/src/queue.rs‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub struct FlushBatch {
128128
///
129129
/// requeue(batch):
130130
/// increment retry_counts[channel]
131-
/// if retry_counts[channel] > MAX_RETRIES: dead-letter (log ERROR, discard)
131+
/// if retry_counts[channel] > MAX_RETRIES: dead-letter (log ERROR, return batch to caller)
132132
/// else: push_front with original received_at, set exponential backoff retry_after with jitter
133133
/// ```
134134
pub struct EventQueue {
@@ -376,12 +376,13 @@ impl EventQueue {
376376
/// not from resetting received_at.
377377
///
378378
/// After [`MAX_RETRIES`] attempts the batch is dead-lettered: logged at
379-
/// ERROR and discarded rather than requeued. This prevents poison batches
380-
/// from looping forever.
379+
/// ERROR and returned to the caller (rather than requeued) so a visible
380+
/// failure notice can be posted to the channel. Returns `None` when the
381+
/// batch was requeued for another attempt.
381382
///
382383
/// Note: does NOT remove from `in_flight_channels` — caller must call
383384
/// `mark_complete` separately.
384-
pub fn requeue(&mut self, batch: FlushBatch) {
385+
pub fn requeue(&mut self, batch: FlushBatch) -> Option<FlushBatch> {
385386
let channel_id = batch.channel_id;
386387
let attempt = {
387388
let count = self.retry_counts.entry(channel_id).or_insert(0);
@@ -402,7 +403,7 @@ impl EventQueue {
402403
// Also clear retry_after so fresh traffic on this channel isn't
403404
// throttled by stale backoff from the discarded poison batch.
404405
self.retry_after.remove(&channel_id);
405-
return;
406+
return Some(batch);
406407
}
407408

408409
// Exponential backoff: BASE * 2^(attempt-1), capped at MAX, with ±20% jitter.
@@ -449,6 +450,7 @@ impl EventQueue {
449450
);
450451
}
451452
self.retry_after.insert(channel_id, Instant::now() + delay);
453+
None
452454
}
453455

454456
/// Re-queue a batch preserving original `received_at` timestamps.
@@ -2690,6 +2692,36 @@ mod tests {
26902692
);
26912693
}
26922694

2695+
#[test]
2696+
fn test_requeue_dead_letters_after_max_retries() {
2697+
let mut q = EventQueue::new(DedupMode::Queue);
2698+
let ch = Uuid::new_v4();
2699+
2700+
q.push(make_queued(ch, "poison"));
2701+
for attempt in 1..=MAX_RETRIES {
2702+
q.retry_after
2703+
.insert(ch, Instant::now() - Duration::from_secs(1));
2704+
let batch = q.flush_next().expect("flush");
2705+
assert!(
2706+
q.requeue(batch).is_none(),
2707+
"attempt {attempt} should requeue, not dead-letter"
2708+
);
2709+
q.mark_complete(ch);
2710+
}
2711+
2712+
// The MAX_RETRIES+1'th failure dead-letters: batch is returned.
2713+
q.retry_after
2714+
.insert(ch, Instant::now() - Duration::from_secs(1));
2715+
let batch = q.flush_next().expect("flush");
2716+
let dead = q.requeue(batch).expect("should dead-letter");
2717+
assert_eq!(dead.channel_id, ch);
2718+
assert_eq!(dead.events.len(), 1);
2719+
q.mark_complete(ch);
2720+
// Retry state is cleared so fresh traffic isn't throttled.
2721+
assert!(!q.retry_counts.contains_key(&ch));
2722+
assert!(!q.retry_after.contains_key(&ch));
2723+
}
2724+
26932725
#[test]
26942726
fn test_retry_throttle_blocks_requeue_channel() {
26952727
let mut q = EventQueue::new(DedupMode::Queue);

‎crates/buzz-agent/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Everything is environment variables. No flags, no config files. (We are a subpro
147147
| `BUZZ_AGENT_MAX_OUTPUT_TOKENS` | `32768` | Per LLM call. Headroom for large tool-call inputs (e.g. file writes via heredoc); Sonnet 4 / Opus 4 cap at 64K. |
148148
| `BUZZ_AGENT_MAX_CONTEXT_TOKENS` | `200000` | Provider context window used by the handoff gate. |
149149
| `BUZZ_AGENT_MAX_HANDOFFS` | `10` | Max context handoffs per session before falling back to truncation. |
150-
| `BUZZ_AGENT_LLM_TIMEOUT_SECS` | `120` | |
150+
| `BUZZ_AGENT_LLM_TIMEOUT_SECS` | `240` | |
151151
| `BUZZ_AGENT_TOOL_TIMEOUT_SECS` | `660` | Per-tool call timeout in seconds |
152152
| `BUZZ_AGENT_MAX_PARALLEL_TOOLS` | `8` | Max concurrent tool calls per turn (1 = sequential) |
153153
| `BUZZ_AGENT_MAX_SESSIONS` | unlimited | Max concurrent ACP sessions. Sessions are cheap; default has no cap. |
@@ -244,7 +244,7 @@ The trust boundary is **the operator who launched the agent**. The harness, MCP
244244
| Tool schema bytes | 4 KiB | `MAX_SCHEMA_BYTES` (oversize → replaced with `{}`) |
245245
| Tool calls per turn | 64 | `MAX_TOOL_CALLS_PER_TURN` |
246246
| Loop rounds | 0 (unlimited) | `BUZZ_AGENT_MAX_ROUNDS` |
247-
| LLM call timeout | 120 s | `BUZZ_AGENT_LLM_TIMEOUT_SECS` |
247+
| LLM call timeout | 240 s | `BUZZ_AGENT_LLM_TIMEOUT_SECS` |
248248
| Tool call timeout | 660 s | `BUZZ_AGENT_TOOL_TIMEOUT_SECS` |
249249

250250
## What This Is NOT

‎crates/buzz-agent/src/config.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Config {
164164
openai_api,
165165
max_rounds: parse_env("BUZZ_AGENT_MAX_ROUNDS", 0)?,
166166
max_output_tokens: parse_env("BUZZ_AGENT_MAX_OUTPUT_TOKENS", 32_768)?,
167-
llm_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_LLM_TIMEOUT_SECS", 120)?),
167+
llm_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_LLM_TIMEOUT_SECS", 240)?),
168168
tool_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_TOOL_TIMEOUT_SECS", 660)?),
169169
mcp_init_timeout: Duration::from_secs(parse_env(
170170
"BUZZ_AGENT_MCP_INIT_TIMEOUT_SECS",

‎crates/buzz-core/src/kind.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ pub const RELAY_ADMIN_ADD_MEMBER: u32 = 9030;
187187
pub const RELAY_ADMIN_REMOVE_MEMBER: u32 = 9031;
188188
/// NIP-43: Change the role of an existing relay member.
189189
pub const RELAY_ADMIN_CHANGE_ROLE: u32 = 9032;
190+
/// Buzz: Set the workspace profile (icon). Admin/owner-signed command.
191+
pub const RELAY_ADMIN_SET_WORKSPACE_PROFILE: u32 = 9033;
190192
// NIP-43 relay membership announcement events (relay-signed)
191193
/// NIP-43: Relay membership list snapshot (relay-signed, replaceable by convention).
192194
pub const KIND_NIP43_MEMBERSHIP_LIST: u32 = 13534;
@@ -455,6 +457,7 @@ pub const ALL_KINDS: &[u32] = &[
455457
RELAY_ADMIN_ADD_MEMBER,
456458
RELAY_ADMIN_REMOVE_MEMBER,
457459
RELAY_ADMIN_CHANGE_ROLE,
460+
RELAY_ADMIN_SET_WORKSPACE_PROFILE,
458461
KIND_NIP43_MEMBERSHIP_LIST,
459462
KIND_NIP43_MEMBER_ADDED,
460463
KIND_NIP43_MEMBER_REMOVED,
@@ -568,11 +571,15 @@ pub const fn is_workflow_execution_kind(kind: u32) -> bool {
568571
kind >= KIND_WORKFLOW_TRIGGERED && kind <= KIND_WORKFLOW_APPROVAL_DENIED
569572
}
570573

571-
/// Returns `true` if `kind` is a NIP-43 relay membership admin command (9030–9032).
574+
/// Returns `true` if `kind` is a NIP-43 relay membership admin command (9030–9032)
575+
/// or the Buzz workspace-profile admin command (9033).
572576
pub const fn is_relay_admin_kind(kind: u32) -> bool {
573577
matches!(
574578
kind,
575-
RELAY_ADMIN_ADD_MEMBER | RELAY_ADMIN_REMOVE_MEMBER | RELAY_ADMIN_CHANGE_ROLE
579+
RELAY_ADMIN_ADD_MEMBER
580+
| RELAY_ADMIN_REMOVE_MEMBER
581+
| RELAY_ADMIN_CHANGE_ROLE
582+
| RELAY_ADMIN_SET_WORKSPACE_PROFILE
576583
)
577584
}
578585

0 commit comments

Comments
 (0)