Fix loop and judge
An exec node's fix_loop repairs the node and measures it again until it
passes. This page is the loop's contract: when it opens, what runs in each
cycle, and how the judge's verdict is read. For why loops and caps work the
way they do, see Caps and budgets.
Keys
A fix_loop takes exactly one of tasks or steps. A node with a fix_loop
can't be read_only.
| Key | Type | Default | Meaning |
|---|---|---|---|
tasks or steps | list | required, one of them | The repair. Runs as an ordered group, like a node's own steps. No task or step in it may take an on_failure. |
judge | mapping | none | One task of any kind, which may not take an on_failure. The shipped one is strict_judge. |
max_attempts | integer | from the layers below | The loop's attempt limit. Above 0. |
early | boolean | false | Open the loop as soon as one of the node's own steps finishes with every task passed and a loop-severity finding. The later steps don't run, and neither does on_failure. See Starting early. Unreleased |
Limits
The loop's limits come from four layers. A later row replaces only the keys it sets, so the last row that sets a key wins. See policy.yaml.
| Layer | Attempts key | Wall-clock key |
|---|---|---|
1. policy.yaml's loops.<node>.fix_loop entry, else its default | attempts | wall_clock_s |
2. The node's policy | max_attempts | timeout_minutes |
| 3. The loop's own keys | max_attempts | none |
4. The work item's own policy (kraft item set-policy) | max_attempts | none |
When the loop opens
After the node's tasks run, Kraft reads every measuring task's findings and
records a findings_measured event. The
loop opens when either is true:
- a finding's severity is in
findings.loop_severitiesinpolicy.yaml(defaultcriticalandimportant); - a task failed without reporting any findings. Kraft writes one
criticalfinding for it, as a subprocess task describes.
Otherwise the node completes. Findings below the loop severities are kept and shown at the review gate.
A step that didn't run in this measurement contributes nothing. When an earlier step fails, the steps after it don't run, and what they found the last time the node was measured isn't read again.
A node with an on_failure handler recovers first: when its tasks fail, the
handler runs once, before the first cycle, and Kraft measures again. That
measurement is recorded with cycle set to -1, and the same rule decides
whether the loop opens, so findings from a task that passed still reach it. If
it leaves the node clean, the node completes.
The judge and the stuck checks read that measurement as a round with no fix of its own. A finding's streak starts again there, and a finding missing only from that round isn't counted as fixed, so its return isn't reported as back again.
Starting early
Unreleased
With early: true, a node doesn't wait for all its steps before the loop
opens. When one of the node's own steps finishes with every task passed and at
least one finding in findings.loop_severities, the measurement ends there. The
later steps don't run, and the loop takes the findings at once, without the
node's on_failure.
A failed task keeps today's path: the node stops at that step and on_failure
runs first. A pause, a rate limit, a budget and every other stop still win over
an early end. The last step of a node has nothing after it to skip, so a finding
there is an ordinary measurement.
Kraft records the findings_measured event before the judge runs, as usual.
When the loop doesn't start
The judge may answer stop_downgrade, or nothing may be left eligible once Kraft
has read the findings. The loop then doesn't open on a measurement that ended
early, and the node doesn't complete. Kraft goes on with the steps that didn't
run, at the same cycle, on the same commit:
- Only those steps run. Their results amend the one
findings_measuredevent instead of recording another, so the judge and the stuck checks see one round. - Kraft keeps the judge's answer for that commit, in its
judge_verdictevent. It doesn't read those findings again on the commit during the node's run, the re-measure afteron_failureincluded. They aren't sent to the repair, and the judge isn't paid to rule on them again. A new commit starts afresh. - The node completes only when the remaining steps pass.
Findings nobody re-read
A step that didn't run on this commit can't say whether its last findings are
fixed. Kraft stores them under unmeasured in the findings_measured event,
apart from findings. They are never eligible and never in the list to fix.
The history shows them as "not re-read this round".
They keep their tags and severities, and they hold their place in the stuck checks: a round that didn't read a finding neither extends nor resets how long it has stood. Kraft never reports a finding stuck, fixed or back again while nobody reads it. Check 6's "same set of findings" comparison is skipped when the previous measurement read other tasks than this one.
One cycle
Each cycle runs these checks in order. A stuck node is one whose escalation runs first, and then the item stops and waits for you.
- measure the node: read the findings
- a loop-severity finding, or a task failed with none?
- no: passnode completes
- yes: checks 1 to 3needs_context, only Kraft-run failures, a budget spent
- one holds: item stops[waits for you]
- none: check 4: the judge, when it is due
- stop_downgrade: completes
- stop_needs_human: stuck
- else: checks 5 and 6attempt or wall-clock limit, same findings again
- limit or same findings: stuck
- none: repair task
- changed nothing: stuck
- changed something: back to measure the node
- none: repair task
- else: checks 5 and 6attempt or wall-clock limit, same findings again
- none: check 4: the judge, when it is due
- yes: checks 1 to 3needs_context, only Kraft-run failures, a budget spent
| # | Check | Outcome |
|---|---|---|
| 1 | A measuring task ended needs_context. | The item stops and waits for you, with its question. |
| 2 | Every failure came from a task Kraft runs itself (a builtin or forge task), and nothing else reported a finding. | The item stops and waits for you, because no worker commit can change the outcome. |
| 3 | A token or dollar budget is spent. | The item stops and waits for you. |
| 4 | The judge, when it is due. | continue goes ahead, stop_needs_human makes the node stuck, and stop_downgrade completes the node. See the verdicts. |
| 5 | The attempt count or wall clock is past its limit. | The node is stuck, with the reason <node>.fix_loop exhausted after N fix cycle(s). |
| 6 | After a repair, the same set of loop-severity findings came back, or one finding came back unchanged three rounds running. | The node is stuck, with a reason that starts stuck:. |
If nothing stopped the loop, Kraft records
fix_cycle_started, runs the repair, and
measures the whole node again from its first step.
Whether the repair spends the attempt depends on how it ended:
| Repair outcome | The attempt |
|---|---|
Ended done, or failed in an agent or subprocess task | Spent. |
| Ended any way, but changed nothing: no change to the checkout's files (an empty commit counts as nothing), no reply to a review thread, no edit to the merge request description | Spent, and the node is stuck: Kraft doesn't measure the same code again. The reason starts stuck: and carries the repair's concerns. Added in 2.6 |
Paused, rate limited, refused to start, or failed in a builtin or forge step | Given back, because the repair tried nothing. Kraft records fix_cycle_refunded instead of measuring again. |
When the repair ends, Kraft records
fix_cycle_finished with whether it
committed a change (committed), so the item's Recent list can say whether a
round changed anything.
The attempt count starts over when the node runs again on a new
pass: after a gate rejection that re-runs it, a
retry you ask for yourself, or a base-change restart. Kraft records the reset as
cap_counters_reset. A retry an
agent asks for keeps the count.
What a repair task is told
A repair task's own prompt isn't used. Its harness profile, agent profile, model and skill
still are. Kraft writes its instruction instead:
- which tasks failed, or that a review reported findings;
- the loop-severity findings, each with its tag, a finding that was in the last
measurement marked
REPEAT; - the judge's reasoning, when the judge ran this cycle;
- once there are two rounds, every round so far, with any finding that was fixed and came back;
- the path of the previous attempt's result file and session summary;
- where the repository keeps its pull-request rules, when the task declares the
pr_rulesinput.
The judge
The judge runs before every cycle except the first one after the node is entered. That first cycle repairs without a judge. The judge also doesn't run while a person's steer or a gate review is waiting to be delivered, because the steer already answers what the judge would rule on.
Its own prompt isn't used either. Its instruction lists every round so far
with each finding's tag, the attempts used of the limit, and the seconds used
of the wall clock. It answers in its result file:
verdict, and its reasoning in concerns.
verdict | What happens |
|---|---|
continue | The cycle goes ahead. The repair task gets concerns as the judge's reasoning. |
stop_needs_human | The node is stuck with judge: and the reasoning. |
stop_downgrade | The node completes with the remaining findings unresolved, and concerns is the note you see at the review gate. Only when no task failed outright, else the cycle goes ahead. After an early end, the remaining steps run. |
Kraft reads a verdict only from a judge that ended done or
done_with_concerns. Any other status, a missing verdict or an unknown one
counts as continue. A verdict never buys a cycle past the attempt limit or
the wall clock: check 5 runs after the judge. A loop with no judge always
continues. Each verdict is recorded as a
judge_verdict event.
Related
- Subprocess tasks: the finding Kraft writes for a failed command.
- Result file: how a judge writes its verdict.
- Caps and budgets: why loops and caps work this way.