hive-c0re: graceful agent stop — quiesce harness, flush state, then stop

This commit is contained in:
damocles 2026-06-19 08:43:08 +02:00 committed by mara
commit 03ea5d601b
8 changed files with 202 additions and 2 deletions

View file

@ -6,12 +6,21 @@
//! spinner); destroy delegates to `actions::destroy` (optionally purging).
use axum::{
extract::{Form, Path as AxumPath, State},
extract::{Form, Path as AxumPath, Query, State},
http::StatusCode,
response::{IntoResponse, Response},
};
use serde::Deserialize;
/// Query params for `post_kill`. `?graceful=1` routes to the graceful-stop
/// orchestration (quiesce the harness, flush `/state`, then container stop)
/// instead of an immediate hard stop. Defaults false → today's hard kill.
#[derive(Deserialize)]
pub(super) struct KillParams {
#[serde(default)]
graceful: bool,
}
use super::{AppState, error_response, guard_agent_name, strip_container_prefix};
use crate::{actions, lifecycle};
@ -75,11 +84,28 @@ where
pub(super) async fn post_kill(
State(state): State<AppState>,
AxumPath(name): AxumPath<String>,
Query(params): Query<KillParams>,
) -> Response {
let logical = strip_container_prefix(&name);
if let Some(reject) = guard_agent_name(&state, &logical).await {
return reject;
}
if params.graceful {
// Graceful stop: enqueue the quiesce orchestration (signal the harness
// → one stop-checkpoint turn → drain → container stop, with a timeout
// fallback to a hard stop). Serialised through the rebuild queue so it
// can't race an in-flight rebuild for the same agent, and its per-step
// progress surfaces on the queue snapshot + build log.
state.coord.rebuild_queue.enqueue(
crate::rebuild_queue::QueueKind::GracefulStop,
logical,
crate::rebuild_queue::QueueSource::Manual,
"manual via dashboard graceful stop".to_owned(),
None,
);
state.coord.emit_rebuild_queue_snapshot();
return (StatusCode::OK, "ok").into_response();
}
// Manager is stoppable from the dashboard like any other
// agent. The host's dashboard server keeps running (it's
// hive-c0re, not the manager container), per-agent approvals