Watch
0
0
Fork
You've already forked hyperhive
0

reconcile: start a stopped harness inside a running container

hive-priv gains AgentHarness { agent_name, action: probe | start }, which
runs systemctl -M h-<name> against the fixed unit hive-agent.service.
run_reconcile and the 1-min tick read the unit for a running wanted-up
agent and start it when it is inactive or failed. A hive-priv without the
op reads as unknown state and leaves reconcile container-only.
This commit is contained in:
atlas 2026-11-19 01:42:18 +01:00 • committed by mara
commit 36515c289d

View file

@ -29,6 +29,18 @@ pub const PAUSED_MARKER_FILE: &str = "paused";
/// Sub-agent container prefix. System container name = `h-<agent_name>`.
pub const AGENT_PREFIX: &str = "h-";
/// What [`PrivRequest::AgentHarness`] does to the agent's harness unit
/// (`hive-agent.service` inside the agent's container).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum HarnessAction {
/// Read the unit's `LoadState` and `ActiveState`, returned in `stdout`
/// as `key=value` lines.
Probe,
/// Queue a start of the unit without waiting for it to come up.
Start,
}
/// Lifecycle verb for [`PrivRequest::ControlInfraContainer`]. Maps directly
/// to `systemctl <verb> <unit>`, where the unit comes from
/// [`InfraContainer::service_unit`].
@ -459,6 +471,16 @@ pub enum PrivRequest {
paused: bool,
},
/// Probe or start the harness unit `hive-agent.service` inside `agent_name`'s
/// container, through `systemctl -M h-<agent_name>`. The unit name is
/// fixed in hive-priv; the request carries only the agent and the verb.
/// An older hive-priv answers an unknown-op error.
AgentHarness {
/// Logical agent name (validated by `validate_agent_name`).
agent_name: String,
action: HarnessAction,
},
/// Start / stop a hive infrastructure service on the host via
/// `systemctl <action> <unit>`, the unit derived from the variant. The
/// [`InfraContainer`] enum is the allowlist — serde rejects unknown /
@ -716,7 +738,37 @@ pub enum PrivEvent {
mod tests {
use hive_types::NixBuilds;
use super::{InfraContainer, PrivRequest, valid_closure_path, valid_meta_rev};
use super::{HarnessAction, InfraContainer, PrivRequest, valid_closure_path, valid_meta_rev};
/// The harness op's wire form: the verb is lowercase and the request
/// carries no unit name; an unknown verb is refused at decode.
#[test]
fn the_harness_op_carries_an_agent_and_a_verb_only() {
for (verb, action) in [
("probe", HarnessAction::Probe),
("start", HarnessAction::Start),
] {
let wire =
serde_json::json!({"op": "agent_harness", "agent_name": "iris", "action": verb});
let PrivRequest::AgentHarness {
agent_name,
action: got,
} = serde_json::from_value(wire.clone()).expect("decodes")
else {
panic!("variant");
};
assert_eq!((agent_name.as_str(), got), ("iris", action));
let again = serde_json::to_value(PrivRequest::AgentHarness {
agent_name,
action: got,
})
.expect("encodes");
assert_eq!(again, wire);
}
let stop =
serde_json::json!({"op": "agent_harness", "agent_name": "iris", "action": "stop"});
assert!(serde_json::from_value::<PrivRequest>(stop).is_err());
}
/// A request from a hive-c0re that predates the field decodes with the
/// agent's namespace left to hive-priv, and the field round-trips.