Watch
0
0
Fork
You've already forked hyperhive
0

hive-agent: keep the last turn's context size in the harness state file and drop the turn sqlite writes

This commit is contained in:
damocles 2026-11-18 02:24:13 +01:00
commit 5e5ff64b3c

View file

@ -183,16 +183,11 @@ pub struct Bus {
/// by the serve loop when it builds the session; unset on claude, whose
/// turn the swarm UI's cancel stops by signalling the `claude` process.
turn_canceller: Arc<OnceLock<hive_runtime::Canceller>>,
/// Current fresh-claude-session id (FK to `sessions.id`). Set by the
/// bin loop after minting a session row on a fresh start; stamped onto
/// every `turn_stats` row until the next fresh session. `None` before
/// the first fresh turn or when the stats db is unavailable.
session_id: Arc<Mutex<Option<i64>>>,
/// One-shot: `run_claude` flips this true when it creates a fresh claude
/// session (`--name <title>` on a title miss). The bin loop takes-and-
/// clears it after the turn to decide whether to mint a new `sessions`
/// row. Session identity itself is handled entirely in `turn.rs` via the
/// constant title + archive — this flag is purely a stats signal.
/// clears it after the turn for the OTEL session-boundary counter. Session
/// identity itself is handled entirely in `turn.rs` via the constant title
/// + archive — this flag is purely a metrics signal.
fresh_session: Arc<AtomicBool>,
/// Per-turn tool-call counter. Reset by the bin loop between
/// turns via `take_tool_calls`. Populated by `observe_stream` as
@ -260,7 +255,6 @@ impl Bus {
compact_pending: Arc::new(Mutex::new(None)),
post_compact_wake: Arc::new(Mutex::new(None)),
turn_canceller: Arc::default(),
session_id: Arc::new(Mutex::new(None)),
fresh_session: Arc::new(AtomicBool::new(false)),
tool_calls: Arc::new(Mutex::new(std::collections::HashMap::new())),
last_turn_ended_unix: Arc::new(AtomicI64::new(0)),
@ -347,32 +341,12 @@ impl Bus {
}
/// Take + clear the fresh-session one-shot. The bin loop calls this
/// after the turn to decide whether to mint a new `sessions` row.
/// after the turn for the OTEL session-boundary counter.
#[must_use]
pub fn take_fresh_session(&self) -> bool {
self.fresh_session.swap(false, Ordering::SeqCst)
}
/// Currently-active session id (FK to `sessions.id`), or `None`.
///
/// # Panics
///
/// Panics if the internal lock is poisoned.
#[must_use]
pub fn current_session_id(&self) -> Option<i64> {
*self.session_id.lock().unwrap()
}
/// Set the active session id after minting a `sessions` row on a
/// fresh start.
///
/// # Panics
///
/// Panics if the internal lock is poisoned.
pub fn set_session_id(&self, id: Option<i64>) {
*self.session_id.lock().unwrap() = id;
}
/// Currently-selected claude model name. Read on every turn so a
/// swarm change takes effect on the next turn.
///
@ -445,8 +419,9 @@ impl Bus {
/// Seed `last_ctx_usage` + `last_cost_usage` at startup without
/// emitting a SSE event. Used by the bin entrypoints to backfill
/// from the most recent `turn_stats` row so the per-agent web UI's
/// ctx + cost badges paint real numbers on cold load.
/// from the context size the last turn kept in the harness state file
/// (`harness_state::read_context_tokens`), so the ctx figure starts from
/// what the last turn saw rather than from nothing.
///
/// # Panics
///
@ -642,7 +617,7 @@ impl Bus {
/// Snapshot + clear the per-turn tool-call counter. The harness
/// calls this between turns to fold the breakdown into a
/// `turn_stats` row, then start the next turn with an empty map.
/// OTEL tool counts, then start the next turn with an empty map.
///
/// # Panics
///