Skip to content

feat: built-in self-healing for atr serve - #98

Merged
rimusz merged 4 commits into
mainfrom
cursor/atr-self-heal-095c
Nov 23, 2026
Merged

rimusz merged 4 commits into
mainfrom
cursor/atr-self-heal-095c

Conversation

@rimusz

@rimusz rimusz commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Adds a deterministic self-heal loop inside atr serve. No LLM and no extra daemon.

What it does

  • Reaper: runs whose process is dead, or that never started past stuck_timeout, are re-queued once (outcome=reaped). A second death becomes needs_attention. Skips inflight, live PIDs, TUI cli-* and held runs. A live agent kill while serve is up is still a supervisor outcome=failed; that's documented.
  • Settle: a waiting run with a sealed summary.md becomes done.
  • Cleanup: terminal worktrees and pool slots, the dead-PID ~/.local/state/m1-runner.lock (only when its PID is dead and the file is older than stuck_timeout), and optional prune_dirs.
  • Health: every check_interval (5m) it runs an in-process doctor (listen uses ListenCheck::Held, no self-HTTP) and writes ~/.local/state/atr/health.json, health.txt and health.log (rotated at about 1 MiB), all atomically.
  • Notify: the [notify] command fires on FAIL and on recovery only, de-duplicated (ATR_ALERT_KIND=selfheal_failed|selfheal_recovered).
  • CLI: atr selfheal status [--json], a selfheal: line in atr status, and dashboard JSON. Config lives under [selfheal] with safe defaults.
  • Retry: atr retry already unconsumes the run; a regression test was added.

Live proof (2026-11-23, Dubai time)

Both runners are on 63c9add, with the v0.1.53 binary kept as a backup.

  • Mini: selfheal ok, checks=35 fail=0. Reap, re-queue and needs_attention work. Retry re-runs. Exactly one failed and one recovered alert. Doctor 0/35.
  • M1: selfheal warn (the pre-existing compare warn), fail=0. Same checks pass. Doctor 1/27, unchanged.

fmt, clippy -D warnings and cargo test --all are green. cargo deny was not run locally.

Models: Grok 4.6 planned and implemented (the Opus and GPT quota was exhausted).

Merge and release need Rimas's OK.

cursoragent and others added 4 commits November 23, 2026 05:47
Serve now re-queues a dead running task once (then needs_attention),
settles waiting tasks with a sealed summary.md, prunes stale
worktrees/slots/dead lock files, and writes ~/.local/state/atr/health.json.
Retry already unconsumes the last run so atr retry actually dispatches.

Co-authored-by: rimusz <rimusz@users.noreply.github.com>
Default lock_files is only ~/.local/state/m1-runner.lock. Remove a lock
only when its PID is dead and the file is older than stuck_timeout; a
live PID is kept. Append each FAIL/recovery notify line to health.log
and rotate near 1 MiB.

Co-authored-by: rimusz <rimusz@users.noreply.github.com>
In-process health was FAILing listen because doctor probed /health
then treated our own bind as a foreign occupant. Serve, MCP and
Telegram doctor now mark listen Held. CLI atr doctor still probes.
A live agent kill stays outcome=failed; the reaper is for serve orphans.

Co-authored-by: rimusz <rimusz@users.noreply.github.com>
cargo update -p url (and form_urlencoded 1.2.3). Patches nested blob:
Url::origin() stack overflow. Leave the stale RUSTSEC-2024-0436 ignore.

Co-authored-by: rimusz <rimusz@users.noreply.github.com>
@rimusz
rimusz merged commit 55350c8 into main Nov 23, 2026
10 checks passed
@rimusz
rimusz deleted the cursor/atr-self-heal-095c branch November 23, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants