Skip to main content

agentmux_srv_core/backend/
record_flags.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The rules that read the record, so nobody has to look
5//! (docs/specs/SPEC_LONG_RUNNING_ZERO_DEGRADATION_2026_11_16.md ยง7, task #47820).
6//!
7//! Once an hour, when the hour that ended is rolled up, two rules run over what the record already holds. Each
8//! thing they find is one event of kind `flag`, written beside the stalls (`events-YYYY-MM.jsonl`, kept a year):
9//!
10//! - **stalls**: more than three stalls of 5 s or more in the hour, or one over 20 s;
11//! - **growth**: a size whose trend rose over each of the last two days by more than the margin and by more
12//!   than its floor, and that more content does not explain.
13//!
14//! A flag is a line in the record: it is read with the events (`App record`, kind `events`) and stops nothing.
15//! What is said of it, to the person and to the machine's steward, is `record_notice`.
16//!
17//! What the growth rule reads, and what it leaves out:
18//! - the `core` part and each `core:` row (srv, the host, the GPU process), only over two days in which srv
19//!   did not start again: a start lowers a size and the climb back is not a leak;
20//! - each window's page: its JS heap and its element count, against its mounted rows. A window that holds
21//!   more rows holds more, so a rise the rows explain is not flagged;
22//! - not the rows of agents and terminals (an agent CLI's memory is not AgentMux's), and not a renderer's
23//!   process row, which the record cannot set against a window's content.
24
25use std::path::Path;
26
27use serde_json::{json, Value};
28
29use super::record::{read_events, read_rollups, Rollup};
30
31/// The kind of a flag's line among the record's events.
32pub const KIND: &str = "flag";
33
34const HOUR_MS: u64 = 3_600_000;
35const DAY_MS: u64 = 24 * HOUR_MS;
36
37/// The events that are stalls: the host's UI thread, and srv's runtime.
38const STALL_KINDS: [&str; 2] = ["ui_stall", "srv_stall"];
39/// A stall this long counts; more than [`STALLS_MANY`] of them in one hour is a flag.
40const STALL_COUNTED_MS: u64 = 5_000;
41const STALLS_MANY: usize = 3;
42/// One stall longer than this is a flag by itself.
43const STALL_LONG_MS: u64 = 20_000;
44
45/// A size is flagged when its trend gained more than this share of its level in a day, two days running.
46const MARGIN: f64 = 0.20;
47/// A day is read only with this many of its 24 hours present.
48const HOURS_NEEDED: usize = 18;
49/// A gain smaller than this never flags: it is inside what the samples move by themselves.
50const FLOOR_BYTES: f64 = 64.0 * 1024.0 * 1024.0;
51const FLOOR_HEAP_MB: f64 = 32.0;
52const FLOOR_ELEMENTS: f64 = 5_000.0;
53/// Content explains a rise when it rose by at least this share of the size's own rise.
54const CONTENT_EXPLAINS: f64 = 0.5;
55
56/// One thing a rule found.
57#[derive(Debug, Clone, PartialEq)]
58pub struct Flag {
59    /// `stalls`, `long_stall` or `growth`.
60    pub rule: &'static str,
61    /// What it is about: a stall's kind, or a series (`core`, `core:srv`, `page:main:heap`).
62    pub key: String,
63    /// The numbers behind it, for the line.
64    pub fields: Value,
65}
66
67impl Flag {
68    /// The fields of the flag's event: the rule, the key and the numbers.
69    fn line(&self) -> Value {
70        let mut line = self.fields.clone();
71        if let Value::Object(map) = &mut line {
72            map.insert("rule".into(), self.rule.into());
73            map.insert("key".into(), self.key.as_str().into());
74        }
75        line
76    }
77}
78
79/// The stall rule over one hour's events: per kind, more than [`STALLS_MANY`] stalls of [`STALL_COUNTED_MS`] or
80/// more, or one over [`STALL_LONG_MS`]. One flag per kind at most; many stalls is the one said when both hold.
81pub fn stall_flags(events: &[Value]) -> Vec<Flag> {
82    let mut out = Vec::new();
83    for kind in STALL_KINDS {
84        let lengths: Vec<u64> = events.iter().filter(|e| e["kind"] == kind).filter_map(|e| e["ms"].as_u64()).collect();
85        let Some(worst) = lengths.iter().copied().max() else { continue };
86        let counted = lengths.iter().filter(|ms| **ms >= STALL_COUNTED_MS).count();
87        let rule = if counted > STALLS_MANY {
88            "stalls"
89        } else if worst > STALL_LONG_MS {
90            "long_stall"
91        } else {
92            continue;
93        };
94        out.push(Flag { rule, key: kind.to_string(), fields: json!({ "n": counted, "worst_ms": worst }) });
95    }
96    out
97}
98
99fn median(mut v: Vec<f64>) -> Option<f64> {
100    if v.is_empty() {
101        return None;
102    }
103    v.sort_by(f64::total_cmp);
104    let mid = v.len() / 2;
105    Some(if v.len() % 2 == 1 { v[mid] } else { (v[mid - 1] + v[mid]) / 2.0 })
106}
107
108/// The Theil-Sen slope of `points` (x, y): the median of the slopes between every two points. A window recycle
109/// or one odd hour moves a least-squares line; it does not move this one. None under two distinct x.
110fn theil_sen(points: &[(f64, f64)]) -> Option<f64> {
111    let mut slopes = Vec::with_capacity(points.len() * points.len().saturating_sub(1) / 2);
112    for (i, a) in points.iter().enumerate() {
113        for b in &points[i + 1..] {
114            if b.0 != a.0 {
115                slopes.push((b.1 - a.1) / (b.0 - a.0));
116            }
117        }
118    }
119    median(slopes)
120}
121
122/// How a figure moved over one day: its middle, and what its trend gained over the 24 hours.
123#[derive(Debug, Clone, Copy, PartialEq)]
124struct Day {
125    level: f64,
126    rise: f64,
127}
128
129impl Day {
130    /// The gain as a share of the level; 0 for a level of 0.
131    fn share(&self) -> f64 {
132        if self.level > 0.0 {
133            self.rise / self.level
134        } else {
135            0.0
136        }
137    }
138}
139
140/// The day that starts at `from`, of a series of (hour start, value). None with too few of its hours.
141fn day(series: &[(u64, f64)], from: u64) -> Option<Day> {
142    let points: Vec<(f64, f64)> =
143        series.iter().filter(|(h, _)| *h >= from && *h < from + DAY_MS).map(|(h, v)| ((*h - from) as f64 / HOUR_MS as f64, *v)).collect();
144    if points.len() < HOURS_NEEDED {
145        return None;
146    }
147    Some(Day { level: median(points.iter().map(|p| p.1).collect())?, rise: theil_sen(&points)? * 24.0 })
148}
149
150/// A size over the hours, with what it is counted in and, for a page, the content it is read against.
151struct Series {
152    key: String,
153    unit: &'static str,
154    floor: f64,
155    values: Vec<(u64, f64)>,
156    content: Option<Vec<(u64, f64)>>,
157}
158
159fn push(all: &mut Vec<Series>, key: String, unit: &'static str, floor: f64, hour: u64, value: f64, content: Option<f64>) {
160    let at = match all.iter().position(|s| s.key == key) {
161        Some(at) => at,
162        None => {
163            all.push(Series { key, unit, floor, values: Vec::new(), content: content.map(|_| Vec::new()) });
164            all.len() - 1
165        }
166    };
167    all[at].values.push((hour, value));
168    if let (Some(list), Some(c)) = (all[at].content.as_mut(), content) {
169        list.push((hour, c));
170    }
171}
172
173/// The series the growth rule reads, from the rollups of its two days (the hourly medians).
174fn series_of(rollups: &[Rollup]) -> Vec<Series> {
175    // Process sizes are read only when srv ran through both days in one version.
176    let one_run = rollups.iter().all(|r| r.restarts == 0) && rollups.windows(2).all(|w| w[0].v == w[1].v && w[1].up_s >= w[0].up_s);
177    let mut all = Vec::new();
178    for r in rollups {
179        if one_run {
180            for (k, stat) in r.parts.iter().filter(|(k, _)| k == "core") {
181                push(&mut all, k.clone(), "bytes", FLOOR_BYTES, r.h, stat.1 as f64, None);
182            }
183            for (k, stat) in r.rows.iter().filter(|(k, _)| k.starts_with("core:")) {
184                push(&mut all, k.clone(), "bytes", FLOOR_BYTES, r.h, stat.1 as f64, None);
185            }
186        }
187        for page in &r.pages {
188            let rows = Some(page.rows.1 as f64);
189            if let Some(heap) = page.heap {
190                push(&mut all, format!("page:{}:heap", page.w), "mb", FLOOR_HEAP_MB, r.h, heap.1 as f64, rows);
191            }
192            push(&mut all, format!("page:{}:dom", page.w), "elements", FLOOR_ELEMENTS, r.h, page.dom.1 as f64, rows);
193        }
194    }
195    all
196}
197
198/// The growth rule over the two days that end at `end` (an hour's start): a series whose trend gained more than
199/// [`MARGIN`] of its level and more than its floor on each day, where its content (a page's rows) did not rise
200/// by at least [`CONTENT_EXPLAINS`] of that share on either day.
201pub fn growth_flags(rollups: &[Rollup], end: u64) -> Vec<Flag> {
202    let start = end.saturating_sub(2 * DAY_MS);
203    let window: Vec<Rollup> = rollups.iter().filter(|r| r.h >= start && r.h < end).cloned().collect();
204    let mut out = Vec::new();
205    for s in series_of(&window) {
206        let (Some(before), Some(last)) = (day(&s.values, start), day(&s.values, start + DAY_MS)) else { continue };
207        let grew = |d: &Day| d.rise > s.floor && d.share() > MARGIN;
208        if !grew(&before) || !grew(&last) {
209            continue;
210        }
211        let content = s.content.as_ref().map(|c| (day(c, start), day(c, start + DAY_MS)));
212        let explained = |d: &Day, c: Option<Day>| c.is_some_and(|c| c.share() >= d.share() * CONTENT_EXPLAINS);
213        if let Some((c_before, c_last)) = content {
214            if explained(&before, c_before) || explained(&last, c_last) {
215                continue;
216            }
217        }
218        let mut fields = json!({
219            "unit": s.unit,
220            "level": last.level.round() as u64,
221            "rise": last.rise.round() as u64,
222            "rise_before": before.rise.round() as u64,
223        });
224        if let Some((_, Some(c))) = content {
225            fields["content_pct"] = json!((c.share() * 100.0).round() as i64);
226        }
227        out.push(Flag { rule: "growth", key: s.key, fields });
228    }
229    out
230}
231
232/// Whether `events` already hold this flag: a stall flag for the hour that ended at `end`, a growth flag for
233/// the same series within the last day (a series that keeps growing is said once a day, not once an hour).
234fn already(events: &[Value], flag: &Flag, end: u64) -> bool {
235    events.iter().filter(|e| e["kind"] == KIND && e["rule"] == flag.rule && e["key"] == flag.key.as_str()).any(|e| {
236        let t = e["t"].as_u64().unwrap_or(0);
237        if flag.rule == "growth" {
238            t + DAY_MS > end
239        } else {
240            t == end
241        }
242    })
243}
244
245/// What the rules find for the hour that ended at or before `now_ms`, less what the record already says.
246pub fn found(dir: &Path, now_ms: u64) -> (u64, Vec<Flag>) {
247    let end = now_ms / HOUR_MS * HOUR_MS;
248    let (_, events) = read_events(dir, end.saturating_sub(DAY_MS), end, usize::MAX);
249    let hour: Vec<Value> =
250        events.iter().filter(|e| e["t"].as_u64().is_some_and(|t| t + HOUR_MS >= end && t < end)).cloned().collect();
251    let (_, rollups) = read_rollups(dir, end.saturating_sub(2 * DAY_MS), end, 48 + 1);
252    let mut flags = stall_flags(&hour);
253    flags.extend(growth_flags(&rollups, end));
254    flags.retain(|f| !already(&events, f, end));
255    (end, flags)
256}
257
258/// How long a flag is still said after its hour: a growing size is found again each day while it grows, so its
259/// flag lasts until the next would be written; a bad hour of stalls is over when the next hour or two are quiet.
260const GROWTH_SAID_MS: u64 = DAY_MS + HOUR_MS;
261const STALLS_SAID_MS: u64 = 2 * HOUR_MS;
262
263/// The flags among `events` that are still said at `now_ms`, oldest first: the newest of each rule and key,
264/// while it is younger than its rule's time.
265pub fn still_said(events: &[Value], now_ms: u64) -> Vec<Value> {
266    let mut out: Vec<Value> = Vec::new();
267    for e in events.iter().filter(|e| e["kind"] == KIND) {
268        let Some(t) = e["t"].as_u64() else { continue };
269        let lasts = if e["rule"] == "growth" { GROWTH_SAID_MS } else { STALLS_SAID_MS };
270        if t > now_ms || t + lasts <= now_ms {
271            continue;
272        }
273        match out.iter_mut().find(|o| o["rule"] == e["rule"] && o["key"] == e["key"]) {
274            Some(same) if same["t"].as_u64().unwrap_or(0) <= t => *same = e.clone(),
275            Some(_) => {}
276            None => out.push(e.clone()),
277        }
278    }
279    out.sort_by_key(|e| e["t"].as_u64().unwrap_or(0));
280    out
281}
282
283/// What a look at the record found.
284#[derive(Debug, Clone, Default, PartialEq)]
285pub struct Looked {
286    /// The flags this look wrote.
287    pub new: Vec<Flag>,
288    /// Every flag still said now ([`still_said`]), these among them, as the record holds them.
289    pub said: Vec<Value>,
290}
291
292/// Run the rules for the hour that just ended and write each new flag as an event at that hour's end. BLOCKING
293/// (file reads and an append). A failure is logged: the rules are never a reason for the record to fail.
294pub fn look(dir: &Path, now_ms: u64) -> Looked {
295    let (end, flags) = found(dir, now_ms);
296    let mut new = Vec::new();
297    for flag in flags {
298        tracing::info!(rule = flag.rule, key = %flag.key, fields = %flag.fields, "[record] flag");
299        match agentmux_common::record_events::append_event(dir, end, KIND, flag.line()) {
300            Ok(()) => new.push(flag),
301            Err(e) => tracing::warn!(error = %e, "[record] a flag could not be written"),
302        }
303    }
304    let (_, events) = read_events(dir, now_ms.saturating_sub(GROWTH_SAID_MS), now_ms, usize::MAX);
305    Looked { new, said: still_said(&events, now_ms) }
306}
307
308#[cfg(test)]
309mod tests {
310    use super::super::record::{PageRoll, Stat};
311    use super::*;
312
313    const MB: u64 = 1024 * 1024;
314    /// 2026-11-16 12:00 UTC, an hour's start.
315    const END: u64 = 1_794_830_400_000;
316
317    fn stall(kind: &str, t: u64, ms: u64) -> Value {
318        json!({ "t": t, "kind": kind, "ms": ms })
319    }
320
321    fn flat(v: u64) -> Stat {
322        Stat(v, v, v, v)
323    }
324
325    /// The rollup of the hour `back` hours before `END`, with a `core` part and one window's page.
326    fn roll(back: u64, core: u64, page: Option<(u64, u64, u64)>) -> Rollup {
327        Rollup {
328            h: END - back * HOUR_MS,
329            n: 12,
330            v: "0.60.40".into(),
331            up_s: (100 - back) * 3_600,
332            restarts: 0,
333            last_t: 0,
334            cpu: None,
335            mem: None,
336            disk_free: None,
337            am: None,
338            parts: vec![("core".into(), flat(core)), ("agents".into(), flat(core * 10))],
339            rows: vec![("agent:b1".into(), flat(core * 10))],
340            pages: page.map(|(heap, dom, rows)| PageRoll { w: "main".into(), heap: Some(flat(heap)), dom: flat(dom), rows: flat(rows) }).into_iter().collect(),
341        }
342    }
343
344    /// 48 hours ending at `END`, oldest first: `core(i)` and `page(i)` give hour `i`'s figures (0 is the oldest).
345    fn two_days(core: impl Fn(u64) -> u64, page: impl Fn(u64) -> Option<(u64, u64, u64)>) -> Vec<Rollup> {
346        (0..48).map(|i| roll(48 - i, core(i), page(i))).collect()
347    }
348
349    #[test]
350    fn many_stalls_in_an_hour_are_a_flag_and_three_are_not() {
351        let three: Vec<Value> = (0..3).map(|i| stall("ui_stall", i, 6_000)).collect();
352        assert!(stall_flags(&three).is_empty());
353        let mut four = three.clone();
354        four.push(stall("ui_stall", 9, 5_000));
355        four.push(stall("ui_stall", 10, 4_999));
356        let flags = stall_flags(&four);
357        assert_eq!(flags.len(), 1);
358        assert_eq!((flags[0].rule, flags[0].key.as_str()), ("stalls", "ui_stall"));
359        assert_eq!(flags[0].fields, json!({ "n": 4, "worst_ms": 6_000 }));
360    }
361
362    #[test]
363    fn one_long_stall_is_a_flag_per_kind_and_twenty_seconds_exactly_is_not() {
364        assert!(stall_flags(&[stall("srv_stall", 1, 20_000)]).is_empty());
365        let flags = stall_flags(&[stall("srv_stall", 1, 20_001), stall("ui_stall", 2, 2_000), stall("other", 3, 99_000)]);
366        assert_eq!(flags.len(), 1);
367        assert_eq!((flags[0].rule, flags[0].key.as_str()), ("long_stall", "srv_stall"));
368        assert_eq!(flags[0].fields, json!({ "n": 1, "worst_ms": 20_001 }));
369    }
370
371    #[test]
372    fn the_slope_is_the_median_of_the_pairs_so_one_drop_does_not_move_it() {
373        let mut line: Vec<(f64, f64)> = (0..24).map(|i| (i as f64, 100.0 + 2.0 * i as f64)).collect();
374        assert_eq!(theil_sen(&line), Some(2.0));
375        line[12].1 = 0.0;
376        assert_eq!(theil_sen(&line), Some(2.0));
377        assert_eq!(theil_sen(&[(1.0, 5.0)]), None);
378        assert_eq!(theil_sen(&[(1.0, 5.0), (1.0, 9.0)]), None);
379    }
380
381    #[test]
382    fn a_core_that_climbs_two_days_running_is_flagged_once_with_its_numbers() {
383        // 300 MB rising 4 MB an hour: 96 MB a day, about a quarter of its level.
384        let flags = growth_flags(&two_days(|i| (300 + 4 * i) * MB, |_| None), END);
385        assert_eq!(flags.len(), 1);
386        assert_eq!((flags[0].rule, flags[0].key.as_str()), ("growth", "core"));
387        assert_eq!(flags[0].fields["unit"], "bytes");
388        assert_eq!(flags[0].fields["rise"], 96 * MB);
389        assert_eq!(flags[0].fields["rise_before"], 96 * MB);
390        assert!(flags[0].fields.get("content_pct").is_none());
391    }
392
393    #[test]
394    fn a_rise_on_one_day_only_or_under_the_floor_or_under_the_margin_is_not_flagged() {
395        // Flat the first day, climbing the second.
396        assert!(growth_flags(&two_days(|i| (300 + 4 * i.saturating_sub(24)) * MB, |_| None), END).is_empty());
397        // 2 MB an hour is 48 MB a day: under the floor, though a quarter of 200 MB.
398        assert!(growth_flags(&two_days(|i| (200 + 2 * i) * MB, |_| None), END).is_empty());
399        // 4 MB an hour on 2 GB: over the floor, under the margin.
400        assert!(growth_flags(&two_days(|i| (2_000 + 4 * i) * MB, |_| None), END).is_empty());
401    }
402
403    #[test]
404    fn a_start_inside_the_two_days_takes_the_process_sizes_out() {
405        let mut days = two_days(|i| (300 + 4 * i) * MB, |_| None);
406        days[30].restarts = 1;
407        assert!(growth_flags(&days, END).is_empty());
408        let mut days = two_days(|i| (300 + 4 * i) * MB, |_| None);
409        for r in days.iter_mut().skip(30) {
410            r.v = "0.60.41".into();
411        }
412        assert!(growth_flags(&days, END).is_empty());
413    }
414
415    #[test]
416    fn a_day_with_too_few_hours_is_not_read() {
417        let mut days = two_days(|i| (300 + 4 * i) * MB, |_| None);
418        days.retain(|r| r.h < END - 40 * HOUR_MS || r.h >= END - DAY_MS);
419        assert!(growth_flags(&days, END).is_empty());
420    }
421
422    #[test]
423    fn a_page_whose_heap_climbs_with_the_same_rows_is_flagged_and_one_whose_rows_climb_too_is_not() {
424        let leak = growth_flags(&two_days(|_| 300 * MB, |i| Some((200 + 3 * i, 40_000, 5_000))), END);
425        assert_eq!(leak.len(), 1);
426        assert_eq!(leak[0].key, "page:main:heap");
427        assert_eq!(leak[0].fields["unit"], "mb");
428        assert_eq!(leak[0].fields["rise"], 72);
429        assert_eq!(leak[0].fields["content_pct"], 0);
430        // The same heap, with rows that rise as fast in proportion: more content, not a leak.
431        assert!(growth_flags(&two_days(|_| 300 * MB, |i| Some((200 + 3 * i, 40_000, 5_000 + 75 * i))), END).is_empty());
432    }
433
434    #[test]
435    fn a_page_s_elements_are_read_against_its_rows_too() {
436        let flags = growth_flags(&two_days(|_| 300 * MB, |i| Some((200, 40_000 + 500 * i, 5_000))), END);
437        assert_eq!(flags.len(), 1);
438        assert_eq!(flags[0].key, "page:main:dom");
439        assert_eq!(flags[0].fields["unit"], "elements");
440        assert_eq!(flags[0].fields["rise"], 12_000);
441    }
442
443    #[test]
444    fn a_stall_flag_is_said_for_two_hours_and_a_growth_flag_until_the_next_days_would_be() {
445        let flag = |t: u64, rule: &str, key: &str| json!({ "t": t, "kind": KIND, "rule": rule, "key": key });
446        let events = vec![
447            flag(END - DAY_MS, "growth", "core"),
448            json!({ "t": END - 10, "kind": "ui_stall", "ms": 9_000 }),
449            flag(END, "stalls", "ui_stall"),
450            flag(END, "growth", "core"),
451        ];
452        let said = |now: u64| -> Vec<(String, u64)> {
453            still_said(&events, now).iter().map(|e| (e["rule"].as_str().unwrap().to_string(), e["t"].as_u64().unwrap())).collect()
454        };
455        // Both of this hour; of the series that keeps growing, only its newest flag. A stall is not a flag.
456        assert_eq!(said(END + 5 * 60_000), [("growth".to_string(), END), ("stalls".to_string(), END)]);
457        // Two hours on the stalls are no longer said. The growth is, until a day and an hour after it.
458        assert_eq!(said(END + 2 * HOUR_MS), [("growth".to_string(), END)]);
459        assert_eq!(said(END + DAY_MS + HOUR_MS - 1).len(), 1);
460        assert!(said(END + DAY_MS + HOUR_MS).is_empty());
461        // Before this hour's flags were written, yesterday's growth was the one said.
462        assert_eq!(said(END - 1), [("growth".to_string(), END - DAY_MS)]);
463    }
464
465    #[test]
466    fn the_hour_s_flags_are_written_once_and_a_growing_series_once_a_day() {
467        let dir = tempfile::tempdir().unwrap();
468        let write = |t: u64, kind: &str, fields: Value| agentmux_common::record_events::append_event(dir.path(), t, kind, fields).unwrap();
469        for i in 0..5 {
470            write(END - 30 * 60_000 + i, "ui_stall", json!({ "ms": 7_000 }));
471        }
472        // A stall of the hour before is not this hour's.
473        write(END - 90 * 60_000, "srv_stall", json!({ "ms": 60_000 }));
474        let rollups: String = two_days(|i| (300 + 4 * i) * MB, |_| None).iter().map(|r| serde_json::to_string(r).unwrap() + "\n").collect();
475        std::fs::write(dir.path().join("rollup-2026-11.jsonl"), rollups).unwrap();
476
477        let (end, flags) = found(dir.path(), END + 5 * 60_000);
478        assert_eq!(end, END);
479        let said: Vec<(&str, &str)> = flags.iter().map(|f| (f.rule, f.key.as_str())).collect();
480        assert_eq!(said, vec![("stalls", "ui_stall"), ("growth", "core")]);
481
482        let looked = look(dir.path(), END + 5 * 60_000);
483        assert_eq!(looked.new.iter().map(|f| f.rule).collect::<Vec<_>>(), ["stalls", "growth"]);
484        assert_eq!(looked.said.len(), 2);
485        // Looked at again in the same hour: nothing new is written, and both are still said.
486        let again = look(dir.path(), END + 20 * 60_000);
487        assert!(again.new.is_empty());
488        assert_eq!(again.said, looked.said);
489        let (_, events) = read_events(dir.path(), END, END, 10);
490        assert_eq!(events.len(), 2);
491        assert_eq!(events[0]["kind"], KIND);
492        assert_eq!((events[0]["rule"].as_str(), events[0]["key"].as_str(), events[0]["n"].as_u64()), (Some("stalls"), Some("ui_stall"), Some(5)));
493        // The same hour looked at again (srv started again inside it) says nothing new.
494        assert!(found(dir.path(), END + 40 * 60_000).1.is_empty());
495        // An hour later the series still grows: not said again within the day. A day later it is.
496        let core = Flag { rule: "growth", key: "core".into(), fields: json!({}) };
497        let (_, all) = read_events(dir.path(), 0, u64::MAX, 100);
498        assert!(already(&all, &core, END + HOUR_MS));
499        assert!(already(&all, &core, END + DAY_MS - HOUR_MS));
500        assert!(!already(&all, &core, END + DAY_MS));
501    }
502}