Skip to content

Commit 5237e89

Browse files
committed
fix(memory): scope local inbox consumers by channel
1 parent d063daf commit 5237e89

3 files changed

Lines changed: 99 additions & 6 deletions

File tree

src/agent/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ impl AgentLogic {
20372037
let _ = memory_node
20382038
.send_packet(MemoryMessage::ListBackgroundJobs {
20392039
chat_id: Some(chat_id.to_string()),
2040-
channel: None,
2040+
channel: Some(inbound.channel.clone()),
20412041
limit: 10,
20422042
reply: SharedReply::new(tx),
20432043
})
@@ -2052,7 +2052,7 @@ impl AgentLogic {
20522052
.send_packet(MemoryMessage::ListClarificationTickets {
20532053
job_id: Some(job.job_id.clone()),
20542054
chat_id: Some(chat_id.to_string()),
2055-
channel: None,
2055+
channel: Some(inbound.channel.clone()),
20562056
status: Some("waiting".to_string()),
20572057
limit: 1,
20582058
reply: SharedReply::new(tx2),

src/channels/terminal_ui/run.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ pub(crate) fn run_ratatui_main(config: RatatuiMainConfig) -> io::Result<()> {
13821382
let crons_tx = crons_tx.clone();
13831383
let jobs_tx = jobs_tx.clone();
13841384
let notifications_tx = notifications_tx.clone();
1385+
let poll_channel_name = channel_name.clone();
13851386
let spawn_result = std::thread::Builder::new()
13861387
.name("ui-db-poller".into())
13871388
.spawn(move || {
@@ -1425,7 +1426,7 @@ pub(crate) fn run_ratatui_main(config: RatatuiMainConfig) -> io::Result<()> {
14251426
let _ = memory_node
14261427
.send_packet(crate::memory::MemoryMessage::ListBackgroundJobs {
14271428
chat_id: None,
1428-
channel: None,
1429+
channel: Some(poll_channel_name.clone()),
14291430
limit: 50,
14301431
reply: crate::memory::SharedReply::new(jtx),
14311432
})
@@ -1439,7 +1440,7 @@ pub(crate) fn run_ratatui_main(config: RatatuiMainConfig) -> io::Result<()> {
14391440
let _ = memory_node
14401441
.send_packet(crate::memory::MemoryMessage::ListNotifications {
14411442
chat_id: None,
1442-
channel: None,
1443+
channel: Some(poll_channel_name.clone()),
14431444
limit: 50,
14441445
unseen_only: false,
14451446
reply: crate::memory::SharedReply::new(ntx),

src/memory.rs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,8 +2315,8 @@ fn dropped_tool_call_ids(
23152315
#[cfg(test)]
23162316
mod root_thread_id_tests {
23172317
use super::{
2318-
is_root_session_thread_id, MemoryMessage, NotificationRecord, SharedReply,
2319-
SqliteMemoryActor,
2318+
is_root_session_thread_id, BackgroundJobRecord, ClarificationTicketRecord, MemoryMessage,
2319+
NotificationRecord, SharedReply, SqliteMemoryActor,
23202320
};
23212321
use crate::session::SessionManager;
23222322
use crate::traits::Memory;
@@ -2391,6 +2391,98 @@ mod root_thread_id_tests {
23912391

23922392
assert_eq!(rows.len(), 1);
23932393
assert_eq!(rows[0].notification_id, "tauri-notification");
2394+
2395+
for (id, channel, updated_at_ms) in [
2396+
("tauri-job", "tauri", 1_i64),
2397+
("terminal-job", "terminal", 2_i64),
2398+
] {
2399+
let (tx, rx) = tokio::sync::oneshot::channel();
2400+
node.send_packet(MemoryMessage::UpsertBackgroundJob {
2401+
record: BackgroundJobRecord {
2402+
job_id: id.to_string(),
2403+
kind: "test".to_string(),
2404+
chat_id: "chat-1".to_string(),
2405+
channel: channel.to_string(),
2406+
thread_id: None,
2407+
state: "waiting".to_string(),
2408+
payload_json: "{}".to_string(),
2409+
resume_after_restart: false,
2410+
detached: false,
2411+
last_error: None,
2412+
created_at_ms: updated_at_ms,
2413+
updated_at_ms,
2414+
},
2415+
reply: SharedReply::new(tx),
2416+
})
2417+
.await
2418+
.expect("enqueue background job");
2419+
rx.await
2420+
.expect("background job actor reply")
2421+
.expect("insert background job");
2422+
}
2423+
2424+
let (tx, rx) = tokio::sync::oneshot::channel();
2425+
node.send_packet(MemoryMessage::ListBackgroundJobs {
2426+
chat_id: None,
2427+
channel: Some("tauri".to_string()),
2428+
limit: 1,
2429+
reply: SharedReply::new(tx),
2430+
})
2431+
.await
2432+
.expect("enqueue background job list");
2433+
let jobs = rx
2434+
.await
2435+
.expect("background job actor reply")
2436+
.expect("list background jobs");
2437+
assert_eq!(jobs.len(), 1);
2438+
assert_eq!(jobs[0].job_id, "tauri-job");
2439+
2440+
for (id, channel, updated_at_ms) in [
2441+
("tauri-ticket", "tauri", 1_i64),
2442+
("terminal-ticket", "terminal", 2_i64),
2443+
] {
2444+
let (tx, rx) = tokio::sync::oneshot::channel();
2445+
node.send_packet(MemoryMessage::UpsertClarificationTicket {
2446+
record: ClarificationTicketRecord {
2447+
ticket_id: id.to_string(),
2448+
job_id: id.to_string(),
2449+
chat_id: "chat-1".to_string(),
2450+
channel: channel.to_string(),
2451+
thread_id: None,
2452+
tool_call_id: None,
2453+
prompt: "Test".to_string(),
2454+
choices_json: None,
2455+
response: None,
2456+
status: "waiting".to_string(),
2457+
created_at_ms: updated_at_ms,
2458+
updated_at_ms,
2459+
},
2460+
reply: SharedReply::new(tx),
2461+
})
2462+
.await
2463+
.expect("enqueue clarification ticket");
2464+
rx.await
2465+
.expect("clarification ticket actor reply")
2466+
.expect("insert clarification ticket");
2467+
}
2468+
2469+
let (tx, rx) = tokio::sync::oneshot::channel();
2470+
node.send_packet(MemoryMessage::ListClarificationTickets {
2471+
job_id: None,
2472+
chat_id: None,
2473+
channel: Some("tauri".to_string()),
2474+
status: None,
2475+
limit: 1,
2476+
reply: SharedReply::new(tx),
2477+
})
2478+
.await
2479+
.expect("enqueue clarification ticket list");
2480+
let tickets = rx
2481+
.await
2482+
.expect("clarification ticket actor reply")
2483+
.expect("list clarification tickets");
2484+
assert_eq!(tickets.len(), 1);
2485+
assert_eq!(tickets[0].ticket_id, "tauri-ticket");
23942486
}
23952487

23962488
#[tokio::test]

0 commit comments

Comments
 (0)