Unconscious agents: 60s idle timer, no cooldown

Gate unconscious agents on 60s of no conscious activity using
sleep_until() instead of polling. Remove COOLDOWN constant — once
idle, agents run back-to-back to keep the GPU busy.

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-10 02:39:55 -04:00
parent eae8d92918
commit 707f836ca0
2 changed files with 31 additions and 13 deletions

View file

@ -526,6 +526,8 @@ impl Mind {
.expect("Mind::run() called twice");
let mut sub_handle: Option<tokio::task::JoinHandle<()>> = None;
let mut unc_handle: Option<tokio::task::JoinHandle<()>> = None;
let mut unc_idle_deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(60);
let mut unc_idle = false;
loop {
let (timeout, has_input) = {
let me = self.shared.lock().unwrap();
@ -553,7 +555,13 @@ impl Mind {
}
}
_ = tokio::time::sleep_until(unc_idle_deadline), if !unc_idle && !self.config.no_agents => {
unc_idle = true;
}
Some((result, target)) = turn_rx.recv() => {
unc_idle_deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(60);
unc_idle = false;
let model_switch = {
let mut s = self.shared.lock().unwrap();
s.turn_handle = None;
@ -584,7 +592,7 @@ impl Mind {
s.trigger(&agent).await;
}));
}
if unc_handle.as_ref().map_or(true, |h| h.is_finished()) {
if unc_idle && unc_handle.as_ref().map_or(true, |h| h.is_finished()) {
let unc = self.unconscious.clone();
unc_handle = Some(tokio::spawn(async move {
unc.lock().await.trigger().await;