Watch
0
0
Fork
You've already forked hyperhive
0

harness stores: a failed lookup is not no-row, bulk done is one transaction, the reminder cap is checked with the insert

This commit is contained in:
damocles 2026-11-12 12:53:28 +01:00 • committed by mara
commit e3bf401f6e

View file

@ -23,7 +23,7 @@ use std::time::Duration;
use tokio::sync::mpsc;
use crate::reminders::Reminders;
use crate::reminders::{Reminders, Stored};
/// Per-tick cap on reminders delivered — mirrors the old c0re
/// `REMINDER_BATCH_LIMIT`, same rationale (bound a deep backlog's
@ -109,21 +109,33 @@ pub fn store(
file_path: Option<&str>,
) -> Result<i64, String> {
let max = remind_max_pending();
// A cheap early check, so a rejected reminder never writes its large body
// to a file; the authoritative one is the count inside the insert below.
if max > 0 {
let pending = store.count_pending().unwrap_or(0);
let pending = store
.count_pending()
.map_err(|e| format!("failed to count pending reminders: {e:#}"))?;
if pending >= max {
return Err(format!(
"reminder rejected: already {pending} pending reminders (cap {max}). \
Cancel some via `cancel_loose_end` or wait for them to fire before \
scheduling more. Override the cap with `HIVE_REMIND_MAX_PENDING_PER_AGENT`."
));
return Err(over_cap(pending, max));
}
}
let due_at = resolve_due_at(timing).map_err(|e| format!("invalid reminder timing: {e:#}"))?;
let (stored_message, stored_path) = prepare_remind_storage(message, file_path)?;
store
.store(&stored_message, stored_path.as_deref(), due_at)
.map_err(|e| format!("failed to store reminder: {e:#}"))
match store
.store_within_cap(&stored_message, stored_path.as_deref(), due_at, max)
.map_err(|e| format!("failed to store reminder: {e:#}"))?
{
Stored::Row(id) => Ok(id),
Stored::AtCap { pending } => Err(over_cap(pending, max)),
}
}
fn over_cap(pending: u64, max: u64) -> String {
format!(
"reminder rejected: already {pending} pending reminders (cap {max}). \
Cancel some via `cancel_loose_end` or wait for them to fire before \
scheduling more. Override the cap with `HIVE_REMIND_MAX_PENDING_PER_AGENT`."
)
}
/// Decide what to actually persist in the reminder row (see the old