Watch
0
0
Fork
You've already forked hyperhive
0

remove the unused reminder rollup request and the stale references to the stats page

This commit is contained in:
iris 2026-11-16 19:07:08 +01:00
commit 37f036ee7d
13 changed files with 26 additions and 117 deletions

View file

@ -227,8 +227,7 @@ Under `/var/lib/hyperhive/agents/<name>/`:
Retention, by the hourly `hive-agent::vacuum::run` sweep, which runs in-container Retention, by the hourly `hive-agent::vacuum::run` sweep, which runs in-container
because hive-c0re can't delete agent-owned files: it reaps delivered (soft-deleted) reminder because hive-c0re can't delete agent-owned files: it reaps delivered (soft-deleted) reminder
rows 14 days after delivery, kept that long only to serve rows 14 days after delivery, and reaps acked todo rows
the trailing-window `ReminderRollup` stats, and reaps acked todo rows
30 days after acking (long enough that only a genuinely quiet 30 days after acking (long enough that only a genuinely quiet
month triggers the "one spurious re-announcement" fallback a month triggers the "one spurious re-announcement" fallback a
reconciled producer like `disk_watch` relies on — see `todos.rs`'s reconciled producer like `disk_watch` relies on — see `todos.rs`'s

View file

@ -117,11 +117,6 @@ pub enum Request {
/// This agent's pending-reminder count — used by the pre-`remind` cap /// This agent's pending-reminder count — used by the pre-`remind` cap
/// check and the harness's own turn-stats sink. /// check and the harness's own turn-stats sink.
CountPendingReminders, CountPendingReminders,
/// Scheduled/delivered/pending reminder counts over a trailing
/// `since_secs` window (`0` = all time) — the harness's own `/api/stats`
/// reminder-activity chart data (was `hive-core-agent-sock`'s
/// `ReminderRollup` against the broker; now served from the local store).
ReminderRollup { since_secs: u64 },
/// Agent self-service request to compact the current session, mirroring /// Agent self-service request to compact the current session, mirroring
/// the `compact` MCP tool. Gated server-side: only /// the `compact` MCP tool. Gated server-side: only
/// honoured when the last completed turn's context usage is above 40% /// honoured when the last completed turn's context usage is above 40%
@ -158,10 +153,6 @@ pub enum Response {
LooseEnds { loose_ends: Vec<LooseEnd> }, LooseEnds { loose_ends: Vec<LooseEnd> },
/// `CountPendingReminders` result. /// `CountPendingReminders` result.
PendingRemindersCount { count: u64 }, PendingRemindersCount { count: u64 },
/// `ReminderRollup` result.
ReminderRollup {
stats: hive_sh4re::inbox::ReminderStats,
},
/// `Transcribe` result: the text spoken in the audio (empty for silence), /// `Transcribe` result: the text spoken in the audio (empty for silence),
/// and whether the service had it already. /// and whether the service had it already.
Transcript { text: String, cached: bool }, Transcript { text: String, cached: bool },

View file

@ -7,18 +7,14 @@
//! Unlike todos (discovered passively via `get_loose_ends`), a reminder is //! Unlike todos (discovered passively via `get_loose_ends`), a reminder is
//! *active push*: it must fire into the turn loop at `due_at` with its own //! *active push*: it must fire into the turn loop at `due_at` with its own
//! message body (see `reminder_timer.rs`). Delivery is *soft*-deleted //! message body (see `reminder_timer.rs`). Delivery is *soft*-deleted
//! (`sent_at` set, not `DELETE`) so the harness's own `/api/stats` reminder //! (`sent_at` set, not `DELETE`); a periodic prune (`vacuum.rs`) reaps old
//! rollup can still report scheduled/delivered/pending counts over a //! delivered rows so the table doesn't grow unbounded.
//! trailing window (mirrors the old c0re `ReminderStats` shape exactly). A
//! periodic prune (`vacuum.rs`) reaps old delivered rows so the table
//! doesn't grow unbounded.
use std::path::Path; use std::path::Path;
use std::sync::Mutex; use std::sync::Mutex;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use hive_sh4re::inbox::ReminderStats;
use hive_sh4re::wire_time; use hive_sh4re::wire_time;
use rusqlite::{Connection, params}; use rusqlite::{Connection, params};
@ -211,8 +207,8 @@ impl Reminders {
} }
/// Soft-delete: stamp `sent_at` so the row drops out of /// Soft-delete: stamp `sent_at` so the row drops out of
/// `count_pending`/`list_pending`/`due` but survives for the rollup /// `count_pending`/`list_pending`/`due` and is reaped later by
/// stats until `prune_delivered_older_than` reaps it. /// `prune_delivered_older_than`.
/// ///
/// # Errors /// # Errors
/// ///
@ -232,7 +228,7 @@ impl Reminders {
} }
/// Cancel a still-pending reminder by id (hard delete — it never /// Cancel a still-pending reminder by id (hard delete — it never
/// fired, so there's nothing to keep for the rollup). Returns the /// fired, so there's nothing to keep). Returns the
/// number of rows deleted (0 = unknown id, or already delivered). /// number of rows deleted (0 = unknown id, or already delivered).
/// ///
/// # Errors /// # Errors
@ -251,47 +247,6 @@ impl Reminders {
Ok(n) Ok(n)
} }
/// Scheduled/delivered/pending counts within the trailing
/// `since_secs` window (`0` = all time) — the local equivalent of the
/// old c0re `ReminderRollup` query, same `sent_at IS NULL/NOT NULL`
/// shape.
///
/// # Errors
///
/// Propagates the sqlite query failure.
///
/// # Panics
///
/// Panics if the connection mutex is poisoned.
pub fn rollup(&self, since_secs: i64) -> Result<ReminderStats> {
let conn = self.conn.lock().unwrap();
let cutoff = if since_secs > 0 {
Utc::now().timestamp().saturating_sub(since_secs)
} else {
i64::MIN
};
let scheduled: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1",
params![cutoff],
|row| row.get(0),
)?;
let delivered: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1 AND sent_at IS NOT NULL",
params![cutoff],
|row| row.get(0),
)?;
let pending: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1 AND sent_at IS NULL",
params![cutoff],
|row| row.get(0),
)?;
Ok(ReminderStats {
scheduled: u64::try_from(scheduled).unwrap_or(0),
delivered: u64::try_from(delivered).unwrap_or(0),
pending: u64::try_from(pending).unwrap_or(0),
})
}
/// Reap delivered rows older than `cutoff` (unix seconds) — called /// Reap delivered rows older than `cutoff` (unix seconds) — called
/// from `vacuum.rs`'s periodic sweep so the table doesn't grow /// from `vacuum.rs`'s periodic sweep so the table doesn't grow
/// unbounded. Returns the number of rows deleted. /// unbounded. Returns the number of rows deleted.
@ -404,16 +359,12 @@ mod tests {
} }
#[test] #[test]
fn mark_delivered_removes_from_pending_but_counts_in_rollup() { fn mark_delivered_removes_from_pending() {
let (_dir, s) = store(); let (_dir, s) = store();
let id = s.store("a", None, 100).unwrap(); let id = s.store("a", None, 100).unwrap();
s.mark_delivered(id).unwrap(); s.mark_delivered(id).unwrap();
assert_eq!(s.count_pending().unwrap(), 0); assert_eq!(s.count_pending().unwrap(), 0);
assert!(s.list_pending().unwrap().is_empty()); assert!(s.list_pending().unwrap().is_empty());
let rollup = s.rollup(0).unwrap();
assert_eq!(rollup.scheduled, 1);
assert_eq!(rollup.delivered, 1);
assert_eq!(rollup.pending, 0);
} }
#[test] #[test]

View file

@ -1,7 +1,7 @@
//! Shared connection setup for the harness's own sqlite writers. //! Shared connection setup for the harness's own sqlite writers.
//! //!
//! A write that overlaps another connection's lock (the stats page, the hourly //! A write that overlaps another connection's lock (the hourly vacuum, a
//! vacuum) fails at once with `SQLITE_BUSY` unless the connection has a busy //! reader) fails at once with `SQLITE_BUSY` unless the connection has a busy
//! timeout, so writers set [`BUSY_TIMEOUT`] to wait instead of dropping the row. //! timeout, so writers set [`BUSY_TIMEOUT`] to wait instead of dropping the row.
use std::time::Duration; use std::time::Duration;

View file

@ -60,8 +60,7 @@ fn socket_path() -> Option<PathBuf> {
} }
/// Dial this same in-agent socket from elsewhere IN THIS PROCESS — the /// Dial this same in-agent socket from elsewhere IN THIS PROCESS — the
/// harness's own `web_ui` endpoints (`api_todos`, `/api/stats` reminder /// harness's own `web_ui` endpoints (`api_todos`) and `Surface::post_turn_counts` all need read access to the
/// rollup) and `Surface::post_turn_counts` all need read access to the
/// `Todos`/`Reminders` stores this module owns behind an `Arc` on a /// `Todos`/`Reminders` stores this module owns behind an `Arc` on a
/// different spawned task, and a loopback dial is simpler than threading /// different spawned task, and a loopback dial is simpler than threading
/// those `Arc`s through every caller. One-shot, best-effort (no retry, /// those `Arc`s through every caller. One-shot, best-effort (no retry,
@ -275,7 +274,6 @@ fn dispatch(
Request::ListReminders => list_reminders(reminders), Request::ListReminders => list_reminders(reminders),
Request::CancelReminder { id } => cancel_reminder(reminders, id), Request::CancelReminder { id } => cancel_reminder(reminders, id),
Request::CountPendingReminders => count_pending_reminders(reminders), Request::CountPendingReminders => count_pending_reminders(reminders),
Request::ReminderRollup { since_secs } => reminder_rollup(reminders, since_secs),
Request::Compact { wake_prompt } => compact(bus, wake_prompt), Request::Compact { wake_prompt } => compact(bus, wake_prompt),
// Answered by `handle_conn` before this runs: it waits on the queue, // Answered by `handle_conn` before this runs: it waits on the queue,
// which this store-only function never does. // which this store-only function never does.
@ -338,19 +336,6 @@ fn count_pending_reminders(reminders: Option<&Reminders>) -> Response {
} }
} }
/// `ReminderRollup` handler: scheduled/delivered/pending counts over a
/// trailing `since_secs` window (`0` = all time).
fn reminder_rollup(reminders: Option<&Reminders>, since_secs: u64) -> Response {
let Some(r) = reminders else {
return no_reminders_store();
};
let since_secs = i64::try_from(since_secs).unwrap_or(i64::MAX);
match r.rollup(since_secs) {
Ok(stats) => Response::ReminderRollup { stats },
Err(e) => err(&e),
}
}
/// `UpsertTodo` handler: writes/refreshes a todo row, logs the outcome, and /// `UpsertTodo` handler: writes/refreshes a todo row, logs the outcome, and
/// fires `wake` on a new-or-changed upsert so the serve loop runs a turn. /// fires `wake` on a new-or-changed upsert so the serve loop runs a turn.
fn upsert_todo( fn upsert_todo(
@ -890,7 +875,6 @@ mod tests {
Request::ListReminders, Request::ListReminders,
Request::CancelReminder { id: 1 }, Request::CancelReminder { id: 1 },
Request::CountPendingReminders, Request::CountPendingReminders,
Request::ReminderRollup { since_secs: 0 },
]; ];
for req in reqs { for req in reqs {
let resp = dispatch(req, &todos, &wake, None, &bus); let resp = dispatch(req, &todos, &wake, None, &bus);
@ -924,10 +908,6 @@ mod tests {
panic!("one reminder, got {loose_ends:?}"); panic!("one reminder, got {loose_ends:?}");
}; };
assert_eq!(message, "check the deploy"); assert_eq!(message, "check the deploy");
assert!(matches!(
run(Request::ReminderRollup { since_secs: 0 }),
Response::ReminderRollup { .. }
));
assert_eq!(acked(&run(Request::CancelReminder { id: *id })), 1); assert_eq!(acked(&run(Request::CancelReminder { id: *id })), 1);
assert_eq!(acked(&run(Request::CancelReminder { id: *id })), 0); assert_eq!(acked(&run(Request::CancelReminder { id: *id })), 0);
@ -1150,7 +1130,6 @@ mod tests {
Request::ListReminders, Request::ListReminders,
Request::CancelReminder { id: 1 }, Request::CancelReminder { id: 1 },
Request::CountPendingReminders, Request::CountPendingReminders,
Request::ReminderRollup { since_secs: 0 },
]; ];
for req in requests { for req in requests {
let label = format!("{req:?}"); let label = format!("{req:?}");

View file

@ -163,7 +163,7 @@ pub async fn write_system_prompt(socket: &Path, label: &str) -> Result<PathBuf>
/// the serve loop must act on. The `compacted` bool is `true` when a /// the serve loop must act on. The `compacted` bool is `true` when a
/// compaction ran this turn (reactively on overflow, or proactively per the /// compaction ran this turn (reactively on overflow, or proactively per the
/// policy — or a successful agent-requested `/compact` at turn end); it's recorded as /// policy — or a successful agent-requested `/compact` at turn end); it's recorded as
/// `result_kind = "compacted"` in turn stats so the stats page can distinguish /// `result_kind = "compacted"` in turn stats so a reader can distinguish
/// those turns. Both `Ok(true)` and `Ok(false)` are ack'd; the error cases /// those turns. Both `Ok(true)` and `Ok(false)` are ack'd; the error cases
/// each map to a distinct serve-loop action (see [`emit_turn_end`] and the /// each map to a distinct serve-loop action (see [`emit_turn_end`] and the
/// `hive-agent` serve loop). /// `hive-agent` serve loop).

View file

@ -3,15 +3,15 @@
//! `ended_at`, `duration_ms`), cost (token counts), and behaviour (tool-call //! `ended_at`, `duration_ms`), cost (token counts), and behaviour (tool-call
//! count + per-tool breakdown). //! count + per-tool breakdown).
//! //!
//! **Captured but not yet read** (written every turn, no reader today — //! **Captured but not yet read** (written every turn, no reader in this
//! kept for a future chart / backfill, not consumed by `stats::snapshot` //! repository — kept for a future chart / backfill): `tool_call_count` (a
//! or the host rollup): `tool_call_count` (the snapshot recomputes tool //! reader recomputes tool totals from `tool_call_breakdown_json` instead),
//! totals from `tool_call_breakdown_json` instead), `open_threads_count` + //! `open_threads_count` +
//! `open_reminders_count` (planned: a loose-ends-over-time trend), and //! `open_reminders_count` (planned: a loose-ends-over-time trend), and
//! `note` (failure detail for `result_kind = "failed"`). //! `note` (failure detail for `result_kind = "failed"`).
//! //!
//! Lives in the harness dir (`HYPERHIVE_HARNESS_DIR`) as //! Lives in the harness dir (`HYPERHIVE_HARNESS_DIR`) as
//! `hyperhive-turn-stats.sqlite`; the agent's own `/stats` page reads it //! `hyperhive-turn-stats.sqlite`; the standalone legacy stats viewer reads it
//! and no vacuum sweeps it. Schema is //! and no vacuum sweeps it. Schema is
//! intentionally append-only — every column has a default so future //! intentionally append-only — every column has a default so future
//! additions don't break old readers; new columns land via //! additions don't break old readers; new columns land via
@ -118,7 +118,7 @@ pub struct TurnStatRow {
/// when no tools were called (saves a sqlite write of `"{}"`). /// when no tools were called (saves a sqlite write of `"{}"`).
pub tool_call_breakdown_json: Option<String>, pub tool_call_breakdown_json: Option<String>,
/// Post-turn loose-ends snapshot. Captured, not yet read — planned to /// Post-turn loose-ends snapshot. Captured, not yet read — planned to
/// feed a loose-ends-over-time trend on the stats page. /// feed a loose-ends-over-time trend.
pub open_threads_count: Option<u64>, pub open_threads_count: Option<u64>,
pub open_reminders_count: Option<u64>, pub open_reminders_count: Option<u64>,
/// `"ok" | "failed" | "prompt_too_long"`. /// `"ok" | "failed" | "prompt_too_long"`.

View file

@ -23,8 +23,7 @@ const VACUUM_INTERVAL: Duration = Duration::from_hours(1);
/// Keep completed bash-task files this long before deleting their trio. /// Keep completed bash-task files this long before deleting their trio.
const BASH_KEEP_SECS: i64 = 48 * 3600; const BASH_KEEP_SECS: i64 = 48 * 3600;
/// Keep delivered (soft-deleted, `sent_at` set) reminder rows this long /// Keep delivered (soft-deleted, `sent_at` set) reminder rows this long
/// before reaping them — same window as `STREAM_KEEP_SECS`, kept around /// before reaping them — same window as `STREAM_KEEP_SECS`.
/// only to serve the trailing-window `ReminderRollup` stats.
const REMINDER_KEEP_SECS: i64 = 14 * 24 * 3600; const REMINDER_KEEP_SECS: i64 = 14 * 24 * 3600;
/// Keep acked (agent-dismissed) todo rows this long before reaping them — /// Keep acked (agent-dismissed) todo rows this long before reaping them —
/// see `todos.rs`'s module doc for why acking doesn't delete outright. Long /// see `todos.rs`'s module doc for why acking doesn't delete outright. Long

View file

@ -22,7 +22,8 @@ pub fn tasks_dir() -> PathBuf {
/// Per-agent turn-stats sqlite — the harness writes one row per claude /// Per-agent turn-stats sqlite — the harness writes one row per claude
/// turn here; the runner appends normalised bash-command heads to its /// turn here; the runner appends normalised bash-command heads to its
/// `bash_commands` table for the /stats "favorite tools" view. /// `bash_commands` table, which the harness reads for its OTEL bash-command
/// counter.
#[must_use] #[must_use]
pub fn turn_stats_db() -> PathBuf { pub fn turn_stats_db() -> PathBuf {
harness_dir().join("hyperhive-turn-stats.sqlite") harness_dir().join("hyperhive-turn-stats.sqlite")

View file

@ -608,8 +608,8 @@ async fn run_task(mut task: TaskFile, socket: &Path, cgroups: Option<&RunCgroups
// full command stays on disk in the task file for `status`/`view` // full command stays on disk in the task file for `status`/`view`
// instead. // instead.
upsert_bash_todo(socket, &id, format!("bash task `{id}` running")).await; upsert_bash_todo(socket, &id, format!("bash task `{id}` running")).await;
// Best-effort: tally the normalised command head for the /stats // Best-effort: tally the normalised command head for the OTEL
// "favorite tools" view. Counted once per execution, regardless of // bash-command counter. Counted once per execution, regardless of
// exit status. Never fails the task. // exit status. Never fails the task.
crate::stats::record_command(&task.cmd); crate::stats::record_command(&task.cmd);

View file

@ -1,6 +1,6 @@
//! Capture of normalised shell-command "heads" per bash task into the //! Capture of normalised shell-command "heads" per bash task into the
//! per-agent turn-stats sqlite (`bash_commands` table), backing the //! per-agent turn-stats sqlite (`bash_commands` table), read by the
//! "favorite tools" doughnut on the /stats page. //! harness for its OTEL bash-command counter.
//! //!
//! Best-effort: a missing db, a lock, or a parse miss is logged and //! Best-effort: a missing db, a lock, or a parse miss is logged and
//! swallowed — recording a stat never affects task execution. The //! swallowed — recording a stat never affects task execution. The

View file

@ -326,8 +326,8 @@ async fn cmd_serve(
// agent-owned, so host-side deletes hit PermissionDenied / readonly-db // agent-owned, so host-side deletes hit PermissionDenied / readonly-db
// under privsep. See issue tracker "perms borked". // under privsep. See issue tracker "perms borked".
// (turn-stats.sqlite has no vacuum — it's one tiny row per turn, // (turn-stats.sqlite has no vacuum — it's one tiny row per turn,
// ~hundreds of KB, and the agent's own /stats page reads it // ~hundreds of KB, and pruning it would just lose trend
// directly; pruning it would just lose trend history for no gain.) // history for no gain.)
// Slow per-container disk sampler: hive-priv measures each agent's state/ // Slow per-container disk sampler: hive-priv measures each agent's state/
// + work/ + writable rootfs every 30 min, cached so a sample only reads // + work/ + writable rootfs every 30 min, cached so a sample only reads
// cgroup files. Feeds `disk_bytes` to the OTEL exporter. See // cgroup files. Feeds `disk_bytes` to the OTEL exporter. See

View file

@ -80,17 +80,6 @@ pub enum ReminderTiming {
At { unix_timestamp: i64 }, At { unix_timestamp: i64 },
} }
/// Reminder activity statistics for an agent over a time window.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReminderStats {
/// Total reminders scheduled in the window (`created_at` >= cutoff).
pub scheduled: u64,
/// Reminders that have been delivered in the window (`sent_at` IS NOT NULL).
pub delivered: u64,
/// Reminders still pending in the window (`sent_at` IS NULL).
pub pending: u64,
}
/// One row in the response to `GetLooseEnds`. Tagged enum so new /// One row in the response to `GetLooseEnds`. Tagged enum so new
/// thread kinds can land without breaking existing handlers. /// thread kinds can land without breaking existing handlers.
/// Per-flavour scoping + per-variant fields + clock-anomaly /// Per-flavour scoping + per-variant fields + clock-anomaly