@giamme/forge 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/SKILL.md +17 -11
- package/VERSION +1 -1
- package/docs/artifacts.md +1 -0
- package/docs/commands.md +121 -7
- package/docs/development.md +3 -0
- package/docs/forge-ui.md +7 -1
- package/docs/reviews.md +2 -0
- package/docs/troubleshooting.md +5 -1
- package/forge +28 -1
- package/package.json +1 -1
- package/references/dataset.md +3 -1
- package/references/decision-models.md +5 -1
- package/references/decompose.md +199 -61
- package/references/runtime.md +29 -0
- package/references/ui.md +10 -0
- package/scripts/forge-compare.py +491 -0
- package/scripts/forge-config.py +3 -3
- package/scripts/forge-contract.py +34 -8
- package/scripts/forge-control.py +105 -13
- package/scripts/forge-dispatch.sh +9 -5
- package/scripts/forge-jev-options.sh +17 -4
- package/scripts/forge-ledger.py +387 -0
- package/scripts/forge-lib-plans.sh +16 -2
- package/scripts/forge-lib-task.sh +390 -28
- package/scripts/forge-parallel-options.sh +20 -4
- package/scripts/forge-parallel.sh +118 -12
- package/scripts/forge-plan-check.py +68 -3
- package/scripts/forge-pr.py +276 -0
- package/scripts/forge-route.py +350 -34
- package/scripts/forge-runs.py +18 -1
- package/scripts/forge-runtime.py +23 -7
- package/scripts/forge-schedule.py +303 -46
- package/scripts/forge-solo.sh +1 -0
- package/scripts/forge-ui-options.sh +25 -0
- package/scripts/forge-verify-failed.py +111 -0
- package/scripts/forge-watch.py +372 -0
- package/scripts/forge_dataset/export.py +87 -41
- package/scripts/forge_dataset/harvest.py +3 -1
- package/scripts/forge_decide/budget.py +39 -8
- package/scripts/forge_decide/doctor.py +49 -0
- package/scripts/forge_fractal/cli.py +23 -6
- package/scripts/forge_infra.py +274 -0
- package/scripts/forge_jev/client.py +13 -9
- package/ui/docs/api.md +83 -15
- package/ui/forge_ui/control.py +11 -3
- package/ui/forge_ui/export.py +6 -2
- package/ui/forge_ui/models.py +16 -16
- package/ui/forge_ui/reader.py +217 -13
- package/ui/forge_ui/repos.py +428 -0
- package/ui/forge_ui/static/app.js +24 -5
- package/ui/forge_ui/static/checksview.js +20 -7
- package/ui/forge_ui/static/cloudmodel.js +8 -5
- package/ui/forge_ui/static/controls.js +6 -3
- package/ui/forge_ui/static/modelstats.js +12 -8
- package/ui/forge_ui/static/panel.js +69 -4
- package/ui/forge_ui/static/runmodel.js +55 -10
- package/ui/forge_ui/static/scene3d.js +3 -2
- package/ui/forge_ui/static/settings.js +147 -29
- package/ui/forge_ui/static/style.css +49 -7
|
@@ -173,6 +173,15 @@ escalation_record_line() { # escalation_record_line <plan> <id> <line>
|
|
|
173
173
|
python3 "$SKILL_DIR/scripts/forge-route.py" record --plan "$1" --task "$2" --line "$3"
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
# tasks/<id>/lateral.tsv, probed and appended the same way (forge-route.py lateral).
|
|
177
|
+
lateral_record_ok() { # lateral_record_ok <plan> <id>
|
|
178
|
+
python3 "$SKILL_DIR/scripts/forge-route.py" lateral --plan "$1" --task "$2" --probe
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
lateral_record_line() { # lateral_record_line <plan> <id> <line>
|
|
182
|
+
python3 "$SKILL_DIR/scripts/forge-route.py" lateral --plan "$1" --task "$2" --line "$3"
|
|
183
|
+
}
|
|
184
|
+
|
|
176
185
|
# Writes the task's implementer column in tasks.tsv: a temp file, then a rename.
|
|
177
186
|
set_dwarf() { # set_dwarf <plan> <id> <spec>
|
|
178
187
|
awk -F'\t' -v OFS='\t' -v id="$2" -v dw="$3" \
|
|
@@ -180,6 +189,13 @@ set_dwarf() { # set_dwarf <plan> <id> <spec>
|
|
|
180
189
|
&& mv "$1/.tasks.tsv.retry" "$1/tasks.tsv"
|
|
181
190
|
}
|
|
182
191
|
|
|
192
|
+
# The same for the reviewer column (6) in tasks.tsv.
|
|
193
|
+
set_qa() { # set_qa <plan> <id> <spec>
|
|
194
|
+
awk -F'\t' -v OFS='\t' -v id="$2" -v qa="$3" \
|
|
195
|
+
'$0 !~ /^#/ && $1==id { $6=qa } { print }' "$1/tasks.tsv" > "$1/.tasks.tsv.retry" \
|
|
196
|
+
&& mv "$1/.tasks.tsv.retry" "$1/tasks.tsv"
|
|
197
|
+
}
|
|
198
|
+
|
|
183
199
|
# --- retry preparation ----------------------------------------------------------
|
|
184
200
|
# Carries the last review's report forward as the findings of the next attempt, and records
|
|
185
201
|
# which commit that report judged (what reviewed.commit holds now, since qa.last is that
|
|
@@ -355,12 +371,273 @@ commit_answer_findings() { # commit_answer_findings <tdir>
|
|
|
355
371
|
rm -f "$tdir/needs_input.md" "$tdir/answer.md"
|
|
356
372
|
}
|
|
357
373
|
|
|
374
|
+
# --- NEEDS_DECISION (#69) ---------------------------------------------------------
|
|
375
|
+
# A task whose reviews do not converge, or that the retry policy cannot move to a stronger model,
|
|
376
|
+
# stops and waits for a person. Only `retry --decide`, `retry --dwarf` (both with --reason and
|
|
377
|
+
# --approved) or `accept` resumes it: the scheduler, a retry budget and a pinned model do not.
|
|
378
|
+
# decision.md holds the reasons and the choices; decisions.tsv (epoch, attempt, choice, reason)
|
|
379
|
+
# records the answer, and everything that counts failures counts only the attempts after its last row.
|
|
380
|
+
decision_reason_text() { # decision_reason_text <reason>: what a reason in decision.md means
|
|
381
|
+
case "$1" in
|
|
382
|
+
converging) echo "the last reviews failed one after another, most of their findings were new, and the worst severity did not improve: more attempts keep finding new problems instead of closing the old ones" ;;
|
|
383
|
+
split) echo "the retry policy found no stronger model to escalate to after repeated failures on one: another attempt on the same model rarely passes" ;;
|
|
384
|
+
cap) echo "the attempts spent across runs reach the task's cap (max_attempts, plus each retry=N a person granted): another attempt needs a person's retry=N" ;;
|
|
385
|
+
*) echo "$1" ;;
|
|
386
|
+
esac
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
# The attempt cap (#69): "<used> <cap>" from forge-route.py attempt-cap, cap - for no cap. Attempts used
|
|
390
|
+
# are the attempts.tsv attempts that were not infrastructure stops; the cap is max_attempts plus every retry=N.
|
|
391
|
+
attempt_cap_of() { # attempt_cap_of <plan> <id>; "? ?" and status 1 when the answer cannot be read
|
|
392
|
+
local out
|
|
393
|
+
out="$(python3 "$SKILL_DIR/scripts/forge-route.py" attempt-cap --plan "$1" --task "$2")"
|
|
394
|
+
if [[ "$out" =~ ^[0-9]+\ ([0-9]+|-)$ ]]; then echo "$out"; return 0; fi
|
|
395
|
+
note "$2: cannot read its attempt cap: forge-route.py attempt-cap printed '${out:0:80}'"
|
|
396
|
+
echo '? ?'
|
|
397
|
+
return 1
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
# A task at its attempt cap runs no attempt until a person raises the cap with --decide retry=N, and that
|
|
401
|
+
# N must reach past it: any other decision waits, as does a plain retry. A task not yet waiting for a
|
|
402
|
+
# decision is stopped for one (`cap`), so no scheduler pass, budget or pin dispatches it.
|
|
403
|
+
attempt_cap_gate() { # attempt_cap_gate <plan> <id> <status> <decide>; 0 may run, 1 refused or stopped
|
|
404
|
+
local PLAN="$1" id="$2" st="$3" decide="$4" used cap n=0
|
|
405
|
+
read -r used cap <<< "$(attempt_cap_of "$PLAN" "$id")"
|
|
406
|
+
# An unreadable cap starts nothing and decides nothing; attempt_cap_of said why.
|
|
407
|
+
[ "$used" != '?' ] || { note "$id: no attempt starts while its attempt cap cannot be read"; return 1; }
|
|
408
|
+
if [ "$cap" = - ] || [ "$used" -lt "$cap" ]; then return 0; fi
|
|
409
|
+
case "$decide" in retry=*) n="${decide#retry=}" ;; esac
|
|
410
|
+
# retry=N raises the cap by N, so it starts an attempt while the spent attempts are under the raised cap:
|
|
411
|
+
# at the cap that is exactly N attempts; past a lowered cap, the attempts the raised cap still leaves.
|
|
412
|
+
if [ "$n" -gt 0 ] && [ "$used" -lt $(( cap + 10#$n )) ]; then return 0; fi
|
|
413
|
+
# A question waiting for its answer is not stopped: the answer is kept, and only the plan's cap can let it run.
|
|
414
|
+
if [ "$st" != NEEDS_DECISION ] && [ "$st" != NEEDS_INPUT ]; then
|
|
415
|
+
stop_for_decision "$PLAN" "$id" cap || return 1
|
|
416
|
+
fi
|
|
417
|
+
if [ "$n" -gt 0 ]; then
|
|
418
|
+
note "$id: retry=$n would not start an attempt: $used attempts are used against a cap of $cap, and the grant must take the cap past $used; retry=$(( used - cap + 1 )) starts attempt $(( used + 1 ))"
|
|
419
|
+
elif [ "$st" = NEEDS_INPUT ]; then
|
|
420
|
+
note "$id: at its attempt cap (attempts $used of $cap), so its answer would start attempt $(( used + 1 )): raise the plan's cap first, forge control set max-attempts N --confirm"
|
|
421
|
+
else
|
|
422
|
+
local accept_too=""
|
|
423
|
+
case "$(decision_from "$PLAN/tasks/$id")" in FAIL|UNKNOWN) accept_too=" (or accept it)" ;; esac
|
|
424
|
+
note "$id: at its attempt cap (attempts $used of $cap): it runs again only on a decision: forge-parallel.sh retry $PLAN $id --decide retry=N --reason \"...\" --approved$accept_too; see $PLAN/tasks/$id/decision.md"
|
|
425
|
+
fi
|
|
426
|
+
return 1
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
# The status a NEEDS_DECISION task had when it stopped, from decision.from, as recorded: the attempt cap
|
|
430
|
+
# stops a task from any status (UNKNOWN, TIMEOUT, INTERRUPTED, INFRA, ...), and only FAIL and UNKNOWN have
|
|
431
|
+
# a reviewer verdict to accept. FAIL when the file is missing or empty, as every stop was before the cap.
|
|
432
|
+
decision_from() { # decision_from <task-dir>
|
|
433
|
+
local st; st="$(head -c 32 "$1/decision.from" 2>/dev/null | tr -dc 'A-Z_')"
|
|
434
|
+
echo "${st:-FAIL}"
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
# decision.md, then the status. Reasons are words (`converging`, `split`); the first line of
|
|
438
|
+
# the file lists them. The status is the last thing written, so a task never reads as
|
|
439
|
+
# NEEDS_DECISION without its decision.md.
|
|
440
|
+
stop_for_decision() { # stop_for_decision <plan> <id> <reason>...
|
|
441
|
+
local PLAN="$1" id="$2" tdir="$1/tasks/$2" reasons="" r win decided summary="" used cap tmp="$1/tasks/$2/.decision.md.tmp"
|
|
442
|
+
local from
|
|
443
|
+
shift 2
|
|
444
|
+
for r in "$@"; do reasons="${reasons:+$reasons, }$r"; done
|
|
445
|
+
[ -n "$reasons" ] || return 0
|
|
446
|
+
# What the stop replaces: a task already waiting keeps the status it first stopped from.
|
|
447
|
+
from="$(task_status "$PLAN" "$id")"
|
|
448
|
+
case "$from" in NEEDS_DECISION|NEEDS_INPUT) from="$(decision_from "$tdir")" ;; esac
|
|
449
|
+
win="$( { tr -dc '0-9' < "$PLAN/converge_window"; } 2>/dev/null | head -c 4)"
|
|
450
|
+
[ -n "$win" ] && [ "$win" -ge 1 ] 2>/dev/null || win=4
|
|
451
|
+
decided="$(awk -F'\t' '$2 ~ /^[0-9]+$/ && $2 + 0 > m { m = $2 + 0 } END { print m + 0 }' "$tdir/decisions.tsv" 2>/dev/null)"
|
|
452
|
+
case ",${reasons// /}," in *,converging,*)
|
|
453
|
+
summary="$(python3 "$SKILL_DIR/scripts/forge-ledger.py" signal "$tdir" 2>/dev/null | sed -n 's/^fire.//p')" ;;
|
|
454
|
+
esac
|
|
455
|
+
{
|
|
456
|
+
echo "reasons: $reasons"
|
|
457
|
+
echo
|
|
458
|
+
echo "$id stopped for your decision. Nothing resumes it except a decision of yours: the scheduler,"
|
|
459
|
+
echo "a retry budget and a pinned model do not."
|
|
460
|
+
echo
|
|
461
|
+
echo "What each reason means:"
|
|
462
|
+
for r in "$@"; do echo " $r: $(decision_reason_text "$r")"; done
|
|
463
|
+
if [ -n "$summary" ]; then echo; echo "Signal: $summary"; fi
|
|
464
|
+
if [ -s "$tdir/split.suggested" ] && [ "${reasons#*split}" != "$reasons" ]; then
|
|
465
|
+
echo; echo "Retry policy: $(head -1 "$tdir/split.suggested")"
|
|
466
|
+
fi
|
|
467
|
+
if [ -s "$tdir/ledger.tsv" ]; then
|
|
468
|
+
echo
|
|
469
|
+
echo "The last reviews (tasks/$id/ledger.tsv):"
|
|
470
|
+
awk -F'\t' -v after="$decided" 'NF == 11 && $2 + 0 > after { print }' "$tdir/ledger.tsv" | tail -n "$win" |
|
|
471
|
+
awk -F'\t' 'BEGIN { printf " %-8s %-14s %-10s %-4s %s\n", "attempt", "verdict", "confirmed", "new", "worst" }
|
|
472
|
+
{ v = $4; if ($5 == "fail") v = v " (gate)"; printf " %-8s %-14s %-10s %-4s %s\n", $2, v, $7, $8, $6 }'
|
|
473
|
+
fi
|
|
474
|
+
echo
|
|
475
|
+
read -r used cap <<< "$(attempt_cap_of "$PLAN" "$id")"
|
|
476
|
+
if [ "$cap" = - ]; then echo "Attempts used so far: $used (no cap)"; else echo "Attempts used so far: $used (attempts $used of $cap)"; fi
|
|
477
|
+
echo
|
|
478
|
+
echo "Choices (each needs your reason; --approved says the decision is yours):"
|
|
479
|
+
echo " N more attempts: forge-parallel.sh retry $PLAN $id --decide retry=N --reason \"...\" --approved"
|
|
480
|
+
case ",${reasons// /}," in
|
|
481
|
+
*,cap,*) echo " (this raises the cap by N; at the cap, only this choice runs it again)" ;;
|
|
482
|
+
esac
|
|
483
|
+
echo " lower the threshold: forge-parallel.sh retry $PLAN $id --decide threshold=P1 --reason \"...\" --approved"
|
|
484
|
+
echo " (this task's blocking threshold, then one retry)"
|
|
485
|
+
echo " a named model: forge-parallel.sh retry $PLAN $id --dwarf <spec> --reason \"...\" --approved"
|
|
486
|
+
case "$from" in FAIL|UNKNOWN) # with no reviewer verdict, accept has nothing to override
|
|
487
|
+
echo " accept it as it is: forge-parallel.sh accept $PLAN $id --reason \"...\" --approved"
|
|
488
|
+
echo " (merges it; its findings become known issues)" ;;
|
|
489
|
+
esac
|
|
490
|
+
echo " split it: replace its row in $PLAN/tasks.tsv with smaller tasks (each with a"
|
|
491
|
+
echo " tasks/<id>/prompt.md) and point its dependents at them, then forge-parallel.sh run $PLAN"
|
|
492
|
+
} > "$tmp" && mv "$tmp" "$tdir/decision.md" || { rm -f "${tmp:?}"; note "$id: could not write decision.md; the task stays FAIL"; return 1; }
|
|
493
|
+
rm -f "${tdir:?}/decided.left"
|
|
494
|
+
echo "$from" > "$tdir/decision.from"
|
|
495
|
+
echo NEEDS_DECISION > "$tdir/status"
|
|
496
|
+
note "$id: stopped for your decision ($reasons) — see $tdir/decision.md"
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
# After an attempt (do_task): the review goes into the findings ledger, and a task that ended FAIL
|
|
500
|
+
# stops for a decision when the signal fires (`converging`) or this attempt's `escalation --check`
|
|
501
|
+
# stopped it (`split`: <stop-before> is escalation.stop as it was before the check, <check-rc> the
|
|
502
|
+
# check's exit). attempts.tsv was written before this and keeps FAIL for the attempt. A later
|
|
503
|
+
# reason (an attempt cap) is one more line here.
|
|
504
|
+
decision_after_attempt() { # decision_after_attempt <plan> <id> <stop-before> <check-rc>
|
|
505
|
+
local PLAN="$1" id="$2" before="${3:-}" crc="${4:-0}" tdir="$1/tasks/$2" reasons="" stop used cap
|
|
506
|
+
python3 "$SKILL_DIR/scripts/forge-ledger.py" append "$PLAN" "$id" >/dev/null 2>&1 \
|
|
507
|
+
|| note "$id: could not add this review to the findings ledger"
|
|
508
|
+
[ "$(task_status "$PLAN" "$id")" = FAIL ] || return 0
|
|
509
|
+
if python3 "$SKILL_DIR/scripts/forge-ledger.py" signal "$tdir" >/dev/null 2>&1; then reasons="converging"; fi
|
|
510
|
+
stop="$(cat "$tdir/escalation.stop" 2>/dev/null)"
|
|
511
|
+
if [ -n "$stop" ] && { [ "$crc" = 3 ] || [ "$stop" != "$before" ]; }; then reasons="${reasons:+$reasons }split"; fi
|
|
512
|
+
read -r used cap <<< "$(attempt_cap_of "$PLAN" "$id")"
|
|
513
|
+
if [ "$used" != '?' ] && [ "$cap" != - ] && [ "$used" -ge "$cap" ]; then reasons="${reasons:+$reasons }cap"; fi
|
|
514
|
+
[ -z "$reasons" ] || stop_for_decision "$PLAN" "$id" $reasons || true
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
# Refuses, with a message, a `retry` that is not an explicit decision for a NEEDS_DECISION task, and a
|
|
518
|
+
# decision offered to a task that waits for none. Runs before anything is written.
|
|
519
|
+
retry_decision_gate() { # retry_decision_gate <plan> <id> <status> <decide> <dwarf> <reason> <approved 0|1>
|
|
520
|
+
local PLAN="$1" id="$2" st="$3" decide="$4" dwarf="$5" reason="$6" approved="$7" n
|
|
521
|
+
if [ "$st" != NEEDS_DECISION ]; then
|
|
522
|
+
[ -z "$decide" ] || die "retry: '$id' is $st, not waiting for a decision; --decide only decides a NEEDS_DECISION task"
|
|
523
|
+
return 0
|
|
524
|
+
fi
|
|
525
|
+
if [ -z "$decide" ] && [ -z "$dwarf" ]; then
|
|
526
|
+
die "retry: '$id' is waiting for your decision, and only a decision resumes it:
|
|
527
|
+
$(sed -n '1,3p' "$PLAN/tasks/$id/decision.md" 2>/dev/null)
|
|
528
|
+
read $PLAN/tasks/$id/decision.md, then retry with --decide retry=N or --decide threshold=Pn, or --dwarf <spec>, each with --reason \"...\" --approved; or accept the task"
|
|
529
|
+
fi
|
|
530
|
+
[ -z "$decide" ] || [ -z "$dwarf" ] || die "retry: give --decide or --dwarf, not both: a decision is one choice"
|
|
531
|
+
case "$decide" in
|
|
532
|
+
"") ;;
|
|
533
|
+
retry=*) n="${decide#retry=}"
|
|
534
|
+
case "$n" in ''|*[!0-9]*) n=0 ;; esac
|
|
535
|
+
[ "${#n}" -le 3 ] && [ "$n" -ge 1 ] && [ "$n" -le 20 ] || die "retry: --decide retry=N takes N from 1 to 20" ;;
|
|
536
|
+
threshold=P[0-3]) ;;
|
|
537
|
+
*) die "retry: --decide takes retry=N (1 to 20) or threshold=P0|P1|P2|P3, not '$decide'" ;;
|
|
538
|
+
esac
|
|
539
|
+
reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
|
|
540
|
+
[ -n "$reason" ] || die "retry: a decision needs --reason \"<why>\": it is recorded with the task"
|
|
541
|
+
[ "$approved" = 1 ] || die "retry: a decision needs --approved: it resumes a task forge stopped, and is only given on the user's instruction"
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
# The decision of a NEEDS_DECISION task, recorded and then the retry prepared as `retry` does.
|
|
545
|
+
# Recorded first because the escalation policy reads decisions.tsv to restart its count; when the
|
|
546
|
+
# preparation refuses, the files the decision touched are put back and the task stays as it was.
|
|
547
|
+
retry_decided() { # retry_decided <plan> <id> <decide> <new-dwarf> <reason>
|
|
548
|
+
local PLAN="$1" id="$2" decide="$3" newdwarf="$4" reason="$5" tdir="$1/tasks/$2" choice f rc=0 attempt
|
|
549
|
+
local undo="$1/tasks/$2/.decision.undo"
|
|
550
|
+
choice="$decide"; [ -n "$choice" ] || choice="dwarf=$newdwarf"
|
|
551
|
+
reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
|
|
552
|
+
attempt="$(cat "$tdir/attempt" 2>/dev/null || echo 0)"
|
|
553
|
+
rm -rf "${undo:?}"; mkdir "$undo" 2>/dev/null || { note "$id: could not record the decision; nothing was retried"; return 1; }
|
|
554
|
+
for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
|
|
555
|
+
if [ -f "$tdir/$f" ]; then cp -p "$tdir/$f" "$undo/$f"; else : > "$undo/$f.absent"; fi
|
|
556
|
+
done
|
|
557
|
+
if ! printf '%s\t%s\t%s\t%s\n' "$(date +%s)" "$attempt" "$choice" "$reason" >> "$tdir/decisions.tsv"; then
|
|
558
|
+
rm -rf "${undo:?}"; note "$id: could not record the decision in decisions.tsv; nothing was retried"; return 1
|
|
559
|
+
fi
|
|
560
|
+
case "$decide" in
|
|
561
|
+
threshold=*) printf '%s\n' "${decide#threshold=}" > "$tdir/qa_threshold" || rc=1 ;;
|
|
562
|
+
esac
|
|
563
|
+
rm -f "${tdir:?}/escalation.stop" "${tdir:?}/split.suggested" "${tdir:?}/escalation.next"
|
|
564
|
+
[ "$rc" != 0 ] || decided_left_set "$tdir" $(( $(decided_attempts "$decide") - 1 )) || rc=$?
|
|
565
|
+
[ "$rc" != 0 ] || prepare_retry "$PLAN" "$id" "$newdwarf" decided || rc=$?
|
|
566
|
+
if [ "$rc" != 0 ]; then
|
|
567
|
+
for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
|
|
568
|
+
if [ -f "$undo/$f" ]; then cp -p "$undo/$f" "$tdir/$f"; else rm -f "${tdir:?}/${f:?}"; fi
|
|
569
|
+
done
|
|
570
|
+
else
|
|
571
|
+
forge_dataset_event decision --dir "$PLAN" --task "$id" --set "choice=$choice" --set "reason=$reason" \
|
|
572
|
+
--set "attempt=$attempt"
|
|
573
|
+
fi
|
|
574
|
+
rm -rf "${undo:?}"
|
|
575
|
+
return $rc
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
# How many attempts a decision grants in all: retry=N is N, every other choice (threshold=Pn,
|
|
579
|
+
# dwarf=<spec>) is the one attempt it resumes the task for. Empty (no decision) is one.
|
|
580
|
+
decided_attempts() { # decided_attempts <decide>
|
|
581
|
+
case "${1:-}" in
|
|
582
|
+
retry=[0-9]*) echo $(( 10#${1#retry=} )) ;;
|
|
583
|
+
*) echo 1 ;;
|
|
584
|
+
esac
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
# The automatic retries a decision still allows, in tasks/<id>/decided.left (a number, written
|
|
588
|
+
# with the decision and counted down as each retry is prepared). It lives in a file because the
|
|
589
|
+
# run that uses it may end first (a quota stop) and a later `run` or `retry` must still honour it.
|
|
590
|
+
# Absent means no decision governs and the retry budget rules; 0 means the decided attempts are used.
|
|
591
|
+
decided_left() { # decided_left <task-dir>: the number, or nothing
|
|
592
|
+
local v; v="$(tr -dc '0-9' < "$1/decided.left" 2>/dev/null | head -c 3)"
|
|
593
|
+
[ -n "$v" ] && echo $(( 10#$v ))
|
|
594
|
+
return 0
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
decided_left_set() { # decided_left_set <task-dir> <n>
|
|
598
|
+
printf '%s\n' "$2" > "$1/.decided.left.tmp" && mv "$1/.decided.left.tmp" "$1/decided.left" \
|
|
599
|
+
|| { rm -f "${1:?}/.decided.left.tmp"; note "could not record the decided attempts left"; return 1; }
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
# The run summary's block for tasks waiting for a decision: one line each, the choices once.
|
|
603
|
+
report_decisions() { # report_decisions <plan>
|
|
604
|
+
local plan="$1" id waiting used cap from acceptable=0
|
|
605
|
+
waiting="$(awk -F'\t' '$2=="NEEDS_DECISION" {print $1}' "$plan/results.tsv" 2>/dev/null)"
|
|
606
|
+
[ -n "$waiting" ] || return 0
|
|
607
|
+
echo "waiting for your decision:"
|
|
608
|
+
for id in $waiting; do
|
|
609
|
+
printf ' %s: %s — %s\n' "$id" "$(sed -n '1s/^reasons: //p' "$plan/tasks/$id/decision.md" 2>/dev/null)" "$plan/tasks/$id/decision.md"
|
|
610
|
+
read -r used cap <<< "$(attempt_cap_of "$plan" "$id")"
|
|
611
|
+
printf ' attempts %s/%s\n' "$used" "$cap"
|
|
612
|
+
from="$(decision_from "$plan/tasks/$id")"
|
|
613
|
+
case "$from" in
|
|
614
|
+
FAIL|UNKNOWN) acceptable=1 ;;
|
|
615
|
+
*) printf ' stopped after a %s attempt: no reviewer verdict, so it cannot be accepted\n' "$from" ;;
|
|
616
|
+
esac
|
|
617
|
+
done
|
|
618
|
+
echo "decide with (each needs --reason \"...\" --approved; decision.md has the commands filled in):"
|
|
619
|
+
echo " forge-parallel.sh retry $plan <task-id> --decide retry=N | --decide threshold=Pn | --dwarf <spec>"
|
|
620
|
+
[ "$acceptable" = 0 ] || echo " forge-parallel.sh accept $plan <task-id> (merge it with its findings as known issues)"
|
|
621
|
+
echo " or split it: replace its row in $plan/tasks.tsv with smaller tasks, then forge-parallel.sh run $plan"
|
|
622
|
+
echo
|
|
623
|
+
}
|
|
624
|
+
|
|
358
625
|
# Shared by `retry` (a human asked) and the scheduler's automatic retries. The findings
|
|
359
626
|
# are the whole point of retrying rather than re-running: the dwarf is told what was
|
|
360
627
|
# wrong with its own previous attempt.
|
|
361
|
-
prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
|
|
628
|
+
prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
|
|
362
629
|
local PLAN="$1" id="$2" newdwarf="${3:-}" T="$1/tasks.tsv" tdir="$1/tasks/$2" st verdict
|
|
363
630
|
st="$(task_status "$PLAN" "$id")"
|
|
631
|
+
# A NEEDS_DECISION task resumes only through retry_decided, which says so with `decided` once the
|
|
632
|
+
# decision is recorded. It retries as the status it stopped from: a FAIL carries its findings, and an
|
|
633
|
+
# unjudged attempt (UNKNOWN, INVALIDATED) goes back to QA rather than to the implementer.
|
|
634
|
+
if [ "$st" = NEEDS_DECISION ]; then
|
|
635
|
+
if [ "${4:-}" != decided ]; then
|
|
636
|
+
note "$id is waiting for your decision (see $tdir/decision.md): forge-parallel.sh retry $PLAN $id --decide ... --reason \"...\" --approved"
|
|
637
|
+
return 2
|
|
638
|
+
fi
|
|
639
|
+
st="$(decision_from "$tdir")"
|
|
640
|
+
fi
|
|
364
641
|
# A NEEDS_INPUT task waits for the user, and nothing here may change before the answer is
|
|
365
642
|
# known to be there: no file removed, no status changed, no escalation.
|
|
366
643
|
if [ "$st" = NEEDS_INPUT ] && ! answer_ready "$tdir"; then
|
|
@@ -537,44 +814,112 @@ prepare_resume() { # prepare_resume <plan> <id>
|
|
|
537
814
|
return 0
|
|
538
815
|
}
|
|
539
816
|
|
|
540
|
-
# --infra-fallback: a
|
|
541
|
-
# its own tier pool (forge-route.py fallback)
|
|
542
|
-
#
|
|
543
|
-
#
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
817
|
+
# --infra-fallback: a lateral stop (capacity, a usage limit, ...) moves the task to the next healthy
|
|
818
|
+
# member of its own tier pool (forge-route.py fallback). A move is no escalation: it is recorded in
|
|
819
|
+
# tasks/<id>/lateral.tsv and as a `lateral` dataset event, not in escalations.tsv, so the retry
|
|
820
|
+
# policy's streak carries across it. No attempt is spent: the stop already refunded it. Returns
|
|
821
|
+
# 1, changing nothing, when there is no candidate, a pin is waiting (a human's choice wins), the plan
|
|
822
|
+
# is Fractal or the move cannot be recorded. The fourth argument names the cause of the stop.
|
|
823
|
+
# The fifth names the stage that stopped: dwarf (the default) or qa. A review that stopped moves to a
|
|
824
|
+
# peer reviewer of the plan's qa-routing.json (forge-route.py qa-fallback), keeping its attempt and its
|
|
825
|
+
# `resume` marker, so the next entry is a QA-only dispatch to the new reviewer; a pin waits for the
|
|
826
|
+
# next full retry as it does for any QA-only resume, and the escalation streak is not touched.
|
|
827
|
+
prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...> [<cause> [<dwarf|qa>]]
|
|
828
|
+
local PLAN="$1" id="$2" tdir="$1/tasks/$2" role="${5:-dwarf}" setter=set_dwarf cur pick cause attempt line phrase
|
|
547
829
|
forge_plan_is_fractal "$PLAN" && return 1
|
|
548
|
-
|
|
549
|
-
|
|
830
|
+
if [ "$role" = qa ]; then
|
|
831
|
+
setter=set_qa
|
|
832
|
+
# A stopped review keeps its attempt only through a valid QA-only resume; a task not yet started
|
|
833
|
+
# (held back by its reviewer's pause) has none to keep, and its full dispatch takes the peer.
|
|
834
|
+
if [ -e "$tdir/resume" ] || [ -n "$(cat "$tdir/status" 2>/dev/null)" ]; then
|
|
835
|
+
resume_check "$PLAN" "$id" || return 1
|
|
836
|
+
fi
|
|
837
|
+
cur="$(field "$PLAN/tasks.tsv" "$id" qa)"
|
|
838
|
+
pick="$(python3 "$SKILL_DIR/scripts/forge-route.py" qa-fallback --plan "$PLAN" --task "$id" --exclude "$3")" || return 1
|
|
839
|
+
else
|
|
840
|
+
[ -e "$tdir/escalation.pin" ] && return 1
|
|
841
|
+
cur="$(field "$PLAN/tasks.tsv" "$id" dwarf)"
|
|
842
|
+
pick="$(python3 "$SKILL_DIR/scripts/forge-route.py" fallback --plan "$PLAN" --task "$id" --exclude "$3")" || return 1
|
|
843
|
+
fi
|
|
550
844
|
[ -n "$pick" ] || return 1
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
845
|
+
cause="${4:--}"
|
|
846
|
+
attempt="$(cat "$tdir/attempt" 2>/dev/null || echo 0)"
|
|
847
|
+
# Learned before anything changes, as a pin's record is: a refused record leaves tasks.tsv as it was.
|
|
848
|
+
if ! lateral_record_ok "$PLAN" "$id"; then
|
|
849
|
+
note "$id: could not record the lateral move in lateral.tsv; nothing was moved"
|
|
850
|
+
return 1
|
|
851
|
+
fi
|
|
852
|
+
"$setter" "$PLAN" "$id" "$pick" || { note "$id: could not write $pick into tasks.tsv; nothing was moved"; return 1; }
|
|
853
|
+
line="$(printf '%s\t%s\t%s\t%s\t%s\t%s' "$(date +%s)" "$attempt" "$role" "$cur" "$pick" "$cause")"
|
|
854
|
+
if ! lateral_record_line "$PLAN" "$id" "$line"; then
|
|
855
|
+
if "$setter" "$PLAN" "$id" "$cur"; then
|
|
856
|
+
note "$id: could not record the lateral move in lateral.tsv; nothing was moved"
|
|
857
|
+
else
|
|
858
|
+
note "$id: could not record the lateral move in lateral.tsv, and tasks.tsv could not be put back to $cur; it keeps $pick"
|
|
859
|
+
fi
|
|
860
|
+
return 1
|
|
861
|
+
fi
|
|
862
|
+
forge_dataset_event lateral --dir "$PLAN" --task "$id" --set "role=$role" --set "from=$cur" --set "to=$pick" \
|
|
863
|
+
--set "cause=$cause" --set "attempt=$attempt"
|
|
864
|
+
# A review's move keeps the escalation streak: only the stop's status and record are cleared.
|
|
865
|
+
if [ "$role" = qa ]; then rm -f "$tdir/status" "$tdir/infra.txt"; else rm -f "$tdir/escalation.next" "$tdir/status" "$tdir/infra.txt"; fi
|
|
866
|
+
# The note names the cause: a capacity stop (also when none came) and a spent budget have their
|
|
867
|
+
# own words; any other class is shown as classed.
|
|
868
|
+
case "$cause" in
|
|
869
|
+
-|capacity) phrase='is at capacity' ;;
|
|
870
|
+
budget) phrase='is out of budget' ;;
|
|
871
|
+
*) phrase="stopped ($cause)" ;;
|
|
872
|
+
esac
|
|
873
|
+
if [ "$role" = qa ]; then
|
|
874
|
+
note "$id: reviewer $cur $phrase; moving sideways to reviewer $pick (same tier)"
|
|
875
|
+
else
|
|
876
|
+
note "$id: $cur $phrase; moving sideways to $pick (same tier)"
|
|
877
|
+
fi
|
|
554
878
|
}
|
|
555
879
|
|
|
556
880
|
# The scheduler's `_prepare_retry` target: prepare, then clear the status so the task
|
|
557
881
|
# reads as PENDING again. `retry` clears it itself, after its own preflight. With --resume it
|
|
558
882
|
# prepares an infrastructure stop's resume instead (prepare_resume), and the status stays;
|
|
559
|
-
# with --dwarf <spec> the spec is the explicit new implementer; --fallback <pairs>
|
|
560
|
-
# prepare_fallback.
|
|
561
|
-
retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --dwarf <spec> | --fallback <pairs>]
|
|
883
|
+
# with --dwarf <spec> the spec is the explicit new implementer; --fallback <pairs> [--cause <cause> [--role qa]]
|
|
884
|
+
# is prepare_fallback.
|
|
885
|
+
retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --dwarf <spec> | --fallback <pairs> [--cause <cause> [--role qa]]]
|
|
562
886
|
if [ "${3:-}" = --resume ]; then
|
|
887
|
+
# An infrastructure stop spends no attempt, but the resume starts one: at the cap it is stopped for a decision.
|
|
888
|
+
attempt_cap_gate "$1" "$2" INFRA "" || return 4
|
|
563
889
|
prepare_resume "$1" "$2"
|
|
564
890
|
return $?
|
|
565
891
|
fi
|
|
566
892
|
if [ "${3:-}" = --fallback ]; then
|
|
567
|
-
|
|
893
|
+
local cause="" role=dwarf
|
|
894
|
+
if [ "${5:-}" = --cause ]; then cause="${6:-}"; fi
|
|
895
|
+
if [ "${7:-}" = --role ]; then role="${8:-dwarf}"; fi
|
|
896
|
+
prepare_fallback "$1" "$2" "${4:-}" "$cause" "$role"
|
|
568
897
|
return $?
|
|
569
898
|
fi
|
|
570
899
|
# --dwarf: `forge control retry --dwarf`, the same explicit escalation as `retry --dwarf`.
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
900
|
+
# --decide, --reason and --approved: the same request for a NEEDS_DECISION task, which only a
|
|
901
|
+
# decision resumes (retry_decision_gate refuses the rest).
|
|
902
|
+
local PLAN="$1" id="$2" newdwarf="" decide="" reason="" approved=0 st
|
|
903
|
+
shift 2
|
|
904
|
+
while [ $# -gt 0 ]; do
|
|
905
|
+
case "$1" in
|
|
906
|
+
--dwarf) [ -n "${2:-}" ] || die "_prepare_retry: --dwarf needs a spec"; newdwarf="$2"; shift 2 ;;
|
|
907
|
+
--decide) decide="${2:-}"; shift 2 ;;
|
|
908
|
+
--reason) reason="${2:-}"; shift 2 ;;
|
|
909
|
+
--approved) approved=1; shift ;;
|
|
910
|
+
*) die "_prepare_retry: unknown option '$1'" ;;
|
|
911
|
+
esac
|
|
912
|
+
done
|
|
913
|
+
st="$(task_status "$PLAN" "$id")"
|
|
914
|
+
retry_decision_gate "$PLAN" "$id" "$st" "$decide" "$newdwarf" "$reason" "$approved"
|
|
915
|
+
# At its attempt cap (#69), a scheduler's or a control's retry is stopped for a decision, not dispatched.
|
|
916
|
+
attempt_cap_gate "$PLAN" "$id" "$st" "$decide" || return 4
|
|
917
|
+
if [ "$st" = NEEDS_DECISION ]; then
|
|
918
|
+
retry_decided "$PLAN" "$id" "$decide" "$newdwarf" "$reason" || return $?
|
|
574
919
|
else
|
|
575
|
-
prepare_retry "$
|
|
920
|
+
prepare_retry "$PLAN" "$id" "$newdwarf" || return $?
|
|
576
921
|
fi
|
|
577
|
-
rm -f "$
|
|
922
|
+
rm -f "$PLAN/tasks/$id/status"
|
|
578
923
|
}
|
|
579
924
|
|
|
580
925
|
# --- implementer guards ---------------------------------------------------------
|
|
@@ -684,17 +1029,34 @@ qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
|
|
|
684
1029
|
}
|
|
685
1030
|
|
|
686
1031
|
# --- report blocks ----------------------------------------------------------------
|
|
1032
|
+
# The wording of each line, and what the causes need, is forge_infra.py's; this block only lays them out.
|
|
1033
|
+
# A lateral move is news whether or not a task is still paused, so its lines come out either way.
|
|
687
1034
|
report_infra() { # report_infra <plan>
|
|
688
|
-
local plan="$1" id n=0
|
|
1035
|
+
local plan="$1" id n=0 infra_ids="" moved held needs=1
|
|
689
1036
|
for id in $(all_ids "$plan/tasks.tsv"); do
|
|
690
1037
|
[ "$(task_status "$plan" "$id")" = INFRA ] || continue
|
|
691
1038
|
[ "$n" = 0 ] && echo "paused on an infrastructure failure (not a task failure, no attempt spent):"
|
|
692
|
-
n=$((n+1))
|
|
693
|
-
|
|
694
|
-
printf ' %-14s %s (%s stage)\n' "$id" "${cls:-unknown}" "$(sed -n 's/^stage=//p' "$plan/tasks/$id/infra.txt" 2>/dev/null | tail -1)"
|
|
1039
|
+
n=$((n+1)); infra_ids="$infra_ids $id"
|
|
1040
|
+
python3 "$SKILL_DIR/scripts/forge_infra.py" stop "$plan" "$id"
|
|
695
1041
|
done
|
|
696
|
-
|
|
697
|
-
|
|
1042
|
+
[ "$n" = 0 ] || ! python3 "$SKILL_DIR/scripts/forge_infra.py" needs-you "$plan" $infra_ids || needs=0
|
|
1043
|
+
# Tasks a pause held back never stopped, so they are not INFRA: the pause the run ended with names them.
|
|
1044
|
+
held="$(python3 "$SKILL_DIR/scripts/forge_infra.py" held "$plan")" && needs=0
|
|
1045
|
+
if [ -n "$held" ]; then
|
|
1046
|
+
echo "held back by an infrastructure pause (not started, no attempt spent):"
|
|
1047
|
+
echo "$held"
|
|
1048
|
+
fi
|
|
1049
|
+
if [ "$n" -gt 0 ] || [ -n "$held" ]; then
|
|
1050
|
+
if [ "$needs" = 0 ]; then
|
|
1051
|
+
echo " fix what is marked 'needs you', then re-run: forge-parallel.sh run $plan"
|
|
1052
|
+
else
|
|
1053
|
+
echo " fix the cause (quota, login, network), then re-run: forge-parallel.sh run $plan"
|
|
1054
|
+
fi
|
|
1055
|
+
echo
|
|
1056
|
+
fi
|
|
1057
|
+
moved="$(python3 "$SKILL_DIR/scripts/forge_infra.py" moved "$plan" "${FORGE_RUN_STARTED:-0}")"
|
|
1058
|
+
if [ -n "$moved" ]; then
|
|
1059
|
+
echo "$moved"
|
|
698
1060
|
echo
|
|
699
1061
|
fi
|
|
700
1062
|
return 0
|
|
@@ -23,14 +23,21 @@
|
|
|
23
23
|
# --infra-retries M run (this run only) waits out quota/auth/network stops
|
|
24
24
|
# --infra-backoff SHAPE run $PLAN/infra_backoff waits between those stops: exp:B[,C],
|
|
25
25
|
# linear:S,T[,C] or list:a,b,... (default exp:60)
|
|
26
|
-
# --infra-fallback run $PLAN/infra_fallback a dwarf's
|
|
27
|
-
# --no-infra-fallback
|
|
26
|
+
# --infra-fallback run $PLAN/infra_fallback a dwarf's stop that another model can take (capacity,
|
|
27
|
+
# --no-infra-fallback plan run usage limit, ...) moves it to the next healthy
|
|
28
|
+
# model of its tier pool; `plan` writes on, a
|
|
29
|
+
# plan without the file stays off
|
|
28
30
|
# --qa-threshold Pn|none|default plan run retry review $PLAN/qa_threshold least severe CONFIRMED
|
|
29
31
|
# finding that still blocks; none (or off) =
|
|
30
32
|
# P3, default removes the file (P2)
|
|
31
33
|
# --verify-retries N run retry integrate $PLAN/verify_retries reruns of a failed verify command
|
|
32
34
|
# --escalate-after N run retry $PLAN/escalate_after failed attempts on one model before the
|
|
33
35
|
# next goes a tier up (default 3; 0 = off)
|
|
36
|
+
# --max-attempts N plan $PLAN/max_attempts attempts a task may spend across runs before it
|
|
37
|
+
# waits for a person (default 8; 0 = no cap). Raised
|
|
38
|
+
# later only with `forge control set max-attempts --confirm`
|
|
39
|
+
# --converge-window N plan $PLAN/converge_window reviews the non-converging signal looks at
|
|
40
|
+
# (default 4; below 2 it never fires)
|
|
34
41
|
# --escalate-effort run retry $PLAN/escalate_effort on: before the stop, retry the same
|
|
35
42
|
# model at the next effort its pairing accepts;
|
|
36
43
|
# tasks already stopped are decided again
|
|
@@ -99,8 +106,9 @@ forge_pp_flag() {
|
|
|
99
106
|
[ "$cmd" = run ] || return 1
|
|
100
107
|
PP_SHIFT=1; printf 'on\n' > "$plan/infra_fallback" ;;
|
|
101
108
|
--no-infra-fallback)
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
PP_SHIFT=1
|
|
110
|
+
# `plan` writes the file itself, after its options, so the default on and this off cannot clash.
|
|
111
|
+
case "$cmd" in plan) PP_INFRA_FALLBACK=off ;; run) printf 'off\n' > "$plan/infra_fallback" ;; *) return 1 ;; esac ;;
|
|
104
112
|
--infra-backoff)
|
|
105
113
|
[ "$cmd" = run ] || return 1
|
|
106
114
|
PP_MSG="$(python3 "$SKILL_DIR/scripts/forge-schedule.py" backoff-check "${2:-}" 2>&1)" || die "${PP_MSG#forge: }"
|
|
@@ -122,6 +130,14 @@ forge_pp_flag() {
|
|
|
122
130
|
if [ "$2" = 0 ]; then
|
|
123
131
|
rm -f "$plan"/tasks/*/escalation.stop "$plan"/tasks/*/split.suggested "$plan"/tasks/*/escalation.next
|
|
124
132
|
fi ;;
|
|
133
|
+
--max-attempts)
|
|
134
|
+
case "$cmd" in plan) ;; *) return 1 ;; esac
|
|
135
|
+
pp_nonneg --max-attempts "${2:-}"
|
|
136
|
+
printf '%s\n' "$2" > "$plan/max_attempts" || die "could not write $plan/max_attempts" ;;
|
|
137
|
+
--converge-window)
|
|
138
|
+
case "$cmd" in plan) ;; *) return 1 ;; esac
|
|
139
|
+
pp_nonneg --converge-window "${2:-}"
|
|
140
|
+
printf '%s\n' "$2" > "$plan/converge_window" || die "could not write $plan/converge_window" ;;
|
|
125
141
|
--escalate-effort)
|
|
126
142
|
case "$cmd" in run|retry) ;; *) return 1 ;; esac
|
|
127
143
|
PP_SHIFT=1 # a switch, not --escalate-after's N
|