git clone https://garage44.eu/jeroen/midas.gitcartopolis-agent · 2026-11-22T09:03:41Z
feat(hub): mail nobody The mails told the person to act on what midas fixes itself: every one of the 73 problem mails in 60 days was a build directory the warmer trimmed once the node was free, and a runner that is away is started again by the host's watch timer. A decision put to the person already shows on the page and wakes a phone that asked to be (push.rs). So alert.rs and its SMTP client go, with the runner-away mail and the decision mail. What only a person can fix stays on the Workspace page, which now also says when the hub's own state disk runs short: the alert was the only thing that watched it. Web Push still wants a sender's address; it comes from a new `contact` in hub.conf, and an `alerts` section left from before is ignored.
DESIGN.md | 11 ++-
docs/development.md | 2 +-
docs/hub.md | 28 +++---
docs/usage.md | 4 +-
src/alert.rs | 187 ---------------------------------------
src/check.rs | 28 ++----
src/collab.rs | 22 +----
src/conf.rs | 22 +----
src/hub.rs | 7 +-
src/main.rs | 12 +--
src/push.rs | 4 +-
src/runners.rs | 49 +++-------
web/src/components/workspace.tsx | 3 +
web/src/lib/types.ts | 4 +-
14 files changed, 66 insertions(+), 317 deletions(-)
diff --git a/DESIGN.md b/DESIGN.md
index 4973636..6548758 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -252,7 +252,16 @@ session is told. The machine stays up first; the agent is told second.
profile or target first, the whole of it last) or three days stale is leased
like any agent would, brought to the branch, and built with the configured steps, each step and its duration
logged. Never cold rather than always current: a node warm at last week's
- commit costs only the workspace's own crates.
+ commit costs only the workspace's own crates. A node somebody holds is
+ trimmed by its own guard instead, after each measure of its build directory
+ (every ten minutes) while no ssh session and no bot is on it: the same order,
+ each part renamed aside in one step so no build sees it half gone.
+- **Nobody is mailed.** A problem midas can fix it fixes; what only a person
+ can (a machine that is off, a setup to rerun as root) is on the Workspace
+ page and in `midas check`, and a decision put to the person wakes their phone
+ (`push.rs`). Mailing what lasted an hour sent 73 mails in 60 days, every one a
+ held node's build directory that the warmer trimmed once it was free
+ (2026-11-22).
## 6. Security
diff --git a/docs/development.md b/docs/development.md
index ca07c95..3a182fc 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -75,7 +75,7 @@ is for and why it is that way. Grouped by where it runs:
- `board.rs`: every session as a card in its stage. `collab.rs`: sessions working together (notes, overlaps, decisions, reservations). `memory.rs`: agents' memory, shared by every machine. `accounts.rs`: the page's people.
- `sessions.rs`: sessions the hub keeps (`hosted/<id>/`), their runner, search over them. `discuss.rs`: talking one over by voice before it starts.
- `autopilot.rs`: answering a session for the person. `focus.rs`: what the person decides, counted, the limits they set on it, and the rules the autopilot may use.
-- `mirror.rs`: git and LFS for nodes. `warm.rs`: keeping nodes' builds warm. `deploy.rs`: `midas deploy`. `ship.rs`: deploying what landed, in batches. `push.rs`: waking a person's phone when something needs them. `alert.rs`: problems mailed to a person. `builds.rs`, `stats.rs`, `chart.rs`: the history kept for good.
+- `mirror.rs`: git and LFS for nodes. `warm.rs`: keeping nodes' builds warm. `deploy.rs`: `midas deploy`. `ship.rs`: deploying what landed, in batches. `push.rs`: waking a person's phone when something needs them. `builds.rs`, `stats.rs`, `chart.rs`: the history kept for good.
- `hubsetup.rs`: `sudo midas hub setup`, which installs the binary and the units in `units/`.
**A build machine and its node**
diff --git a/docs/hub.md b/docs/hub.md
index 2748bba..bb7079d 100644
--- a/docs/hub.md
+++ b/docs/hub.md
@@ -544,7 +544,7 @@ sender's pid, command line and session, a panic with where, or, from the
supervisor, a death the runner could not record (SIGKILL, a crash). The hub
stamps every runner's polls. One silent for 90 s is *away* (`runner_away`):
its sessions show as paused on the page, a line over the Sessions list says
-since when, it is mailed to `alerts` after ten minutes, and when it is back
+since when, and when it is back
(`runner_back`) an autopilot it ran gets back the time it was away. Workspace ▸
Services lists every stop and Activity counts them; `GET /v1/runners?since=S`
has them for anything else. The supervisor and its runner go together only by
@@ -1165,21 +1165,23 @@ it keeps doing TLS. It need not add a key any more either.
## 8. Hear about problems
-After each warm round (every 15 minutes) the hub takes what `midas check` fails
-for the nodes — no heartbeat, low disk, a build directory over its ceiling — and
-for its own disk (under 10 GB free where its state is), and
-mails each one still there an hour after it was first seen, once, to an
-`alerts` section of the same file. The warmer gets its chance first, so what
-arrives is what needs somebody:
+midas mails nobody. What it can fix it fixes: a build directory over its
+ceiling is trimmed by the warmer on a free node and by the node's own guard on
+a held one, once no session is on it (`midas log --kind trim`). What only a
+person can fix is on the Workspace page, over the network diagram — a node not
+reporting or out of the pool, short of disk or overloaded, the hub short of
+disk (under 10 GB free where its state is), a session waiting long for a node
+— and in `midas check`. A decision put to the person (`midas ask`) wakes a
+phone that turned on notifications (More ▸ Notify this device).
+
+Web Push services ask the sender for a way to reach it; name the owner's
+address in the same file (no mail goes to it):
```json
-"alerts": {"to": "you@example.org", "from": "midas <noreply@example.org>"}
+"contact": "you@example.org"
```
-It speaks plain SMTP to `smtp` (default `127.0.0.1:25`), which must relay for
-this machine without a login — a local Postfix does. Without the section, the
-problems are only logged (`midas log --kind alert`). Drained nodes are left
-out.
+An `alerts` section left from before is ignored.
## 9. Keep a copy elsewhere
@@ -1228,7 +1230,7 @@ healthy.
| `/srv/midas/callers.json` | caller keys (and their git tokens) |
| `/srv/midas/openai.key` | the OpenAI key for talking sessions over by voice (optional) |
| `/srv/midas/remote-mcp.json` | remote MCP servers and the tokens the hub calls them with (`midas remote set`) |
-| `/srv/midas/state/` | nodes, leases, the landing queue, readings, the log, the landing gate's receipts, the problems seen and mailed (`alerts.json`), and the history kept for good (`builds`, `takes`, `pool`, `landings`, `sessions` `.jsonl`, and `power/` by day) |
+| `/srv/midas/state/` | nodes, leases, the landing queue, readings, the log, the landing gate's receipts, and the history kept for good (`builds`, `takes`, `pool`, `landings`, `sessions` `.jsonl`, and `power/` by day) |
| `/srv/midas/deploy/` | deploys queued, being built, and built |
| `/var/lib/midas/deploy/` | root's copy of what is about to be published |
| `/srv/midas/.ssh/` | written by the hub itself from its node list |
diff --git a/docs/usage.md b/docs/usage.md
index c1fe380..8e85b9c 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -313,8 +313,8 @@ editing`), and a new file in common is news once for as long as both sessions
last and neither lands. The note names what each side changes in the file
(`src/a.rs (you: fn x; them: fn y)`). Who should give way, or whether one session should carry on the other's
work, is for the sessions to propose and the people steering them to decide:
-`midas ask` puts it to the person — mailed when the hub has `alerts` in
-hub.conf, and on the web page with a button per option — and the answer
+`midas ask` puts it to the person — on the web page with a button per option,
+and to a phone that turned on notifications — and the answer
reaches the asking session and every `--with` session as a note.
A next turn (`take --next`) drains the node for you: whoever is in line passes
diff --git a/src/alert.rs b/src/alert.rs
deleted file mode 100644
index 95865ce..0000000
--- a/src/alert.rs
+++ /dev/null
@@ -1,187 +0,0 @@
-//! Problems nobody fixed go to a person. After each warm (every 15 minutes) the
-//! hub takes what `midas check` fails for the nodes; one still there an hour
-//! after it was first seen is mailed once, to `hub.conf`'s `alerts.to`. What
-//! the warmer can fix it fixes first, so what reaches the mail is what needs
-//! somebody: a node that stopped reporting, a disk filled by something other
-//! than the build directory, a fix that failed.
-//!
-//! Before this, a problem showed only in a session's opening notes, and no
-//! session's work was to act on it: the Macs sat at 110 and 90 GB against the
-//! 24 GB ceiling for days.
-
-use std::collections::BTreeMap;
-use std::io::{BufRead, BufReader, Write};
-use std::net::TcpStream;
-use std::time::Duration;
-
-use anyhow::{bail, Context, Result};
-use serde::{Deserialize, Serialize};
-use serde_json::json;
-
-use crate::events;
-use crate::registry;
-
-/// How long a problem must last before it is mailed: longer than a warm, so
-/// the warmer gets its chance, and than a node's restart.
-const LASTS_S: i64 = 3600;
-
-#[derive(Serialize, Deserialize)]
-struct Seen {
- since: i64,
- text: String,
- mailed: bool,
-}
-
-pub fn run() -> Result<()> {
- let path = registry::root().join("alerts.json");
- let mut seen: BTreeMap<String, Seen> = std::fs::read_to_string(&path).ok()
- .and_then(|t| serde_json::from_str(&t).ok()).unwrap_or_default();
- let now = registry::now();
- let problems: BTreeMap<String, String> = crate::check::node_problems()?.into_iter().map(|p| (key(&p), p)).collect();
- seen.retain(|k, _| problems.contains_key(k));
- for (k, text) in &problems {
- let s = seen.entry(k.clone()).or_insert(Seen { since: now, text: String::new(), mailed: false });
- s.text = text.clone();
- }
- let due: Vec<&mut Seen> = seen.values_mut().filter(|s| !s.mailed && now - s.since >= LASTS_S).collect();
- if !due.is_empty() {
- let lines: Vec<String> = due.iter().map(|s| format!("- {} (for {} min)", s.text, (now - s.since) / 60)).collect();
- events::emit("alert", json!({"problems": lines}));
- if let Some(a) = crate::conf::hub().alerts {
- let subject = match lines.len() {
- 1 => format!("midas: {}", due[0].text),
- n => format!("midas: {n} workspace problems"),
- };
- let body = format!("Still there an hour after midas first saw them:\n\n{}\n\n\
- `midas check` in any agent session shows the whole report. Each problem is mailed once; \
- one that clears and comes back is mailed again.\n", lines.join("\n"));
- mail(&a, &subject, &body).context("mailing the alert")?;
- }
- for s in due {
- s.mailed = true;
- }
- }
- let tmp = path.with_extension("json.tmp");
- std::fs::write(&tmp, serde_json::to_string_pretty(&seen)?)?;
- std::fs::rename(&tmp, &path)?;
- Ok(())
-}
-
-/// A problem's identity: its text without the numbers, so "3 GB free" and
-/// "2 GB free" are the same problem and not a fresh one every reading. The node
-/// before the colon keeps its digits: mac-1 is not mac-2.
-fn key(problem: &str) -> String {
- let (node, what) = problem.split_once(':').unwrap_or(("", problem));
- let mut out = format!("{node}:");
- for c in what.chars() {
- if c.is_ascii_digit() {
- if !out.ends_with('#') {
- out.push('#');
- }
- } else {
- out.push(c);
- }
- }
- out
-}
-
-/// Plain SMTP to a relay that takes this machine's mail without a login. Not
-/// `sendmail`: the warmer runs with NoNewPrivileges, and Postfix's sendmail
-/// needs its setgid postdrop.
-pub(crate) fn mail(a: &crate::conf::Alerts, subject: &str, body: &str) -> Result<()> {
- let stream = TcpStream::connect(&a.smtp).with_context(|| format!("connecting to {}", a.smtp))?;
- stream.set_read_timeout(Some(Duration::from_secs(30)))?;
- let mut r = BufReader::new(stream.try_clone()?);
- let mut w = stream;
- let mut expect = |code: &str| -> Result<()> {
- loop {
- let mut line = String::new();
- r.read_line(&mut line)?;
- if !line.starts_with(code) {
- bail!("the mail server said {:?}, wanted {code}", line.trim());
- }
- if line.as_bytes().get(3) != Some(&b'-') {
- return Ok(());
- }
- }
- };
- expect("220")?;
- for (cmd, code) in [("EHLO midas".to_string(), "250"), (format!("MAIL FROM:<{}>", bare(&a.from)), "250"),
- (format!("RCPT TO:<{}>", bare(&a.to)), "250"), ("DATA".into(), "354")] {
- write!(w, "{cmd}\r\n")?;
- expect(code)?;
- }
- let mut msg = format!("From: {}\r\nTo: {}\r\nSubject: {subject}\r\nDate: {}\r\n\
- Content-Type: text/plain; charset=utf-8\r\n\r\n", a.from, a.to, chrono::Utc::now().to_rfc2822());
- for line in body.lines() {
- // A line of one dot ends the message; a leading dot is doubled.
- msg.push_str(if line.starts_with('.') { "." } else { "" });
- msg.push_str(line);
- msg.push_str("\r\n");
- }
- write!(w, "{msg}.\r\n")?;
- expect("250")?;
- write!(w, "QUIT\r\n")?;
- Ok(())
-}
-
-/// `midas <noreply@example.org>` → `noreply@example.org`.
-fn bare(addr: &str) -> &str {
- match (addr.find('<'), addr.rfind('>')) {
- (Some(a), Some(b)) if a < b => &addr[a + 1..b],
- _ => addr.trim(),
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn a_problem_keeps_its_identity_when_its_numbers_change() {
- assert_eq!(key("mac-1: 3 GB free on /work"), key("mac-1: 12 GB free on /work"));
- assert_ne!(key("mac-1: 3 GB free on /work"), key("mac-2: 3 GB free on /work"));
- }
-
- #[test]
- fn a_mail_goes_through_an_smtp_conversation() {
- let server = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
- let smtp = server.local_addr().unwrap().to_string();
- let got = std::thread::spawn(move || {
- let (s, _) = server.accept().unwrap();
- let mut r = BufReader::new(s.try_clone().unwrap());
- let mut w = s;
- let mut said = String::new();
- let mut line = String::new();
- write!(w, "220 hi\r\n").unwrap();
- for reply in ["250-hello\r\n250 SIZE 1000", "250 ok", "250 ok", "354 go on"] {
- line.clear();
- r.read_line(&mut line).unwrap();
- said.push_str(&line);
- write!(w, "{reply}\r\n").unwrap();
- }
- loop {
- line.clear();
- r.read_line(&mut line).unwrap();
- if line == ".\r\n" {
- break;
- }
- said.push_str(&line);
- }
- write!(w, "250 queued\r\n").unwrap();
- said
- });
- let a = crate::conf::Alerts { to: "you@example.org".into(), from: "midas <noreply@example.org>".into(), smtp };
- mail(&a, "midas: mac-1: 3 GB free", "one\n.dot\n").unwrap();
- let said = got.join().unwrap();
- assert!(said.starts_with("EHLO midas\r\nMAIL FROM:<noreply@example.org>\r\nRCPT TO:<you@example.org>\r\nDATA\r\n"), "{said}");
- assert!(said.contains("Subject: midas: mac-1: 3 GB free\r\n"));
- assert!(said.ends_with("\r\none\r\n..dot\r\n"), "{said}");
- }
-
- #[test]
- fn an_address_loses_its_name() {
- assert_eq!(bare("midas <noreply@example.org>"), "noreply@example.org");
- assert_eq!(bare("someone@example.org"), "someone@example.org");
- }
-}
diff --git a/src/check.rs b/src/check.rs
index 4a038bd..93018ec 100644
--- a/src/check.rs
+++ b/src/check.rs
@@ -33,13 +33,13 @@ const NODE_OWNER: &str = "for the node's owner";
struct Report {
/// Every check printed, ✓ too.
verbose: bool,
- /// Collect the problems instead of printing (the hub's alerts).
+ /// Collect the problems instead of printing (the tests).
quiet: bool,
/// Problems the caller can act on: the exit status.
yours: i32,
/// Problems for an owner: printed and labelled, not counted.
owners: i32,
- /// Every problem's text, whoever's (what the alerts mail).
+ /// Every problem's text, whoever's.
problems: Vec<String>,
/// The section being checked: its name, what passed, what did not.
section: String,
@@ -243,22 +243,6 @@ pub fn check(verbose: bool) -> Result<i32> {
Ok(r.yours.min(100))
}
-/// What `midas check` fails for the nodes, read from the hub's own state: what
-/// the hub mails about when it lasts (`alert.rs`). Drained nodes are left out —
-/// somebody already knows about them.
-pub fn node_problems() -> Result<Vec<String>> {
- let mut r = Report { quiet: true, ..Default::default() };
- let nodes = registry::Locked::open()?.nodes().clone();
- for n in nodes.iter().filter(|n| n["enabled"].as_bool().unwrap_or(true) && !n["drained"].is_object()) {
- let reading = registry::reading(n["id"].as_str().unwrap_or("?"));
- node(&mut r, n, reading.as_ref());
- }
- // And the disk the alerts themselves run on: nobody else watches it.
- if let Some((free, _)) = crate::util::disk_space(®istry::root()) {
- r.owner_check(free >= HUB_LOW_DISK, &format!("hub: {} GB free on its state disk", free / 1_000_000_000), "for the hub's owner");
- }
- Ok(r.problems)
-}
fn node(r: &mut Report, n: &Value, reading: Option<&Value>) {
let id = n["id"].as_str().unwrap_or("?");
@@ -278,9 +262,11 @@ fn node(r: &mut Report, n: &Value, reading: Option<&Value>) {
r.owner_check(free >= 10_000_000_000, &format!("{id}: {} GB free on /work", free / 1_000_000_000), NODE_OWNER);
}
if let Some(t) = rd["target_bytes"].as_u64() {
- // The warmer's own ceiling, which follows the disk: it trims a node over it.
+ // The warmer's own ceiling, which follows the disk: the node's guard trims
+ // target/ back under it once no session is on it (node::trim_target).
let c = crate::warm::ceiling(t, rd["disk_free"].as_u64());
- r.owner_check(t <= c, &format!("{id}: target/ {:.1} GB (ceiling {})", t as f64 / 1e9, c / 1_000_000_000), NODE_OWNER);
+ r.owner_check(t <= c, &format!("{id}: target/ {:.1} GB (ceiling {})", t as f64 / 1e9, c / 1_000_000_000),
+ "trimmed by the node once no session is on it");
}
match rd["warm"].as_str().and_then(|w| w.get(..8)) {
Some(w) => r.owner_check(true, &format!("{id}: warm at {w}"), NODE_OWNER),
@@ -308,7 +294,7 @@ mod tests {
let rd = json!({"at": registry::now(), "disk_free": 12_000_000_000u64, "target_bytes": 29_400_000_000u64, "warm": "0123456789"});
node(&mut r, &json!({"id": "mac-1"}), Some(&rd));
assert_eq!((r.yours, r.owners), (0, 1));
- assert_eq!(r.problems, vec!["mac-1: target/ 29.4 GB (ceiling 24)".to_string()], "the alert's text, without the label");
+ assert_eq!(r.problems, vec!["mac-1: target/ 29.4 GB (ceiling 24)".to_string()], "the text, without the label");
// With 50 GB free the same target/ is within what the disk allows.
let mut roomy = Report { quiet: true, ..Default::default() };
node(&mut roomy, &json!({"id": "mac-1"}), Some(&json!({"at": registry::now(), "disk_free": 50_000_000_000u64, "target_bytes": 29_400_000_000u64, "warm": "0123456789"})));
diff --git a/src/collab.rs b/src/collab.rs
index 8208271..362a21d 100644
--- a/src/collab.rs
+++ b/src/collab.rs
@@ -1098,8 +1098,9 @@ pub fn todos() -> Value {
// ── Decisions ────────────────────────────────────────────────────────────────
//
// What only the person steering the sessions may decide. A session asks
-// (`midas ask "…" --option A --option B --with <other session>`); the hub
-// mails the person and the web page shows it with a button per option; the
+// (`midas ask "…" --option A --option B --with <other session>`); the web
+// page shows it with a button per option, and wakes a phone that asked to be
+// (`push.rs`); the
// answer reaches the asker and every session it named, as a note.
/// Ask the person. Returns its id (`d<n>`).
@@ -1182,23 +1183,6 @@ pub fn decisions() -> Value {
json!(v)
}
-/// The mail a new decision sends the person, if the hub mails (`alerts` in
-/// hub.conf). Best effort, off the request's thread.
-pub fn mail_decision(id: &str, by: &str, question: &str, options: &[String]) {
- let Some(a) = crate::conf::hub().alerts else { return };
- let opts = if options.is_empty() { "(a free answer)".to_string() } else {
- options.iter().enumerate().map(|(i, o)| format!(" {}. {o}", i + 1)).collect::<Vec<_>>().join("\n")
- };
- let subject = format!("midas: {by} asks you to decide ({id})");
- let body = format!("{question}\n\n{opts}\n\nAnswer on the workspace's web page (Decisions), or from a session: \
- midas decide {id} <number or option>\n");
- crate::util::spawn_detached("mailing a decision", move || {
- if let Err(e) = crate::alert::mail(&a, &subject, &body) {
- events::emit("error", json!({"actor": "hub", "what": format!("mailing a decision: {e:#}")}));
- }
- });
-}
-
// ── Archived cards ───────────────────────────────────────────────────────────
//
// A person puts a session's card away (a landing they have seen, a session
diff --git a/src/conf.rs b/src/conf.rs
index 350a476..8465e8d 100644
--- a/src/conf.rs
+++ b/src/conf.rs
@@ -32,10 +32,10 @@ pub struct HubConf {
/// repository's.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub deploy: std::collections::BTreeMap<String, Deploy>,
- /// Where a problem that outlasts an hour is mailed (`alert.rs`). Unset, it
- /// is only logged.
+ /// An address the hub's owner is reached at, which Web Push services ask a
+ /// sender to name (`push.rs`). Nothing is mailed to it: midas mails nobody.
#[serde(default, skip_serializing_if = "Option::is_none")]
- pub alerts: Option<Alerts>,
+ pub contact: Option<String>,
/// Each project's own part of the shared workflow skills (`skills/`), by
/// repository, `owner/name`: what its landing gates on. A session reads its
/// project's with `midas project`.
@@ -91,20 +91,6 @@ pub struct Target {
pub deploy: Deploy,
}
-/// Mail for problems nobody has fixed: sent through an SMTP server that relays
-/// for this machine without a login (a local Postfix, say).
-#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
-pub struct Alerts {
- pub to: String,
- pub from: String,
- #[serde(default = "local_smtp")]
- pub smtp: String,
-}
-
-fn local_smtp() -> String {
- "127.0.0.1:25".into()
-}
-
/// One thing the workspace deploys (`midas deploy <target>`): built on a node from a
/// commit on the warm branch, then published on this machine by root. Every
/// field here is the root-owned config's — nothing an agent or a node sends
@@ -294,7 +280,7 @@ impl Default for HubConf {
agent_keys: vec![],
warm: Warm::default(),
deploy: Default::default(),
- alerts: None,
+ contact: None,
projects: Default::default(),
self_update: String::new(),
}
diff --git a/src/hub.rs b/src/hub.rs
index 5ad3abc..bf7cd59 100644
--- a/src/hub.rs
+++ b/src/hub.rs
@@ -510,9 +510,11 @@ fn api(method: &str, path: &str, query: &str, body: &Value, who: &Who, peer: &st
None => json!({"caller": null, "account": null, "role": null}),
})),
("GET", "state") => {
- // With the hub's own address and build, for the page's network diagram.
+ // With the hub's own address and build, for the page's network diagram,
+ // and its state disk's free space, which nothing but the page watches.
let mut st = registry::snapshot()?;
- st["hub"] = json!({"listen": crate::conf::hub().listen, "version": crate::VERSION});
+ st["hub"] = json!({"listen": crate::conf::hub().listen, "version": crate::VERSION,
+ "disk_free": crate::util::disk_space(®istry::root()).map(|d| d.0)});
return Ok((200, st));
}
// Paired devices (device.rs), with the tools each announced: no tokens.
@@ -1189,7 +1191,6 @@ fn api(method: &str, path: &str, query: &str, body: &Value, who: &Who, peer: &st
.filter_map(|v| v.as_str().map(str::to_string)).collect() };
let (question, options, with) = (s("question").unwrap_or_default(), list("options"), list("with"));
let id = crate::collab::decision_add(&owner, &question, &options, &with)?;
- crate::collab::mail_decision(&id, &owner, &question, &options);
(200, json!({"id": id}))
}
("POST", "decisions/answer") => {
diff --git a/src/main.rs b/src/main.rs
index 0d8cee0..5c357b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,6 @@
mod accounts;
mod agents;
mod acp;
-mod alert;
mod ask;
mod browser;
mod autopilot;
@@ -1578,16 +1577,7 @@ fn run(cmd: Cmd, owner: Option<String>) -> anyhow::Result<i32> {
Cmd::Hub(HubCmd::Caller(CallerCmd::List)) => hubsetup::caller_list(),
Cmd::Hub(HubCmd::Caller(CallerCmd::Remove { name })) => hubsetup::caller_remove(&name),
Cmd::Hub(HubCmd::Git { node }) => mirror::serve_git(&node),
- Cmd::Hub(HubCmd::Warm { node, dry_run }) => warm::warm(node.as_deref(), dry_run).inspect(|_| {
- // After the warm, so what it fixed is not mailed; only for the timer's
- // full round, not a one-node warm somebody started.
- if node.is_none() && !dry_run {
- if let Err(e) = alert::run() {
- events::emit("error", json!({"actor": "alert", "what": format!("{e:#}")}));
- eprintln!("midas alert: {e:#}");
- }
- }
- }),
+ Cmd::Hub(HubCmd::Warm { node, dry_run }) => warm::warm(node.as_deref(), dry_run),
Cmd::Hub(HubCmd::Backup) => hubsetup::backup(),
Cmd::Hub(HubCmd::DeployBuild) => deploy::build_pending(),
Cmd::Hub(HubCmd::DeployPublish) => deploy::publish_ready(),
diff --git a/src/push.rs b/src/push.rs
index 16b0c08..a33b3ae 100644
--- a/src/push.rs
+++ b/src/push.rs
@@ -208,8 +208,8 @@ fn send_all(waiting: usize, to: &BTreeSet<String>) {
}
let Ok(k) = key() else { return };
let Ok(public) = public_key() else { return };
- // Push services want a way to reach the sender: the address problems are mailed to, else a placeholder.
- let sub = crate::conf::hub().alerts.map(|a| format!("mailto:{}", a.to)).unwrap_or_else(|| "mailto:midas@localhost".into());
+ // Push services want a way to reach the sender: the owner's address, else a placeholder.
+ let sub = format!("mailto:{}", crate::conf::hub().contact.unwrap_or_else(|| "midas@localhost".into()));
let mut gone: Vec<String> = Vec::new();
let subs = read_subs();
for s in subs.iter().filter(|s| ours(s)) {
diff --git a/src/runners.rs b/src/runners.rs
index 9245023..422b169 100644
--- a/src/runners.rs
+++ b/src/runners.rs
@@ -15,8 +15,8 @@
//! a death the runner could not record (SIGKILL, a crash).
//! * **On the hub**, every runner's polls are stamped. One that has not asked for
//! work for [`AWAY_AFTER_S`] is *away* (`runner_away`): its sessions show as
-//! paused on the page, a mail goes out after [`MAIL_AFTER_S`], and when it is
-//! back (`runner_back`) an autopilot it was running gets the time back.
+//! paused on the page, and when it is back (`runner_back`) an autopilot it was
+//! running gets the time back.
//! * `GET /v1/runners` reads the events back for the page: each runner now, its
//! stops, and the time it was away.
@@ -282,8 +282,6 @@ pub fn guard(name: &str) {
/// Not asking for work this long, a runner is away. A poll waits at most twenty
/// seconds for something to give, and the runner asks again at once.
pub const AWAY_AFTER_S: i64 = 90;
-/// Away this long, it is mailed (`alerts` in hub.conf).
-pub const MAIL_AFTER_S: i64 = 600;
#[derive(Default)]
struct Seen {
@@ -291,7 +289,6 @@ struct Seen {
polled: i64,
/// Since when it is away, once that is noticed.
away: Option<i64>,
- mailed: bool,
}
fn seen() -> std::sync::MutexGuard<'static, BTreeMap<String, Seen>> {
@@ -306,7 +303,6 @@ pub fn polled(runner: &str) {
let mut s = seen();
let r = s.entry(runner.to_string()).or_default();
r.polled = now;
- r.mailed = false;
r.away.take()
};
if let Some(since) = back {
@@ -320,46 +316,29 @@ pub fn away_since(runner: &str) -> Option<i64> {
}
/// The hub's watch over its runners, every fifteen seconds: one that stopped
-/// asking is away, said once, and mailed once if it stays away.
+/// asking is away, said once. Nobody is mailed: the host's watch timer starts it
+/// again, and the page shows the time it was away.
pub fn watch() {
loop {
std::thread::sleep(Duration::from_secs(15));
- let now = crate::registry::now();
- let (gone, mail) = notice(now);
- for (name, since) in gone {
+ for (name, since) in notice(crate::registry::now()) {
let sessions = live_sessions(&name);
events::emit("runner_away", json!({"runner": name, "since": since, "sessions": sessions}));
}
- for (name, since) in mail {
- let Some(a) = crate::conf::hub().alerts else { continue };
- let body = format!("The sessions runner {name} has not asked the hub for work since {} UTC ({} min). \
- The {} sessions it was running are paused until it is back.\n\n\
- On its machine: `pgrep -af 'midas sessions run'`, and the end of ~/.local/state/midas/runner.log.\n",
- chrono::DateTime::from_timestamp(since, 0).map(|t| t.format("%Y-%m-%d %H:%M").to_string()).unwrap_or_default(),
- (now - since) / 60, live_sessions(&name));
- if let Err(e) = crate::alert::mail(&a, &format!("midas: the sessions runner {name} is away"), &body) {
- events::emit("error", json!({"what": format!("mailing that {name} is away: {e:#}")}));
- }
- }
}
}
-/// What changed by `now`: the runners newly away, and those away long enough to mail, each with since when.
+/// The runners newly away by `now`, each with since when.
type Noticed = Vec<(String, i64)>;
-fn notice(now: i64) -> (Noticed, Noticed) {
+fn notice(now: i64) -> Noticed {
let mut gone = Vec::new();
- let mut mail = Vec::new();
for (name, r) in seen().iter_mut() {
if r.away.is_none() && now - r.polled >= AWAY_AFTER_S {
r.away = Some(r.polled);
gone.push((name.clone(), r.polled));
}
- if let Some(since) = r.away.filter(|since| !r.mailed && now - since >= MAIL_AFTER_S) {
- r.mailed = true;
- mail.push((name.clone(), since));
- }
}
- (gone, mail)
+ gone
}
/// The sessions a runner has that are live: started, at work, or waiting on the person.
@@ -433,22 +412,18 @@ mod tests {
use super::*;
#[test]
- fn a_runner_that_stops_asking_is_away_then_mailed_once_and_back_when_it_asks() {
+ fn a_runner_that_stops_asking_is_away_once_and_back_when_it_asks() {
let name = "runner@test-away";
polled(name);
let t0 = seen()[name].polled;
let mine = |v: &Noticed| v.iter().filter(|(n, _)| n == name).count();
// Within the poll's wait: still there.
- assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S - 1).0), 0);
+ assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S - 1)), 0);
assert_eq!(away_since(name), None);
// Past it: away since its last poll, said once.
- assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S).0), 1);
+ assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S)), 1);
assert_eq!(away_since(name), Some(t0));
- assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S + 15).0), 0);
- // Mailed once, after MAIL_AFTER_S.
- assert_eq!(mine(¬ice(t0 + MAIL_AFTER_S - 1).1), 0);
- assert_eq!(mine(¬ice(t0 + MAIL_AFTER_S).1), 1);
- assert_eq!(mine(¬ice(t0 + MAIL_AFTER_S + 60).1), 0);
+ assert_eq!(mine(¬ice(t0 + AWAY_AFTER_S + 15)), 0);
// It asks again: there, and away anew only after another silence.
polled(name);
assert_eq!(away_since(name), None);
diff --git a/web/src/components/workspace.tsx b/web/src/components/workspace.tsx
index ffa63b8..fb3b40a 100644
--- a/web/src/components/workspace.tsx
+++ b/web/src/components/workspace.tsx
@@ -223,6 +223,9 @@ class DeployDialog extends MithrilComponent {
/** Something wrong with the machines, in a line each: what the person may want to act on first. */
function problems(ws: WorkspaceState): string[] {
const out: string[] = []
+ // Its state, git mirrors and sessions share one disk: full, every take and every write fails (check.rs's HUB_LOW_DISK).
+ const hubFree = ws.hub?.disk_free
+ if (hubFree != null && hubFree < 10e9) out.push(`the hub is short of disk: ${Math.floor(hubFree / 1e9)} GB free where its state is`)
for (const n of ws.nodes) {
const lease = ws.leases[n.id]
const st = nodeState(n, lease)
diff --git a/web/src/lib/types.ts b/web/src/lib/types.ts
index 7b34c40..2de6507 100644
--- a/web/src/lib/types.ts
+++ b/web/src/lib/types.ts
@@ -66,8 +66,8 @@ export interface LandingTurn {
}
export interface WorkspaceState {
- /** The hub itself: where it listens on the tunnel, and its build. */
- hub?: {listen: string; version: string}
+ /** The hub itself: where it listens on the tunnel, its build, and its state disk's free bytes. */
+ hub?: {listen: string; version: string; disk_free?: number | null}
nodes: Node[]
leases: Record<string, Lease>
waiters: Record<string, Waiter>