From 99ebfcfb38cb5c7589cf9c5417b819f0bc34fa94 Mon Sep 17 00:00:00 2001 From: Semprini Date: Sat, 19 Sep 2026 18:06:22 +1200 Subject: [PATCH] Run semprini-core's service desk every minute; --hold never shortens The service desk (Semprini/service-desk) is fulfilled by semprini-core's core_stack/scripts/service-desk.py. The daemon runs its poll between agent runs, skips it during a hold, and posts to Stack Maintenance what needs a person: an approval, a failure, an "Ask core" request, a finished request. --hold from a shell no longer shortens a longer hold: sync-to-host.sh's 15 minutes on each deploy cut a 2-hour hold short on 2026-09-19. Co-Authored-By: Claude Opus 5 --- CLAUDE.md | 9 +++++++- README.md | 3 ++- maintainer.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 990587d..0a93dd5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,7 +39,14 @@ JSON result. one triage run covers the whole hold. It lives in `hold.json` next to the state file because a shell has to reach a daemon that owns its own state file, and it expires by itself so nothing stays paused by accident. semprini-core's `sync-to-host.sh` sets 15 - minutes on each deploy. + minutes on each deploy. `--hold` from a shell never shortens a longer hold already in + force; `hold` in Matrix does what it says. +- **Service desk** (1 min, `desk` in config): runs semprini-core's + `core_stack/scripts/service-desk.py poll --json`, which fulfils the open requests in + `Semprini/service-desk` (zones, for now) and answers in each issue. It is a script, not + an agent run: it takes its turn between runs and waits out a hold. Requests needing + approval, failures, "Ask core" requests and finished requests are posted to Stack + Maintenance. Nothing from an issue reaches the agent unless the operator passes it on. - **Alerts** (`#stack-alerts`, written by `@alerts` via Loki → Alertmanager → matrix-alerts): FIRING messages are batched for `alerts.batch_seconds` and triaged in one run, answered in a thread under the alert. Non-`ok` results are mirrored to Stack diff --git a/README.md b/README.md index f701ab5..203d46c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ A message that is exactly one of these words is handled at once, even mid-run: |---|---| | `status` | What it is doing, the queue, health, host, next upgrade | | `cancel` / `stop` | Stop the agent run in progress | -| `hold 45m ` | Stand down for a while: `hold` alone is 30 minutes, 8 hours is the most. Your messages still run and alerts still collect; health checks, triage and upgrades wait, and it says so when the hold starts and when it runs out | +| `hold 45m ` | Stand down for a while: `hold` alone is 30 minutes, 8 hours is the most. Your messages still run and alerts still collect; health checks, triage, upgrades and the service desk wait, and it says so when the hold starts and when it runs out | | `resume` | End a hold now | | `new` | Forget this room's conversation | | `upgrade` | Run the weekly upgrade now | @@ -49,6 +49,7 @@ A message that is exactly one of these words is handled at once, even mid-run: | — Host rebooted | Verify every stack came back | | Daily, 21:00 UTC | 📋 report: monitors, downtime, alerts, agent runs, commits, pending reboot or decision | | Weekly, Sat 22:00 UTC | Upgrade every image and host packages: test, pin, commit, push, roll back on failure. Majors and reboots are escalated | +| Every minute | Service desk: semprini-core's `service-desk.py` fulfils the open requests in [Semprini/service-desk](https://git.semprini.me/Semprini/service-desk). What needs you is posted here: 🙋 an approval (`/approve` or `/reject` on the issue), ⛔ a failure (`/retry` once fixed), 📨 an "Ask core" request, ✅ a finished one. Waits out a hold | | Hourly | Self-update from this repo | Scope for remediation is **whatever Uptime Kuma tracks at check time**, re-read every diff --git a/maintainer.py b/maintainer.py index 020f8a1..c316421 100755 --- a/maintainer.py +++ b/maintainer.py @@ -21,6 +21,9 @@ Event-driven where something announces itself: - a daily report at a fixed UTC hour - the weekly upgrade at a fixed UTC weekday and hour - self-update from this checkout's git remote + - the service desk (1 min): semprini-core's scripts/service-desk.py + fulfils the open requests in Semprini/service-desk. It is a script, + not an agent run; what needs a person is posted to Stack Maintenance. All agent work runs one task at a time through the canonical stack-support agent (semprini-core/agents/stack-support.agent.md), headless via Claude Code. @@ -129,6 +132,14 @@ DEFAULTS = { "git_author_name": "Claude Code", "git_author_email": "claude-code@semprini.me", }, + # The service desk: requests to core, as issues in Semprini/service-desk. + # semprini-core's script fulfils them; it runs here so it takes turns with + # agent runs and waits out a hold. interval_seconds 0 turns it off. + "desk": { + "script": "core_stack/scripts/service-desk.py", + "interval_seconds": 60, + "timeout_seconds": 900, + }, "matrix": { "homeserver": "https://matrix.semprini.me", "user_id": "", @@ -139,7 +150,7 @@ DEFAULTS = { }, } -NESTED = ("alerts", "host", "git", "gitea", "matrix") +NESTED = ("alerts", "host", "git", "gitea", "desk", "matrix") def load_config(path): @@ -1584,6 +1595,10 @@ class Maintainer: if now - s.get("last_health", 0) >= cfg["health_interval_seconds"]: s["last_health"] = now self.health_cycle() + if (cfg["desk"]["interval_seconds"] and not self.hold() + and now - s.get("last_desk", 0) >= cfg["desk"]["interval_seconds"]): + s["last_desk"] = now + self.desk_poll() if s.get("last_digest", 0) < last_daily_slot(utcnow(), cfg["digest_hour_utc"]).timestamp(): s["last_digest"] = now self.digest() @@ -1603,6 +1618,39 @@ class Maintainer: self.self_update() self.save() + def desk_poll(self): + """One pass over the service desk's open requests. The script builds + what they ask for and answers in each issue; this relays what needs a + person: an approval, a failure, a request for a person, a finished one.""" + script = os.path.join(self.cfg["repo_dir"], self.cfg["desk"]["script"]) + if not os.path.isfile(script): + return + try: + p = subprocess.run([sys.executable, script, "poll", "--json"], capture_output=True, text=True, + cwd=os.path.dirname(os.path.dirname(script)), + timeout=self.cfg["desk"]["timeout_seconds"]) + out = json.loads(p.stdout or "{}") if p.returncode == 0 else None + except (subprocess.TimeoutExpired, ValueError) as e: + self.note_error(f"service desk: {e}") + return + if out is None: + self.note_error(f"service desk exited {p.returncode}: {p.stderr.strip()[-300:]}") + return + say = {"needs-approval": ("🙋", "needs your approval: {text}. Comment `/approve` or `/reject` on it"), + "failed": ("⛔", "failed: {text}. Once fixed, comment `/retry` on it"), + "triage": ("📨", "is a request for a person"), + "done": ("✅", "is done")} + for ev in out.get("events", []): + log(f"Desk #{ev['issue']} {ev['state']}: {ev['text']}") + if ev.get("notify") and ev["state"] in say: + icon, what = say[ev["state"]] + self.send(f"{icon} **Service desk #{ev['issue']}** {ev['title']} " + f"{what.format(text=ev['text'][:400])}: {ev['url']}") + for err in out.get("errors", []): + log(f"Desk: {err}") + if not err.startswith("#"): # the desk itself, not one request + self.note_error(f"service desk: {err}") + def health_cycle(self): with self.lock: if any(t["kind"] == "health" for t in self.state.get("queue") or []): @@ -2131,6 +2179,9 @@ def self_check(cfg): for r in cfg["git"]["repos"]: if not os.path.isdir(os.path.join(r["path"], ".git")): warnings.append(f"{r['path']} is not a git checkout") + desk = os.path.join(cfg["repo_dir"], cfg["desk"]["script"]) + if cfg["desk"]["interval_seconds"] and not os.path.isfile(desk): + warnings.append(f"no service desk script at {desk}: requests wait") for w in warnings: print(f"WARN: {w}") for e in errors: @@ -2199,6 +2250,12 @@ def main(): if minutes is None: print(f"not a duration: {args.hold!r} — try 45m or 2h") return 1 + # Scripts hold too (sync-to-host.sh sets 15 minutes on every deploy), and + # must not cut short a longer hold someone set for their own work. + held = read_hold(cfg) + if held and held["until"] >= time.time() + minutes * 60: + print("already holding " + hold_line(held)) + return 0 print("holding " + hold_line(write_hold(cfg, minutes, args.reason, "the command line"))) return 0 if args.resume: