Auto-drive Goal Loop¶
auto-drive-to-merge and auto-drive-light run one loop. The goal is to get
the pull request merged under the owner's conditions. Each turn, an agent reads
a fresh reading of the live state and the task text, then chooses the next
action. Fixed code does only mechanical work: reading state, pushing, merging
and waiting for an event. It never decides that a run ends because of how the
run is going.
Issue #3129 describes the design. This page is the specification. It closes
1924, #3094, #3109 and #3035.¶
Contents¶
- How a run goes
- A turn
- The reading
- Actions
- Guidance
- Minor review findings
- Waiting
- How a run ends
- Failures inside a turn
- Turn records
- Reported outcomes
- Trust boundaries that stay
- Removed behaviour
- Retired keys and aliases
- Goal contract v1
- Files
- Known limits
- Related
How a run goes¶
auto-drive-to-merge
step-recovery-init, autodrive-pr-input, autodrive-build (unchanged)
autodrive-loop -> autodrive-goal-loop recipe
autodrive_goal_loop.sh (the driver)
repeat:
final? one gh pr view: merged, closed, refused
read reading.json + guidance
turn autodrive-goal-turn recipe (one agent step)
act review | wait | merge (the goal's actions)
continue | wait-owner | handoff | ready | stop (shared)
record record.md
autodrive-report (short)
auto-drive-light is the same up to its eligibility measurement. It then runs
the same loop with that measurement given to the agent as information. It no
longer escalates to auto-drive-to-merge, because both drives run one loop.
Its no_merge default stays true, so it is merging-off unless the operator
says otherwise.
A turn¶
One turn is one fresh amplihack recipe run of autodrive-goal-turn. The
driver starts every turn at the same recipe depth, so the loop has no depth
limit.
- Read. Mechanical tools take a reading and the guidance and write them to the turn folder.
- Decide and act. One agent step. The agent does any agentic work itself: fix and push through the hooks, bring the base in, install a host input, or carry out a later task step. It ends by naming one next action and its arguments.
- Mechanical action. The action the agent named runs: one of the goal's
actions (
review,wait,merge) or a shared one (continue,wait-owner,handoff,ready,stop). - Record. The turn record is written.
Each turn takes one action. If the action word is missing or unknown, no mechanical action runs, the turn record says so, and the next turn starts.
A fresh reading between actions is what keeps the loop from judging a stale state (#3090). An agent's tool call also cannot block for a 30-minute check, which is why waiting is an action and not part of the agent step.
Write a PR comment or other message to a person only when the reader has something to act on: a push and what changed; the final check result before merge or readiness; a question or decision for a named owner; a block the run cannot clear; or the merge. Otherwise, write only the turn record. Keep the required hand-off comments, answers to rejected outcomes, turn records and readings unchanged.
The reading¶
reading.json (schema 1) holds, for this turn:
| Section | Contents |
|---|---|
repo |
Repository, worktree path, current branch, whether the worktree is clean, commits not yet pushed |
merge_authority |
no_merge, dry run, and the effective authority |
pr |
Head, base, mergeable, mergeStateStatus, draft, state |
checks |
Check runs and commit statuses at the head, with counts and an overall state. required lists known required names. required_checks pairs each name with its expected GitHub App ID, or null for any source. A branch response that lists a name without its App policy adds source_known: false. required_known is true when both the rulesets and classic required names are accounted for. required_error explains incomplete policy. The reading then shows all observed checks, applies known requirements and marks an otherwise passing result unverified. A required check with no result is pending, as is a head with no reported checks. unverified_checks gives the observed checks that cannot establish success and the reason for each. |
reviews |
GitHub review verdicts and Crusty round verdicts, each with the head it was given at and the round's minor findings. Each minor finding is {id, summary, outcome, evidence?, reason?}, where outcome is fixed, filed or open (see Minor review findings); a round whose record or minor findings could not be read is listed with its error |
base |
Merge base, how far behind the PR is, conflicting files from git merge-tree --write-tree, and the files the base changed since the merge base that the PR also touches |
repository |
Allowed merge methods; whether strict status checks are required (strict_status_checks, strict_source, strict_unreadable); merge_state_behind as evidence only |
guidance |
Name, time, caller, source, new flag and size of each entry; guidance_error when guidance could not be read |
outcomes |
Every required outcome an agent has named in this run, from the run's ledger, with its latest status, evidence, reason, the turn that last judged it and whether a rejection was answered; outcomes_error when the ledger could not be read |
previous |
The last turn's number, action and mechanical result; after a failed turn run also its recovery and failure (the runner's class and whether it was retryable, whether the agent finished deciding, the completed and failed steps, the operator's limit-wait setting for a usage limit, and the turn log's path; see Failures inside a turn) |
goal |
autodrive_minor_findings, the effective treatment of minor findings (fix_all, judge or file_all), and autodrive_minor_findings_error, which is null unless the value given was unknown; autodrive_minor_judge_rule, which is fix_if_few_lines under judge and null otherwise; autodrive_minor_issues, how filed findings are grouped (each or one_per_pr), and autodrive_minor_issues_error, which is null unless the value given was unknown (see Minor review findings) |
goal_file |
Path to the goal text |
turns_dir |
Path to the turn records |
Strict status checks come from the rules endpoint, then classic branch
protection. If the classic protection endpoint is unavailable, the regular
branch endpoint can still supply required checks. When the available policy
leaves strictness unknown, strict_status_checks is null and
strict_unreadable gives the reason. merge_state_behind reports whether
GitHub's mergeStateStatus is BEHIND, beside the policy and as evidence only:
it never sets the policy, never overrides one that was read, and never fills in
one that could not be read (#3141). GitHub can report BEHIND under a policy
that does not require an up-to-date branch.
Required workflow rules make CI policy incomplete because check runs and
commit statuses alone cannot establish whether the configured workflows ran
successfully. The reading and the wait report this in required_error.
Fetching the base is allowed. Reading never changes the worktree. A read that fails records its error in its own section and never ends the turn.
Actions¶
The agent picks one. The word is used only to dispatch the mechanical step.
| Action | What runs |
|---|---|
review |
One Crusty round (autodrive-crusty-round). Its verdict is evidence in the next reading. Nothing requires the reviewed head to equal the current head. |
wait |
Reads the head's checks over REST at the configured interval. Returns when the checks complete, the head changes or guidance arrives. Returns base-conflict, with head, base and base_sha, as soon as a read of the PR shows mergeable false and mergeable_state dirty, because GitHub runs no checks for a PR that conflicts with its base (#3440). An unknown mergeable state keeps the wait going. |
merge |
Merges with an allowed merge method and --match-head-commit. Authority comes only from the captured authorisation. Before it merges, guidance must have been read again after the decision, and every required outcome is checked by name. |
continue |
Nothing mechanical; the next turn reads the live state again. The agent chooses it after it pushed, installed something or did a task step. |
wait-owner |
Waits for the owner's answer: amplihack recipe guidance wait with no command. args: owner, question. Before the wait starts, the turn tool writes waiting.json in the run folder and one line in the run log; amplihack recipe waiting lists the run while it waits, and the record is removed when the wait returns (issue #3364). |
handoff |
Posts one PR comment naming the owner, the decision and the evidence. The run ends. args: owner, decision, text. |
ready |
Posts one PR comment that the PR is ready. The run ends. args: text, and owner when someone other than the operator decides. |
stop |
The owner asked the run to stop. Posts the continuation note. The run ends as stopped. args: owner, text. |
The agent ends its reply with one JSON object on its own line:
{"action": "<word>", "args": {...}, "outcomes": [...], "why": "..."}. The turn tool saves it as
decision.json; args is at most 64 KiB and why at most 16 KiB. outcomes
is optional on every action except merge; its shape is under
Required outcomes, and a list of the wrong shape makes the
decision invalid. A reply
with no such object, or a word outside ^[a-z][a-z0-9-]{0,31}$, runs no
mechanical action.
Work the agent does inside its own step, before it names the action:
- Fix what a review or CI found and push with plain
git push, through the hooks. - After a full check fails (the pre-push hook, a local full test run or a CI
job), rerun only the part that failed until it passes: the named failing
tests or the one failing test binary or script, in the same environment.
Then run the full check once; for a push, that is the pre-push hook. Record
the part that failed, the narrow command and its result in
why. Report a failure the narrow rerun cannot reproduce rather than fix it blind, and read a failure only CI shows from the CI job log first. - Bring the base in only when the PR conflicts, when the task text asks, or when the repository requires an up-to-date branch. Use a merge commit, resolve any conflict, and push. Never rebase, amend, squash or force-push. A branch that is only behind, with no strict checks, gets no base merge.
- Install a host input the repository needs and the run lacks, such as a
.venvor a pinned tool, by the repository's own instructions. Prefer the worktree or the run's folder. Never use sudo or a system package manager and never touch~/.claudeor~/.amplihack. An input that needs privileges is a hand-off to the host's owner. - Carry out the task's later steps. A merging-off run does not end at the readiness assessment.
Setup instructions come from origin/<base>. If the PR changed a setup script,
a hook or a CI-tooling file, the agent follows the PR's version only on explicit
operator guidance. Otherwise it hands off.
Hand-off¶
The owner comes from the task text or guidance. If neither names one, it is the operator who started the run. A hand-off is for a decision that belongs to that owner, or for a failure that keeps repeating when nothing the agent can do will change it, such as GitHub being unreachable. It does not change the PR's draft or ready state. The text is written in the journalistic style with literal words. It never quotes guidance, task text or secrets.
When the required checks cannot start and each wait returns with nothing changed, the run cannot clear the cause: hand off under the hand-off rule, naming the owner and the decision.
Merging off¶
Merging is off when the captured authorisation has no_merge or a dry run. Once
the PR is ready and the task's later steps are done, the agent takes ready.
The comment says three things: the PR is ready, merging is off for this run, and
who decides the merge.
With merging on, the run ends at merged. The report lists any task steps written for after the merge.
A ready decision with merging on¶
Each turn runs as a nested autodrive-goal-turn recipe run, and the runner
adds that run's own captured invocation to every agent prompt in it. The
driver passes the drive's merge authority to the turn run (no_merge and
autodrive_dry_run, narrowed by the drive's context as the merge action
narrows it), so that record agrees with goal.merge_authority.effective in
the reading. The merge action still reads only the drive's own invocation.
When a turn chooses ready while the reading shows effective authority and the
goal has a merge action, the turn recipe's reconsider-ready agent step
assesses it before the driver dispatches it:
- every merge condition and required outcome met at the reading's head: the
action becomes
merge, with that head inargs.head. The merge action checks the head, the authority, guidance, the outcomes and the merge state again before it merges; - nothing shown unmet, but GitHub has not settled a condition yet (mergeability
or merge state
UNKNOWNor missing): the action becomescontinue, and the next ordinary turn reads again; - otherwise (an unreadable or partial reading, an unmet condition, or an assessment that fails): the turn's own action stands.
The step adds no wait, retry or end of its own. no_merge, a dry run and a
goal without a merge action skip it.
Guidance¶
Guidance is what an operator sends with
amplihack recipe guide.
The loop reads it:
- at the start of every turn, into the reading;
- by the agent, before any action it expects to take more than about five minutes;
- by the wait step, before it starts;
- at the start of the next turn after a wait.
Later guidance governs over earlier guidance and over the task text.
Guidance can narrow what the run does, for example "hold", "do not merge" or
"stop". It can never widen merge authority or relax a trust boundary. Merge
authority comes only from no_merge and the drive's top-level captured
invocation.
Guidance that arrives between the turn's reading and the action makes the action
skip, with outcome skipped-guidance. The next turn decides again.
Guidance that cannot be read is unknown, never absent. A failed read at the
start of a turn puts guidance_error in the reading, so the agent judges with
that in view. A failed read after the decision tells the goal's action that
guidance is unknown (AUTODRIVE_GUIDANCE_UNKNOWN=true). The auto-drive merge
then refuses with guidance-unknown, and the next turn reads guidance again
and decides. The other actions still run, so a run whose guidance cannot be
read can still wait, review, hand off or stop.
Required outcomes¶
An outcome that the task text or guidance requires is one of the run's
conditions (#3129, the guidance case of 7115122327). The agent names each one
in the decision's outcomes list:
{"name": "<short name in the agent's own words>", "status": "met|unmet|rejected",
"evidence": "<what meets it>", "reason": "<why it is rejected>",
"treatment": "fixed|filed"}
treatment is optional. It records how a minor finding was dealt with, and
only the reading's display of minor:<id> outcomes uses it (see
Minor review findings). The driver keeps it only when
it is a string, cut to 16 characters. It is never validated, and no action
depends on its value.
The list has at most 256 entries with unique names of at most 200 bytes on one
line. The limit was 64 until #3160: under fix_all and judge each minor
finding is a named outcome, and a merge must restate every name in the ledger,
so a long run could otherwise never merge. evidence and reason are at most
2000 bytes each, and a rejected entry needs a reason.
- The ledger. After each turn's decision the driver runs
autodrive_goal_turn.sh outcomes, which merges the list into the run's ledger,<autodrive_state_dir>/outcomes.json. Every name ever listed is kept, with its latest status. Nothing truncates the ledger, so a later turn cannot drop a name and no name drops out of the merge check. Its one bound is the 512 KiB read cap. The turn that takes the ledger past it prints an error naming the count, which the driver logs as a warning. After that every reading reportsoutcomes_error, and a merge refuses withoutcomes-unreadable. Each reading lists the ledger underoutcomes. - The answer. A
rejectedoutcome is answered in one PR comment that names it and gives the agent's reason. It is posted once for each reason. A comment that fails the secret screen or cannot be posted leaves the outcome unanswered, and the next turn tries again. - The check by name. The auto-drive
mergerefuses withoutcomes-unmet, naming each outcome, unless the merge decision listsoutcomes(an empty list when none is required) and every name in the ledger is in it asmet, or asrejectedwith that same reason already answered. A ledger that exists and cannot be read refuses the merge withoutcomes-unreadable. - The end. A
ready,handofforstopcomment lists every outcome in the ledger with its status.
The mechanical check makes sure that no named outcome is forgotten at the merge. Whether an outcome is met stays the agent's judgement, with its evidence on record.
Where evidence goes¶
The agent records evidence wherever the task and the repository allow (#3129,
the PR 1 case of 7114891207). When the task keeps the PR title or description
exactly as they are, the agent leaves them alone, posts the evidence in a PR
comment and names that comment in the outcome's evidence. The comment
counts, and the merge goes ahead on it. The goal text (goal-merge-pr.md,
rule 2) and the turn prompt (autodrive-goal-turn.yaml) both say so.
No step requires evidence in the PR description. The parsed-record readiness
gate is gone (see Removed behaviour), so the location of
the evidence cannot end a run, hand off or return the PR to draft. The merge
action reads the description only to build the commit message
(autodrive_merge_message.sh), so a kept description becomes the commit
message as it is. The behaviour test
kept_description::a_kept_description_sends_the_evidence_to_a_comment_and_the_run_merges
runs a drive whose task keeps the description and whose PR body holds no
evidence. It checks that the turn prompt carries the rule, that the evidence
comment comes before the merge, that the run never edits the PR or returns it
to draft, and that the merge goes ahead with the title and description as
they were.
To print the guidance a run has received:
Entries that arrived after the previous reading are marked NEW, and each entry
is marked read or not yet read. read means the block was delivered to an
agent step, not that the agent acted on it; an unread entry whose run has
recorded its end also shows that end. With --json the command prints each
entry's metadata, including read, and a drops array for steps that could not
take guidance, and no text. Guidance text is never put into JSON, context, argv
or logs.
The goal loop reads with recipe guidance show <PR URL>, and recipe guide
<PR URL> writes to the folders that show reads: the folder of each live run
for the pull request, whatever work root the run was started with, and the pull
request's state folder. A drive started with an explicit work root and guided by
pull request URL therefore sees the entry at its next turn. The jq expressions
in the loop use entries[] and folders[] keys that have not changed; read
and drops are additions to schema 1. See
recipe guidance.
Stopping gracefully¶
The owner can stop a run with amplihack recipe stop, or with guidance asking
it to stop. For guidance, the agent commits and pushes, then ends with a
hand-off. The hand-off text is the continuation note and names the owner who
asked.
Minor review findings¶
How a run treats the minor findings of a review is a setting the caller passes, not a policy written into the recipe (#3160, #2391).
The setting¶
autodrive_minor_findings is a recipe context value on auto-drive-to-merge
and auto-drive-light. Both pass it to the goal loop, whose reading carries it
into every turn.
amplihack recipe run auto-drive-to-merge -c pr_number=3129
amplihack recipe run auto-drive-to-merge -c pr_number=3129 -c autodrive_minor_findings=judge
amplihack recipe run auto-drive-light -c pr_number=3129 -c autodrive_minor_findings=file_all
| Value | What the agent does with each minor finding |
|---|---|
fix_all (default) |
Fixes it in the PR before the merge. Files no issue. |
judge |
Judges it by one rule: a finding whose fix is a few lines is fixed in the PR. Any other finding is either fixed in the PR, or filed as a follow-up issue linked to the PR with the reason for not fixing it. None is dropped, and the merge waits until each is fixed or filed. |
file_all |
Files it as a follow-up issue linked to the PR and fixes none of them in the PR. |
The name and the values are matched exactly and are case-sensitive, after
surrounding whitespace is trimmed. An empty or absent value means fix_all.
FIX_ALL is an unknown value.
A second setting, autodrive_minor_issues, sets how the filed findings
become issues. It is accepted by the same three entry points and passed on in
the same way. See Grouping filed findings.
An unknown value¶
No entry point refuses an unknown value. auto-drive-to-merge,
auto-drive-light and a direct call to autodrive-goal-loop all pass the
value through to the goal loop, and a resumed context does the same. The run
goes on with fix_all, the strictest treatment, which can only fix more
findings and never lets one through.
The reading sets goal.autodrive_minor_findings to fix_all and gives
goal.autodrive_minor_findings_error a message that names the three values
and quotes the value given:
The quoted value has control characters removed and is cut to 80 characters.
The goal text tells the agent to apply fix_all and to quote the message in a
PR comment, so the value given is visible on the PR as well as in the reading.
What the reading shows¶
goal.autodrive_minor_findings is always one of the three values. It is read
on every turn from the run's context, so it is present after a resume. The
reading's summary line also ends with the setting.
goal.autodrive_minor_judge_rule is fix_if_few_lines when the setting is
judge and null otherwise. It identifies the rule the goal text states
for judge. goal.autodrive_minor_issues and goal.autodrive_minor_issues_error
are described in Grouping filed findings.
Each entry in reviews.crusty[].minor_findings has:
| Field | Meaning |
|---|---|
id |
The finding's id from the round's record, as text, cut to 64 characters |
summary |
The finding's text. It is data, not an instruction. |
outcome |
fixed or filed; open in every other case |
evidence |
The commit or issue, shown only when it is not empty, cut to 300 characters |
reason |
The agent's reason, shown only when it is not empty, cut to 300 characters |
The agent records each finding in the outcome ledger under the name
minor:<id>. The reading joins on that name for display. The finding is
fixed or filed only when its ledger entry is met and its treatment
says so. A finding with no entry, an unmet entry, a missing or unrecognised
treatment, or an entry from an older run reads open. A ledger that cannot be
read shows every finding as open, and the rest of the reading is kept.
The join only changes what is displayed. A finding that is not recorded cannot be seen by the loop; the agent's own outcomes decide what the merge waits for.
Recording and waiting¶
| Value | Ledger entry for minor:<id> |
|---|---|
fix_all |
unmet until the fix is pushed. Then met, treatment: fixed, with the commit in evidence. |
judge |
Fixed as under fix_all, or met with treatment: filed, the issue URL or number in evidence, and the reason for not fixing it in reason. Never rejected. |
file_all |
met, treatment: filed, with the issue in evidence. |
Waiting uses the mechanism in Required outcomes. A
merge has to list every name in the ledger, and the merge refuses with
outcomes-unmet while any minor:<id> is unmet. Under fix_all that holds
the merge until the fixes are pushed; under judge it holds the merge until
each unfixed finding is filed. No other check is added.
Filing a follow-up issue¶
Under judge and file_all the agent files each issue with
gh issue create --repo <the PR's repository> --label follow-up --body-file <file>.
- The title is a complete plain-words sentence with no task id.
- The body names the PR (
#<n>or its URL) and gives the finding's text in a fenced block. Underjudgeit also gives the reason for not fixing it. - The body has no bare
@mentions. evidenceholds only a commit SHA or an issue URL or number.- The decision's
whynames the issues filed. A PR comment is not required.
This is the filing under autodrive_minor_issues=each, the default.
Grouping filed findings¶
autodrive_minor_issues is a recipe context value on auto-drive-to-merge,
auto-drive-light and autodrive-goal-loop. The two pull request recipes pass
it to the goal loop, and the reading reads it from the run's context on every
turn, so a resumed run keeps it.
amplihack recipe run auto-drive-to-merge -c pr_number=3129 -c autodrive_minor_findings=judge -c autodrive_minor_issues=one_per_pr
| Value | What becomes of the filed findings |
|---|---|
each (default) |
Each finding is its own follow-up issue, as in Filing a follow-up issue. |
one_per_pr |
Every finding of the PR is one checklist item in a single follow-up issue for that PR. |
An empty, blank or absent value means each. An unknown value is not rejected:
the run goes on with each, the reading sets goal.autodrive_minor_issues to
each and gives goal.autodrive_minor_issues_error a message that quotes the
value given, cleaned and cut to 80 characters, and the goal text tells the
agent to quote it in a PR comment.
The setting matters only where findings are filed. Under fix_all nothing is
filed, so one_per_pr changes nothing; the reading still shows the value.
Under judge and file_all it sets how the filed findings are grouped. The
meanings of the autodrive_minor_findings values do not change.
Under one_per_pr the agent writes the findings to a file, one JSON object per
line with id, summary, evidence and reason, and runs
bash "$AMPLIHACK_HOME/amplifier-bundle/tools/autodrive_followups.sh" group --repo <owner/repo> --pr <n> --findings <file> [--task-id <id>]
The command uses REST only, with no search and no GraphQL:
- It lists the repository's open
follow-upissues and finds the one whose body contains the line<!-- autodrive-minor-issue repo=<owner/repo> pr=<n> -->. Pull requests in the list are skipped. When several issues hold the line, the one with the lowest number is used. The title is never matched. A closed issue is not reused: later findings go into a new issue. - When there is no such issue it creates one with the
follow-uplabel, the titleMinor review findings left from pull request #<n>followed by the PR's title, and a body that refers to the PR, the task when--task-idis given, the marker line and the checklist. - Each item is
- [ ] <summary> <!-- finding=<id> -->with two nested lines,Evidence:andReason:. A finding with no reason still gets an item, whose reason line says that none was given. Text is sanitised as in the issues of the follow-up set. - When the issue exists, the command adds an item for each id the body does
not list yet, and for each id only once within the file, with one
PATCHof the whole body. When every id is listed it changes nothing. - It prints the issue's URL. The agent gives that URL as the
evidenceof eachminor:<id>outcome, withtreatment: filed. - A body above 65,000 characters is not written; the command exits non-zero with the reason, and the agent files the remaining findings another way.
Later rounds of the same PR, a resumed run and the follow-up set of
autodrive_followups.sh file (see
auto-drive-to-merge) all find the same issue by its
marker. The merge waits as before: each minor:<id> stays unmet until it is
an item of that issue.
Limits¶
outcomeis what the agent reported. The loop does not check it against GitHub. The review of the PR is the control.- Ids that repeat across review rounds share one name, so a later round's
finding can show as
fixedorfiledfrom an earlier round's entry. - A
treatmentfrom an earlier turn is kept when a later turn sets the same outcomeunmetwithout one. The reading showsfixedorfiledonly besidemet. - A drive that began on an earlier release has no key in its context or state.
It resumes as
fix_all, and its existing findings readopenuntil the agent records them. groupreads the issue and then writes its whole body, with no lock. A checkbox ticked on GitHub between the read and the write is lost, and two paths that rungroupfor the same PR at the same moment can each create an issue. Run onegroupat a time for a PR.
Waiting¶
- Checks completing or the pull request changing. The wait reads the head,
target branch, and target tip immediately, then reads the check runs and
commit statuses for that snapshot. While checks are pending, it sleeps for
the configured interval before reading again. The wait and the turn reading
verify the target's required-check policy and PR snapshot before reporting
a pass. A head change ends the wait. When the wait detects a change to the
target branch, target tip, or required-check policy, it scans again in the
same wait. A required-only wait conditionally refreshes policy on each
pending scan and before reporting a failure. A required
check with no result also prompts a conditional policy refresh in either
mode. The turn reading discards results if the PR snapshot or policy
changes during verification.
A rate-limit retry during the scan or final verification
requires another scan. The turn reading also revalidates the PR snapshot
after a rate-limit retry between the first PR lookup and the scan.
A candidate pass based on GitHub Actions check runs also reads their
workflow runs. A queued or running workflow keeps the result pending even
while the check runs still show the previous attempt's passes. After a
rerun, a pass requires matching successful job IDs from the current attempt.
The verifier rechecks the workflow runs after reading those jobs and again
after the final policy and PR reads to detect a newly queued attempt. The
wait and reading then confirm the PR snapshot again before publishing
the result for those workflow runs. Missing attempt evidence leaves the
result unverified, which can happen when a partial rerun does not execute
every check used for the pass. The
execution_detailfield reports a sanitised API diagnostic or the check suite or attempt that could not be matched. Withargs.required: trueand readable required names, the wait selects the required checks by name and expected App. When a check run and a commit status share a required name, both are retained. A failed status blocks a pass even when the check run passed, and an App-specific requirement retains the status's unknown source attribution. A commit status can satisfy a requirement that allows any source. Skipped and neutral required jobs, a completed commit status whose required App cannot be verified, and a completed check whose required App policy is unreadable appear inunverified_checks. If there is no pending or failing check, these conditions producechecks_state: unverified. A result needs at least one success to pass. The wait uses all reported checks when the policy has no required names or is incomplete. With incomplete policy, both modes apply known requirements, mark an otherwise passing resultunverified, and include the observed counts andrequired_errorin the result. - A login with room. The runner's usage-limit wait (#2992) handles this, and limit-resume (#3112) restarts the run. The loop adds nothing.
- The owner's answer. The waiting step arms a FIFO in the run's
guidance-wake/folder.amplihack recipe guidewrites one byte to every armed FIFO after it stores an entry. The waiter reads guidance again after arming, so an entry that arrived just before the wait is not missed. The same mechanism ends a check wait when new guidance arrives, and repository integrations use it for pull-request and worktree changes. If the FIFO cannot be armed (exit 3 fromguidance wait), the question for the owner ends in a hand-off that names the owner and the question. The check wait runs directly when its FIFO cannot be armed.
The reading and the wait share cached REST responses. They send If-None-Match
when a cached response has an ETag. A 304 Not Modified reuses the response,
including any links to later pages, without using the primary rate allowance.
The repository record (repos/<repo>), read for the allowed merge methods,
is one of these responses. The cache is the ci-rest folder in the run's
state folder, so a new run reads each response once again.
When classic branch protection answers 404 Branch not protected or
Required status checks not enabled for the base, the answer is kept in the
same cache for the rest of the run, for that repository and base. Later
readings, the wait and the policy check before a pass reuse it and send no
request to that endpoint. Any other 404, and any other error, is not kept and
is read again. The rules endpoint is still read at every policy read, so a
ruleset change during the run is seen. Classic protection turned on after the
answer was kept is seen by the next run.
When GitHub declines a call because of a rate limit, the response's
Retry-After, X-RateLimit-Remaining, and X-RateLimit-Reset headers
determine the deadline when available. The turn captures these headers from
GraphQL reads in the build and PR turns as well as REST CI reads. The
gh api rate_limit lookup can supply a missing reset when its counter is
exhausted. The turn sleeps once until the deadline and retries that call.
There is no fixed recheck period or reset-window count for these retries.
A response with no requests remaining and an X-RateLimit-Reset that is not
after the time of the answer means that the limit window has ended. When
Retry-After gives no later deadline, the turn uses the lookup. If the lookup
shows the declined resource with requests remaining, the turn makes the call
again at once, once per call. If the lookup shows the resource at 0 with a
reset after the time of the comparison, the turn sleeps until that reset and
retries the call. If the lookup shows the resource at 0 with a reset at or
before that time, that window has ended too, and the turn makes the call again
at once, under the same one retry per call. The same applies when the response
has no usable reset and the lookup shows the resource at 0 with a reset at or
before the time of the answer. These rules hold for every call made through
the shared read helper: the build and PR readings, the issue claim check, the
CI wait and the merge.
With no future deadline, the read waits for guidance or cancellation without retrying. This happens in these cases:
- The response shows requests remaining, which is a secondary limit, and has
no
Retry-After. - The response has no rate-limit headers or no usable reset, and the lookup shows no exhausted counter with a future reset.
- The limit window has ended, and the lookup failed or shows neither requests remaining nor the resource at 0 with a reset.
- The call is declined again after its immediate retry.
The lookup can show a counter with room even though the request was declined, so the guidance wait can be long. Guidance returns the declined read as unresolved, and the agent sees it in that turn. For a CI wait, guidance ends the wait, and the agent sees it on the next turn.
Each live wait uses waiting.json in the run folder, with run_id, target,
turn and started_at. An owner wait adds owner and question; a record
with no class lists as owner. A service or usage-limit wait adds class
service_connection or usage_limit, service (the harness), and, for a
usage limit, account (the last part of the harness's home folder path, or
default), with no owner or question. A reading (the build reading, the
PR reading or the issue claim check) waiting for guidance after a declined
GitHub read adds class github-rate-limit and resource (core or
graphql), with an empty owner and a question. Each writer removes its
record when the wait returns. A reading also removes its record on exit,
unless another wait has replaced it. The run log gets one line when the wait
starts. A CI wait writes no record of its own here, because it runs inside a
wait that the loop already shows.
amplihack recipe waiting --json includes class, service, account and
resource. The last three are null when absent or not strings. The text
output has six columns: kind, class, age, owner, question and run id. For
service and usage-limit waits, the owner column shows the service and
account, and the question column shows the event that ends the wait,
guidance or the owner's stop. For a GitHub reading wait, the owner column
shows GitHub and the declined resource, and the question column shows
guidance or the owner's stop. See
amplihack recipe waiting.
CI check interval¶
Set checks_watch_interval when you start auto-drive-to-merge,
auto-drive-light, autodrive-build or default-workflow. The recipe passes
it to the wait as RECIPE_VAR_checks_watch_interval. Give a whole number of
seconds from 1 through 9223372036 with no leading zero. An empty or
omitted value uses 120 seconds. An invalid value also uses 120 seconds and
prints one warning to stderr.
How a run ends¶
After each turn the driver ends the run when:
- the fresh PR reading shows
MERGEDorCLOSED; - the turn carried out a
handoff,readyorstopaction; - step recovery recorded a hand-off during the turn (the report's exit 81);
- a pre-agent failure repeated with the same structured class and detail (#3424; see A failure that repeats);
- the owner stopped the run.
Trust-boundary refusals also end the run: exit 79 from any child, or the
runner's structural_refusal failure-class marker on a turn run's log
(terminal_refusal in autodrive_refusal.sh; nothing reads the transcript's
wording). Nothing reads the turn record to decide, and nothing counts time.
The one count is of turns in which no agent made a decision, described below.
Failures inside a turn¶
These never end the run. They go into the next turn's reading:
- a push rejected by the hooks;
- a merge refused by GitHub (its reason is returned as information);
- a Crusty round that fails;
- a
ghorgiterror while reading; - a wait that returns an error.
A turn run that fails does not end the run either (#3129 R1), except in the
cases in the table below. The runner's own handling runs first: the
usage-limit wait, limit-resume and step recovery. If the turn run still fails,
the driver resets nothing. The agent may have edited, committed or pushed
before a later step failed, and all of that is kept. The turn's result.json
has outcome turn-failed, the recovery chosen and the failure. The next
turn's reading carries them as previous, so a fresh agent judges the
failure. A decision the failed turn saved is not carried out. The guidance
mark does not move, so guidance the failed turn was given shows as new again.
Each failed turn also writes one line to the run's own log, the file named by
AMPLIHACK_RECIPE_LOG, which a detached run sets (#3286). The line gives the
turn number, the runner's class and the error: the last line of the turn log
that is neither blank nor a failure-class marker. The write is best effort: it
happens only when the variable names an absolute path to a regular file of
this user that is not a symbolic link, and a failed write changes nothing
else.
The failure fields are evidence for the agent. The driver uses only the
runner's structured class and detail to detect an unchanged pre-agent pair:
| Field | Source |
|---|---|
exit |
The turn run's exit status |
class, detail, retryable |
The runner's own classification and signal detail, from the JSON of its last amplihack.recipe.failure_class marker line. That line is the runner's structured output (FAILURE_CLASS_MARKER_PREFIX in failure_class.rs), the same one the trust-boundary check reads (classify_child in autodrive_refusal.sh). |
completed_steps, failed_steps |
The same marker's JSON fields |
agent_finished |
true when decision.json was saved, or the marker lists decide as completed |
usage_limit |
true when the marker's class is usage_limit |
usage_limit_wait |
For a usage limit, the operator's recipe.usage_limit_wait, read with amplihack config get in the turn's working folder, as the runner reads it; null when it was not read or could not be |
log |
The turn log's path. The agent reads the end of it and judges the cause itself. |
Nothing in the driver reads the wording of the turn log. The goal text tells the agent to read the log, judge the cause and act on it, for example by installing a missing input.
What runs before the next turn:
| Case | What runs |
|---|---|
Any failure, whether or not the agent had decided: a step after the agent failed, the agent step crashed, a setup or environment fault, a transport fault, agent_api, work, indeterminate, or a usage limit |
The next turn starts at once, with the evidence above. |
Two consecutive failures before an agent made a decision, with a valid marker carrying the same structured class and detail (any class except service_connection, and usage_limit with the limit wait on) |
The driver publishes one hand-off naming the failure and the change that would clear it, then arms the existing owner wait. A guidance, pull-request, worktree or owner-stop event clears the comparison before another turn. This includes a marker whose failed_steps lists decide while completed_steps does not. |
A failure the runner classed usage_limit, when the operator's own recipe.usage_limit_wait reads false |
The run ends as usage_limit and the driver exits 1. See The limit wait turned off. |
Two such failures classed service_connection |
The service wait. See Waits after a repeated pre-agent failure. |
Two such failures classed usage_limit, when recipe.usage_limit_wait is unset or true |
The usage-limit wait, described in the same section. |
| The launch bundle no longer holds the turn recipe, the turn tool or the goal tool, as regular files | No turn can run, so the run waits for the owner's word (amplihack recipe guidance wait, an event with no timer), then starts the next turn. If no wake can be armed, the question goes to the operator in a hand-off, as wait-owner does. This is a fact the driver checks on disk, not a reading of the log. |
Any failure of a --once turn |
The run ends, as usage_limit for a usage limit and as failed otherwise, and the driver exits 1. The caller asked for one turn. |
Exit 79 and the runner's structural_refusal marker are not in this table.
They are trust-boundary refusals and end the run as refused before
failed_turn runs.
A failure that repeats¶
A failure that happens on every turn makes the loop start the next turn at once, with no changed input. The loop has no timer or retry count. Two cases differ:
- An agent ran. The agent step runs and a later step fails every time, for
example a broken publish step. Each turn runs a full agent step. That agent
reads
previous.failureand can act on it, and the goal text tells it to hand off when a failure repeats and nothing it can do changes the cause. Nothing in code ends such a run. - No agent made a decision (#3424). The turn run can fail before any step ran,
or its
decidestep can fail before writingdecision.json, for example because the trusted-bundle check refused a group-writable bundle or Codex refused a no-worktree launch. The driver compares the runner's structured class and detail for consecutive failures. The second unchanged failure publishes one hand-off and arms the existing owner wait. The wait returns for guidance, a pull-request change, a worktree change or the owner's stop, and a fresh reading then decides what to do.
A turn counts as one in which no agent made a decision only on positive
evidence. The runner's last failure-class marker is present, parses, and lists
completed_steps and failed_steps as arrays, decide is not completed, and
decision.json was not written. Empty arrays cover a failure before any step
ran. A failed decide step covers a Codex refusal after the step began. A turn
with no marker, with a marker that does not parse, or with one that does not
list both fields is unknown rather than pre-agent. Such a turn clears the
comparison, as a turn in which an agent made a decision does, and the next
turn's agent reads its failure. The driver compares the marker's class and
signal detail. It keeps that signature only in memory, clears it when an event
wakes the wait, and adds no timer or retry limit.
The runner writes its failure-class marker for a failed trusted-bundle check,
classed environmental and not retryable, with empty step lists, before its
Error: line, so the turn log ends with the error. Because a turn without
that marker never counts, the end rule depends on it;
crates/amplihack-cli/tests/issue_3286_untrusted_bundle_marker.rs runs the
real amplihack recipe run on a group-writable bundle and checks the marker,
its empty step lists and the error line after it.
Waits after a repeated pre-agent failure¶
For two classes, no answer from the owner changes the cause of a repeated
pre-agent failure. The driver then waits for an event instead of the owner
(#3599). It writes no wait-owner decision and publishes no hand-off.
| Class | recovery |
The wait ends when |
|---|---|---|
service_connection: the harness could not reach its model service |
service-wait |
An agent step of any recipe run in the same work root, on the same harness, makes a tool call. Its PostToolUse hook runs amplihack recipe guidance deliver, which wakes the waiters in <work root>/events/harness/<harness>/. |
usage_limit, when recipe.usage_limit_wait is unset or true |
usage-limit-wait |
The harness's login file changes (a login or a login rotation writes it), or, for Codex, the earliest reset that the account's own rate-limit reading states for a window at its limit. With no stated reset, only a login change ends this part of the wait. |
Guidance and the owner's stop end either wait too. The driver runs the event
command under amplihack recipe guidance wait --, so the first of the three
events ends the wait, and the next turn reads the state again. The harness is
the value of AMPLIHACK_AGENT_BINARY (claude, codex or copilot). With no
known harness, or when the event command cannot watch for its event, the wait
is for guidance and the owner's stop alone. A hand-off is published only when
no wait can be armed at all. That hand-off gives the class and the service and
asks no owner decision.
"Same host" means the same work root (AMPLIHACK_WORK_ROOT). A step of a run
under another work root on the same machine does not end a service wait. A
bare start of an agent step does not end it either: the connection failure
comes after the harness process has started, so only a tool call shows that
the model service answered. When every run in the work root waits on the same
harness, no run makes a tool call, so no event ends the service wait. The
runs then wait for guidance or the owner's stop: send guidance to each run
once the service answers again, or start one agent step on that harness in
the same work root. Nothing in either wait sets a timer, polls or retries.
The runner classes the failures from the harness's own error, never from agent text:
- The Codex adapter's connection category is
service_connection. - Claude Code's
Unable to connect to API (<code>)andUnable to connect to API. Check your internet connectionareservice_connection. ItsUnable to connect to API: SSL ...messages are not: a certificate fault needs a person to change the trust store or proxy, so it keeps the owner wait. - No fixed Copilot connection message is known, so a Copilot connection
failure classes as
transient_transportorindeterminateand, when it repeats, takes the owner wait. Issue #3607 tracks this. - The Codex adapter's login-refusal category is
authentication. The runner then reads the account's rate-limit windows, which takes no model call. A window at or above its limit makes the classusage_limit. An account with room, or a reading that fails, keepsauthentication, and the repeated failure takes the owner wait. A failed reading is added to the failure's evidence. The runner does not guess a limit it could not read, so a spent account whose reading fails still reaches the owner wait. - Claude and Copilot login refusals keep
authentication, since amplihack has no rate-limit reading for them.
After the wait ends, a further failure with the same class and detail starts the same class wait again, never the owner wait.
The limit wait turned off¶
R1 says a usage limit never ends the run. One case still ends it: a failure the
runner classed usage_limit while the operator's own recipe.usage_limit_wait
is false (or AMPLIHACK_USAGE_LIMIT_WAIT=0). This is kept on purpose, for
three reasons:
- The setting is the operator's, and nothing in amplihack writes it. Its
meaning, in
limit_wait/settings.rs, is that a limit is to be passed up at once rather than waited out. Ending the run withusage_limitpasses it up. - If the run went on, every next turn's agent step would meet the same limit at once until the reset, with no wait: the loop above at its most wasteful. The operator asked for the limit result at once, not for a run that keeps meeting the limit.
- Nothing is lost. The runner records the step as resumable, and the same command resumes the run.
The driver reads the setting itself with amplihack config get. It does not
read the runner's log line. If the setting cannot be read, the run is not
ended for a limit.
Turn records¶
Each turn has a folder, <autodrive_state_dir>/turns/NNN/, mode 0700, holding
reading.json and record.md. The record has three parts:
- a mechanical header: turn number, UTC time, head, merge state, a summary of the checks, and the guidance seen;
- the agent's paragraph saying what it chose and why, in literal words;
- the mechanical result line.
A sample:
Turn 004 · 2026-11-23T18:42:07Z
Head 9f3c1d2 · mergeStateStatus BLOCKED · checks: 11 passed, 1 running (required: scripts/check fast and full)
Guidance seen: none new
The required check is still running at the current head. The branch is
behind dev, but dev changed none of this PR's files and the repository does
not require an up-to-date branch, so I did not bring dev in. I chose to wait
for the check.
Result: wait returned after the check completed (passed).
The prompt for the next turn includes the previous record in full. The report
lists the records. No code parses record.md. A paragraph that matches the
secret screen is replaced by a line naming the pattern class.
Reported outcomes¶
report.rs builds the report from the merge tool's result
(merge-result.json), the driver's loop-end.json, and a final fresh PR
reading. It makes no network call, never fails and never uses the turn records.
Each file must be a regular file, not a symlink, within the size cap, in the
bound state folder, with a matching run ID.
stop_reason |
Meaning |
|---|---|
completed |
Merged at the expected head, or the ready end with merging off |
handoff |
A hand-off to a named owner, or ready with merging on |
closed |
The PR was closed |
stopped |
The owner stopped the run |
terminal_refusal |
A trust boundary refused |
failed |
A --once turn run failed after the runner's recovery |
usage_limit |
A usage limit, with the operator's limit wait turned off, or in a --once turn |
orphaned |
Unchanged |
Only completed counts as success. A merge counts only when loop-end.json
says merged, which only the driver writes, after its own reading of GitHub.
A PR merged by someone else counts as completed, and the report says the merge
was not by this run's merge action. The values waiting_for_checks,
no_progress, budget_exhausted, unreadable and the base-behind form of
not_merged no longer occur.
Trust boundaries that stay¶
These are trust boundaries, not run-health gates, and they stay as strict as they were:
- Merge authority comes only from the operator's inputs (
no_merge) and the captured invocation: effective = allows merge, PR selected, notno_merge, not dry run. The run's own context can narrow it and never grant it:no_mergeandautodrive_dry_runmust also be exactlyfalsethere. An unreadable record givesauthorization-unreadableand no merge; exit 79 from the authorisation helper passes up. - The pinned launch bundle. Tools, recipes and goal text resolve only inside
the bundle, as regular files and not symlinks. Edits in the worktree are
ignored. A launch checks that the bundle has every file in the bundle's own
list,
skills/auto-drive-to-merge/required-assets.txt. A bundle with no such list is checked against the list compiled into the binary, which is closed: a file a release starts to need is added to that release's own list. A bundle with its own list is validated against that list even when a later release's binary checks it. A bundle without a list must contain every file in the compiled fallback; an older bundle can still fail that check. A bundle that lacks a listed file, or whose own list is empty or names a path outside the bundle, does not launch, and the runner's marker has classenvironmentaland signalmissing bundle asset. - The run's binary. Every step and sub-recipe of a run starts the
amplihackthe run started with (AMPLIHACK_BIN, and that binary's folder first onPATH), so an install during the run changes neither the binary nor the private auto-drive bundle the run uses. A run started after the install uses the new release. Installing a release does not change the behaviour of an older binary already running. --match-head-commitwith an allowed merge method. The merge action requires the head the agent names to equal this turn's reading and to be 40 or 64 lowercase hex characters. Required checks must be green.- Never rebasing or force-pushing. Never
--adminor any bypass. - Never reading a token. The text the loop publishes passes a secret screen, and
@mentionsand remote images are neutralised. A match gives outcomerefused-secret, nothing is published and the run carries on. - Refusing a cross-repository PR.
- The pane-ownership proof in limit-resume.
Removed behaviour¶
| Removed | Was in | Closes |
|---|---|---|
| Automatic base merge | autodrive_merge.sh, merge loop, finalize, merge-evidence step-01 |
#1924, #3094 (and fixes #2342) |
End on pending checks (checks-pending) and the hand-back to draft |
autodrive_merge.sh, autodrive-handoff.yaml |
#3109 |
| Loop-health STUCK stop and no-progress stop | The auto-drive loop and Crusty loop | #3035 |
| Round and wall-clock budgets as stopping rules | autodrive_budget.sh |
|
| Parsed-record readiness gates | Merge-evidence and merge-round records | |
| End of a merging-off run at its readiness assessment | Merge round | ui-platform #695, #705 |
| Eligibility escalation to auto-drive-to-merge | auto-drive-light.yaml |
Hook repair, the issue-claim check and the build stage's other ends are in the
build recipes, which a later change covers. loop-health-evaluator.yaml stays,
because hook repair still uses it. The loop never calls hook repair or
loop-health-evaluator.
Retired keys and aliases¶
The autodrive_budget_* keys are still declared and are accepted, and nothing
reads them. The run log has one plain note that they are retired. An unknown
autodrive_budget_* key no longer fails the run. light_eligibility is accepted
and ignored.
For one release (#3049), renamed or removed recipes and tools keep a file under the old name. Runs in flight keep their pinned bundle: an auto-drive run on 1.2.212 runs every recipe and tool from the launch copy of the bundle made when it started, so an upgrade under it changes nothing it calls (see Callers in 1.2.212). A tool alias keeps the name, not the old interface.
| Alias | Now |
|---|---|
autodrive-merge-loop recipe |
Runs the goal loop |
autodrive-crusty-loop recipe |
Runs one review action |
autodrive-merge-round, autodrive-merge-evidence, autodrive-finalize recipes |
Each runs one turn (--once) |
autodrive_loop.sh, autodrive_merge_loop_run.sh |
Forward to the driver where the old call maps onto it |
autodrive_budget.sh, autodrive_progress.sh, autodrive_round_word.sh, autodrive_escalate.sh, autodrive_done_override.sh, autodrive_crusty_rereview.sh |
Print one line naming the replacement and exit 0 |
Every autodrive_budget.sh subcommand exits 0, so a call to check means
"carry on". No alias brings back a stop. Aliases are real files, because the
bundle copy skips symbolic links.
Callers in 1.2.212¶
Every 1.2.212 caller of the ten tools this change rewrites was walked against
this branch's tools (crusty round 3 of #3143). The installed 1.2.212 bundle is
byte-identical to tag v1.2.212, and the five added tools have no 1.2.212
caller. The table holds for 1.2.213 too. Of these files, 1.2.213 changes only
autodrive_merge.sh (reason wording, and BEHIND and DIRTY each still return
8) and the round budget in autodrive_merge_loop_run.sh (#3131, #3152), and it
changes no code under crates/*/src, so how a run finds its tools is the same.
How a 1.2.212 run finds its tools:
- An
auto-drive-to-merge,auto-drive-lightorautodrive-*run copies the bundle into its own run folder when it starts. It loads its recipe and sub-recipe search path from that copy, and every step getsAMPLIHACK_HOMEset to the copy (v1.2.212execute.rslines 863-889 and 1178-1190). A nested auto-drive run copies its parent's copy. - Each 1.2.212 tool that calls another finds it in its own folder, so inside the copy.
- Other runs have no copy. Their steps read
AMPLIHACK_HOME, the live~/.amplihacklink, at step time. Of the ten tools, onlyautodrive_refusal.shis reached this way.quick-changeandworkflow-publishsourceworkflow_hook_repair.sh, which runsloop-health-evaluator, whoseloop-evidence-collector.yamlsources it.
| Tool | Reached by a 1.2.212 run after the upgrade | If a 1.2.212 caller reached this branch's version |
|---|---|---|
autodrive_refusal.sh |
Yes, by runs without a launch copy | Works. The four 1.2.212 functions are byte-identical; log_body and usage_limit_failure were added. tests/issue_1437_autodrive_refusal.sh covers the four. |
autodrive_merge.sh |
No | Same function names, arguments and result fields. The return codes for pending checks (7, now 3) and for base-behind (8, now 4) are gone, because the goal loop has no base-sync path (#3094). |
autodrive_budget.sh, autodrive_progress.sh |
No | Status 0 and no output, which the callers read as "no stop". |
autodrive_done_override.sh |
No | Status 0, so the caller always takes its "another round" branch. |
autodrive_crusty_rereview.sh |
No | Status 0 with no re-review. |
autodrive_round_word.sh |
No | The merge-round step that sources it finds no autodrive_round_word or autodrive_round_file and stops with status 127. |
autodrive_escalate.sh |
No | The 1.2.212 autodrive_loop.sh that sources it finds none of the old stop functions and fails at its first call. |
autodrive_loop.sh |
No | Runs one review or the goal loop, but writes no loop_result or merge-ready-result.json, so a 1.2.212 caller reads its result as unreadable and hands off. --context pr_number is ignored; the number comes from RECIPE_VAR_pr_number. |
autodrive_merge_loop_run.sh |
No | Runs the goal loop; the 1.2.212 autodrive-merge-loop step reads no result and hands off. |
No 1.2.212 run can reach a tool that fails its call. The failures in the last four rows would need a 1.2.212 recipe running with this branch's tools in the same bundle, and neither an install nor a launch copy produces that mix.
Two mixes of binary and bundle are refused or limited rather than broken:
- A newer
amplihacktyped by an agent inside a 1.2.212 run keeps that run'sAMPLIHACK_HOME. The commands 1.2.212 prompts ask for (orch helper autodrive state|worktree,orch helper autodrive-completion-write,hygiene artifact-guard) run none of these tools. A newerrecipe run autodrive-*refuses at launch, because the 1.2.212 copy lacks the goal loop's required files. - A 1.2.212 binary run by path against this bundle launches, but it has no
recipe guidancecommand, so every guidance read fails. Guidance is then unknown and the merge refuses withguidance-unknown.
Goal contract v1¶
The shared module holds no pull request fields. A later change supplies its own goal, reading tool and actions without editing the shared files. The driver takes a goal text, the task text, a goal tool, the state folder and the worktree.
The goal tool is a script in the bundle's tools/ folder. The environment
variable AUTODRIVE_GOAL_CONTRACT=1 selects the contract; any other value makes
the tool exit 2.
| Call | Does |
|---|---|
actions |
Prints the action words it supports, separated by spaces |
final |
Prints one word if the goal has ended (for example merged), nothing otherwise. refused is reserved. Exit 79 passes through. |
read <turn_dir> |
Writes goal.json |
act <word> <turn_dir> |
Carries out the action and writes result.json |
publish <body_file> |
Posts the hand-off or ready text |
goal.json has schema 1 and a required summary. Three optional fields are
read by the driver:
| Field | Use |
|---|---|
subject |
A short name for the goal, copied into loop-end.json |
guidance_target |
A target amplihack recipe guidance show|wait accepts (an https:// pull request URL). The driver reads that folder's guidance into the reading and gives the turn run the folder in AMPLIHACK_RUN_GUIDANCE_DIRS. |
worktree |
The absolute folder the agent works in, when it is not the run's checkout |
act <word> <turn_dir> reads the agent's decision.json and this turn's
goal.json and reading.json from the turn folder, and
AUTODRIVE_GUIDANCE_UNKNOWN, which is true when guidance could not be read
again after the decision. result.json has
outcome and summary. The shared words continue, wait-owner, handoff,
ready and stop are reserved. The driver rejects a goal tool whose action
words collide with them before turn 1, and exits 2.
The goal tool runs with AUTODRIVE_GOAL_CONTRACT=1, AUTODRIVE_STATE_DIR,
AUTODRIVE_REPO, AUTODRIVE_WORKTREE, AUTODRIVE_LOOP_HOME,
AUTODRIVE_INVOCATION_FILE and AUTODRIVE_TASK_FILE, and the run's own
RECIPE_VAR_* context. The turn run gets none of the AUTODRIVE_* variables.
The driver writes loop-end.json with end, run_id, subject, detail,
turn and time; a merged end adds after_merge and a ready end adds
verify_readiness. Only the driver writes it. The driver removes any
loop-end.json left by an earlier run when it starts, and any the agent leaves
in a turn.
The driver is started by the autodrive-goal-loop recipe:
autodrive_goal_loop.sh --goal-tool <name.sh> --goal-file <bundle-relative path>
--state-dir <dir> --repo <dir> [--task-file <f>] [--notes-file <f>]
[--invocation <invocation.json>] [--once]
--once runs one turn and returns; the one-release recipe aliases use it.
The driver's exit codes: 0 for an end (or one --once turn), 1 for an error, a
failed --once turn, or a usage limit the operator asked to receive at once, 2
for a usage error or a refused contract (no turn runs), 75 and 79 passed up
unchanged. It prints exactly one JSON line on
stdout.
The auto-drive goal tools are autodrive_pr_goal.sh (actions review wait merge)
and autodrive_pr_reading.sh. The goal text is
amplifier-bundle/skills/auto-drive-to-merge/goal-merge-pr.md. The outcomes of
its actions:
| Action | Outcomes |
|---|---|
review |
reviewed, review-failed |
wait |
checks-complete with head, base, base_sha, and checks_state of passed, failed, or unverified. Other outcomes are head-changed, guidance-arrived, and wait-error. |
merge |
merged, not-authorised, authorization-unreadable, guidance-unknown, outcomes-unmet, outcomes-unreadable, checks-not-green, refused, not-open, message-unavailable, invalid-head, head-mismatch |
The shared outcomes are continued, no-action, skipped-guidance,
turn-failed, ended, invalid-args, refused-secret, guidance-arrived
and wait-error.
Files¶
Shared module:
autodrive_goal_loop.sh, the driverautodrive_goal_turn.sh, the turn toolautodrive_goal_lib.sh, the validators, atomic writes and text screensautodrive-goal-loop.yaml, the entry recipeautodrive-goal-turn.yaml, the turn recipe
Auto-drive:
autodrive_pr_goal.sh,autodrive_pr_reading.sh,autodrive_merge.shgoal-merge-pr.mdamplifier-bundle/skills/auto-drive-to-merge/SKILL.mdand its second copy,docs/claude/skills/auto-drive-to-merge/SKILL.md. The two are kept identical.auto-drive-to-merge.yaml,auto-drive-light.yaml,autodrive-crusty-round.yaml
Rust:
run_guidance/wake.rsandcommands/recipe/guidance.rscommands/orch/autodrive/report.rsandtrusted.rs
Trade-offs¶
- Nothing in code stops a loop whose agent keeps choosing to continue. Each turn costs one agent call.
- A pull request someone else merges ends the loop as
completed; the report says the merge was not by this run's merge action. - The merge action does not tell a pending required check from a failing one:
both are
checks-not-green. The goal text tells the agent towaiton pending checks before it choosesmerge.
Known limits¶
-
The turn run gets no
AUTODRIVE_*variables. The driver passes the goal contract only to the goal tool, so the agent step cannot read or steer the driver's own state through the environment. -
The agent step can run
gh pr mergeitself. The guard that blocked it (#1551) was removed in #2340. The launch stamp tells the agent only the loop's merge action merges, but that is a directive and not a mechanical block.--match-head-commitand GitHub's branch protection remain the real boundary. #3144 tracks restoring enforcement. - An agent that keeps choosing to continue costs one agent call per turn. The
agent is told to hand off when a failure keeps repeating. The operator can
use
amplihack recipe stop. - A turn run that fails the same way every turn starts the next turn at once, with no changed input, while an agent runs in it (A failure that repeats). Where no agent makes a decision, the second unchanged marked failure publishes one hand-off and waits for an owner event.
gh pr checks --watchpolls GitHub insidegh. The loop adds no poll of its own.- A CI wait on a head with no checks continues until checks complete, the head changes, guidance arrives or the operator stops the run.
- An operator who passes
--step-timeouttimes out the whole loop step. - A pending required check is reported by the merge action as
checks-not-green. - Guidance newness is by entry name order. An entry stamped before the mark but
published after it loses its
NEWflag and its wake, but still reaches later agent prompts. - Same-user processes can read and forge state files. The
completedoutcome is protected by the driver-onlyloop-end.json.