Skip to content

Commit 56d32be

Browse files
fix(queue): resolve scheduled target branches (#962)
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
1 parent 1ea4179 commit 56d32be

6 files changed

Lines changed: 197 additions & 19 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ jobs:
696696
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.target.outputs.target_enabled == 'true' }}
697697
id: live-item
698698
env:
699+
CLAIM_DECISION: ${{ steps.claim-exact-review-queue.outputs.decision }}
699700
GH_TOKEN: ${{ steps.target-read-token.outputs.token }}
700701
TARGET_REPO: ${{ steps.target.outputs.target_repo }}
701702
ITEM_NUMBER: ${{ steps.target.outputs.item_number }}
@@ -704,11 +705,47 @@ jobs:
704705
set -euo pipefail
705706
test -n "$GH_TOKEN"
706707
target_branch="$CLAIM_TARGET_BRANCH"
707-
if ! printf '%s' "$target_branch" | grep -Eq '^[A-Za-z0-9_.\/-]+$'; then
708-
echo "Invalid target branch for $TARGET_REPO: $target_branch" >&2
709-
exit 1
708+
branch_is_usable() {
709+
local branch="$1"
710+
[ -n "$branch" ] &&
711+
printf '%s' "$branch" | grep -Eq '^[A-Za-z0-9_.\/-]+$' &&
712+
! printf '%s' "$branch" | grep -Eq '^[0-9]+$' &&
713+
[[ "$branch" != *".."* ]]
714+
}
715+
if ! branch_is_usable "$target_branch"; then
716+
queued_target_branch="$target_branch"
717+
branch_error="$(mktemp)"
718+
if ! target_branch="$(gh api "repos/$TARGET_REPO" --jq '.default_branch // empty' 2>"$branch_error")" ||
719+
! branch_is_usable "$target_branch"; then
720+
echo "::warning::Unable to resolve a usable default branch for $TARGET_REPO after queued target branch '$queued_target_branch' was rejected; releasing the claim for retry."
721+
cat "$branch_error" >&2
722+
rm -f "$branch_error"
723+
retry_at="$(node -e 'process.stdout.write(new Date(Date.now() + 5 * 60_000).toISOString())')"
724+
{
725+
echo "admission_retry=true"
726+
echo "retry_at=$retry_at"
727+
echo "proceed=false"
728+
echo "terminal_noop=false"
729+
echo "terminal_missing=false"
730+
echo "guarded_open=false"
731+
echo "guarded_open_action="
732+
} >> "$GITHUB_OUTPUT"
733+
exit 0
734+
fi
735+
rm -f "$branch_error"
736+
echo "::warning::Resolved invalid queued target branch '$queued_target_branch' to default branch '$target_branch' for $TARGET_REPO."
710737
fi
711-
echo "target_branch=$target_branch" >> "$GITHUB_OUTPUT"
738+
effective_decision="$(CLAIM_DECISION="$CLAIM_DECISION" TARGET_BRANCH="$target_branch" node <<'NODE'
739+
const decision = JSON.parse(process.env.CLAIM_DECISION || "{}");
740+
decision.targetBranch = process.env.TARGET_BRANCH;
741+
process.stdout.write(JSON.stringify(decision));
742+
NODE
743+
)"
744+
{
745+
echo "admission_retry=false"
746+
echo "target_branch=$target_branch"
747+
echo "decision=$effective_decision"
748+
} >> "$GITHUB_OUTPUT"
712749
live_item_error="$(mktemp)"
713750
if ! live_item="$(gh api "repos/$TARGET_REPO/issues/$ITEM_NUMBER" 2>"$live_item_error")"; then
714751
if grep -Eqi 'HTTP 404|Not Found' "$live_item_error" && gh api "repos/$TARGET_REPO" >/dev/null; then
@@ -760,7 +797,7 @@ jobs:
760797
esac
761798

762799
- name: Create target write token
763-
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' }}
800+
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' }}
764801
id: target-write-token
765802
continue-on-error: true
766803
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
@@ -777,7 +814,7 @@ jobs:
777814

778815
- uses: ./.github/actions/setup-pnpm
779816
id: setup-pnpm
780-
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' }}
817+
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' }}
781818
with:
782819
build-script: ${{ steps.live-item.outputs.proceed == 'true' && 'build:all' || 'build:repair' }}
783820

@@ -1208,12 +1245,12 @@ jobs:
12081245

12091246
- name: Create exact review artifact bundle
12101247
id: create-exact-review-bundle
1211-
if: ${{ always() && steps.claim-exact-review-queue.outputs.claimed == 'true' && !cancelled() && steps.target.outputs.target_enabled == 'true' && steps.live-item.outcome == 'success' && steps.setup-pnpm.outcome == 'success' && steps.review-exact-event-item.outputs.superseded != 'true' && (steps.live-item.outputs.proceed != 'true' || (steps.review-exact-event-item.outcome == 'success' && steps.review-exact-event-item.outputs.retry_at == '')) }}
1248+
if: ${{ always() && steps.claim-exact-review-queue.outputs.claimed == 'true' && !cancelled() && steps.target.outputs.target_enabled == 'true' && steps.live-item.outcome == 'success' && steps.live-item.outputs.admission_retry != 'true' && steps.setup-pnpm.outcome == 'success' && steps.review-exact-event-item.outputs.superseded != 'true' && (steps.live-item.outputs.proceed != 'true' || (steps.review-exact-event-item.outcome == 'success' && steps.review-exact-event-item.outputs.retry_at == '')) }}
12121249
env:
12131250
EXACT_REVIEW_ACTION_LEDGER_ROOT: ${{ env.CLAWSWEEPER_ACTION_LEDGER_OUTPUT_ROOT }}
12141251
EXACT_REVIEW_BUNDLE_DIR: .artifacts/exact-review-bundle
12151252
EXACT_REVIEW_CLAIM_GENERATION: ${{ steps.claim-exact-review-queue.outputs.claim_generation }}
1216-
EXACT_REVIEW_DECISION: ${{ steps.claim-exact-review-queue.outputs.decision }}
1253+
EXACT_REVIEW_DECISION: ${{ steps.live-item.outputs.decision }}
12171254
EXACT_REVIEW_GENERATION_ATTEMPT: ${{ github.run_attempt }}
12181255
EXACT_REVIEW_ITEM_KEY: ${{ steps.claim-exact-review-queue.outputs.item_key }}
12191256
EXACT_REVIEW_ITEM_KIND: ${{ fromJSON(steps.claim-exact-review-queue.outputs.decision).itemKind }}
@@ -1297,7 +1334,7 @@ jobs:
12971334
if: ${{ always() && steps.claim-exact-review-queue.outputs.claimed == 'true' && !cancelled() && steps.upload-exact-review-bundle.outcome == 'success' }}
12981335
env:
12991336
ARTIFACT_NAME: ${{ steps.create-exact-review-bundle.outputs.artifact_name }}
1300-
CLAIM_DECISION: ${{ steps.claim-exact-review-queue.outputs.decision }}
1337+
CLAIM_DECISION: ${{ steps.live-item.outputs.decision }}
13011338
CLAIM_GENERATION: ${{ steps.claim-exact-review-queue.outputs.claim_generation }}
13021339
ITEM_KEY: ${{ steps.claim-exact-review-queue.outputs.item_key }}
13031340
LEASE_REVISION: ${{ steps.claim-exact-review-queue.outputs.lease_revision }}
@@ -1443,6 +1480,7 @@ jobs:
14431480
id: exact-review-generation-result
14441481
if: ${{ steps.claim-exact-review-queue.outputs.claimed == 'true' && always() }}
14451482
env:
1483+
ADMISSION_RETRY: ${{ steps.live-item.outputs.admission_retry }}
14461484
TARGET_ENABLED: ${{ steps.target.outputs.target_enabled }}
14471485
LIVE_OUTCOME: ${{ steps.live-item.outcome }}
14481486
REVIEW_OUTCOME: ${{ steps.review-exact-event-item.outcome }}
@@ -1452,7 +1490,11 @@ jobs:
14521490
DIRECT_PUBLICATION_ACCEPTED: ${{ steps.direct-exact-review-publication.outputs.accepted }}
14531491
run: |
14541492
outcome=failure
1455-
if [ "$TARGET_ENABLED" = "false" ]; then
1493+
requeue_latest=false
1494+
if [ "$ADMISSION_RETRY" = "true" ]; then
1495+
outcome=success
1496+
requeue_latest=true
1497+
elif [ "$TARGET_ENABLED" = "false" ]; then
14561498
outcome=success
14571499
elif [ "$RESERVATION_STATUS" = "superseded" ] || [ "$REVIEW_SUPERSEDED" = "true" ]; then
14581500
outcome=success
@@ -1462,6 +1504,7 @@ jobs:
14621504
outcome=success
14631505
fi
14641506
echo "outcome=$outcome" >> "$GITHUB_OUTPUT"
1507+
echo "requeue_latest=$requeue_latest" >> "$GITHUB_OUTPUT"
14651508

14661509
- name: Complete exact-review queue lease
14671510
id: complete-exact-review-queue
@@ -1475,7 +1518,8 @@ jobs:
14751518
QUEUE_LEASE_ID: ${{ steps.claim-exact-review-queue.outputs.lease_id }}
14761519
QUEUE_LEASE_REVISION: ${{ steps.claim-exact-review-queue.outputs.lease_revision }}
14771520
QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
1478-
RETRY_AT: ${{ steps.reserve-exact-review-lease.outputs.retry_at || steps.review-exact-event-item.outputs.retry_at }}
1521+
REQUEUE_LATEST: ${{ steps.exact-review-generation-result.outputs.requeue_latest }}
1522+
RETRY_AT: ${{ steps.live-item.outputs.retry_at || steps.reserve-exact-review-lease.outputs.retry_at || steps.review-exact-event-item.outputs.retry_at }}
14791523
RUN_ATTEMPT: ${{ github.run_attempt }}
14801524
run: |
14811525
set -euo pipefail
@@ -1500,6 +1544,7 @@ jobs:
15001544
const outcome = ["success", "cancelled", "failure"].includes(primaryOutcome)
15011545
? primaryOutcome
15021546
: "failure";
1547+
const requeueLatest = process.env.REQUEUE_LATEST === "true";
15031548
const retryAt = String(process.env.RETRY_AT || "").trim();
15041549
process.stdout.write(JSON.stringify({
15051550
lease_id: process.env.QUEUE_LEASE_ID,
@@ -1513,6 +1558,7 @@ jobs:
15131558
run_id: process.env.GITHUB_RUN_ID,
15141559
run_attempt: runAttempt,
15151560
outcome,
1561+
...(requeueLatest ? { requeue_latest: true } : {}),
15161562
...(retryAt ? { retry_at: retryAt } : {}),
15171563
}));
15181564
')"
@@ -2988,18 +3034,29 @@ jobs:
29883034
working-directory: clawsweeper
29893035
env:
29903036
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
3037+
GH_TOKEN: ${{ steps.target-read-token.outputs.token || github.token }}
29913038
QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
29923039
run: |
29933040
set -euo pipefail
29943041
lane="normal_backfill"
29953042
if [ "${{ steps.mode.outputs.hot_intake }}" = "true" ]; then
29963043
lane="hot_intake"
29973044
fi
3045+
target_repo="${{ steps.target.outputs.target_repo }}"
3046+
target_branch="$(gh api "repos/$target_repo" --jq '.default_branch // empty')"
3047+
if [ -z "$target_branch" ] ||
3048+
! printf '%s' "$target_branch" | grep -Eq '^[A-Za-z0-9_.\/-]+$' ||
3049+
printf '%s' "$target_branch" | grep -Eq '^[0-9]+$' ||
3050+
[[ "$target_branch" == *".."* ]]; then
3051+
echo "Invalid default branch for scheduled target $target_repo: $target_branch" >&2
3052+
exit 1
3053+
fi
3054+
echo "::notice::Scheduled review payloads will use default branch '$target_branch' for $target_repo."
29983055
result="$(pnpm run --silent repair:scheduled-review-enqueue -- \
29993056
--plan plan.json \
30003057
--lane "$lane" \
3001-
--target-repo "${{ steps.target.outputs.target_repo }}" \
3002-
--target-branch "${{ steps.target.outputs.target_branch }}" \
3058+
--target-repo "$target_repo" \
3059+
--target-branch "$target_branch" \
30033060
--queue-url "$QUEUE_URL" \
30043061
--delivery-prefix "scheduled:${{ github.run_id }}:${{ github.run_attempt }}")"
30053062
jq -e '.offered >= .attempted and .attempted >= (.queued + .deduped + .shed + .rejected)' <<<"$result" >/dev/null

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ checkpoint, and status-only commits are intentionally omitted.
99

1010
### Changed
1111

12+
- Repaired legacy exact-review decisions whose empty branch was shifted to the string `0`, resolved invalid queued branches from the target repository default, and requeued temporary branch-resolution failures without spending the eight-attempt review-failure budget.
1213
- Made scheduled exact reviews immediately ready after fleet admission, automatically retried recoverable parked reviews on a bounded 5/10/20-minute cycle, and exposed backoff/park reason counts in queue status and the dashboard.
1314
- Aligned normal fanout and planner priority with the dashboard's canonical tuple coverage identities, so legacy backfill reports no longer hide untracked open items behind canonical re-reviews.
1415
- Sized scheduled candidate batches from live free review capacity, apportioned fleet fanout by untracked backlog while retaining round-robin fairness, and skipped empty repositories before both normal and hot fanout so a dominant backlog can fill idle review slots without starving smaller targets.

‎src/repair/scheduled-review-enqueue.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export async function enqueueScheduledReviewPlan(
4747
options: EnqueueOptions,
4848
): Promise<ScheduledReviewEnqueueSummary> {
4949
const fetchImpl = options.fetchImpl ?? fetch;
50+
const targetBranch = options.targetBranch.trim();
51+
if (!isPlausibleTargetBranch(targetBranch)) {
52+
throw new Error("scheduled review target branch is invalid");
53+
}
5054
for (const candidate of options.plan.candidates) validateCandidate(candidate, options.targetRepo);
5155
const queueUrl = options.queueUrl.replace(/\/$/, "");
5256
const capabilityResponse = await fetchImpl(`${queueUrl}/api/exact-review-queue`, {
@@ -96,7 +100,7 @@ export async function enqueueScheduledReviewPlan(
96100
delivery_id: `${options.deliveryPrefix}:${index}:${candidate.number}`,
97101
decision: {
98102
targetRepo: options.targetRepo,
99-
targetBranch: options.targetBranch,
103+
targetBranch,
100104
itemNumber: candidate.number,
101105
itemKind: candidate.kind,
102106
sourceEvent: candidate.kind === "pull_request" ? "pull_request" : "issues",
@@ -142,6 +146,10 @@ export async function enqueueScheduledReviewPlan(
142146
return summary;
143147
}
144148

149+
function isPlausibleTargetBranch(value: string): boolean {
150+
return /^[A-Za-z0-9_./-]+$/.test(value) && !/^\d+$/.test(value) && !value.includes("..");
151+
}
152+
145153
function validateCandidate(candidate: PlanCandidate, targetRepo: string): void {
146154
if (candidate.repo !== targetRepo)
147155
throw new Error("scheduled review candidate repository mismatch");

‎test/dashboard-worker.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9045,7 +9045,7 @@ test("exact-review automatic parked recovery remains bounded", async () => {
90459045
assert.equal(await storage.getAlarm(), null);
90469046
});
90479047

9048-
test("exact-review requeue_latest and publication completions ignore the review ceiling", async () => {
9048+
test("exact-review admission requeue_latest resets failures instead of parking at the review ceiling", async () => {
90499049
const storage = new MemoryDurableStorage();
90509050
const review = leasedExactReviewQueueItem(113_342, "9130");
90519051
const publication = leasedExactReviewPublicationItem(113_343, "9131");

‎test/repair/scheduled-review-enqueue.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,30 @@ test("scheduled review enqueue reports the full selection-to-queue funnel and st
119119
);
120120
}
121121
const second = JSON.parse(requests[1]!.body);
122+
assert.equal(second.decision.targetBranch, "main");
122123
assert.equal(second.decision.sourceAction, "scheduled_normal_backfill");
123124
assert.equal(second.decision.sourceEvent, "pull_request");
124125
assert.equal(second.decision.supersedesInProgress, false);
125126
});
126127

128+
test("scheduled review enqueue rejects numeric target branches before queue admission", async () => {
129+
await assert.rejects(
130+
enqueueScheduledReviewPlan({
131+
plan: { candidates: [] },
132+
lane: "normal_backfill",
133+
targetRepo: "openclaw/openclaw",
134+
targetBranch: "0",
135+
queueUrl: "https://queue.example",
136+
secret: "secret",
137+
deliveryPrefix: "scheduled:100:1",
138+
fetchImpl: async () => {
139+
throw new Error("fetch must not run");
140+
},
141+
}),
142+
/target branch is invalid/,
143+
);
144+
});
145+
127146
test("scheduled review enqueue fails closed until the queue advertises pacing", async () => {
128147
await assert.rejects(
129148
enqueueScheduledReviewPlan({

0 commit comments

Comments
 (0)