parallelize graceful agent drains, serialize container stops on fast lane; unify shutdown+checkpoint+compact prompt

This commit is contained in:
damocles 2026-06-29 19:19:20 +02:00 committed by mara
commit fc42f97691
5 changed files with 189 additions and 60 deletions

View file

@ -191,8 +191,13 @@ fn graceful_stop_message() -> hive_sh4re::DeliveredMessage {
hive_sh4re::DeliveredMessage {
from: "graceful-stop".into(),
body: "You are being gracefully stopped — the container will shut down after this turn, \
and new inbound messages are already fenced. Flush anything worth keeping to your \
durable /state files now, then end your turn. Do not start new long-running work."
and new inbound messages are already fenced. This is your one checkpoint turn: \
flush anything worth keeping into your durable /state files now update your \
notes / CLAUDE.md / TODO.md with in-flight task state, decisions made, important \
file paths, and whatever you'd need to resume cleanly later with only a summary \
of this conversation to go on. Do not start new work or reply to anyone; just \
write your notes and end your turn. The session may be compacted after this turn \
so a later cold start resumes cheaply."
.into(),
id: 0,
redelivered: false,
@ -541,6 +546,9 @@ async fn serve_loop<S: Surface>(
stats.as_ref(),
files,
&turn_lock,
// The graceful prompt IS the checkpoint — compact
// directly afterwards if needed, no second wake.
turn::CompactionMode::CompactOnly,
graceful_stop_message(),
)
.await;
@ -549,7 +557,16 @@ async fn serve_loop<S: Surface>(
}
},
};
let ctrl = handle_turn::<S>(socket, &bus, stats.as_ref(), files, &turn_lock, next).await;
let ctrl = handle_turn::<S>(
socket,
&bus,
stats.as_ref(),
files,
&turn_lock,
turn::CompactionMode::CheckpointThenCompact,
next,
)
.await;
if ctrl.auth_failed {
*login_state.lock().unwrap() = LoginState::NeedsLogin;
turn::wait_for_login(
@ -578,6 +595,7 @@ async fn handle_turn<S: Surface>(
stats: Option<&TurnStats>,
files: &turn::TurnFiles,
turn_lock: &TurnLock,
compaction: turn::CompactionMode,
first: hive_sh4re::DeliveredMessage,
) -> TurnControl {
let from = first.from;
@ -598,7 +616,7 @@ async fn handle_turn<S: Surface>(
let prompt = serve_common::format_wake_prompt(&from, &body, unread, redelivered);
let outcome = {
let _guard = turn_lock.lock().await;
turn::drive_turn(&prompt, files, bus).await
turn::drive_turn_with(&prompt, files, bus, compaction).await
};
turn::emit_turn_end(bus, &outcome);
bus.set_state(TurnState::Idle);