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
6 changed files with 26 additions and 117 deletions

View file

@ -7,18 +7,14 @@
//! 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
//! message body (see `reminder_timer.rs`). Delivery is *soft*-deleted
//! (`sent_at` set, not `DELETE`) so the harness's own `/api/stats` reminder
//! rollup can still report scheduled/delivered/pending counts over a
//! 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.
//! (`sent_at` set, not `DELETE`); a periodic prune (`vacuum.rs`) reaps old
//! delivered rows so the table doesn't grow unbounded.
use std::path::Path;
use std::sync::Mutex;
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use hive_sh4re::inbox::ReminderStats;
use hive_sh4re::wire_time;
use rusqlite::{Connection, params};
@ -211,8 +207,8 @@ impl Reminders {
}
/// Soft-delete: stamp `sent_at` so the row drops out of
/// `count_pending`/`list_pending`/`due` but survives for the rollup
/// stats until `prune_delivered_older_than` reaps it.
/// `count_pending`/`list_pending`/`due` and is reaped later by
/// `prune_delivered_older_than`.
///
/// # Errors
///
@ -232,7 +228,7 @@ impl Reminders {
}
/// 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).
///
/// # Errors
@ -251,47 +247,6 @@ impl Reminders {
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
/// from `vacuum.rs`'s periodic sweep so the table doesn't grow
/// unbounded. Returns the number of rows deleted.
@ -404,16 +359,12 @@ mod tests {
}
#[test]
fn mark_delivered_removes_from_pending_but_counts_in_rollup() {
fn mark_delivered_removes_from_pending() {
let (_dir, s) = store();
let id = s.store("a", None, 100).unwrap();
s.mark_delivered(id).unwrap();
assert_eq!(s.count_pending().unwrap(), 0);
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]

View file

@ -1,7 +1,7 @@
//! Shared connection setup for the harness's own sqlite writers.
//!
//! A write that overlaps another connection's lock (the stats page, the hourly
//! vacuum) fails at once with `SQLITE_BUSY` unless the connection has a busy
//! A write that overlaps another connection's lock (the hourly vacuum, a
//! 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.
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
/// harness's own `web_ui` endpoints (`api_todos`, `/api/stats` reminder
/// rollup) and `Surface::post_turn_counts` all need read access to the
/// harness's own `web_ui` endpoints (`api_todos`) and `Surface::post_turn_counts` all need read access to the
/// `Todos`/`Reminders` stores this module owns behind an `Arc` on a
/// different spawned task, and a loopback dial is simpler than threading
/// those `Arc`s through every caller. One-shot, best-effort (no retry,
@ -275,7 +274,6 @@ fn dispatch(
Request::ListReminders => list_reminders(reminders),
Request::CancelReminder { id } => cancel_reminder(reminders, id),
Request::CountPendingReminders => count_pending_reminders(reminders),
Request::ReminderRollup { since_secs } => reminder_rollup(reminders, since_secs),
Request::Compact { wake_prompt } => compact(bus, wake_prompt),
// Answered by `handle_conn` before this runs: it waits on the queue,
// 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
/// fires `wake` on a new-or-changed upsert so the serve loop runs a turn.
fn upsert_todo(
@ -890,7 +875,6 @@ mod tests {
Request::ListReminders,
Request::CancelReminder { id: 1 },
Request::CountPendingReminders,
Request::ReminderRollup { since_secs: 0 },
];
for req in reqs {
let resp = dispatch(req, &todos, &wake, None, &bus);
@ -924,10 +908,6 @@ mod tests {
panic!("one reminder, got {loose_ends:?}");
};
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 })), 0);
@ -1150,7 +1130,6 @@ mod tests {
Request::ListReminders,
Request::CancelReminder { id: 1 },
Request::CountPendingReminders,
Request::ReminderRollup { since_secs: 0 },
];
for req in requests {
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
/// 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
/// `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
/// each map to a distinct serve-loop action (see [`emit_turn_end`] and the
/// `hive-agent` serve loop).

View file

@ -3,15 +3,15 @@
//! `ended_at`, `duration_ms`), cost (token counts), and behaviour (tool-call
//! count + per-tool breakdown).
//!
//! **Captured but not yet read** (written every turn, no reader today —
//! kept for a future chart / backfill, not consumed by `stats::snapshot`
//! or the host rollup): `tool_call_count` (the snapshot recomputes tool
//! totals from `tool_call_breakdown_json` instead), `open_threads_count` +
//! **Captured but not yet read** (written every turn, no reader in this
//! repository — kept for a future chart / backfill): `tool_call_count` (a
//! reader recomputes tool totals from `tool_call_breakdown_json` instead),
//! `open_threads_count` +
//! `open_reminders_count` (planned: a loose-ends-over-time trend), and
//! `note` (failure detail for `result_kind = "failed"`).
//!
//! 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
//! intentionally append-only — every column has a default so future
//! 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 `"{}"`).
pub tool_call_breakdown_json: Option<String>,
/// 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_reminders_count: Option<u64>,
/// `"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.
const BASH_KEEP_SECS: i64 = 48 * 3600;
/// Keep delivered (soft-deleted, `sent_at` set) reminder rows this long
/// before reaping them — same window as `STREAM_KEEP_SECS`, kept around
/// only to serve the trailing-window `ReminderRollup` stats.
/// before reaping them — same window as `STREAM_KEEP_SECS`.
const REMINDER_KEEP_SECS: i64 = 14 * 24 * 3600;
/// 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