Skip to content

babysit-pr: deterministic driver CLI and session-owned push chain (PROF-16952) - #1070

Open
jbachorik wants to merge 10 commits into
mainfrom
drydock/jb-patient-cotton-otter
Open

jbachorik wants to merge 10 commits into
mainfrom
drydock/jb-patient-cotton-otter

Conversation

@jbachorik

@jbachorik jbachorik commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Moves every mechanical step of the babysit-pr skill out of LLM prose and into a tested stdlib CLI, utils/babysit-pr.py, with its pure decision logic in utils/babysit_pr_policy.py. The session, not the worker, now owns review, commit, push and replies.

Actor Does
CLI Run state, REST polling, trust gate, CI reruns, Bits triggers, status comment, handoff patch, push, replies
Worker (babysit-pr agent) Triages the events wait returns, fixes code, runs tests, drafts replies. Never commits or pushes
Session Applies the patch as a signed commit, runs pre-pr-review, runs push-and-reply, decides design questions

The skill shrinks from 366 to 132 lines; it now points at CLI commands instead of inline gh/jq recipes.

Motivation:

In a real run, triage and fixes took minutes, but the push chain stalled twice:

  • Marker race. The worker polled for the review marker with sleep 180/300/420 and kept seeing rc=1 after the session had written it.
  • Worker-environment hangs stalled an earlier cycle.

Both come from the same design: a long-lived LLM worker that improvises bash for every step, and a review marker that crosses a session boundary with no synchronous handoff. Now the session that writes the marker also checks it and pushes, so there is nothing to poll.

Additional Notes:

  • Ordering guarantee. push-and-reply posts the queued replies only after git push --force-with-lease against the handoff base succeeds; {commit} in a reply becomes the pushed SHA. A rerun after an interruption does not push twice and posts only the replies GitHub does not hold yet.
  • Fail-closed checks. The worker cannot push: its worktree gets a build/babysit-pr-<n>.json marker with an empty scope, so .githooks/pre-push refuses. A handoff is refused for files outside the scope-guard allowlist or the declared scope. apply-handoff refuses an unsigned commit. review-marker.py and TRUSTED_BOT_IDS are read from origin/main only.
  • CI-safe automation. wait reruns a GitHub Actions run once, only after all its jobs finished, and records it before the request. A cancelled check counts as pending, never as a failure: ci.yml's concurrency group cancels superseded runs, and rerunning one cancels the live run. start adds no label: ci.yml runs on pull_request: labeled, so a label would restart CI on every babysit start.
  • Bounded calls. Every gh/git call has a timeout, and inside wait each call is capped at the time left in the slice; a write starts only with its full timeout left, so it is never cut off mid-flight. wait returns within 8 minutes, below the 600 s bash tool timeout.
  • Label dropped. The dog-sitter label is no longer added or removed; the status comment is the run signal. PRs labelled by the old skill keep the label until removed by hand.
  • Unchanged: .githooks/pre-push, utils/babysit-scope-guard.py, and both create triggers (.claude/hooks/babysit-pr.py, .pi/extensions/babysit-pr.ts).
  • Accepted costs.
    • Every poll re-reads the full comment history of the PR through REST: 10-minute polls, 20 when idle.
    • GitHub calls inside a poll run under the per-PR flock. Each call is bounded by its timeout.
    • A CHANGES_REQUESTED review the worker acks without replying does not block green_done; the acked event is listed in the stop summary.
  • Stale knowledgebase note. .knowledgebase/memories/find-marker-branch-babysit-mismatch.md no longer applies, since the worker no longer pushes. Cairn owns that file; it is left for a cairn update.
  • Review. Sphinx range review, standard effort, on the first candidate: 1 HIGH, 6 MEDIUM, 13 LOW. The HIGH (a push that landed before a crash blocked the replies) and the cheap MEDIUM/LOW findings are fixed in babysit-pr: close crash windows and tighten handoff checks. A Sphinx review of that fix range found no HIGH; its one cheap fix was reviewed by a medium code review: one LOW left open (apply-handoff gives a misleading refusal reason when the patch file is missing). A first babysit run on this PR found that the CLI reran CI per failing job, lost the rerun record on a failed request, and treated cancelled checks as failures; together with the label, that cancelled live CI runs. Fixed in babysit-pr: rerun once per workflow run, ignore cancelled checks, drop the label and two follow-ups, each reviewed by a medium code review. A second babysit run triaged the Bits and Codex findings on fa42f258d and handed them to the session, since they are outside the worker's allowlist. They are fixed in babysit-pr: address review findings on wait budget, completion, signing and rebase and two follow-ups, each reviewed by a medium code review. Open LOWs: the misleading refusal reason when the patch file is missing; no test pins the idle backoff while GitHub refuses a rerun; no test covers recovering a landed rebase push after the base moved; fix_rounds_left can read -1 after a manual push of the handoff head. Findings dismissed with reasons: full-history polling, GitHub calls under the lock, permission cache across a resume, compatibility with state files from an earlier version (none was released).
  • Human review: mandatory. The change decides which public PR comments may steer an automated push, and it moves the push path. A human must check the trust gate and the push-then-reply ordering.

How to test the change?:

bash utils/tests/test_babysit_pr.sh runs 63 hermetic tests against a fake gh (utils/tests/fake_gh.py) and temporary git repos with SSH commit signing. They cover the policy decisions, the trust gate, scope and allowlist refusal, signing, crash adoption, lease rejection, resumed replies, rerun dedupe and retry, cancelled-check handling, the wait-slice budget, completion while events are pending, the round cap and the fail-closed origin/main reads. CI runs the suite through the utils/tests/*.sh glob in script-tests. A real-PR run is the ticket's production-check criterion.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16952

@jbachorik jbachorik added AI human_review:mandatory Human review required — see PR description labels Nov 27, 2026
@jbachorik

Copy link
Copy Markdown
Collaborator Author

@DataDog review

Comment thread utils/tests/fake_gh.py Fixed
Comment thread utils/babysit-pr.py Fixed
@jbachorik jbachorik added the dog-sitter Actively watched by babysit-pr: fixes pushed through the repo gates label Nov 27, 2026
@jbachorik

jbachorik commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

🐶 babysit-pr is watching this PR — CI breakages and mechanical findings are fixed and pushed automatically; design decisions are always brought to you.

This run
  • 17:16 · started · head 3d49e8615
  • 17:19 · stopped · stopped by the session: rerun loop bug found on this PR

✅ stopped 17:19 UTC · stopped by the session: rerun loop bug found on this PR

@jbachorik jbachorik removed the dog-sitter Actively watched by babysit-pr: fixes pushed through the repo gates label Nov 27, 2026

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Pending review events can be skipped when a resumed worker declares success. Retry scheduling and timeout handling also contain paths that interrupt monitoring or strand a staged handoff.

Open Bits AI session

🤖 Bits Code Review · Commit 3d49e86

Comment thread utils/babysit_pr_policy.py Outdated
Comment on lines +161 to +163
for f in ci["failing"]:
if f["kind"] == "gha" and f["run_id"] not in state["retried_runs"]:
out["actions"].append(("rerun", f["run_id"], f["name"]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Deduplicate rerun actions by workflow run

When multiple failed checks share an Actions workflow run, this loop schedules a rerun for each check. A focused in-memory reproduction produced two actions for the same run. GitHub rejects the second request while the first rerun is active, so poll_once exits before saving the successful retry or delivering events. Deduplicate the scheduled actions by run ID.

Suggested change
for f in ci["failing"]:
if f["kind"] == "gha" and f["run_id"] not in state["retried_runs"]:
out["actions"].append(("rerun", f["run_id"], f["name"]))
scheduled_reruns = set()
for f in ci["failing"]:
if f["kind"] == "gha" and f["run_id"] not in state["retried_runs"]:
if f["run_id"] not in scheduled_reruns:
out["actions"].append(("rerun", f["run_id"], f["name"]))
scheduled_reruns.add(f["run_id"])

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in cb06f2eba ("rerun once per workflow run"). decide() in utils/babysit_pr_policy.py now keeps a rerun set and schedules at most one ("rerun", run_id, name) action per workflow run in a single poll (lines 170-177 at fa42f258d). The retried_runs check covers later polls.

Comment thread utils/babysit-pr.py Outdated
Comment on lines +307 to +308
if act[0] == "rerun":
gh_api("repos/%s/actions/runs/%d/rerun-failed-jobs" % (REPO, act[1]), "POST")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Wait for workflow completion before requesting a rerun

A failed matrix check can finish while sibling jobs in its workflow are still running. This immediately requests a rerun without checking the workflow's status, but GitHub refuses rerun-failed-jobs until the workflow completes. The resulting EnvError makes wait exit instead of continuing to monitor. Defer the request until the underlying workflow run is completed.

Suggested change
if act[0] == "rerun":
gh_api("repos/%s/actions/runs/%d/rerun-failed-jobs" % (REPO, act[1]), "POST")
if act[0] == "rerun":
workflow = gh_api("repos/%s/actions/runs/%d" % (REPO, act[1]))
if workflow["status"] != "completed":
continue
gh_api("repos/%s/actions/runs/%d/rerun-failed-jobs" % (REPO, act[1]), "POST")

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in 6b7e67b2a ("rerun only finished runs"). ci_summary() now collects running_runs, the GHA run ids that still have a check in flight. decide() skips the rerun action while f["run_id"] in ci["running_runs"] (utils/babysit_pr_policy.py, lines 173-175 at fa42f258d). If GitHub answers "already running" anyway, poll_once takes the run back out of retried_runs and retries on a later poll; the poll does not fail.

Comment thread utils/babysit-pr.py Outdated
st["inbox"][ev["key"]] = ev
st["idle_polls"] = 0 if changed else st["idle_polls"] + 1
st["next_poll_at"] = now + policy.next_interval(st["idle_polls"])
if d["outcome"] in ("stop", "green_done"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Deliver pending inbox events before declaring success

When a worker resumes with an unacknowledged top-level comment or review, its initial wait --immediate polls again. Inbox keys are treated as already surfaced, allowing the policy to return green_done before the existing inbox is delivered. An in-memory reproduction marked the run stopped while comment:21 remained pending. Require an empty inbox before accepting green_done, while retaining unconditional stops for closure and the run cap.

Suggested change
if d["outcome"] in ("stop", "green_done"):
if d["outcome"] == "stop" or (d["outcome"] == "green_done" and not st["inbox"]):

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e: green_done no longer ends the run while the inbox holds unacknowledged events. Pinned by test_green_done_waits_for_inbox.

Comment thread utils/babysit-pr.py Outdated
Comment on lines +565 to +566
except Refused:
# Restore the base tree so the next apply-handoff starts clean.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Roll back the applied handoff after commit timeouts

If signing or a commit hook exceeds the git timeout, run raises EnvError, which bypasses this Refused-only rollback. A focused timeout injection confirmed that neither reset nor reverse-apply runs. The patch therefore remains applied and staged while the saved handoff remains staged; another apply-handoff refuses the dirty checkout, requiring manual recovery. Include timeout failures in the rollback handler.

Suggested change
except Refused:
# Restore the base tree so the next apply-handoff starts clean.
except (Refused, EnvError):
# Restore the base tree so the next apply-handoff starts clean.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e: apply-handoff restores the base tree on EnvError (timeouts) as well as Refused. Pinned by test_commit_timeout_restores_base_tree.

Comment thread utils/babysit-pr.py Outdated
emit(inbox_result(st))
return 0
due = st["next_poll_at"]
if immediate or now >= due:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Enforce the wait deadline across polling operations

Slow GitHub responses can make one poll exceed the advertised eight-minute wait limit: its sequential reads each have independent three-attempt timeout budgets, followed by permission lookups and writes. The overall deadline is checked only afterward, and an overdue poll starts before that check. This can exceed the worker's 600-second tool timeout and interrupt monitoring. Propagate a shared deadline through polling operations and check it before starting another poll.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e and 490343b: wait starts no poll past its slice end, every call is capped at the time left, and a write starts only with its full timeout left, so it is never cut off mid-flight. Pinned by test_no_poll_once_slice_ended, test_budget_caps_every_call and test_write_needs_full_timeout_left.

@dd-octo-sts

dd-octo-sts Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Memory overhead check: ✅ within budget

Profiler 07d79500f, pipeline. Budget: utils/memcheck/budget.txt. NMT and /proc values are profiled minus no-profiler runs on the same runner.

scenario metric value Δ since budget set limit headroom
allocs native_mem_live_bytes 21.71 MiB +18 KiB 21.95 MiB 248 KiB ok
allocs native_mem_max_bytes 22.97 MiB +17 KiB 23.20 MiB 239 KiB ok
allocs nmt.class 302 KiB +5 KiB 563 KiB 261 KiB ok
allocs nmt.internal 364 KiB −4 KiB 666 KiB 301 KiB ok
classesM native_mem_live_bytes (coverage-corrected) 23.31 MiB +32 KiB 23.55 MiB 244 KiB ok
classesM native_mem_max_bytes (coverage-corrected) 25.18 MiB −13 KiB 25.45 MiB 279 KiB ok
classesM nmt.class 2.94 MiB −2 KiB 3.20 MiB 268 KiB ok
classesM nmt.internal 3.20 MiB +0 KiB 3.50 MiB 307 KiB ok
mixed native_mem_live_bytes 23.14 MiB −13 KiB 23.45 MiB 321 KiB ok
mixed native_mem_max_bytes 40.74 MiB +24 KiB 41.00 MiB 262 KiB ok
mixed nmt.class 304 KiB −4 KiB 563 KiB 260 KiB ok
mixed nmt.internal 400 KiB −9 KiB 717 KiB 316 KiB ok
threads native_mem_live_bytes 19.08 MiB −10 KiB 19.35 MiB 277 KiB ok
threads native_mem_max_bytes 20.09 MiB −17 KiB 20.40 MiB 314 KiB ok
threads nmt.class 114 KiB +1 KiB 410 KiB 296 KiB ok
threads nmt.internal 160 KiB −4 KiB 461 KiB 301 KiB ok
traces native_mem_live_bytes 20.22 MiB −14 KiB 20.50 MiB 290 KiB ok
traces native_mem_max_bytes 21.40 MiB −12 KiB 21.70 MiB 309 KiB ok
traces nmt.class 470 KiB −1 KiB 768 KiB 298 KiB ok
traces nmt.internal 608 KiB −6 KiB 870 KiB 262 KiB ok

✅ nmt.tracing absent in every scenario.

Not budgeted (too noisy on shared runners)
scenario nmt.code nmt.gc nmt.total proc.VmRSS proc.RssAnon
allocs 1.65 MiB 6 KiB 2.75 MiB 31.23 MiB 26.77 MiB
classesM 6.60 MiB −44 KiB 15.50 MiB 36.75 MiB 32.33 MiB
mixed 1.62 MiB 6 KiB 2.73 MiB 33.30 MiB 28.71 MiB
threads 4 KiB 1 KiB 782 KiB 24.76 MiB 19.64 MiB
traces 3.74 MiB −23 KiB 5.26 MiB 29.10 MiB 24.58 MiB

@dd-octo-sts

dd-octo-sts Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #46070742793 | Commit: 7d6931c | Duration: 34m 8s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-11-27 22:08:53 UTC

@dd-octo-sts

dd-octo-sts Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 30 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 07d79500

10 not applicable (not scheduled): musl-x64-openj9, musl-arm64-openj9. OpenJ9 requires glibc; upstream publishes no musl runtime.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 07d7950 | Docs | Give us feedback!

@jbachorik
jbachorik marked this pull request as ready for review November 27, 2026 19:49
@jbachorik
jbachorik requested a review from a team as a code owner November 27, 2026 19:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T19:51:48.424947Z fa42f25 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa42f258d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread utils/babysit-pr.py Outdated
Comment on lines +334 to +338
if d["outcome"] in ("stop", "green_done"):
reason = d["facts"].get("reason") or "CI green, Bits passed, threads answered"
summary = finish(st, reason)
save(st)
return {"outcome": d["outcome"], "summary": summary}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep unacknowledged inbox events from completing the run

If a worker exits before acknowledging a top-level comment or review, its replacement starts with wait --immediate. This adds the existing inbox keys to surfaced, suppressing those events in the new decision. When CI and Bits are green and no inline threads remain, the policy returns green_done, and the run stops before returning the outstanding inbox. I reproduced action_needed followed by green_done with comment:20 still unhandled. Require an empty inbox before accepting green_done, or return the outstanding events first.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e: green_done no longer ends the run while the inbox holds unacknowledged events. Pinned by test_green_done_waits_for_inbox.

Comment thread utils/babysit-pr.py
Comment on lines +634 to +638
if h["phase"] in ("staged", "committed") and not (h["kind"] == "fix" and h["phase"] == "staged"):
if st["fix_rounds_used"] >= MAX_ROUNDS:
raise Refused("fix-push round cap (%d) reached" % MAX_ROUNDS)
if gh_api("repos/%s/pulls/%d" % (REPO, a.pr))["state"] != "open":
raise Refused("PR is no longer open")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the run deadline before initiating a push

When a handoff is staged before the two-hour deadline but its review or human decision finishes afterward, push-and-reply still pushes: it checks the round cap but never checks deadline_at. The only deadline enforcement is in polling, which does not run while the handoff awaits the parent. I reproduced a successful push with deadline_at=1. Refuse a new push after the deadline while still allowing reply recovery for a push that already landed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e and 490343b: a new push is refused past deadline_at; recovering the replies of a push that already landed still works past both caps. Pinned by test_push_refused_after_cap and test_replies_recover_after_cap_when_push_landed.

Comment thread utils/babysit-pr.py Outdated
Comment on lines +370 to +372
if immediate or now >= due:
immediate = False
res = poll_once(a.pr, now)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the wait deadline to polling operations

When GitHub calls are slow or retry, wait can exceed both its advertised eight-minute bound and the worker's 600-second tool timeout. poll_once synchronously performs six snapshot requests plus uncached permission lookups and writes; each GET independently allows three 60-second attempts. The end deadline is checked only after the entire poll returns, so several slow requests can strand or terminate the worker despite --max-wait. Pass a shared remaining-time budget through polling and subprocess calls so a slice actually returns within its bound.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e and 490343b: wait starts no poll past its slice end, every call is capped at the time left, and a write starts only with its full timeout left, so it is never cut off mid-flight. Pinned by test_no_poll_once_slice_ended, test_budget_caps_every_call and test_write_needs_full_timeout_left.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

A resumed worker can stop with trusted feedback still pending, and commit-message text can fool the unsigned-commit check. Feedback truncation, aggregate polling time, and a stale-base rebase instruction also leave concrete failure paths.

Open Bits AI session

🤖 Bits Code Review · Commit fa42f25

Comment thread utils/babysit-pr.py Outdated

def is_signed(commit):
"""True when the commit object carries a signature header (gpgsig covers GPG and SSH)."""
return "\ngpgsig " in git("cat-file", "commit", commit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Check only commit headers when detecting signatures

If signing is disabled and the worker-provided commit message contains a line beginning gpgsig , this check accepts an unsigned commit. A focused reproduction using an unsigned Git commit object with that text only in its message returned true. This bypasses apply-handoff's mandatory signing check; inspect only the commit headers.

Suggested change
return "\ngpgsig " in git("cat-file", "commit", commit)
return "\ngpgsig " in git("cat-file", "commit", commit).split("\n\n", 1)[0]

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in beb3c7e: is_signed reads only the header block, so message text cannot fake gpgsig. Pinned by test_signature_in_message_is_not_a_signature.

Comment thread utils/babysit-pr.py Outdated
st["inbox"][ev["key"]] = ev
st["idle_polls"] = 0 if changed else st["idle_polls"] + 1
st["next_poll_at"] = now + policy.next_interval(st["idle_polls"])
if d["outcome"] in ("stop", "green_done"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Preserve pending inbox work before declaring completion

When a relaunched worker polls immediately with unacknowledged top-level feedback and green CI/Bits, inbox keys are treated as already surfaced. The policy returns green_done, and this branch stops the run before returning the pending inbox. A focused reproduction stopped with comment:20 still pending. Require an empty inbox before declaring completion.

Suggested change
if d["outcome"] in ("stop", "green_done"):
if d["outcome"] == "stop" or (d["outcome"] == "green_done" and not st["inbox"]):

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e: green_done no longer ends the run while the inbox holds unacknowledged events. Pinned by test_green_done_waits_for_inbox.


def _brief(c):
user = (c.get("user") or {}).get("login")
body = re.sub(r"\s+", " ", c.get("body") or "")[:200]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Preserve complete trusted feedback in worker events

Trusted inline comments, reviews, and top-level comments reach the worker with only a flattened 200-character gist. A focused policy execution confirmed that a review with a longer preamble loses the actual finding entirely, despite snapshot fetching its full body. Carry complete bodies on all trusted event surfaces while retaining brief gists for summaries.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e: thread, review and comment events carry the full body; gist stays for summaries. Pinned by test_events_carry_full_body.

Comment thread utils/babysit-pr.py
due = st["next_poll_at"]
if immediate or now >= due:
immediate = False
res = poll_once(a.pr, now)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Enforce the wait deadline throughout polling

The wait deadline is checked only after synchronous polling finishes. With seven uncached commenters and mocked 50-second API responses, wait consumed 650 simulated seconds despite its 480-second limit; every individual call stayed below its timeout. The worker's 600-second shell timeout can therefore interrupt polling before JSON is returned. Propagate the remaining deadline through API calls, retries, and permission lookups.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e and 490343b: wait starts no poll past its slice end, every call is capped at the time left, and a write starts only with its full timeout left, so it is never cut off mid-flight. Pinned by test_no_poll_once_slice_ended, test_budget_caps_every_call and test_write_needs_full_timeout_left.

Comment thread .agents/skills/babysit-pr/SKILL.md Outdated
Comment on lines +57 to +58
- **`rebase`** — a merge conflict with the worker's resolution plan. Rebase onto
`origin/<base>` here (commits stay signed), run `pre-pr-review`, then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fetch the current base before rebasing

When the base advances and creates a conflict, neither the CLI nor this session flow fetches the updated base. Rebasing onto the stale origin/ can do nothing, after which push-and-reply refuses the unchanged HEAD and conflict handling stalls. Restore the fetch step before rebasing.

Suggested change
- **`rebase`** — a merge conflict with the worker's resolution plan. Rebase onto
`origin/<base>` here (commits stay signed), run `pre-pr-review`, then
- **`rebase`** — a merge conflict with the worker's resolution plan. Run `git fetch origin`,
then rebase onto `origin/<base>` here (commits stay signed), run `pre-pr-review`, then

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in beb3c7e and 490343b: the skill fetches before the rebase, and push-and-reply fetches the base itself and checks HEAD against FETCH_HEAD. Pinned by test_rebase_check_fetches_base.

@jbachorik

jbachorik commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

🐶 babysit-pr is watching this PR — CI breakages and mechanical findings are fixed and pushed automatically; design decisions are always brought to you.

This run
  • 20:12 · started · head fa42f258d
  • 20:13 · CI · green on fa42f258d
  • 20:13 · Bits · failure on fa42f258d
  • 20:16 · answered · inline 4722148719
  • 20:16 · answered · inline 4722148739
  • 20:17 · handoff · decision for the session: PR 1070: 11 valid Bits/Codex findings sit outside the scope-guard allowlist (utils/, SKILL.md); the session has to fix t
  • 21:30 · asked · decision resolved by the session: session fixed A-G in beb3c7e, 490343b, 07d7950
  • 21:30 · answered · inline 4722148754
  • 21:31 · answered · inline 4723180661
  • 21:31 · answered · inline 4723226032
  • 21:31 · answered · inline 4722148763
  • 21:31 · answered · inline 4723226016
  • 21:31 · answered · inline 4723180669
  • 21:31 · answered · inline 4722148771
  • 21:31 · answered · inline 4723180676
  • 21:31 · answered · inline 4723226045
  • 21:31 · answered · inline 4723226039
  • 21:31 · answered · inline 4723226051
  • 21:31 · answered · inline 4722081174
  • 21:31 · answered · inline 4722081127
  • 21:32 · resumed · worker relaunched on 07d79500f
  • 21:32 · CI · pending on 07d79500f
  • 21:32 · Bits · pending on 07d79500f
  • 21:42 · Bits · failure on 07d79500f
  • 21:43 · handoff · decision for the session: Decision: Bits P2 on utils/babysit-pr.py:368 (poll_once drops discovered events when publish_status runs out of budget)

👀 watching · since 20:12 UTC · CI pending · 15 findings answered · Bits failure

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The PR moves babysitting mechanics into a CLI with session-owned commits, pushes, and replies; signature detection, pending-inbox completion, feedback truncation, polling overruns, and stale-base rebasing are fixed. One issue remains: budget exhaustion during the status update can discard fetched findings and repeatedly prevent their delivery to the worker.

Open Bits AI session

🤖 Bits Code Review · Commit 07d7950

Comment thread utils/babysit-pr.py
Comment on lines +366 to +368
if changed:
publish_status(st)
save(st)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve discovered feedback before the budgeted status update

When snapshot and permission reads consume 420–480 seconds, publish_status refuses to start its write because less than its full timeout remains. poll_once has not yet saved the discovered inbox events or permission cache, so this handler returns continue and discards them. A focused mocked reproduction repeated two 450-second polls without persisting or delivering the trusted finding. Save poll progress before the optional status update so sustained latency cannot indefinitely starve feedback delivery.

Suggested change
if changed:
publish_status(st)
save(st)
save(st)
if changed:
publish_status(st)
save(st)

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI human_review:mandatory Human review required — see PR description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant