fix(#2593): mark forge notifications read on broker-delivery
This commit is contained in:
parent
b62652c01b
commit
da056d0043
3 changed files with 104 additions and 212 deletions
|
|
@ -140,7 +140,7 @@ pub(crate) fn read_harness_state() -> (bool, bool, Option<String>) {
|
|||
}
|
||||
|
||||
/// Write the turn-loop's harness state fields via a read-modify-write so
|
||||
/// any other writer's fields (e.g. `forge_notify`'s `forge_cursor`) survive.
|
||||
/// any other writer's fields in the consolidated state file survive.
|
||||
/// Pass `active_model: Some(s)` to update the resolved model (surfaced in
|
||||
/// the dashboard badge); `None` leaves the stored value untouched.
|
||||
pub(crate) fn write_harness_state(
|
||||
|
|
@ -160,40 +160,6 @@ pub(crate) fn write_harness_state(
|
|||
write_harness_json(&v);
|
||||
}
|
||||
|
||||
/// Parse the `forge_notify` delivery-dedupe cursor (notification thread id
|
||||
/// -> last-delivered `updated_at`) out of a harness-state JSON value.
|
||||
/// Empty when the field is absent (first boot) or malformed.
|
||||
fn forge_cursor_from_json(v: &serde_json::Value) -> std::collections::HashMap<u64, String> {
|
||||
v.get("forge_cursor")
|
||||
.cloned()
|
||||
.and_then(|c| serde_json::from_value(c).ok())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Restore the `forge_notify` delivery-dedupe cursor from the consolidated
|
||||
/// state file so a container rebuild/restart doesn't re-deliver the whole
|
||||
/// currently-unread backlog.
|
||||
pub fn read_forge_cursor() -> std::collections::HashMap<u64, String> {
|
||||
forge_cursor_from_json(&read_harness_json())
|
||||
}
|
||||
|
||||
/// Persist the `forge_notify` delivery-dedupe cursor into the consolidated
|
||||
/// state file, read-modify-write under the shared lock so the turn-loop's
|
||||
/// own fields survive. Best-effort: a serialize failure is a no-op.
|
||||
pub fn write_forge_cursor<S: std::hash::BuildHasher>(
|
||||
cursor: &std::collections::HashMap<u64, String, S>,
|
||||
) {
|
||||
let Ok(value) = serde_json::to_value(cursor) else {
|
||||
return;
|
||||
};
|
||||
let _guard = HARNESS_JSON_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let mut v = read_harness_json();
|
||||
v["forge_cursor"] = value;
|
||||
write_harness_json(&v);
|
||||
}
|
||||
|
||||
/// Compiled-in fallback model used when neither `HIVE_DEFAULT_MODEL` nor a
|
||||
/// persisted runtime override is present.
|
||||
pub const DEFAULT_MODEL: &str = "haiku";
|
||||
|
|
@ -280,35 +246,7 @@ pub fn context_window_tokens(model: &str) -> u64 {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{DEFAULT_EFFORT, EFFORT_LEVELS, forge_cursor_from_json, is_valid_effort};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn forge_cursor_absent_field_is_empty() {
|
||||
// First boot / a state file that only carries the turn-loop fields:
|
||||
// no cursor yet, so we re-deliver the currently-unread set once.
|
||||
assert!(forge_cursor_from_json(&json!({ "rate_limited": false })).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forge_cursor_malformed_field_is_empty() {
|
||||
// A wrong-typed / corrupt cursor degrades to empty rather than
|
||||
// aborting the poller.
|
||||
assert!(forge_cursor_from_json(&json!({ "forge_cursor": "nonsense" })).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forge_cursor_roundtrips_u64_keys() {
|
||||
// serde_json stringifies integer map keys; confirm the u64 thread
|
||||
// ids the cursor is keyed on survive the JSON round-trip.
|
||||
let v = json!({
|
||||
"forge_cursor": { "42": "2026-06-22T16:00:00Z", "99": "2026-06-22T17:30:00Z" }
|
||||
});
|
||||
let cursor = forge_cursor_from_json(&v);
|
||||
assert_eq!(cursor.len(), 2);
|
||||
assert_eq!(cursor.get(&42), Some(&"2026-06-22T16:00:00Z".to_owned()));
|
||||
assert_eq!(cursor.get(&99), Some(&"2026-06-22T17:30:00Z".to_owned()));
|
||||
}
|
||||
use super::{DEFAULT_EFFORT, EFFORT_LEVELS, is_valid_effort};
|
||||
|
||||
#[test]
|
||||
fn effort_validation_accepts_only_known_levels() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue