refactor(agent): remove vestigial turn_lock (serve loop is single-driver)
This commit is contained in:
parent
66f5b8720d
commit
efaf56c2d5
2 changed files with 3 additions and 21 deletions
|
|
@ -8,7 +8,6 @@ use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use hive_ag3nt::web_ui::TurnLock;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
@ -429,7 +428,6 @@ async fn serve_main<S: Surface>(socket: &Path, poll_ms: u64) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let files = turn::TurnFiles::prepare(socket, &label).await?;
|
let files = turn::TurnFiles::prepare(socket, &label).await?;
|
||||||
let turn_lock: TurnLock = Arc::new(tokio::sync::Mutex::new(()));
|
|
||||||
// Plugin install failures come back as a Vec<String> — route each
|
// Plugin install failures come back as a Vec<String> — route each
|
||||||
// through `<parent>` via the `send_to_parent` failure-notify path.
|
// through `<parent>` via the `send_to_parent` failure-notify path.
|
||||||
// The broker resolves `<parent>` per `topology::parent_of`;
|
// The broker resolves `<parent>` per `topology::parent_of`;
|
||||||
|
|
@ -477,7 +475,6 @@ async fn serve_main<S: Surface>(socket: &Path, poll_ms: u64) -> Result<()> {
|
||||||
bus,
|
bus,
|
||||||
stats,
|
stats,
|
||||||
&files,
|
&files,
|
||||||
turn_lock,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
@ -499,7 +496,6 @@ async fn serve_loop<S: Surface>(
|
||||||
bus: Bus,
|
bus: Bus,
|
||||||
stats: Option<TurnStats>,
|
stats: Option<TurnStats>,
|
||||||
files: &turn::TurnFiles,
|
files: &turn::TurnFiles,
|
||||||
turn_lock: TurnLock,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
tracing::info!(socket = %socket.display(), "harness serve");
|
tracing::info!(socket = %socket.display(), "harness serve");
|
||||||
S::requeue_inflight(socket).await;
|
S::requeue_inflight(socket).await;
|
||||||
|
|
@ -520,10 +516,7 @@ async fn serve_loop<S: Surface>(
|
||||||
// Idle: no message this poll. Service a queued operator
|
// Idle: no message this poll. Service a queued operator
|
||||||
// `/compact` here so it runs even when no turn is driving
|
// `/compact` here so it runs even when no turn is driving
|
||||||
// (the in-flight case is handled at the end of drive_turn).
|
// (the in-flight case is handled at the end of drive_turn).
|
||||||
let compacted = {
|
let compacted = turn::run_pending_compact(files, &bus, &session).await;
|
||||||
let _guard = turn_lock.lock().await;
|
|
||||||
turn::run_pending_compact(files, &bus, &session).await
|
|
||||||
};
|
|
||||||
if !compacted {
|
if !compacted {
|
||||||
tokio::time::sleep(interval).await;
|
tokio::time::sleep(interval).await;
|
||||||
}
|
}
|
||||||
|
|
@ -547,7 +540,6 @@ async fn serve_loop<S: Surface>(
|
||||||
&bus,
|
&bus,
|
||||||
stats.as_ref(),
|
stats.as_ref(),
|
||||||
files,
|
files,
|
||||||
&turn_lock,
|
|
||||||
&session,
|
&session,
|
||||||
graceful_stop_message(),
|
graceful_stop_message(),
|
||||||
)
|
)
|
||||||
|
|
@ -558,7 +550,7 @@ async fn serve_loop<S: Surface>(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let ctrl =
|
let ctrl =
|
||||||
handle_turn::<S>(socket, &bus, stats.as_ref(), files, &turn_lock, &session, next).await;
|
handle_turn::<S>(socket, &bus, stats.as_ref(), files, &session, next).await;
|
||||||
if ctrl.auth_failed {
|
if ctrl.auth_failed {
|
||||||
*login_state.lock().unwrap() = LoginState::NeedsLogin;
|
*login_state.lock().unwrap() = LoginState::NeedsLogin;
|
||||||
login::wait_for_login(
|
login::wait_for_login(
|
||||||
|
|
@ -586,7 +578,6 @@ async fn handle_turn<S: Surface>(
|
||||||
bus: &Bus,
|
bus: &Bus,
|
||||||
stats: Option<&TurnStats>,
|
stats: Option<&TurnStats>,
|
||||||
files: &turn::TurnFiles,
|
files: &turn::TurnFiles,
|
||||||
turn_lock: &TurnLock,
|
|
||||||
session: &turn::AgentSession,
|
session: &turn::AgentSession,
|
||||||
first: hive_sh4re::DeliveredMessage,
|
first: hive_sh4re::DeliveredMessage,
|
||||||
) -> TurnControl {
|
) -> TurnControl {
|
||||||
|
|
@ -607,10 +598,7 @@ async fn handle_turn<S: Surface>(
|
||||||
let started_instant = std::time::Instant::now();
|
let started_instant = std::time::Instant::now();
|
||||||
let model_at_start = bus.model();
|
let model_at_start = bus.model();
|
||||||
let prompt = serve_common::format_wake_prompt(msg_id, &from, &body, unread, redelivered);
|
let prompt = serve_common::format_wake_prompt(msg_id, &from, &body, unread, redelivered);
|
||||||
let outcome = {
|
let outcome = turn::drive_turn(&prompt, files, bus, session).await;
|
||||||
let _guard = turn_lock.lock().await;
|
|
||||||
turn::drive_turn(&prompt, files, bus, session).await
|
|
||||||
};
|
|
||||||
turn::emit_turn_end(bus, &outcome);
|
turn::emit_turn_end(bus, &outcome);
|
||||||
bus.set_state(TurnState::Idle);
|
bus.set_state(TurnState::Idle);
|
||||||
if matches!(
|
if matches!(
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,6 @@ const SOCKET_FETCH_TIMEOUT: std::time::Duration = std::time::Duration::from_secs
|
||||||
/// render.
|
/// render.
|
||||||
pub type LoginStateCell = Arc<Mutex<LoginState>>;
|
pub type LoginStateCell = Arc<Mutex<LoginState>>;
|
||||||
|
|
||||||
/// Shared turn lock. The serve loop acquires this (as an async mutex) for the
|
|
||||||
/// duration of every `drive_turn` call. The `/api/compact` handler tries
|
|
||||||
/// `try_lock()` and rejects immediately if a turn is in flight, preventing
|
|
||||||
/// concurrent access to the claude session.
|
|
||||||
pub type TurnLock = Arc<tokio::sync::Mutex<()>>;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState {
|
struct AppState {
|
||||||
label: String,
|
label: String,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue