address review: drop backwards-compat request/response aliases, use canonical names

This commit is contained in:
damocles 2026-07-19 15:12:14 +02:00 committed by mara
commit 144912f8e0
14 changed files with 183 additions and 229 deletions

View file

@ -5,18 +5,14 @@
use std::sync::Arc;
use hive_agent_sock::AgentResponse;
use hive_agent_sock::Response;
use super::require_descendant;
use crate::coordinator::Coordinator;
/// `Start` — start a container, kicking its next turn. The caller must be an
/// ancestor of `name` in the topology (the root covers every agent).
pub(super) async fn handle_start(
coord: &Arc<Coordinator>,
agent: &str,
name: &str,
) -> AgentResponse {
pub(super) async fn handle_start(coord: &Arc<Coordinator>, agent: &str, name: &str) -> Response {
if let Some(err) = require_descendant(agent, name, "start") {
return err;
}
@ -31,18 +27,14 @@ pub(super) async fn handle_start(
format!("agent `{agent}` start tool"),
)
.await;
AgentResponse::Ok
Response::Ok
}
/// `Restart` — enqueue a restart for a container. The caller must be an
/// ancestor of `name` in the topology. The infra-container branch is
/// orthogonal: it is gated on the `infra_admin` capability and audited, so it
/// stays ahead of the topology guard.
pub(super) async fn handle_restart(
coord: &Arc<Coordinator>,
agent: &str,
name: &str,
) -> AgentResponse {
pub(super) async fn handle_restart(coord: &Arc<Coordinator>, agent: &str, name: &str) -> Response {
// Infra-container restart: an agent holding the `infra_admin`
// capability can restart a hive infrastructure container (hive-ci /
// hive-gateway / hive-forge / hive-matrix) by passing its name to the
@ -63,7 +55,7 @@ pub(super) async fn handle_restart(
format!("agent `{agent}` restart tool"),
)
.await;
AgentResponse::Ok
Response::Ok
}
/// Restart a hive infrastructure container on behalf of an agent that
@ -75,7 +67,7 @@ async fn handle_restart_infra(
coord: &Arc<Coordinator>,
agent: &str,
container: hive_priv_sock::InfraContainer,
) -> AgentResponse {
) -> Response {
let name = container.unit_name();
// Record the attempt in the operator-visible privileged-action audit
// trail, then emit a live `AuditEntryAdded` so the dashboard audit view
@ -97,7 +89,7 @@ async fn handle_restart_infra(
crate::audit_log::AuditOutcome::Err,
Some("denied: missing infra_admin capability"),
);
return AgentResponse::Err {
return Response::Err {
message: format!(
"restarting infra container `{name}` requires the `infra_admin` capability"
),
@ -107,23 +99,19 @@ async fn handle_restart_infra(
match crate::priv_client::restart_infra_container(container).await {
Ok(()) => {
audit(crate::audit_log::AuditOutcome::Ok, None);
AgentResponse::Ok
Response::Ok
}
Err(e) => {
let msg = format!("{e:#}");
audit(crate::audit_log::AuditOutcome::Err, Some(&msg));
AgentResponse::Err { message: msg }
Response::Err { message: msg }
}
}
}
/// `Kill` — kill a container, unregister it, notify the manager. The caller
/// must be an ancestor of `name` in the topology.
pub(super) async fn handle_kill(
coord: &Arc<Coordinator>,
agent: &str,
name: &str,
) -> AgentResponse {
pub(super) async fn handle_kill(coord: &Arc<Coordinator>, agent: &str, name: &str) -> Response {
if let Some(err) = require_descendant(agent, name, "kill") {
return err;
}
@ -144,9 +132,9 @@ pub(super) async fn handle_kill(
coord.notify_manager(&hive_sh4re::HelperEvent::Killed {
agent: name.to_owned(),
});
AgentResponse::Ok
Response::Ok
}
Err(e) => AgentResponse::Err {
Err(e) => Response::Err {
message: format!("{e:#}"),
},
}
@ -154,7 +142,7 @@ pub(super) async fn handle_kill(
/// `Update` — enqueue a rebuild for a container. The caller must be an
/// ancestor of `name` in the topology.
pub(super) fn handle_update(coord: &Arc<Coordinator>, agent: &str, name: &str) -> AgentResponse {
pub(super) fn handle_update(coord: &Arc<Coordinator>, agent: &str, name: &str) -> Response {
if let Some(err) = require_descendant(agent, name, "rebuild") {
return err;
}
@ -165,12 +153,12 @@ pub(super) fn handle_update(coord: &Arc<Coordinator>, agent: &str, name: &str) -
crate::job_queue::Source::Manual,
format!("agent `{agent}` update tool"),
);
AgentResponse::Ok
Response::Ok
}
/// `ListDescendants` — every topological descendant of `agent` with
/// its running/stopped state, parents before children.
pub(super) async fn handle_list_descendants(agent: &str) -> AgentResponse {
pub(super) async fn handle_list_descendants(agent: &str) -> Response {
tracing::debug!(%agent, "agent: list descendants");
// All containers known to nixos-container (running only).
let running_set: std::collections::HashSet<String> = match crate::lifecycle::list().await {
@ -182,7 +170,7 @@ pub(super) async fn handle_list_descendants(agent: &str) -> AgentResponse {
})
.collect(),
Err(e) => {
return AgentResponse::Err {
return Response::Err {
message: format!("list containers failed: {e:#}"),
};
}
@ -203,5 +191,5 @@ pub(super) async fn handle_list_descendants(agent: &str) -> AgentResponse {
hive_sh4re::ContainerInfo { name, running }
})
.collect();
AgentResponse::Containers { containers }
Response::Containers { containers }
}