From b79333cb7f88e310fc46f55b5911a9535e915dab Mon Sep 17 00:00:00 2001 From: Jonathan Mohrbacher Date: Tue, 1 Dec 2026 16:11:41 -0500 Subject: [PATCH 1/3] monitoring-deployments: one pass, then end the turn; capped wait only for unwatched rollouts lgtm-shepherd's rollout sweep already runs monitor-rollout.py every 4-6 minutes for configured repos and wakes the author session on an outcome, so the skill no longer tells agents to re-invoke the script in a loop. Exit 3 now asks who is watching: watched -> end the turn; unwatched -> at most 15 passes per merge, then at most two scheduled wakes, then the human. The script's exit-3 text no longer says "Re-invoke." (lgtm reads only the exit code). Pressure-tested before and after. lgtm-0q1b.53 --- .../skills/monitoring-deployments/SKILL.md | 117 ++++++++++++++---- .../monitoring-deployments/monitor-rollout.py | 54 ++++---- .../test_monitor_rollout.py | 45 +++++++ .../skills/shepherding-pull-requests/SKILL.md | 3 +- 4 files changed, 171 insertions(+), 48 deletions(-) diff --git a/assets/opencode/skills/monitoring-deployments/SKILL.md b/assets/opencode/skills/monitoring-deployments/SKILL.md index ca8f6d48..489d89bf 100644 --- a/assets/opencode/skills/monitoring-deployments/SKILL.md +++ b/assets/opencode/skills/monitoring-deployments/SKILL.md @@ -1,6 +1,6 @@ --- name: monitoring-deployments -description: Use when a merged PR's change still needs to reach its Kubernetes environments -- watching a merged commit roll out to UAT/PROD until the new image is live and pods are healthy, or diagnosing a stuck rollout (deploy not bumped, CrashLoopBackOff, ImagePullBackOff, restart spike), or when a merged commit has no deploy check because a merge queue batched it behind a later commit. Work-only; kubectl/AKS-based. +description: Use when a merged PR's change still needs to reach its Kubernetes environments -- watching a merged commit roll out to UAT/PROD until the new image is live and pods are healthy, or diagnosing a stuck rollout (deploy not bumped, CrashLoopBackOff, ImagePullBackOff, restart spike), or when a merged commit has no deploy check because a merge queue batched it behind a later commit. Also use when a rollout wake from lgtm-shepherd arrives, and when tempted to re-run monitor-rollout.py until a rollout finishes. Work-only; kubectl/AKS-based. --- # Monitoring Deployments @@ -8,9 +8,9 @@ description: Use when a merged PR's change still needs to reach its Kubernetes e Merged is not deployed. A PR can merge green and still fail to reach prod: the image build breaks, the GitOps controller never bumps the deployment, or the new pods crashloop. This skill is `shepherding-pull-requests` one lifecycle -phase later -- you hold the *rollout* the way that skill holds the PR, until -the merged commit is actually running and healthy, or until there's a real -decision (fix-forward vs roll back) for the user to make. +phase later, and holds the *rollout* the way that skill holds the PR: by +being wakeable, not by watching. Check once, act on what you find, and end +the turn; the rollout watcher brings you back when there is an outcome. ## When to use @@ -20,6 +20,9 @@ decision (fix-forward vs roll back) for the user to make. - Your merge commit has no deploy check at all and you need to tell "the pipeline never ran" from "the merge queue batched you behind a later commit" (see "Merge queues" below — assume batching first). +- A rollout wake from `lgtm-shepherd` arrived. Do the payload's `YOUR TASK`; + the invocation it carries is one pass, not the start of a loop. Report and + end the turn. **When NOT to use:** non-k8s deploy targets (Lambda, serverless, static hosting); pre-merge work (that's `shepherding-pull-requests`). @@ -39,34 +42,86 @@ If `INTERNAL.md` is absent (not yet fetched, or the page doesn't exist), the tooling still works — supply `--target` values directly. Never paste real cluster/namespace/registry names back into this SKILL.md or the script. -## Tooling: monitor-rollout.py +## One pass, then end the turn -A companion script polls the rollout and prints the next action. Each -invocation has a ~60s wall-clock budget (Anthropic prompt-cache TTL is 5 min; a longer blocking call -expires warm cache), so **you re-invoke it in a loop** — the script owns the -within-60s pacing, you own the loop and the fix step. +**Do not re-invoke `monitor-rollout.py` in a loop.** `lgtm-shepherd`'s rollout +sweep already watches merges to the repos it is configured for: it runs this +same script every 4-6 minutes for up to 30 hours, and wakes the PR's author +session once, when every watched target (UAT and PROD alike) is live and +healthy, a pod wedges, or the 30 hours run out. A wedge or an expiry also +reaches the human as a shepherd chat line, whether or not you are around. +Polling it yourself pays for a watch that exists. ```bash python ~/.agents/skills/monitoring-deployments/monitor-rollout.py \ - --pr \ + --merge-sha --repo / \ --target [--target ...] ``` -It waits for the PR to merge, derives the image tag from the merge commit's -short SHA (prefix match, tolerant of a `_N` build-attempt suffix), then watches -each target's deployment spec image and pod health. +One invocation is one pass: it polls for up to 60 seconds and exits. It +derives the image tag from the merge commit's short SHA (prefix match, +tolerant of a `_N` build-attempt suffix), then reads each target's deployment +spec image and pod health. Always pass `--repo`: without it a merge-queue +batch (below) reads as exit 3 forever. `--pr ` instead of `--merge-sha` +waits for the merge first; `--pod-selector` if pods aren't labeled +`app=`; `--help` for the rest. -| Exit code | Meaning | What to do | +| Exit | Meaning | Do | |---|---|---| -| `0` | All targets on the new tag, pods Running and pod-level `Ready` | Done. | -| `1` | A new-revision pod is wedged — CrashLoopBackOff / image-pull error in **any** of its containers (sidecars included), or a restart spike **on a pod that is still unready** | Read stdout (it names the container), investigate (step below), then re-invoke or escalate. | -| `2` | Unrecoverable (gh/kubectl failed, unknown context, missing deployment) | Surface to user; don't silently retry. | -| `3` | Still rolling (merge pending, spec not bumped, pods updating) | Re-invoke immediately. | -| `4` | Deployed **as an ancestor** of a later commit, pods healthy (merge-queue batch — see below) | Done. Record the batch head as the deployed SHA, not yours. | +| `0` | All targets on the new tag, pods Running and pod-level `Ready` | Report it live. | +| `1` | A new-revision pod is wedged — CrashLoopBackOff / image-pull error in **any** of its containers (sidecars included), or a restart spike **on a pod that is still unready** | Investigate now ("The fix step" below). It will not self-heal. | +| `2` | Unrecoverable (gh/kubectl failed, unknown context, missing deployment) | Tell the user; do not retry. | +| `3` | Still rolling (merge pending, spec not bumped, pods updating) | **Who is watching?** (below) | +| `4` | Deployed **as an ancestor** of a later commit, pods healthy (merge-queue batch — see below) | Report it live under the batch head's SHA, not yours. | -Pass `--merge-sha ` instead of `--pr` to skip merge polling; `--repo -owner/repo` if not in the repo dir; `--pod-selector` if pods aren't labeled -`app=`. Run `--help` for the rest. +### Exit 3: who is watching? + +The sweep watches the repos under `repos:` in cloudbox's rollout config: + +```bash +sed -n '/^repos:/,/^$/p' ~/.config/lgtm/rollout.yml # cloudbox only +``` + +- **Watched, and you opened the PR** (the shepherd finds you by the + `agent-wait add --pr ... --watch` record from `shepherding-pull-requests`): + **end the turn.** Report "still rolling as of `