c0re: schedule_prompt approval kind + worker + manager surface (#444 step 2)

This commit is contained in:
damocles 2026-05-26 01:11:36 +02:00 committed by Mara
commit aa7d8d9c9a
9 changed files with 612 additions and 4 deletions

View file

@ -62,6 +62,32 @@ pub fn parent_of(name: &str) -> Option<String> {
read().get(name).cloned().flatten()
}
/// True when `candidate` is `ancestor` or any descendant of
/// `ancestor` per the current topology. Walks parents from
/// `candidate` upward; the walk terminates at root or on a cycle
/// (cycle defence: bounded to 32 hops, more than any plausible
/// hive depth). Used by the cancel-authorization check in
/// `manager_server::handle_cancel_schedule` to enforce
/// "managers can cancel anything their subtree owns."
#[must_use]
pub fn is_descendant_of(candidate: &str, ancestor: &str) -> bool {
if candidate == ancestor {
return true;
}
let topo = read();
let mut cur = candidate.to_owned();
for _ in 0..32 {
let Some(parent) = topo.get(&cur).cloned().flatten() else {
return false;
};
if parent == ancestor {
return true;
}
cur = parent;
}
false
}
/// Persist the topology map. Sorted JSON output (BTreeMap is sorted by
/// key) keeps git diffs minimal across re-writes. Best-effort —
/// returns an `io::Error` so callers can decide whether a failure