Hold off resuming while the host is short on memory or swapping

This commit is contained in:
2026-08-18 21:20:38 +02:00
parent 53fa55728f
commit 5a5dc94ae8
3 changed files with 118 additions and 9 deletions
+25 -9
View File
@@ -62,6 +62,20 @@ runs `claude stop <old id>` after a successful resume. Without that the husk
would be picked up again on a later tick and resumed into a *second* session
working the same conversation — two agents racing on the same git worktree.
### Host headroom
A resume starts a fresh process that reloads a whole conversation, so before
listing sessions — and again before each resume — the watchdog reads
`/proc/meminfo` and holds off while the host is short: less than
`--min-available-mb` of `MemAvailable`, or swap fuller than
`--max-swap-used-pct`. Each resume of the same run is charged for its own
headroom, because a session launched seconds ago has not grown into its memory
yet.
Holding off costs nothing: the block is still there on the next tick. On a host
that reports no `MemAvailable` the guard stays inactive rather than blocking
every resume.
### Circuit breakers
Three limits stop a broken session, or a still-ongoing outage, from spawning an
@@ -164,15 +178,17 @@ A stalled session that has been resumed shows up as a new job in
Every option is a CLI flag with an environment-variable fallback — nothing is
hardcoded. To make one permanent, add it to the crontab line.
| Flag | Env var | Default |
| ----------------- | ------------------------- | -------------------- |
| `--claude-bin` | `CLAUDE_BIN` | `claude` |
| `--claude-home` | `CLAUDE_HOME` | `~/.claude` |
| `--max-attempts` | `WATCHDOG_MAX_ATTEMPTS` | `1` |
| `--max-per-day` | `WATCHDOG_MAX_PER_DAY` | `50` |
| `--max-per-run` | `WATCHDOG_MAX_PER_RUN` | `0` (all) |
| `--prompt` | `WATCHDOG_PROMPT` | see `--help` |
| `--dry-run` | — | off |
| Flag | Env var | Default |
| --------------------- | ---------------------------- | ------------ |
| `--claude-bin` | `CLAUDE_BIN` | `claude` |
| `--claude-home` | `CLAUDE_HOME` | `~/.claude` |
| `--max-attempts` | `WATCHDOG_MAX_ATTEMPTS` | `1` |
| `--max-per-day` | `WATCHDOG_MAX_PER_DAY` | `50` |
| `--max-per-run` | `WATCHDOG_MAX_PER_RUN` | `0` (all) |
| `--max-swap-used-pct` | `WATCHDOG_MAX_SWAP_USED_PCT` | `50` |
| `--min-available-mb` | `WATCHDOG_MIN_AVAILABLE_MB` | `2048` |
| `--prompt` | `WATCHDOG_PROMPT` | see `--help` |
| `--dry-run` | — | off |
## Files