Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
branch, as a carry or a person's merge puts it there. A review unit whose pull request is
not on the base its stack gives it is now retargeted each round, the host's base is read
back to confirm, and after three failed rounds the unit is held `base_not_moved` with the
pull request and the expected base named.
pull request and the expected base named. While that retarget is pending, one comment on the
pull request says its base has merged and that it is not to be merged until it shows the
base its stack gives it. `abk status` and `abk explain` show a unit held `landed_off_default` or
`base_not_moved` with its pull request, the branches and what a person can do, and a
dependent says it waits on a unit that landed off the default branch.

- The rerun of a failed test now collects a test of the `integration` kind that a repository's
default settings deselect. Before, the rerun carried no marker expression, so such a test was
Expand Down
6 changes: 6 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ unit put back for any other cause waits for the next pass, and the tick log says
still on as `held_base`, and who holds it as `held_by`. A record with no cause is one from before causes or one an event ended,
and one with a cause this release does not know reads the same way: the pass never readmits it, and `abk status` lists it.

A merge is recorded only when it is on the default branch. A pull request merged into the branch
of a unit that had already merged leaves its unit held `landed_off_default`, and its dependents
keep waiting, until its commit reaches the default branch. A pull request that is not on the base
its stack gives it is retargeted each round and the host's base read back; after three failed
rounds the unit is held `base_not_moved`.

**The code host outage.** A git push the code host refuses (an authentication refusal, an HTTP 401, 403
or 5xx, a connection it closed), or cannot reach while the control group is up, parks its unit with the cause
`host_unavailable`, and a fetch it refuses or cannot reach is noted without parking its unit. The call that
Expand Down
5 changes: 4 additions & 1 deletion src/agent_build_kit/cli/explain_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from agent_build_kit.pipeline.external_file import external_reason, held_units
from agent_build_kit.pipeline.regression_agent import waited_fixes
from agent_build_kit.pipeline.resolution_lane import lane_record, resolving_phrase
from agent_build_kit.pipeline.unit_store import Cause
from agent_build_kit.pipeline.unit_store import Cause, landing_hold_text
from agent_build_kit.pipeline.units import PLANNED, RUNNING, history_stamp


Expand Down Expand Up @@ -168,6 +168,9 @@ def cmd_explain(args: argparse.Namespace, inst: Installation) -> int:
)
if record is None:
return 0
if unit is not None and (landing := landing_hold_text(unit)):
print(f"{args.unit} is {landing}")
return 0
if record is None:
print(f"no record covers {args.unit} at {at.isoformat()}")
return 0
Expand Down
22 changes: 21 additions & 1 deletion src/agent_build_kit/cli/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@
build_retarget,
conflict_phrase,
late_check_running,
pr_base_on_host,
pr_based_on,
recheck_landings,
remove_merged_branches,
retry_host_retargets,
warn_base_merged,
)
from agent_build_kit.pipeline.external_file import Hold as ExternalHold
from agent_build_kit.pipeline.external_file import (
Expand Down Expand Up @@ -351,6 +353,7 @@
awaits_release,
feedback_source_of,
guidance_excerpt,
landing_hold_text,
waiting_for,
)
from agent_build_kit.pipeline.unit_test_slots import slot_status_lines, waiting_since
Expand Down Expand Up @@ -1365,6 +1368,8 @@ def cmd_status(args: argparse.Namespace, inst: Installation) -> int:
log(f" held by the checks: {unit.id} ({where}) — {unit.note}")
if unit.state == HELD and unit.cause is Cause.DIRTY_WORKTREE:
log(f" parked: {unit.id} ({where}) — {unit.note}")
if landing := landing_hold_text(unit):
log(f" held: {unit.id} ({where}) {landing}")
if unit.state == RUNNING and unit.cause is Cause.LOGIN:
log(
f" paused for the login: {unit.id} ({where}) until it is renewed; "
Expand Down Expand Up @@ -1402,7 +1407,14 @@ def cmd_status(args: argparse.Namespace, inst: Installation) -> int:
if waits:
merging = merge_parents(unit, waits, units, config.active().repos)
wait = dependency_wait(waits, merging=merging)
log(f" {unit.id} ({where}) {wait}")
off = [
"a parent landed off the default branch"
for parent in units
if parent.id in {each.id for each in waits}
and parent.state == HELD
and parent.cause is Cause.LANDED_OFF_DEFAULT
]
log(f" {unit.id} ({where}) {wait}{''.join(f' — {each}' for each in off)}")
if is_superseded(unit):
log(f" superseded: {unit.id} ({where}) by {', '.join(unit.superseded_by)}")
if unit.close_pending:
Expand Down Expand Up @@ -7195,6 +7207,14 @@ def poll_all(inst: Installation, *, store: UnitStore, lane: Lane | None = None)
resume=resume,
log=log,
)
# The warning goes up before the retarget is tried, so a person sees it while the base is stale.
warn_base_merged(
store,
base_on_host=pr_base_on_host,
forge_of=lambda unit: inst.forge_of(unit.repo),
posts_root=inst.state_dir,
log=log,
)
retry_host_retargets(store, claim=claim, resume=resume, log=log)

labels = StateLabels(inst.forge_of, log=log)
Expand Down
60 changes: 60 additions & 0 deletions src/agent_build_kit/pipeline/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
depth_of,
is_superseded,
local_ref,
reachable,
through_satisfied,
trunk_of,
)
Expand Down Expand Up @@ -1305,6 +1306,65 @@ def retarget(unit: StoredUnit, base: str) -> bool:
)


def warn_base_merged(
store: UnitStore,
*,
base_on_host: Callable[[StoredUnit], str | None],
forge_of: Callable[[StoredUnit], tuple[Forge, RepoId]],
posts_root: Path,
log: Log = print,
) -> list[str]:
"""Each round: post once, on the pull request of an in-review unit whose base branch has
merged and whose host base (`base_on_host`) is not yet the base its graph gives it, the
warning that it is being moved and is not to be merged until it shows the base its stack
gives it.
The comment carries a marker line and its ids are recorded in the own-posts record under
`posts_root`, so a later round does not post it again. Returns the ids it posted for."""
graph = store.all()
by_id = {other.id: other for other in graph}
posted_for: list[str] = []
for unit in graph:
if unit.state != IN_REVIEW or not unit.pr:
continue
wanted = base_of(unit, graph)
ancestors = reachable(
unit.depends_on,
lambda uid: by_id[uid].depends_on if uid in by_id else (),
)
merged_branches = {
by_id[uid].branch
for uid in ancestors
if uid in by_id
and by_id[uid].repo == unit.repo
and by_id[uid].state in (MERGED, SATISFIED)
and by_id[uid].branch
}
if not merged_branches - {wanted}:
continue # None of its own ancestors could be its stale base: do not ask the host.
on_host = base_on_host(unit)
if on_host is None or on_host == wanted or on_host not in merged_branches:
continue
body = (
f"The base branch `{on_host}` of this pull request has merged. It is being moved "
f"onto `{wanted}`. Do not merge it until it shows `{wanted}` as its base.\n{MARKER}"
)
try:
forge, repo_id = forge_of(unit)
found = forge.comment_exists(repo_id, unit.pr, MARKER, body)
ids = [found] if found else forge.post_comment(repo_id, unit.pr, body=body)
except TRANSIENT as error:
log(f"{unit.id}: warning on #{unit.pr} not posted — {error}")
continue
if not ids:
log(f"{unit.id}: warning on #{unit.pr} not posted; tried again next round")
continue
record_posts(posts_root, forges.key(repo_id), unit.pr, ids)
if not found:
log(f"{unit.id}: warned on #{unit.pr} that its base {on_host} has merged")
posted_for.append(unit.id)
return posted_for


def _unit_on_branch(store: UnitStore, repo: str, branch: str, not_id: str) -> StoredUnit | None:
"""The unit, other than `not_id`, whose branch is `branch` in `repo`."""
return next(
Expand Down
17 changes: 17 additions & 0 deletions src/agent_build_kit/pipeline/unit_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,23 @@ def waiting_for(unit: StoredUnit) -> str:
return _WAITING_FOR.get(unit.cause, "") if unit.cause else ""


def landing_hold_text(unit: StoredUnit) -> str:
"""What a unit held `landed_off_default` or `base_not_moved` says, with its pull request,
its note (the branches) and what a person can do; "" for any other unit."""
pull = f"#{unit.pr}" if unit.pr else "its pull request"
if unit.state == HELD and unit.cause is Cause.LANDED_OFF_DEFAULT:
return (
f"landed off the default branch: {pull} — {unit.note}; carry its work onto "
"the default branch, then release the hold"
)
if unit.state == HELD and unit.cause is Cause.BASE_NOT_MOVED:
return (
f"base not moved: {pull} — {unit.note}; retarget the pull request onto its "
"base by hand, then release the hold"
)
return ""


# How long a parked unit waits, by consecutive parking.
PARK_BACKOFF = (
timedelta(minutes=1),
Expand Down
7 changes: 7 additions & 0 deletions src/agent_build_kit/skills/abk-pipeline/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ default branch`. It holds no claim on the unit while it waits or
runs, so `abk settle --accept` works then, and a result that comes back after an accept changes
nothing.

A merge is recorded only when it is on the default branch. A pull request merged into the branch
of a unit that already merged leaves its unit held `landed_off_default` (its dependents keep
waiting) until its commit reaches the default branch, as a carry or a person's merge puts it there.
A review unit whose pull request cannot be retargeted onto the base its stack gives it is held
`base_not_moved` after three failed rounds; `abk status` and `abk explain` name the pull request,
the branches and what a person can do.

### Paused for a rejected login

When an account's Claude login is rejected (the CLI says `Failed to authenticate`, HTTP 401, `OAuth
Expand Down
106 changes: 104 additions & 2 deletions tests/cli/test_status_landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@

from __future__ import annotations

import argparse
from pathlib import Path

import pytest

from agent_build_kit.cli.explain_cmd import cmd_explain
from agent_build_kit.forges.base import Check, CheckStatus
from agent_build_kit.installation import Installation
from agent_build_kit.pipeline.pr_poller import HOLD_LABEL
from agent_build_kit.pipeline.units import IN_REVIEW
from agent_build_kit.pipeline.unit_store import Cause, UnitStore
from agent_build_kit.pipeline.units import HELD, IN_REVIEW, PLANNED
from agent_build_kit.pipeline.verdict import ReviewTier
from agent_build_kit.pipeline.verdict_record import VERDICTS
from tests.conftest import run_status
from tests.conftest import make_installation, run_status
from tests.factories import new_unit
from tests.landing_support import PR, UNIT, Landing, landing
from tests.verdict_fakes import write_verdicts

Expand Down Expand Up @@ -99,3 +104,100 @@ def test_a_decline_ended_by_a_rework_is_no_longer_shown(

assert lines
assert not any("held by label" in line or "not landed" in line for line in lines)


PARENT = "feature/1"
DEPENDENT = "feature/2"
OFF_PR = 5
OFF_BRANCH = f"spec/{PARENT}"


@pytest.fixture
def held_installation(tmp_path: Path) -> Installation:
return make_installation(
tmp_path, planning={"state_dir": ".", "worktree_root": str(tmp_path.parent / "trees")}
)


def hold(inst: Installation, cause: Cause, note: str) -> None:
"""`feature/1` held with `cause`, and `feature/2` parked on it."""
store = UnitStore(inst.state_dir / "units.json")
store.upsert([new_unit(PARENT), new_unit(DEPENDENT, depends_on=(PARENT,))])
store.set_state(PARENT, HELD, pr=OFF_PR, branch=OFF_BRANCH, note=note, cause=cause)
store.set_state(DEPENDENT, PLANNED, note="parked", cause=Cause.GATED)
store.set_needs(DEPENDENT, (PARENT,))


def test_status_shows_a_unit_landed_off_the_default_branch_and_what_a_person_can_do(
held_installation: Installation,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
hold(held_installation, Cause.LANDED_OFF_DEFAULT, f"#{OFF_PR} was merged into {OFF_BRANCH}")

lines = run_status(held_installation, monkeypatch, capsys)

shown_lines = [line for line in lines if f"{PARENT} " in line and "landed off" in line]
assert len(shown_lines) == 1, "\n".join(lines)
shown = shown_lines[0]
assert "landed off the default branch" in shown
assert f"#{OFF_PR}" in shown
assert OFF_BRANCH in shown
assert "carry" in shown, "it says what a person can do"


def test_status_says_a_dependent_waits_on_a_unit_landed_off_the_default_branch(
held_installation: Installation,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
hold(held_installation, Cause.LANDED_OFF_DEFAULT, f"#{OFF_PR} was merged into {OFF_BRANCH}")

lines = run_status(held_installation, monkeypatch, capsys)

waiting = [line for line in lines if f"{DEPENDENT} " in line]
assert waiting
assert any("landed off the default branch" in line for line in waiting), "\n".join(lines)


def test_status_shows_a_unit_whose_base_was_not_moved_and_what_a_person_can_do(
held_installation: Installation,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
hold(held_installation, Cause.BASE_NOT_MOVED, f"#{OFF_PR} could not be moved onto main")

lines = run_status(held_installation, monkeypatch, capsys)

shown_lines = [line for line in lines if f"{PARENT} " in line and "base not moved" in line]
assert len(shown_lines) == 1, "\n".join(lines)
shown = shown_lines[0]
assert f"#{OFF_PR}" in shown
assert "main" in shown
assert "retarget" in shown, "it says what a person can do"


@pytest.mark.parametrize(
("cause", "words"),
[
(Cause.LANDED_OFF_DEFAULT, ("landed off the default branch", OFF_BRANCH, "carry")),
(Cause.BASE_NOT_MOVED, ("base not moved", "main", "retarget")),
],
ids=["landed-off-default", "base-not-moved"],
)
def test_explain_says_why_a_unit_is_held_for_these_causes(
held_installation: Installation,
capsys: pytest.CaptureFixture[str],
cause: Cause,
words: tuple[str, ...],
) -> None:
hold(held_installation, cause, f"#{OFF_PR} on {OFF_BRANCH}, wanted main")
capsys.readouterr()

code = cmd_explain(argparse.Namespace(unit=PARENT, at=None), held_installation)

out = capsys.readouterr().out
assert code == 0
assert f"#{OFF_PR}" in out
for word in words:
assert word in out, out
30 changes: 30 additions & 0 deletions tests/docs/test_merge_landing_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""The architecture guide and the `abk-pipeline` skill say that a merge is recorded only when it is
on the default branch, and what `landed_off_default` and `base_not_moved` mean
(spec: merge-must-land-on-the-default-branch)."""

from __future__ import annotations

import pytest

from tests.doc_text import ROOT
from tests.prompt_text import flat

ARCHITECTURE = flat((ROOT / "docs" / "architecture.md").read_text())
SKILL = flat(
(ROOT / "src" / "agent_build_kit" / "skills" / "abk-pipeline" / "SKILL.md").read_text()
)


def test_the_architecture_says_a_merge_is_recorded_only_when_on_the_default_branch() -> None:
assert "recorded only when" in ARCHITECTURE
assert "default branch" in ARCHITECTURE


@pytest.mark.parametrize("cause", ["landed_off_default", "base_not_moved"])
def test_the_architecture_explains_the_cause_beyond_the_list_of_causes(cause: str) -> None:
assert ARCHITECTURE.count(f"`{cause}`") >= 2


@pytest.mark.parametrize("cause", ["landed_off_default", "base_not_moved"])
def test_the_skill_mentions_the_cause(cause: str) -> None:
assert f"`{cause}`" in SKILL
9 changes: 9 additions & 0 deletions tests/forges/stand_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ def labels_on(self, *args, **kwargs) -> list[str]:
raise NotImplementedError


class FindingForge(StandInForge):
"""A host that finds a comment it holds by its marker and exact body, as the real reads do."""

def comment_exists(
self, repo: RepoId, pr: int, marker: str, body: str, *, reply_to: str | None = None
) -> str | None:
return "comment-1" if any(marker in c and body == c for c in self.comments) else None


def lookup(forge: StandInForge):
"""A `for_repo` the `wiring.build_*` factories accept: every repo name
resolves to this one stand-in."""
Expand Down
Loading