refactor(#2591): make NodeKind the queue payload — drop JobPayload, agent into variants

This commit is contained in:
atlas 2026-07-20 23:00:20 +02:00 committed by mara
commit be2dfa8cd3
8 changed files with 233 additions and 177 deletions

View file

@ -63,13 +63,20 @@ fn stop_chain(agent: &str, graceful: bool, running: bool) -> Vec<NodeSpec> {
// `SetWanted` is the group root and owns the agent lease; the mechanical
// steps are its children (borrow the lease, run once it reaches `Finishing`,
// dep-ordered among themselves).
let mut n = vec![node(agent, NodeKind::SetWanted { up: false }, Vec::new())];
let a = || agent.to_owned();
let mut n = vec![node(
NodeKind::SetWanted {
agent: a(),
up: false,
},
Vec::new(),
)];
if graceful && running {
n.push(child(0, agent, NodeKind::Signal, Vec::new()));
n.push(child(0, agent, NodeKind::Drain, after_ok(1)));
n.push(child(0, agent, NodeKind::Reconcile, after_ok(2)));
n.push(child(0, NodeKind::Signal { agent: a() }, Vec::new()));
n.push(child(0, NodeKind::Drain { agent: a() }, after_ok(1)));
n.push(child(0, NodeKind::Reconcile { agent: a() }, after_ok(2)));
} else {
n.push(child(0, agent, NodeKind::Reconcile, Vec::new()));
n.push(child(0, NodeKind::Reconcile { agent: a() }, Vec::new()));
}
n
}
@ -79,14 +86,26 @@ fn stop_chain(agent: &str, graceful: bool, running: bool) -> Vec<NodeSpec> {
/// current derivations), otherwise a plain `Reconcile` (which starts a down
/// agent and noops an already-running one).
fn start_chain(agent: &str, running: bool, stale: bool) -> Vec<NodeSpec> {
let mut n = vec![node(agent, NodeKind::SetWanted { up: true }, Vec::new())];
let mut n = vec![node(
NodeKind::SetWanted {
agent: agent.to_owned(),
up: true,
},
Vec::new(),
)];
if !running && stale {
// Rebuild subtree after the SetWanted head (base = 1, so the rebuild's
// `Prebuild` root deps `after_ok(0)` = the head). `Prebuild` +
// `Reconcile` are their own group roots (top-level, per `rebuild_nodes`).
n.extend(rebuild_nodes(agent, true, 1));
} else {
n.push(child(0, agent, NodeKind::Reconcile, Vec::new()));
n.push(child(
0,
NodeKind::Reconcile {
agent: agent.to_owned(),
},
Vec::new(),
));
}
n
}
@ -101,22 +120,27 @@ fn start_chain(agent: &str, running: bool, stale: bool) -> Vec<NodeSpec> {
/// converges to intent — a stopped (`wanted = Off`) agent stays stopped,
/// a crashed (`wanted = Up`) agent comes back up.
fn restart_chain(agent: &str, graceful: bool, running: bool) -> Vec<NodeSpec> {
let a = || agent.to_owned();
if !running {
// Nothing to bounce — a lone Reconcile converges to intent.
return vec![node(agent, NodeKind::Reconcile, Vec::new())];
return vec![node(NodeKind::Reconcile { agent: a() }, Vec::new())];
}
// Running: mechanical stop then Reconcile. The first stop node is the group
// ROOT (no SetWanted head) and owns the agent lease; the rest are its
// children (borrow the lease, dep-ordered), so the bounce holds one
// continuous lease and `Reconcile` cancel-cascades if a stop step fails.
let mut n = vec![if graceful {
node(agent, NodeKind::Signal, Vec::new())
node(NodeKind::Signal { agent: a() }, Vec::new())
} else {
node(agent, NodeKind::StopForUpdate, Vec::new())
node(NodeKind::StopForUpdate { agent: a() }, Vec::new())
}];
if graceful {
n.push(child(0, agent, NodeKind::Drain, Vec::new()));
n.push(child(0, agent, NodeKind::StopForUpdate, after_ok(1)));
n.push(child(0, NodeKind::Drain { agent: a() }, Vec::new()));
n.push(child(
0,
NodeKind::StopForUpdate { agent: a() },
after_ok(1),
));
}
// `Reconcile` gates on the last mechanical step. When the only step is the
// root itself (non-graceful, `StopForUpdate` == index 0), the parent gate
@ -128,7 +152,7 @@ fn restart_chain(agent: &str, graceful: bool, running: bool) -> Vec<NodeSpec> {
} else {
Vec::new()
};
n.push(child(0, agent, NodeKind::Reconcile, deps));
n.push(child(0, NodeKind::Reconcile { agent: a() }, deps));
n
}
@ -151,7 +175,6 @@ fn concat_subgraphs(chains: Vec<Vec<NodeSpec>>) -> Vec<NodeSpec> {
})
.collect();
out.push(NodeSpec {
agent: spec.agent,
kind: spec.kind,
deps,
// Rebase the structural parent by the same offset (a subgraph