Watch
0
0
Fork
You've already forked hyperhive
0

hive-subagent-mcp: publish each subagent's run state to the swarm queue

This commit is contained in:
damocles 2026-11-15 15:57:00 +01:00 • committed by mara
commit 1652959741

View file

@ -738,6 +738,9 @@ impl State {
/// here is what makes a signal for a session that already ended a 404
/// rather than a late stop reason recorded against it.
fn finish_turn(&self, name: &str, end: &TurnEnd) {
if let Some(term) = &self.term {
term.finished(name, exit_status(end));
}
self.revoke_signal_token(name);
let mut killed = self.killed.lock().unwrap_or_else(PoisonError::into_inner);
match end {
@ -755,6 +758,15 @@ impl State {
.remove(name);
}
/// Tell the swarm `name`'s run began, with the model and effort `info`
/// names. The end is reported by `finish_turn`, which every run's end goes
/// through; the gaps between a goal run's turns are not an end.
fn announce_running(&self, name: &str, info: &Arc<crate::swarm_term::RunInfo>) {
if let Some(term) = &self.term {
term.running(name, info);
}
}
/// The signal `name`'s last turn died on, if it died on one.
fn killed_by(&self, name: &str) -> Option<i32> {
self.killed
@ -1853,6 +1865,19 @@ impl LivenessSink {
}
}
/// The exit status a run's end reports to the swarm: `0` when it completed,
/// nothing when a signal killed it, and `1` for any other failure. A failed
/// turn's own exit code is not kept on [`TurnEnd`] (it carries the message
/// shown to the caller), and an ACP failure has no process status at all, so
/// the swarm sees "failed" and the end todo has the detail.
fn exit_status(end: &TurnEnd) -> Option<i32> {
match end {
TurnEnd::Complete => Some(0),
TurnEnd::Killed { .. } => None,
TurnEnd::Failed(_) => Some(1),
}
}
/// What a run's rows say about how it was started: its `config`'s model and
/// effort, which the swarm shows beside the subagent's name.
fn run_info(config: &Config) -> Arc<crate::swarm_term::RunInfo> {
@ -1924,6 +1949,7 @@ fn spawn_and_track(
};
let info = run_info(config);
state.announce_running(name, &info);
let config = config.clone();
let state = Arc::clone(state);
let task_name = name.to_owned();
@ -2040,6 +2066,7 @@ fn spawn_and_track_acp(
state.note_event(name);
let info = run_info(&config);
state.announce_running(name, &info);
let state = Arc::clone(state);
let task_name = name.to_owned();
tokio::spawn(async move {
@ -3164,6 +3191,15 @@ mod tests {
}
}
/// What the swarm is told when a run ends: success is 0, a signal is no
/// code at all, and any other failure is 1.
#[test]
fn a_runs_end_reports_its_exit_status_to_the_swarm() {
assert_eq!(exit_status(&TurnEnd::Complete), Some(0));
assert_eq!(exit_status(&TurnEnd::Killed { signal: 9 }), None);
assert_eq!(exit_status(&TurnEnd::Failed("boom".to_owned())), Some(1));
}
#[test]
fn classify_end_separates_a_signalled_child_from_a_clean_one() {
assert_eq!(classify_end(Ok(()), None), TurnEnd::Complete);