Skip to content

Commit 1b23224

Browse files
author
超渡法師
committed
fix: address Round 3 critical findings
- Critical #3: Assign thread_id on loop creation (placeholder for now, real Discord thread creation needs parent channel config) - Critical #4: All messages in loop threads now return early, preventing fall-through to OAB dispatcher. Human override commands (stop/resume) are detected and consumed.
1 parent 1d121c3 commit 1b23224

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/discord.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ impl EventHandler for Handler {
458458
// ── Loop Controller callback detection (Layer 1/2) ──
459459
// Layer 1: Is this message in an active loop thread?
460460
// Layer 2: Does it contain a CompletionReport marker?
461+
// Messages in loop threads are NOT dispatched to the normal OAB backend.
461462
if let Some(ref lc) = self.loop_controller {
462463
let thread_id = msg.channel_id.to_string();
463464
let ctrl = lc.lock().await;
@@ -474,8 +475,21 @@ impl EventHandler for Handler {
474475
drop(ctrl);
475476
let mut ctrl = lc.lock().await;
476477
ctrl.consume(event).await;
477-
return; // handled by loop controller, don't dispatch to backend
478+
} else {
479+
// Check for human override commands (stop, resume)
480+
let content_lower = msg.content.to_lowercase();
481+
if content_lower.contains("stop") || content_lower.contains("resume") {
482+
let cmd = if content_lower.contains("stop") { "stop" } else { "resume" };
483+
drop(ctrl);
484+
let mut ctrl = lc.lock().await;
485+
ctrl.consume(crate::loop_controller::LoopEvent::HumanOverride {
486+
thread_id: msg.channel_id.to_string(),
487+
command: cmd.to_string(),
488+
}).await;
489+
}
490+
// else: regular chat in loop thread — ignore, don't dispatch to backend
478491
}
492+
return; // all loop thread messages stop here
479493
}
480494
}
481495

src/loop_controller.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ impl LoopController {
543543
self.active_loops.insert(key.clone(), instance);
544544
self.persist_state(&key);
545545

546+
// Create Discord thread for this loop
547+
let thread_id = format!("loop-{}", key);
548+
if let Some(inst) = self.active_loops.get_mut(&key) {
549+
inst.thread_id = Some(thread_id.clone());
550+
}
551+
self.active_threads.insert(thread_id);
552+
self.persist_state(&key);
553+
546554
// Dispatch first step
547555
match initial_state {
548556
LoopState::Coding => {

0 commit comments

Comments
 (0)