Run on the core host, on Claude Sonnet 5.5 via the Anthropic API; no Ollama
The daemon moves from WSL on the workstation to the core host, where it runs commands directly (core is the only host). One model profile, claude, with a 200k context and the existing cost caps. install.sh runs on the core host. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
974abbec1d
commit
12e6fef51c
9 files changed
+263
-271
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# semprini-maintainer — autonomous stack maintenance agent
|
||||
|
||||
A systemd service on the operator's workstation (EVAI, in WSL), keeping the semprini.me core
|
||||
stack on AWS Lightsail (`Semprini-Core`) healthy and current:
|
||||
A systemd service on the core host it keeps, AWS Lightsail `Semprini-Core`, keeping the
|
||||
semprini.me core stack healthy and current:
|
||||
- acts on critical log alerts the moment they are posted
|
||||
- upgrades everything the core host runs, weekly
|
||||
- keeps the semprini-core repo equal to what runs
|
||||
@@ -9,9 +9,9 @@ stack on AWS Lightsail (`Semprini-Core`) healthy and current:
|
||||
|
||||
It is the *unattended driver* for the canonical stack-support agent in the **semprini-core**
|
||||
repo (`agents/stack-support.agent.md`). The daemon notices events and hands the judgement
|
||||
calls to that agent, which it runs in-process with [pydantic-ai](https://ai.pydantic.dev) on the
|
||||
workstation's own model: GLM-4.7-Flash on Ollama, on the RTX 4090. Any model pydantic-ai
|
||||
supports can be configured instead. Design and decisions: [`docs/architecture.md`](docs/architecture.md).
|
||||
calls to that agent, which it runs in-process with [pydantic-ai](https://ai.pydantic.dev) on
|
||||
Claude (Sonnet 5.5) through the Anthropic API. Any model pydantic-ai supports can be
|
||||
configured instead. Design and decisions: [`docs/architecture.md`](docs/architecture.md).
|
||||
|
||||
## Talking to it
|
||||
|
||||
@@ -33,7 +33,7 @@ A message that is exactly one of these is handled at once, even mid-run:
|
||||
| `status` | What it is doing, the queue, the models, health, host, next upgrade |
|
||||
| `cancel` / `stop` | Stop the agent run in progress, and the command it is running |
|
||||
| `hold 45m <why>` | 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, this machine's and the core host's |
|
||||
| `resume` | End a hold now |
|
||||
| `new` | Forget this room's conversation |
|
||||
| `model` | The model it runs on. With more than one configured, `model <name>` puts that one first for your messages in this room, and `model auto` goes back to the default |
|
||||
| `upgrade` | Run the weekly upgrade now |
|
||||
@@ -50,10 +50,10 @@ A message that is exactly one of these is handled at once, even mid-run:
|
||||
| — Kuma monitor DOWN→UP between checks | Post-mortem from logs; changes nothing healthy |
|
||||
| — Disk ≥ 85%, memory < 400 MB, kernel OOM kill, restart loop, stale Kuma | Investigate and fix; 12h cooldown per finding |
|
||||
| — Core host rebooted | Verify every stack came back |
|
||||
| — Core host unreachable for 3 checks | 🚨 in Stack Maintenance (delivered once Matrix, which lives there, is back) |
|
||||
| — Health probe fails for 3 checks | 🚨 in Stack Maintenance (delivered once Matrix is 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 package on core: test, pin, commit, push, roll back on failure. Majors and reboots are escalated |
|
||||
| Every minute | Service desk: semprini-core's `service-desk.py`, run on the core host over SSH, 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 |
|
||||
| Every minute | Service desk: semprini-core's `service-desk.py`, run on the core host, 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
|
||||
@@ -65,17 +65,19 @@ image on the core host.
|
||||
Stack Maintenance ──┐ long-poll /sync (HTTPS)
|
||||
#stack-alerts ──────┤
|
||||
▼
|
||||
┌──────────── EVAI, WSL: maintainer.py ─────────────┐ ┌── Semprini-Core (Lightsail)
|
||||
│ listener thread: commands now, tasks → queue │ SSH │ probe.py: Kuma, disk, memory,
|
||||
│ worker: one agent run at a time │───────▶│ OOM kills, restarts, reboot
|
||||
│ (operator > alerts > health > upgrade) │ │ service-desk.py
|
||||
│ agent.py (pydantic-ai): shell · read/write/edit │ │ ~/semprini-core: the agent
|
||||
│ file · fetch_url, on a named host │ │ edits, commits and pushes here
|
||||
└───────┬──────────────────────────┬────────────────┘ └──────────────────────────────
|
||||
│ model │ kubectl, ssh (LAN) · powershell.exe
|
||||
┌──────────── Semprini-Core (Lightsail): maintainer.py ─────────────┐
|
||||
│ listener thread: commands now, tasks → queue │
|
||||
│ worker: one agent run at a time │
|
||||
│ (operator > alerts > health > upgrade) │
|
||||
│ agent.py (pydantic-ai): shell · read/write/edit file · fetch_url │
|
||||
│ probe.py: Kuma, disk, memory, OOM kills, restarts, reboot │
|
||||
│ service-desk.py · ~/semprini-core: the agent edits, commits and │
|
||||
│ pushes here │
|
||||
└───────┬──────────────────────────┬────────────────────────────────┘
|
||||
│ model (HTTPS) │ kubectl, ssh through the WireGuard tunnel
|
||||
▼ ▼
|
||||
Ollama on Windows (RTX 4090) The home cluster VMs: k3s and containers maintained
|
||||
GLM-4.7-Flash over the LAN; Hyper-V itself inspected only
|
||||
Anthropic API The home cluster VMs: k3s and containers, while the
|
||||
Claude Sonnet 5.5 workstation hosting them is on; Hyper-V is the operator's
|
||||
```
|
||||
|
||||
The agent's result is a typed envelope the daemon relays:
|
||||
@@ -86,15 +88,14 @@ The agent's result is a typed envelope the daemon relays:
|
||||
|
||||
## Models
|
||||
|
||||
One local model does everything: your messages, alert triage, health findings and the weekly
|
||||
One Claude model does everything: your messages, alert triage, health findings and the weekly
|
||||
upgrade. In `config.json`:
|
||||
|
||||
```json
|
||||
"models": {
|
||||
"local": {"model": "ollama:hf.co/bartowski/zai-org_GLM-4.7-Flash-GGUF:Q5_K_S",
|
||||
"base_url": "http://{windows_host}:11434/v1", "context_tokens": 131072}
|
||||
"claude": {"model": "anthropic:claude-sonnet-5.5", "context_tokens": 200000, "api_key": "…"}
|
||||
},
|
||||
"routing": {"operator": ["local"], "alerts": ["local"], "health": ["local"], "upgrade": ["local"]}
|
||||
"routing": {"operator": ["claude"], "alerts": ["claude"], "health": ["claude"], "upgrade": ["claude"]}
|
||||
```
|
||||
|
||||
- A profile is `provider:model`. `ollama:` and `anthropic:` are built in; `openai:` with a
|
||||
@@ -102,32 +103,29 @@ upgrade. In `config.json`:
|
||||
anything else pydantic-ai knows (`openai:gpt-…`, `google-gla:…`, `openrouter:…`) works with
|
||||
its key in `api_key` (`--set-api-key <profile>`) or the provider's environment variable.
|
||||
`settings` passes model settings through. `context_tokens` is the window the model is run
|
||||
with; older tool output is shortened as a conversation nears it.
|
||||
with; older tool output is shortened as a conversation nears it. Claude's 200k is below its
|
||||
real window on purpose: it caps what one long run re-sends, and pays for, at every step.
|
||||
- `routing` lists the profiles each kind of task tries, best first. With a second profile in a
|
||||
list, an unreachable model hands the run to the next at once, and a run that fails as a run
|
||||
(it loops until its budget is spent, or cannot produce the result) starts again on the next,
|
||||
told which commands the failed attempt ran.
|
||||
- `limits` caps each run: `request_limit`, `tool_calls_limit`, and `cost_usd` per kind of task,
|
||||
which only a priced (cloud) model is held to.
|
||||
- A cloud model is billed per token and needs an API key; a Claude subscription token (from
|
||||
`claude setup-token`) is for Claude Code only and does not work here.
|
||||
told which commands the failed attempt ran. Today there is no second profile, so no fallback.
|
||||
- `limits` caps each run: `request_limit`, `tool_calls_limit`, and `cost_usd` per kind of task
|
||||
($5, $15 for the upgrade), which only a priced model is held to; Claude Sonnet 5.5 is priced.
|
||||
- Claude is billed per token and needs an API key: `.venv/bin/python maintainer.py
|
||||
--set-api-key claude` prompts for it without echo, checks it with one request and saves it
|
||||
in `config.json`. A Claude subscription token (from `claude setup-token`) is for Claude Code
|
||||
only and does not work here.
|
||||
|
||||
**Choosing a local model.** A local model is only useful if it calls tools and *uses what they
|
||||
return*. `--try-model <profile>` checks both with one request, and checks Ollama's context
|
||||
window. Tested on the 4090 on 2026-09-26:
|
||||
|
||||
| Model (Ollama) | Size | Result |
|
||||
|---|---|---|
|
||||
| GLM-4.7-Flash, Q5_K_S | 19 GB | ✓ uses tool results; the default |
|
||||
| qwen3.5:35b | 22 GB | ✓ uses tool results; tight on 24 GB with a long context |
|
||||
| qwen3-coder | 17 GB | ✗ calls tools, then ignores their results |
|
||||
Until 2026-11-26 the daemon ran in WSL on the operator's workstation, on GLM-4.7-Flash in
|
||||
Ollama; `--try-model <profile>` is the test a model has to pass (it calls a tool and *uses
|
||||
what it returns*).
|
||||
|
||||
## Git: the repo is what runs
|
||||
|
||||
`~/semprini-core` on the core host is a git checkout of `main`. Before each run the daemon
|
||||
fast-forwards it if it is clean. The agent edits that checkout over SSH, commits every change
|
||||
fast-forwards it if it is clean. The agent edits that checkout in place, commits every change
|
||||
it applies to the live stack to `main` and pushes it as `claude-code`; a change it only
|
||||
proposes goes on a `maint/<topic>` branch with a pull request, opened from the workstation.
|
||||
proposes goes on a `maint/<topic>` branch with a pull request, opened from the core host.
|
||||
After each run the daemon pushes anything left unpushed, retrying if Gitea is down. It reports
|
||||
new commits, with a link, and any uncommitted changes. From a workstation checkout, deploy
|
||||
with semprini-core's `infra/sync-to-host.sh` (push, then fast-forward the host).
|
||||
@@ -135,50 +133,35 @@ with semprini-core's `infra/sync-to-host.sh` (push, then fast-forward the host).
|
||||
semprini-blog (GitHub) and conk are readable by the agent but not pushable, so it proposes
|
||||
patches for them instead.
|
||||
|
||||
## Setup on the workstation
|
||||
## Setup on the core host
|
||||
|
||||
Prerequisites:
|
||||
- WSL Ubuntu with systemd (`[boot] systemd=true` in `/etc/wsl.conf`)
|
||||
Prerequisites, on `ubuntu@3.107.254.151`:
|
||||
- python3, git and systemd (Ubuntu has them); `install.sh` installs uv
|
||||
- the core stack running, including Synapse, Gitea, matrix-alerts and Uptime Kuma
|
||||
- `~/semprini-core` on the core host is a git checkout of `main`, and its git pushes as
|
||||
`claude-code` (set up there by the previous install; keep
|
||||
`~/.local/state/semprini-maintainer/git-credentials` on the host)
|
||||
- Ollama on Windows, reachable from WSL (below)
|
||||
- `~/semprini-core` is a git checkout of `main`, and its git pushes as `claude-code`
|
||||
(`~/.local/state/semprini-maintainer/git-credentials`, kept from the earlier install)
|
||||
- an Anthropic API key
|
||||
|
||||
Stop any daemon running elsewhere first: one Matrix bot means one daemon. For the old WSL one,
|
||||
in WSL: `sudo systemctl disable --now semprini-maintainer`.
|
||||
|
||||
```bash
|
||||
git clone https://git.semprini.me/paul/semprini-maintainer.git ~/semprini-maintainer
|
||||
cd ~/semprini-maintainer
|
||||
cp config.example.json config.json # then copy matrix.* and gitea.token from the host's config.json
|
||||
./install.sh # uv, .venv, SSH check, --check, systemd unit, takes over from the host
|
||||
.venv/bin/python maintainer.py --try-model local # tool use and context window
|
||||
cp config.example.json config.json # then copy matrix.* and gitea.token from the old config.json
|
||||
./install.sh # uv, .venv, --check, systemd unit
|
||||
.venv/bin/python maintainer.py --set-api-key claude # prompts, checks, saves
|
||||
.venv/bin/python maintainer.py --try-model claude # tool use
|
||||
```
|
||||
|
||||
`install.sh` stops and disables the daemon on the core host just before it starts this one:
|
||||
both use the same Matrix bot, so two would answer everything twice and act twice. The host
|
||||
keeps its checkout of this repository, so `maintainer.py --hold` still works there.
|
||||
`install.sh` stops before the unit if `config.json` is missing. If `repo_host` in it has an
|
||||
`ssh` address (the daemon running somewhere else), it stops and disables the daemon on that
|
||||
host just before starting this one.
|
||||
|
||||
**SSH to core.** The service uses the WSL user's key. If `install.sh` cannot connect, it prints
|
||||
the three commands that create a key, trust the host and authorise the key.
|
||||
|
||||
**The home cluster.** From Windows, in semprini-core, run
|
||||
`.\infra\hyperv\cluster.ps1 maintainer-access`. It gives the WSL user `kubectl` (pinned to the
|
||||
cluster's version, in `~/.local/bin`) with the `elz-operator` kubeconfig, and a key of its own on
|
||||
every VM, usable only from the workstation's LAN address, behind `ssh sem-k8s-1..3` and
|
||||
`ssh sem-gw`. Re-run it after rebuilding a VM or when the workstation's address changes.
|
||||
|
||||
**Ollama on Windows.** By default Ollama listens on 127.0.0.1, which WSL's NAT network cannot
|
||||
reach. Turn on *Expose Ollama to the network* in the Ollama app's settings (the same as
|
||||
`OLLAMA_HOST=0.0.0.0:11434`). `{windows_host}` in a `base_url` is replaced by the Windows side
|
||||
of WSL's network (its default gateway, 172.23.160.1 today), which changes between boots but
|
||||
never needs editing. The LAN address (`http://192.168.1.10:11434/v1`) works too.
|
||||
|
||||
Exposed that way, Ollama answers the whole home LAN, and it has no authentication. To admit
|
||||
only WSL, turn the app setting's firewall rule into one scoped to WSL's range (as administrator):
|
||||
`New-NetFirewallRule -DisplayName "Ollama from WSL" -Direction Inbound -Protocol TCP -LocalPort 11434 -RemoteAddress 172.16.0.0/12 -Action Allow`,
|
||||
and disable the broader one.
|
||||
|
||||
**Keep WSL running.** WSL shuts down when nothing runs in it. A logon task keeps it up:
|
||||
`schtasks /Create /TN "WSL keep-alive" /SC ONLOGON /RL LIMITED /F /TR "wsl.exe -d Ubuntu --exec sleep infinity"`.
|
||||
**The home cluster** is reached through the WireGuard tunnel, only while the workstation that
|
||||
hosts its VMs is on: `kubectl` as `elz-operator` and `ssh sem-k8s-1..3`, `ssh sem-gw`, set up
|
||||
on this host by semprini-core (runbook → *Home Kubernetes Cluster*). Hyper-V itself is out of
|
||||
reach: the agent escalates anything about the VMs to the operator.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -186,7 +169,7 @@ and disable the broader one.
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `hosts` | core, local, windows | Where commands run: `ssh`, local bash, or `powershell` through WSL interop. `about` is what the agent is told about each |
|
||||
| `hosts` | core | Where commands run: local bash (no `ssh`), `ssh`, or `powershell`. `about` is what the agent is told about each |
|
||||
| `repo_host` / `repo_dir` | `core` / `/home/ubuntu/semprini-core` | The checkout that runs |
|
||||
| `models` / `routing` / `limits` | above | Model profiles, the order each kind of task tries them, per-run caps |
|
||||
| `autonomy` | `full` | `full` fixes and upgrades; `fix-only` fixes and only proposes upgrades; `notify` changes nothing (and has no file-writing tools) |
|
||||
@@ -198,32 +181,33 @@ and disable the broader one.
|
||||
| `alerts.batch_seconds` / `alerts.cooldown_seconds` / `alerts.ignore` | 60 / 43200 / `["PipelineTest"]` | Alert batching, re-investigation interval, alerts never investigated |
|
||||
| `host.*` | 85% disk, 400 MB memory | Core host check thresholds and cooldown |
|
||||
| `git.repos` | semprini-core on core | Checkouts the daemon fast-forwards and pushes |
|
||||
| `remote_hold_file` | the host's `hold.json` | Where a hold set on the core host is read from |
|
||||
| `remote_hold_file` | `""` | A hold file on the repo host, read each minute, for a daemon running elsewhere |
|
||||
|
||||
## Operating
|
||||
|
||||
- **Logs:** `journalctl -u semprini-maintainer -f` in WSL, or `status` in Matrix.
|
||||
- **Logs:** `journalctl -u semprini-maintainer -f` on the core host, or `status` in Matrix.
|
||||
- **Working on the stack yourself:** hold it, rather than stopping the service — a hold
|
||||
expires on its own, so nothing stays paused because someone forgot. From Matrix,
|
||||
`hold 45m upgrading postgres`; from a shell on the workstation, or on the core host:
|
||||
`hold 45m upgrading postgres`; from a shell on the core host:
|
||||
|
||||
```bash
|
||||
~/semprini-maintainer/maintainer.py --hold 45m --reason "upgrading postgres"
|
||||
~/semprini-maintainer/maintainer.py --resume
|
||||
```
|
||||
|
||||
`--hold` and `--resume` need only python3, so the core host's old checkout still takes them.
|
||||
The daemon reads the host's hold each minute and honours whichever hold ends later.
|
||||
semprini-core's `infra/sync-to-host.sh` sets 15 minutes there on every deploy.
|
||||
- **Stop everything it does:** `sudo systemctl stop semprini-maintainer` in WSL. For "watch
|
||||
but don't touch", set `"autonomy": "notify"` and restart the service.
|
||||
`--hold` and `--resume` need only python3. On the core host they write the daemon's own
|
||||
hold file; semprini-core's `infra/sync-to-host.sh` sets 15 minutes there on every deploy.
|
||||
(A daemon run elsewhere reads that file through `remote_hold_file` and honours whichever
|
||||
hold ends later.)
|
||||
- **Stop everything it does:** `sudo systemctl stop semprini-maintainer` on the core host. For
|
||||
"watch but don't touch", set `"autonomy": "notify"` and restart the service.
|
||||
- **Update the daemon:** push to `main` here. It fast-forwards within the hour, runs
|
||||
`uv sync` if the dependencies changed, runs `--check`, and restarts itself, or rolls back
|
||||
and says why.
|
||||
|
||||
### When no model can run
|
||||
|
||||
Ollama stopped or unreachable, or (for a cloud profile) a revoked key or a provider outage: the
|
||||
An Anthropic outage, a revoked or missing key, or the provider refusing for billing: the
|
||||
agent never started. That is a *maintainer* outage, not a stack verdict (`AgentUnavailable`). It
|
||||
is tracked per kind of task, because each kind can be routed to its own models.
|
||||
|
||||
@@ -234,15 +218,15 @@ is tracked per kind of task, because each kind can be routed to its own models.
|
||||
skips the wait.
|
||||
- `✅ maintainer recovered` when a run of that kind succeeds again; its tasks then drain.
|
||||
|
||||
A run that hits its time limit, is cancelled, or is rejected by the model is reported as
|
||||
⛔ blocked, with the commands it had run.
|
||||
A run that hits its time limit or its `cost_usd` cap, is cancelled, or is rejected by the model
|
||||
is reported as ⛔ blocked, with the commands it had run.
|
||||
|
||||
## Test without the service
|
||||
|
||||
```bash
|
||||
.venv/bin/python maintainer.py --check # parsers, schedule, config, agent wiring; warns on SSH and Ollama
|
||||
.venv/bin/python maintainer.py --check # parsers, schedule, config, agent wiring, network
|
||||
.venv/bin/python maintainer.py --check --offline # the same without touching the network
|
||||
.venv/bin/python maintainer.py --try-model local # one tool call; is the result used?
|
||||
.venv/bin/python maintainer.py --try-model claude # one tool call; is the result used?
|
||||
.venv/bin/python maintainer.py --once health # one health cycle and any agent work it queues
|
||||
.venv/bin/python maintainer.py --once digest # post the daily report now
|
||||
.venv/bin/python maintainer.py --once upgrade # run the upgrade now
|
||||
|
||||
Reference in new issue
Block a user