Skip to content

Commit db5617d

Browse files
morgmartclaude
andauthored
fix(desktop): emit singular mention feed category so alerts route correctly (#6665)
## Problem Mentions — and thread replies that @-mention you — played the **Needs action** sound instead of the **@Mentions** sound. Reported by @morgmart: "I set Needs action to a different sound and it's the only one I ever hear." ## Root cause Two vocabularies got conflated in #475: - **Section / filter vocabulary** (plural): `mentions`, `needs_action`, `activity`, `agent_activity` — the shape of `FeedSections`, the `--types` filter, and the agent-facing CLI docs. - **Per-item category vocabulary** (singular for mention): `mention`, `needs_action`, `activity`, `agent_activity` — the `FeedItemCategory` contract in `desktop/src/shared/api/types.ts`, unchanged since #12. The Tauri feed builder reused the filter string `"mentions"` as each mention item's `category`. Only one word differs between the vocabularies, so only mentions broke. Every frontend consumer compares against the singular, so real mentions never matched and fell through to the resolver's `needs_action` fallback. The E2E mock bridge emits the singular form, so tests never saw the drift. ### Symptoms this fixes (all from the one mislabel) - Mentions and mentioning thread replies played the Needs-action sound - Mention notifications used the Needs-action title format - Mentions in muted channels were suppressed (the mute-bypass never fired) - Inbox / Home feed labelled mentions "Channel update" - Channel activity popover's mentions list was always empty ## Fix **Fix the owner, not the symptoms.** `FeedItemInfo.category` becomes a `FeedItemCategory` enum whose serde form is exactly the TS union, so a misspelled category can't compile at the producer. A serialization test pins each variant to its wire string. **Frontend:** `slotForFeedKind` maps every known category explicitly. The `needs_action` fallback for unknown categories is **kept on purpose** — a contract drift should cost the user the wrong sound, not a missed alert — but it now `console.warn`s so the drift is visible to developers instead of masquerading as intended behavior. `e2eBridge.ts` and `tauri.ts` now derive the category type from `types.ts` instead of retyping it. Not touched: the plural `--types` filter and `FeedSections` keys. Those are the section vocabulary and are correct as-is. ## Verification - `just ci` green (file-size ratchet, Rust/Tauri/desktop/mobile tests, desktop + web builds) - New tests: 2 Rust (`feed_item_category_serializes_to_frontend_contract`, `feed_item_from_event_carries_singular_mention_category`), 3 TS in `sound.test.mjs` incl. one that feeds the old `"mentions"` string and asserts fallback + warning - **Runtime, dev build against the production relay:** controlled test from an agent identity into a test channel — - mention in channel → @Mentions sound, inbox shows "Mentioned in" ✅ (was Needs-action) - thread reply with mention → @Mentions sound, once ✅ (was Needs-action) - plain thread reply in the channel being viewed → silent, as designed ✅ ## Reviewers - @tlongwell-block — #475 introduced the plural category; please confirm it wasn't intentional - @wesbillman — owner of the original `FeedItemCategory` contract (#12) and most of the feed builder - @taylorkmho — owner of the sound-slot model and resolver (#968); the fallback-with-warning shape is the part to weigh in on - cc @klopez4212 --------- Signed-off-by: morgmart <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 01091c1 commit db5617d

7 files changed

Lines changed: 145 additions & 13 deletions

File tree

‎desktop/src-tauri/src/commands/messages.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
events,
1414
managed_agents::{find_managed_agent_mut, load_managed_agents, ManagedAgentRecord},
1515
models::{
16-
FeedItemInfo, FeedMeta, FeedResponse, FeedSections, SearchResponse,
16+
FeedItemCategory, FeedItemInfo, FeedMeta, FeedResponse, FeedSections, SearchResponse,
1717
SendChannelMessageResponse, ThreadRepliesResponse,
1818
},
1919
nostr_convert,
@@ -138,14 +138,14 @@ pub async fn get_feed(
138138
let mentions: Vec<FeedItemInfo> = mention_events
139139
.iter()
140140
.map(|ev| {
141-
let mut item = feed_item_from_event(ev, "mentions");
141+
let mut item = feed_item_from_event(ev, FeedItemCategory::Mention);
142142
apply_link_preview_suppression(&mut item.tags, &item.id, &suppressed_mentions);
143143
item
144144
})
145145
.collect();
146146
let needs_action: Vec<FeedItemInfo> = approval_events
147147
.iter()
148-
.map(|ev| feed_item_from_event(ev, "needs_action"))
148+
.map(|ev| feed_item_from_event(ev, FeedItemCategory::NeedsAction))
149149
.collect();
150150

151151
let total = (mentions.len() + needs_action.len()) as u64;
@@ -966,7 +966,7 @@ fn tags_to_vec(ev: &nostr::Event) -> Vec<Vec<String>> {
966966
ev.tags.iter().map(|t| t.as_slice().to_vec()).collect()
967967
}
968968

969-
fn feed_item_from_event(ev: &nostr::Event, category: &str) -> FeedItemInfo {
969+
fn feed_item_from_event(ev: &nostr::Event, category: FeedItemCategory) -> FeedItemInfo {
970970
let channel_id = channel_id_from_tags(ev);
971971
FeedItemInfo {
972972
id: ev.id.to_hex(),
@@ -978,7 +978,7 @@ fn feed_item_from_event(ev: &nostr::Event, category: &str) -> FeedItemInfo {
978978
channel_name: String::new(),
979979
channel_type: None,
980980
tags: tags_to_vec(ev),
981-
category: category.to_string(),
981+
category,
982982
}
983983
}
984984
#[cfg(test)]

‎desktop/src-tauri/src/commands/messages_tests.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,43 @@ fn provided_thread_ref_validates_and_preserves_root_and_parent() {
236236
assert_eq!(thread_ref.parent_event_id.to_hex(), parent);
237237
assert!(thread_ref::provided_thread_ref("not-hex", &parent).is_err());
238238
}
239+
240+
/// `FeedItem.category` is a wire contract with the desktop frontend
241+
/// (`desktop/src/shared/api/types.ts`). The frontend routes notification
242+
/// sounds, titles, mute-bypass, and inbox labels off these exact strings, so
243+
/// the serialized form must stay singular `mention` — not the plural section
244+
/// name `mentions` used by `FeedSections` and the `--types` filter.
245+
#[test]
246+
fn feed_item_category_serializes_to_frontend_contract() {
247+
let cases = [
248+
(FeedItemCategory::Mention, "mention"),
249+
(FeedItemCategory::NeedsAction, "needs_action"),
250+
(FeedItemCategory::Activity, "activity"),
251+
(FeedItemCategory::AgentActivity, "agent_activity"),
252+
];
253+
for (category, expected) in cases {
254+
let value = serde_json::to_value(category).expect("category should serialize");
255+
assert_eq!(value, serde_json::Value::String(expected.to_string()));
256+
}
257+
}
258+
259+
#[test]
260+
fn feed_item_from_event_carries_singular_mention_category() {
261+
let pubkey = Keys::generate().public_key().to_hex();
262+
let event = build_managed_agent_channel_message(
263+
uuid::Uuid::new_v4(),
264+
"hey @you",
265+
None,
266+
std::slice::from_ref(&pubkey),
267+
&[],
268+
)
269+
.expect("message should build")
270+
.sign_with_keys(&Keys::generate())
271+
.expect("message should sign");
272+
273+
let item = feed_item_from_event(&event, FeedItemCategory::Mention);
274+
let json = serde_json::to_value(&item).expect("feed item should serialize");
275+
276+
assert_eq!(json["category"], "mention");
277+
assert_eq!(json["id"], event.id.to_hex());
278+
}

‎desktop/src-tauri/src/models.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ pub struct ChannelMembersResponse {
178178
pub next_cursor: Option<String>,
179179
}
180180

181+
/// Per-item classification of a home feed entry.
182+
///
183+
/// This is the wire contract for `FeedItem.category` in the desktop frontend
184+
/// (`desktop/src/shared/api/types.ts`). It is distinct from the plural
185+
/// *section* vocabulary (`mentions`, `needs_action`, …) used by
186+
/// [`FeedSections`] and the `--types` filter: a mention item lives in the
187+
/// `mentions` section but carries the singular `mention` category.
188+
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
189+
#[serde(rename_all = "snake_case")]
190+
pub enum FeedItemCategory {
191+
Mention,
192+
NeedsAction,
193+
Activity,
194+
AgentActivity,
195+
}
196+
181197
#[derive(Serialize, Deserialize)]
182198
pub struct FeedItemInfo {
183199
pub id: String,
@@ -190,7 +206,7 @@ pub struct FeedItemInfo {
190206
#[serde(default)]
191207
pub channel_type: Option<String>,
192208
pub tags: Vec<Vec<String>>,
193-
pub category: String,
209+
pub category: FeedItemCategory,
194210
}
195211

196212
#[derive(Serialize, Deserialize)]

‎desktop/src/features/notifications/lib/sound.test.mjs‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import { shouldPlayNotificationSound } from "./sound.ts";
4+
import {
5+
KIND_APPROVAL_REQUEST,
6+
KIND_STREAM_MESSAGE_V2,
7+
KIND_JOB_ACCEPTED,
8+
} from "../../../shared/constants/kinds.ts";
9+
import { shouldPlayNotificationSound, slotForFeedKind } from "./sound.ts";
10+
11+
test("routes each feed category to its own sound slot", () => {
12+
assert.equal(slotForFeedKind(KIND_STREAM_MESSAGE_V2, "mention"), "mention");
13+
assert.equal(
14+
slotForFeedKind(KIND_APPROVAL_REQUEST, "needs_action"),
15+
"needs_action",
16+
);
17+
assert.equal(
18+
slotForFeedKind(KIND_STREAM_MESSAGE_V2, "activity"),
19+
"needs_action",
20+
);
21+
assert.equal(
22+
slotForFeedKind(KIND_STREAM_MESSAGE_V2, "agent_activity"),
23+
"needs_action",
24+
);
25+
});
26+
27+
test("agent job kinds pick their slot for non-mention categories", () => {
28+
assert.equal(
29+
slotForFeedKind(KIND_JOB_ACCEPTED, "agent_activity"),
30+
"job_accepted",
31+
);
32+
});
33+
34+
test("a mention outranks the agent job kind that carried it", () => {
35+
assert.equal(slotForFeedKind(KIND_JOB_ACCEPTED, "mention"), "mention");
36+
});
37+
38+
test("unknown category falls back to needs_action and warns", () => {
39+
const warnings = [];
40+
const originalWarn = console.warn;
41+
console.warn = (...args) => warnings.push(args.join(" "));
42+
try {
43+
// The backend once emitted the plural section name here; the fallback
44+
// keeps the user alerted while the warning keeps the drift visible.
45+
assert.equal(
46+
slotForFeedKind(KIND_STREAM_MESSAGE_V2, "mentions"),
47+
"needs_action",
48+
);
49+
} finally {
50+
console.warn = originalWarn;
51+
}
52+
assert.equal(warnings.length, 1);
53+
assert.match(warnings[0], /unknown feed item category "mentions"/);
54+
});
555

656
test("silences notifications from Huddle backing channels", () => {
757
const silentChannelIds = new Set(["active-huddle"]);

‎desktop/src/features/notifications/lib/sound.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
KIND_APPROVAL_REQUEST,
32
KIND_JOB_ACCEPTED,
43
KIND_JOB_ERROR,
54
KIND_JOB_PROGRESS,
@@ -115,6 +114,17 @@ export function resolveSlotSound(
115114
return prefs.sounds[slot];
116115
}
117116

117+
/**
118+
* Pick the sound slot for a home-feed item.
119+
*
120+
* `category` is the backend's per-item classification (`FeedItemCategory` in
121+
* `desktop/src-tauri/src/models.rs`). A mention always wins — being addressed
122+
* directly outranks whatever kind of event carried it, including agent job
123+
* events. Every other known category maps explicitly; anything else falls
124+
* back to `needs_action` so a contract drift costs the user the wrong sound
125+
* rather than a missed alert — and warns so the drift is visible to
126+
* developers instead of silently masquerading as intended.
127+
*/
118128
export function slotForFeedKind(
119129
kind: number,
120130
category: FeedItemCategory,
@@ -124,8 +134,20 @@ export function slotForFeedKind(
124134
if (kind === KIND_JOB_PROGRESS) return "job_progress";
125135
if (kind === KIND_JOB_RESULT) return "job_result";
126136
if (kind === KIND_JOB_ERROR) return "job_error";
127-
if (kind === KIND_APPROVAL_REQUEST) return "needs_action";
128-
return "needs_action";
137+
138+
switch (category) {
139+
case "needs_action":
140+
case "activity":
141+
case "agent_activity":
142+
return "needs_action";
143+
default: {
144+
const unexpected: never = category;
145+
console.warn(
146+
`[notifications] unknown feed item category ${JSON.stringify(unexpected)} for kind ${kind}; falling back to needs_action`,
147+
);
148+
return "needs_action";
149+
}
150+
}
129151
}
130152

131153
export function shouldPlayNotificationSound(

‎desktop/src/shared/api/tauri.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type RawFeedItem = {
6464
channel_name: string;
6565
channel_type: string | null;
6666
tags: string[][];
67-
category: "mention" | "needs_action" | "activity" | "agent_activity";
67+
category: HomeFeedResponse["feed"]["mentions"][number]["category"];
6868
};
6969

7070
type RawHomeFeedResponse = {

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { relayClient } from "@/shared/api/relayClient";
1919
import { activateRateLimit } from "@/shared/api/relayRateLimitGate";
2020
import { resolveAgentParallelism } from "@/features/agents/lib/agentParallelism";
2121
import type { ConnectionState } from "@/shared/api/relayClientShared";
22-
import type { ChannelTemplate, RelayEvent } from "@/shared/api/types";
22+
import type {
23+
ChannelTemplate,
24+
FeedItemCategory,
25+
RelayEvent,
26+
} from "@/shared/api/types";
2327
import { getMarkdownParseCount } from "@/shared/ui/markdown/nodeCache";
2428
import { syncAgentTurnsFromEvents } from "@/features/agents/activeAgentTurnsStore";
2529
import { recordTimeoutFromRejection } from "@/features/moderation/lib/timeoutStore";
@@ -771,7 +775,7 @@ type RawFeedItem = {
771775
// backend always emits the key, as `null` when unknown.
772776
channel_type?: string | null;
773777
tags: string[][];
774-
category: "mention" | "needs_action" | "activity" | "agent_activity";
778+
category: FeedItemCategory;
775779
};
776780

777781
type RawHomeFeedResponse = {

0 commit comments

Comments
 (0)