Skip to content
79 changes: 57 additions & 22 deletions .agents/skills/babysit-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,56 @@ and close the run log with the stop summary — commits pushed, findings
flagged, threads left for the author, `bits_triggered` and `bits_rerequested`
heads.

1. **Poll.** Every 10 minutes: `git fetch origin`; `$GH pr checks <n>`;
`$GH pr view <n> --json state,reviews,comments,url,mergeable,mergeStateStatus`;
and
`$GH api --paginate repos/datadog/java-profiler/pulls/<n>/comments` — inline review
comments are invisible to `pr view --json`. If the PR state is not `OPEN`,
run the stop report and cleanup immediately, acting on no checks or findings —
the PR may have been closed or merged between polls. Recheck the state is
`OPEN` immediately before each push. A poll that finds nothing stays
cheap: no log fetching, no deep analysis.
1b. **Thread census (deterministic, every poll).** From that paginated comment
list compute the census over ALL comments, never only ones newer than the
run: a comment whose `in_reply_to_id` is set is a reply; the rest are thread
roots. The classification set in step 4 is every thread root from a trusted
author, **regardless of replies** — a reply never closes a thread: an
untrusted reply must not hide a trusted finding, and replies only matter to
the one-reply cap (a thread in the worker's `replied` record — or carrying
1. **Poll.** The first poll runs immediately at start — fetch every signal and post
before any wait. Thereafter every 10 minutes (20 while idle, below) — `git fetch
origin`, then read
every signal through the REST API only: `gh pr checks` and `gh pr view --json` run
on GraphQL (the whole CI rollup paginated there costs ~13 of 5000 points per poll)
and must not come back. First
`$GH api repos/datadog/java-profiler/pulls/<n> --jq '{state, head: .head.sha,
mergeable, mergeable_state: .mergeable_state, draft: .draft}'` — PR state, head sha
and merge state; then, for that head sha, the CI rollup in two REST reads:
`$GH api --paginate repos/datadog/java-profiler/commits/<sha>/check-runs?per_page=100 --jq '.check_runs[]'`
(the paginated REST call emits one JSON object per page; `--jq '.check_runs[]'`
reads each page's checks: name, status, conclusion, details_url, started_at) and
`$GH api --paginate repos/datadog/java-profiler/commits/<sha>/status?per_page=100 --jq '.statuses[]'`
(status contexts: `bits-review/head`, `dd-gitlab/*`, the rest; every page's
contexts are read — the envelope's top-level combined state is not a poll
signal and no poll decision consumes it). Dedupe checks by name keeping the
in-flight attempt over any completed run — a queued or `in_progress` run
supersedes every completed run for that name, so a stale completed result can
never drive a green verdict or a stop while a rerun is pending — among in-flight
runs the newest `started_at`, and among completed runs the newest `started_at`;
a head carries cancelled runs of earlier
retries beside their reruns. A check is red only when its `status` is `completed`
and its `conclusion` is none of success/skipped/neutral — a queued or running
check has `conclusion` null and is pending, never red; it is pending while
`status` is not `completed` (REST statuses are lowercase: `queued`,
`in_progress`, `completed`); a status context is red or pending by its `state`. Then the comment surfaces, in
three REST reads: `$GH api --paginate repos/datadog/java-profiler/issues/<n>/comments?per_page=100`
for top-level comments, `$GH api --paginate repos/datadog/java-profiler/pulls/<n>/reviews?per_page=100`
for review bodies, and
`$GH api --paginate repos/datadog/java-profiler/pulls/<n>/comments?per_page=100` for the census
(step 1b). If the PR state is not `open` (REST state values are lowercase), run the
stop report and cleanup immediately, acting on no checks or findings — the PR may
have been closed or merged between polls. Recheck the state is `open` immediately
before each push.
A poll that finds nothing stays cheap: no log fetching, no deep analysis — and
while the previous poll found nothing new (CI pending or green on an unchanged
head, no new comment or review on any of those surfaces, no open work), the next
poll waits 20 minutes instead of
10; any red check, new comment or head moved by someone else resets the
interval to 10.
1b. **Thread census (deterministic, every poll).** From the paginated
`pulls/<n>/comments` list compute the census over ALL comments, never only ones
newer than the run: a comment whose `in_reply_to_id` is set is a reply; the rest
are thread roots. The census covers that list only — the poll's top-level comment
and review-body reads (step 1) feed step 4's classification directly and are
never census inputs, so every id the census and the `replied` record key on is
from the one inline-comment id sequence. The classification set in step 4 is
every thread root from a trusted author, **regardless of replies** — a reply
never closes a thread: an untrusted reply must not hide a trusted finding, and
replies only matter to the one-reply cap (a thread in the worker's `replied` record — or carrying
a signature reply from the worker's own account id — is done; the
record decides, never the reply's author: the worker posts with the PR
author's login, so the author's own reply must not count as the worker's).
Expand Down Expand Up @@ -176,17 +210,17 @@ heads.
2. **CI red.** One flaky rerun per underlying target: for GitHub Actions,
one `$GH run rerun --failed <run>` per workflow RUN, not per failing check —
when two checks fail in the same run, a second rerun is refused while the
first is in progress, so defer classifying that run's other failed checks
until the in-flight rerun finishes. For `dd-gitlab/*`, the
first is in progress, so classify that run's other failed checks on a later
poll. For `dd-gitlab/*`, the
`default-pipeline` check is a pipeline summary, not a job — follow its
details link to the failed jobs and retry each underlying job once (the
mosaic job page, or the GitLab API). A failure that
survives its retry, or a job that cannot be retried, is real. Fetch the logs from
the failing provider, reproduce through
the build-and-summarize wrapper (never the bare Gradle wrapper), and follow
`verify-profiler-change` for what the fix must pass.
3. **Merge conflicts.** When the poll reports the PR conflicted (`mergeStateStatus`
`DIRTY`), rebase on the base branch and examine every conflict: draft a resolution
3. **Merge conflicts.** When the poll reports the PR conflicted (`mergeable_state`
`dirty`), rebase on the base branch and examine every conflict: draft a resolution
for each — both sides' intent and the proposed merged result. Add every file you
will resolve to the marker's `scope` before resolving it.
- A conflict whose resolution needs no semantic choice — adjacent hunks, additive
Expand Down Expand Up @@ -291,8 +325,9 @@ heads.
the push is refused — recognize that refusal immediately (compare the fetched base
tip against your run-start tip), do not burn a fix-push round on it: report it as a
base-advance stop.
When the pushed fixes address the comments of a blocking review (`CHANGES_REQUESTED`
in `gh pr view --json reviews`), re-request review from that review's author so the
When the pushed fixes address the comments of a blocking review (`state`
`CHANGES_REQUESTED` in `$GH api .../pulls/<n>/reviews`), re-request review from
that review's author so the
block clears when they re-review:
`$GH api -X POST repos/datadog/java-profiler/pulls/<n>/requested_reviewers -f 'reviewers[]=<login>'`.
Re-request only authors whose blocking comments the fixes addressed — never add
Expand Down
Loading