Fix: reap stale agent pid files in poc-hook

scan_pid_files was removed as dead code but it was actually needed
by the hook path — the bug was that it was never wired in. Add
reap_agent_pids() directly to poc-hook.rs and call it on every
UserPromptSubmit. Kills timed-out agents (10min) and cleans up
pid files for dead processes.

Also remove dead subconscious/subconscious.rs (420 lines) — was
forked to claude/agent_cycles.rs and never removed.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 13:27:59 -04:00
parent 39965556dd
commit f4def8d03b
3 changed files with 41 additions and 421 deletions

View file

@ -83,6 +83,46 @@ fn check_notifications() {
}
}
/// Check for stale agent processes in a state dir.
/// Cleans up pid files for dead processes and kills timed-out ones.
fn reap_agent_pids(state_dir: &std::path::Path, timeout_secs: u64) {
let Ok(entries) = fs::read_dir(state_dir) else { return };
for entry in entries.flatten() {
let name = entry.file_name();
let name_str = name.to_string_lossy();
let Some(pid_str) = name_str.strip_prefix("pid-") else { continue };
let Ok(pid) = pid_str.parse::<i32>() else { continue };
if unsafe { libc::kill(pid, 0) } != 0 {
fs::remove_file(entry.path()).ok();
continue;
}
if timeout_secs > 0 {
if let Ok(meta) = entry.metadata() {
if let Ok(modified) = meta.modified() {
if modified.elapsed().unwrap_or_default().as_secs() > timeout_secs {
unsafe { libc::kill(pid, libc::SIGTERM); }
fs::remove_file(entry.path()).ok();
}
}
}
}
}
}
/// Reap all agent output directories.
fn reap_all_agents() {
let agent_output = poc_memory::store::memory_dir().join("agent-output");
if let Ok(entries) = fs::read_dir(&agent_output) {
for entry in entries.flatten() {
if entry.file_type().map_or(false, |t| t.is_dir()) {
reap_agent_pids(&entry.path(), 600); // 10 min timeout
}
}
}
}
/// Check if enough new conversation has accumulated to trigger an observation run.
fn maybe_trigger_observation(transcript: &PathBuf) {
let cursor_file = poc_memory::store::memory_dir().join("observation-cursor");
@ -189,6 +229,7 @@ fn main() {
"UserPromptSubmit" => {
signal_user();
check_notifications();
reap_all_agents();
print!("{}", poc_memory::memory_search::run_hook(&input));
if let Some(ref t) = transcript {