Phase 5b: per-agent config flakes; approve validates + advances commit
This commit is contained in:
parent
22b65d35f3
commit
433c0d212e
6 changed files with 182 additions and 25 deletions
|
|
@ -20,7 +20,7 @@ pub async fn serve(socket: &Path, coord: Arc<Coordinator>) -> Result<()> {
|
|||
|
||||
let listener = UnixListener::bind(socket)
|
||||
.with_context(|| format!("bind admin socket {}", socket.display()))?;
|
||||
tracing::info!(socket = %socket.display(), agent_flake = %coord.agent_flake, "hive-c0re admin listening");
|
||||
tracing::info!(socket = %socket.display(), hyperhive_flake = %coord.hyperhive_flake, "hive-c0re admin listening");
|
||||
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await.context("accept connection")?;
|
||||
|
|
@ -61,7 +61,10 @@ async fn dispatch(req: &HostRequest, coord: &Coordinator) -> HostResponse {
|
|||
HostRequest::Spawn { name } => {
|
||||
tracing::info!(%name, "spawn");
|
||||
let agent_dir = coord.register_agent(name)?;
|
||||
if let Err(e) = lifecycle::spawn(name, &coord.agent_flake, &agent_dir).await {
|
||||
let config_dir = Coordinator::agent_config_dir(name);
|
||||
if let Err(e) =
|
||||
lifecycle::spawn(name, &coord.hyperhive_flake, &agent_dir, &config_dir).await
|
||||
{
|
||||
// Roll back socket registration if container creation failed.
|
||||
coord.unregister_agent(name);
|
||||
return Err(e);
|
||||
|
|
@ -77,18 +80,29 @@ async fn dispatch(req: &HostRequest, coord: &Coordinator) -> HostResponse {
|
|||
HostRequest::Rebuild { name } => {
|
||||
tracing::info!(%name, "rebuild");
|
||||
let agent_dir = coord.register_agent(name)?;
|
||||
lifecycle::rebuild(name, &coord.agent_flake, &agent_dir).await?;
|
||||
let config_dir = Coordinator::agent_config_dir(name);
|
||||
lifecycle::rebuild(name, &coord.hyperhive_flake, &agent_dir, &config_dir).await?;
|
||||
HostResponse::success()
|
||||
}
|
||||
HostRequest::List => HostResponse::list(lifecycle::list().await?),
|
||||
HostRequest::Pending => HostResponse::pending(coord.approvals.pending()?),
|
||||
HostRequest::Approve { id } => {
|
||||
let approval = coord.approvals.mark_approved(*id)?;
|
||||
tracing::info!(%approval.id, %approval.agent, %approval.commit_ref, "approval applied: rebuilding agent");
|
||||
tracing::info!(%approval.id, %approval.agent, %approval.commit_ref, "approval applied: advancing main + rebuilding");
|
||||
let agent_dir = coord.register_agent(&approval.agent)?;
|
||||
if let Err(e) =
|
||||
lifecycle::rebuild(&approval.agent, &coord.agent_flake, &agent_dir).await
|
||||
{
|
||||
let config_dir = Coordinator::agent_config_dir(&approval.agent);
|
||||
let result: anyhow::Result<()> = async {
|
||||
lifecycle::apply_commit(&config_dir, &approval.commit_ref).await?;
|
||||
lifecycle::rebuild(
|
||||
&approval.agent,
|
||||
&coord.hyperhive_flake,
|
||||
&agent_dir,
|
||||
&config_dir,
|
||||
)
|
||||
.await
|
||||
}
|
||||
.await;
|
||||
if let Err(e) = result {
|
||||
let note = format!("{e:#}");
|
||||
let _ = coord.approvals.mark_failed(approval.id, ¬e);
|
||||
return Err(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue