agentleFS
rotnovrotnov/pycc/.claude/skills/autopilot-async-monitoring/SKILL.md

autopilot-async-monitoring

Skill2 starsChanged 3 months agoMITView on GitHub

Use when driving the pycc autonomous-delivery autopilot loop (writing-plans -> subagent-driven-development chains, PR/CI monitoring, background Agent orchestration) and deciding how to wait on async state such as a pull request, a CI run, or any dispatched `Agent` -- a one-off spike/build/benchmark task just as much as a nested sub-dispatch inside a pipeline. Covers checking real state before waiting, monitoring only currently-active work, and never ending a turn to "wait for a notification" while a dispatched agent, or a background child it started, is still live.

  • Commits and pushes

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Before setting up any wait (a ScheduleWakeup, a poll loop, or handing off to "the next check"), query the actual current state directly …

    line 19
  2. Very specific:

    Pull requests: check mergeStateStatus/mergeable and the actual check list (gh pr checks) before waiting on CI — CI may not even have …

    line 23
  3. Distinctive:

    Do not wait on CI without first confirming the PR is in a state where CI runs at all.

    line 26
  4. Very specific:

    When waiting on one or more open pull requests to reach a terminal CI state, do not fall back to a periodic ScheduleWakeup (e.g.

    line 36
  5. Very specific:

    Instead, run the gha-watch-ci-pr skill's ci-watch.sh <repo> <pr-number> [<pr-number> ...] via the Monitor tool (persistent: false, a …

    line 43
  6. Very specific:

    When every listed failing check in a CHECK FAILED line is CANCELLED (no genuine FAILURE/TIMED_OUT/STARTUP_FAILURE among them), the script …

    line 72
  7. Very specific:

    After the script reports STALE (a common case when multiple PRs from the same session are queued and one merges before another), update the …

    line 82
  8. Very specific:

    If ci-watch.sh is not applicable (e.g.

    line 89
  9. Very specific:

    When opening a PR (gh pr create) from an autonomous agent session, add a footer line identifying the session and client, e.g.: Session: …

    line 97
  10. Distinctive:

    Default to serializing instead: fully land one PR (open → CI green → merge) before opening the next.

    line 120
  11. Distinctive:

    Do not keep checking on pull requests, branches, or tasks that are no longer part of the current active work (e.g.

    line 145
  12. Distinctive:

    Never assume a dispatched agent will "notify" you the moment its own work concludes — if it ends its turn while it still has a live …

    line 185
  13. Very specific:

    Check the actual current state directly (git log on the relevant worktree/branch, PR/CI status via gh, a sub-agent's actual reported result …

    line 189
  14. Distinctive:

    Keep working synchronously within one continuous turn: dispatch a task, wait for and read its real result, review it, run the fix loop if …

    line 193
  15. Distinctive:

    When dispatching an agent whose task may itself involve a long-running background process (a build, a container run, a watched job), say so …

    line 198

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- ievo:start -->

Before applying the instructions below, read .ievo/evolution/skills/autopilot-async-monitoring.md if it exists, and apply ALL rules from its sections IN ADDITION to the skill's instructions.

<!-- ievo:end -->

Autopilot async monitoring

Procedural rules for waiting on asynchronous state correctly during this project's autonomous PR-by-PR delivery loop: pull requests, CI runs, and any dispatched background agent — a plain first-level Agent dispatch just as much as a nested orchestrator that itself dispatches sub-agents.

Check real state before waiting

Before setting up any wait (a ScheduleWakeup, a poll loop, or handing off to "the next check"), query the actual current state directly rather than assuming a prior plan is still accurate:

  • Pull requests: check mergeStateStatus/mergeable and the actual check list (gh pr checks) before waiting on CI — CI may not even have started because the PR has a merge conflict, or it may already be green. Do not wait on CI without first confirming the PR is in a state where CI runs at all.
  • Dispatched agents: a Task/Agent sub-dispatch is not something the dispatching agent can passively wait on across its own turn boundary. When resuming or checking on a dispatched agent, look at its actual reported result, its branch/worktree's real git log, or its written artifacts — never assume "still running" without evidence.

Use gha-watch-ci-pr's ci-watch.sh + Monitor instead of a fixed ScheduleWakeup interval

When waiting on one or more open pull requests to reach a terminal CI state, do not fall back to a periodic ScheduleWakeup (e.g. every 20-30 minutes) as the default mechanism — a fixed wakeup interval means a real event (a conflict, a stale/behind branch, a failed check, or a fully green PR ready to merge) can sit unreported for most of that interval, which is exactly the "minutes into hours" dead time this skill exists to eliminate.

Instead, run the gha-watch-ci-pr skill's ci-watch.sh <repo> <pr-number> [<pr-number> ...] via the Monitor tool (persistent: false, a generous timeout_ms — the script exits on its own once every listed PR reaches a terminal state, so the timeout is just a backstop). The script polls every POLL_INTERVAL seconds (default 10, overridable via env) and prints exactly one line per PR the moment it becomes: MERGED/CLOSED, CONFLICTS (merge base diverged), STALE (branch fell behind base — e.g. a sibling PR merged first), CHECK FAILED -- <name> (<conclusion>)[, <name> (<conclusion>)...] (every non-passing check is named, not just the first), BLOCKED (every check completed with none failing, but mergeStateStatus is something other than CLEAN/BEHIND — typically an unresolved required review or conversation thread under branch protection), or READY (every check green and mergeStateStatus: CLEAN). It is silent between polls — no per-poll spam, only real terminal events reach the conversation as Monitor notifications. The READY and BLOCKED verdicts are reported only after the same verdict holds on two consecutive polls, and — when the base branch's required status contexts are readable — only once every required context is present and completed in the rollup, so a gap between chained workflows cannot resolve the watch early however long the next workflow takes to register (a required context that stays missing for REQ_MISS_POLLS consecutive polls, default 30, drops the binding with one non-terminal NOTE so a name-mismatched context cannot suppress the verdict forever); a head change (new push) resets the confirmation; an empty statusCheckRollup (GitHub Actions not started yet) is never terminal — after EMPTY_NOTE_POLLS consecutive empty polls (default 30) the script emits one non-terminal NOTE line (once per consecutive-empty streak, so it can recur after a later non-empty poll) and keeps watching.

When every listed failing check in a CHECK FAILED line is CANCELLED (no genuine FAILURE/TIMED_OUT/STARTUP_FAILURE among them), the script appends a hint that this is often a partial-rerun or GitHub Actions infra artifact rather than a code defect — see issue-implement's "Attribute CI failures before reacting" step for how to act on it (a full, non---failed rerun of every affected top-level workflow run, not a diff investigation).

This composes with the "check real state before waiting" rule above: the script is that state check, run in a loop instead of once, so the terminal event surfaces itself instead of needing a manual re-check every wakeup. After the script reports STALE (a common case when multiple PRs from the same session are queued and one merges before another), update the affected branch (git fetch origin main && git merge origin/main or rebase) and re-arm a fresh Monitor call for the remaining PR(s) — the script does not retry a resolved PR itself, by design, so it terminates cleanly rather than looping forever on a branch update it cannot perform itself.

If ci-watch.sh is not applicable (e.g. watching something that isn't a GitHub PR), the same pattern — a poll loop that emits one line per terminal state and exits once every tracked item resolves, run via Monitor — still beats a fixed wakeup interval; write an equivalent small script rather than reverting to periodic polling.

Identify the session in every PR body

When opening a PR (gh pr create) from an autonomous agent session, add a footer line identifying the session and client, e.g.: Session: claude-code <$CLAUDE_CODE_SESSION_ID> (Claude Code exposes the running session's ID via that env var — check for the Codex-equivalent identifier when running under Codex instead of assuming the same var name applies). A PR opened by a background-dispatched agent (e.g. from a writing-plans -> subagent-driven-development chain) is otherwise easy to lose track of — this makes it traceable back to the exact session/transcript that produced it, which matters most for exactly that background-dispatch case (see PR #328, which the orchestrating session genuinely forgot about for a while).

Serialize PRs under strict branch protection — don't open several at once

This repo's branch protection is strict (a PR must be up to date with main before it merges). Under strict protection, opening multiple PRs in parallel within one session — even for genuinely independent changes — creates a real race: merging any one of them immediately makes every other open PR STALE/BEHIND, which then needs its own fetch, merge, re-test, push, and CI re-wait. With several PRs open at once this can cascade (a catch-up push can itself go stale again before it lands), and it happened repeatedly in one session here (#320/#322/#324/#326/#327).

Default to serializing instead: fully land one PR (open → CI green → merge) before opening the next. This costs some session wall-clock time waiting on one PR's CI before starting the next, but it eliminates the stale-branch chase entirely, since no two merges are ever racing. Only batch multiple PRs loosely when they are genuinely tiny, docs/overlay-only, and unlikely to touch overlapping lines — and even then, expect at least one STALE catch-up round per PR that lands ahead of the others, not zero.

Draft-then-ready queuing lets you prepare more than one PR's worth of work concurrently without violating this rule: open every independent change as a draft PR to reserve the work, but mark only one PR "Ready for review" at a time. Land that one PR fully (CI green -> merge), then take the next queued draft, rebase it onto the new main, mark it ready, and only then let its CI run. This preserves the "no two merges ever race" guarantee while avoiding a strict end-to-end serialization of the underlying work. Verify per-repo before relying on the CI-cost angle of this: opening a PR as draft only blocks the merge button by default — it does NOT skip CI unless the repo's own workflows explicitly gate a job on github.event.pull_request.draft == false (this project's .github/workflows/*.yml carry no such guard as of 2026-08-04, so a draft PR here still runs the full check suite; adding that guard would itself be a CI-workflow change subject to this project's D-024/D-125 review rules).

Monitor only active work

Do not keep checking on pull requests, branches, or tasks that are no longer part of the current active work (e.g. a PR from an earlier, already-merged or superseded milestone). Scope monitoring to what the current task genuinely depends on.

Any session that dispatches an Agent must not stop-and-wait on it — including a plain first-level dispatch, not only a nested sub-dispatch

This applies just as much to a top-level session's own first Agent dispatch as to a dispatched orchestrator's nested sub-dispatch — being "the outermost session" or "only one hop deep" changes nothing about the mechanics below. When an agent (a top-level session running a single spike/build/benchmark task, or one running a multi-task pipeline like subagent-driven-development) dispatches an Agent and then ends its turn with reasoning like "I'll wait for the monitor's notification rather than poll further" — this does not work, regardless of dispatch depth or the run_in_background flag passed to the dispatch itself.

The actual mechanism: a task-notification to the parent fires only when the dispatched agent stops with no live background children of its own (a backgrounded shell command, a running container, a Monitor-watched process it started). If that agent ends its turn while such a child is still running, the notification is not skipped outright — it is deferred until that suppression condition later clears, which can take arbitrarily long and does not run on any fixed schedule the parent can predict. The run_in_background flag on the dispatch itself does not change this: it governs how the parent is notified about the dispatch, not whether the dispatched agent's own background children suppress that notification. A returned Agent result whose text claims work is still continuing and promises to notify later is a stopped agent making a promise the platform does not keep on its behalf — treat it exactly like any other stopped agent: verify the real state directly, or resume it, never end your own turn to "wait for the notification."

Observed cost: a PR-13 delivery pipeline opened its PR at ~01:52 UTC and merged at ~05:16 UTC — a ~3.5 hour gap dominated by an orchestrator repeatedly stopping to "wait" rather than by real CI/build time (which was closer to 15-20 minutes total across all the runs involved).

The fix, applied when resuming a stalled dispatch:

  1. Never assume a dispatched agent will "notify" you the moment its own work concludes — if it ends its turn while it still has a live background child of its own, the notification is deferred until that child's state is next resolved, not guaranteed on any interval you control.
  2. Check the actual current state directly (git log on the relevant worktree/branch, PR/CI status via gh, a sub-agent's actual reported result or written report file, the real state of anything it started in the background) rather than assuming work is still in flight.
  3. Keep working synchronously within one continuous turn: dispatch a task, wait for and read its real result, review it, run the fix loop if needed, move to the next task — ending the turn only on genuine forward progress (a task's review passed, a PR opened, a real blocker found), never merely to "wait."
  4. When dispatching an agent whose task may itself involve a long-running background process (a build, a container run, a watched job), say so explicitly in the dispatch brief and instruct it not to end its own turn while that child is still live — either block on it synchronously within its own turn, or keep polling it itself before stopping, so its returned result always reflects real, current state rather than a promise to follow up later.

This applies to any deeply-nested autonomous delivery pipeline in this project (a top-level Agent dispatch that itself runs writing-plans -> subagent-driven-development) and to a plain, non-nested, single-task Agent dispatch alike — not just one specific PR.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.