-
Notifications
You must be signed in to change notification settings - Fork 15
feat: allow per-PR fix-loop budget via label #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env bash | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 6. Protected scripts require human approval The PR modifies multiple files under the protected scripts/ path, so it must receive human review and must not be auto-approved. The feature rationale provides context, but there is no linked issue authorizing these governance/infrastructure changes. Agent Prompt
|
||
| # shellcheck shell=bash | ||
| # fix-budget.lib.sh — parse a per-PR fix-loop budget from PR labels. | ||
| # | ||
| # A label of the form `fullsend-fix-budget/N` (N a positive integer) lets a | ||
| # maintainer cap the review->fix loop for a single PR below the global | ||
| # iteration cap. The label can only TIGHTEN the cap, never raise it: | ||
| # enforcement lives in pre-fix, which applies min(label_budget, cap). | ||
| # | ||
| # Bundled into pre-fix.sh via bundle-sh.sh. | ||
| # | ||
| # Expected env vars (optional): | ||
| # PR_LABELS — PR label names separated by commas and/or newlines. Absent/empty | ||
| # is fine: parse_fix_budget then returns nothing and the cap is | ||
| # unchanged. (The upstream dispatcher comma-joins labels; a | ||
| # newline-joined value is also accepted.) | ||
|
|
||
| [[ -n "${FIX_BUDGET_SH_LOADED:-}" ]] && return 0 | ||
| FIX_BUDGET_SH_LOADED=1 | ||
|
|
||
| FIX_BUDGET_LABEL_PREFIX="fullsend-fix-budget/" | ||
|
|
||
| # parse_fix_budget [labels] | ||
| # Reads label names (arg 1, or PR_LABELS env when omitted) separated by commas | ||
| # and/or newlines. Echoes the smallest valid budget found, or nothing when no | ||
| # valid label is present. A malformed value (non-integer, zero, negative) is | ||
| # ignored, not fatal — a bad label must not silently drop the existing cap. | ||
| parse_fix_budget() { | ||
| local labels="${1-${PR_LABELS:-}}" | ||
| local best="" label n | ||
| # Accept comma-joined labels (the upstream dispatcher format) as well as | ||
| # newline-joined: normalize commas to newlines before splitting. | ||
| labels="${labels//,/$'\n'}" | ||
| while IFS= read -r label; do | ||
|
Comment on lines
+28
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. Feature lacks linked authorization This PR adds a new parser, runtime guard, generated bundle changes, and tests well beyond the rule's 20-line threshold, but the PR metadata contains no linked authorizing issue. The non-trivial feature therefore lacks the required explicit authorization. Agent Prompt
|
||
| # Trim surrounding whitespace so " fullsend-fix-budget/3 " still matches. | ||
| label="${label#"${label%%[![:space:]]*}"}" | ||
| label="${label%"${label##*[![:space:]]}"}" | ||
| [[ "${label}" == "${FIX_BUDGET_LABEL_PREFIX}"* ]] || continue | ||
| n="${label#"${FIX_BUDGET_LABEL_PREFIX}"}" | ||
| # Bound the digit count. An arbitrarily long value would overflow Bash's | ||
| # signed 64-bit arithmetic in the `-lt` comparison (e.g. 2^64 evaluates as | ||
| # 0), which would look "tighter" than any cap and block every fix run. | ||
| # A budget above 99999 is meaningless next to caps of 5/10, so treat an | ||
| # over-long value as malformed and ignore it. | ||
| [[ "${n}" =~ ^[1-9][0-9]{0,4}$ ]] || continue | ||
| if [[ -z "${best}" || "${n}" -lt "${best}" ]]; then | ||
| best="${n}" | ||
| fi | ||
| done <<< "${labels}" | ||
| [[ -n "${best}" ]] && printf '%s\n' "${best}" | ||
| return 0 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck shell=bash | ||
| # review-labels.lib.sh — recognize pipeline-managed "control" labels. | ||
| # | ||
| # Control labels are set by the review pipeline (or a maintainer, for the | ||
| # fix-budget knob), not by the review agent. post-review refuses to add or | ||
| # remove them via agent-recommended label_actions. Kept in a sourceable lib so | ||
| # the same definition is exercised by both production and the unit test — a | ||
| # duplicated copy in the test would pass even if the production branch drifted. | ||
| # | ||
| # Bundled into post-review.sh via bundle-sh.sh. | ||
|
|
||
| [[ -n "${REVIEW_LABELS_SH_LOADED:-}" ]] && return 0 | ||
| REVIEW_LABELS_SH_LOADED=1 | ||
|
|
||
| REVIEW_CONTROL_LABELS=( | ||
| "ready-for-merge" "requires-manual-review" "rejected" | ||
| "ready-for-review" "fullsend-no-fix" "fullsend-fix" | ||
| ) | ||
|
|
||
| # is_control_label LABEL — return 0 if LABEL is pipeline-managed, 1 otherwise. | ||
| is_control_label() { | ||
| local label="$1" | ||
| local cl | ||
| for cl in "${REVIEW_CONTROL_LABELS[@]}"; do | ||
| if [[ "${cl}" == "${label}" ]]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| # Pipeline-managed label prefixes. | ||
| if [[ "${label}" == risk/* ]]; then | ||
| return 0 | ||
| fi | ||
| # Maintainer-set fix-loop budget (fullsend-fix-budget/N); pipeline-managed so | ||
| # the review agent preserves it rather than treating it as a contextual label. | ||
| if [[ "${label}" == fullsend-fix-budget/* ]]; then | ||
| return 0 | ||
| fi | ||
| return 1 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MEDIUM] Activation recipe prescribes an
env.runnerentry that pre-/post-fix do not need, and that would fail closed on GitLabThis comment tells the follow-up author to activate the label by re-adding
PR_LABELS: "${PR_LABELS}"to the sharedenv.runnerblock together with areusable-fix.ymlchange. Verified againstfullsend-ai/fullsendmain (7495cdc5):childScriptEnv()ininternal/cli/run.go:3586-3587builds the pre-/post-script environment fromos.Environ()first and only then overlaysRunnerEnv. A step-levelenv: PR_LABELSon the "Run fix agent" step (reusable-fix.yml:361-385) therefore already reaches pre-fix and post-fix — the only two consumers — with noenv.runnerentry at all.harness/fix.yamlis forge-shared. The GitLab agent template (internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/fullsend-agent.yml) sets every other key in this shared block (TARGET_BRANCH,HUMAN_INSTRUCTION,REVIEW_BODY_FILE,PRE_AGENT_HEAD,PUSH_TOKEN, ...) but has zero references toPR_LABELS. Adding the entry as written reproduces, on every GitLab fix run, the exactValidateRunnerEnvWithfail-closed abort (harness.go:734-737,env.runner[PR_LABELS]: host variable PR_LABELS is not set) that the earlier thread on this file caught for GitHub.forge.github.env.runner(~line 119) andforge.gitlab.env.runner(~line 136) are the correct home for any forge-specific entry, and the recipe does not mention them.This refines the suggestion in the earlier CRITICAL thread (which proposed re-adding the
env.runnerline in the wiring PR): that step is unnecessary, and unsafe in the shared block.Suggestion. Rewrite the comment to state that the workflow step env alone is sufficient for pre-/post-fix (
childScriptEnvinherits the process environment), so the GitHub wiring is justPR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }}on the "Run fix agent" step. If anenv.runnerentry is ever wanted, say it must go inforge.github.env.runner, and inforge.gitlab.env.runneronly after the GitLab agent template exports a set-possibly-emptyPR_LABELS— never in the shared block.