Skip to content

Commit 10ad04b

Browse files
committed
fix: harden apply cursor rotation
1 parent dead2dc commit 10ad04b

4 files changed

Lines changed: 134 additions & 6 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,8 +2171,6 @@ jobs:
21712171
sync_open_pr_batch="true"
21722172
item_numbers=""
21732173
fi
2174-
explicit_item_numbers="$item_numbers"
2175-
auto_selected_apply_batch=false
21762174
sync_comments_only="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_sync_comments_only || 'false' }}"
21772175
product_direction_enabled=false
21782176
case "${CLAWSWEEPER_UNCONFIRMED_PRODUCT_DIRECTION_CLOSE_ENABLED,,}" in
@@ -2261,6 +2259,8 @@ jobs:
22612259
sync_open_pr_batch="true"
22622260
item_numbers=""
22632261
fi
2262+
explicit_item_numbers="$item_numbers"
2263+
auto_selected_apply_batch=false
22642264
sync_comments_only="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_sync_comments_only || 'false' }}"
22652265
product_direction_enabled=false
22662266
case "${CLAWSWEEPER_UNCONFIRMED_PRODUCT_DIRECTION_CLOSE_ENABLED,,}" in
@@ -2485,11 +2485,12 @@ jobs:
24852485
closed_total=$((closed_total + closed_in_chunk))
24862486
echo "Checkpoint $checkpoint result_count=$result_count closed_in_chunk=$closed_in_chunk closed_total=$closed_total/$limit"
24872487
apply_publish_paths=(records apply-report.json)
2488-
if [ "$auto_selected_apply_batch" = "true" ] && [ "$result_count" -gt 0 ]; then
2488+
if [ "$auto_selected_apply_batch" = "true" ]; then
24892489
pnpm run workflow -- write-apply-cursor \
24902490
--cursor-path "$apply_cursor_path" \
24912491
--report ".artifacts/apply-reports/apply-report-$checkpoint.json" \
2492-
--target-repo "$TARGET_REPO"
2492+
--target-repo "$TARGET_REPO" \
2493+
--item-numbers "$item_numbers"
24932494
apply_publish_paths+=(results/apply-cursors)
24942495
fi
24952496
publish_changes "chore: apply sweep decisions checkpoint $checkpoint" "${apply_publish_paths[@]}"
@@ -2501,9 +2502,11 @@ jobs:
25012502
publish_status "chore: update sweep apply checkpoint $checkpoint status"
25022503
echo "::endgroup::"
25032504
if [ "$result_count" -ge "$close_processed_limit" ]; then
2504-
if [ "$auto_selected_apply_batch" = "true" ] || [ "$closed_in_chunk" -gt 0 ]; then
2505+
if [ "$closed_in_chunk" -gt 0 ]; then
25052506
echo "Close scan reached its $close_processed_limit-record budget; queueing a fresh-token continuation."
25062507
continue_apply=true
2508+
elif [ "$auto_selected_apply_batch" = "true" ]; then
2509+
echo "Close scan reached its $close_processed_limit-record budget with no fresh closes; cursor is persisted and the next scheduled apply run will advance the next window."
25072510
else
25082511
echo "Explicit close scan reached its $close_processed_limit-record budget without fresh closes; stopping to avoid a retry loop."
25092512
fi

‎src/repair/workflow-utils.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function runCli(): void {
8787
requiredString("cursor-path"),
8888
requiredString("report"),
8989
requiredString("target-repo"),
90+
optionalString("item-numbers"),
9091
),
9192
);
9293
break;
@@ -343,6 +344,7 @@ function selectedProposedItemCandidates(
343344
if (repoFor(markdown, name) !== options.targetRepo) return [];
344345
const type = frontMatterValue(markdown, "type");
345346
if (options.applyKind !== "all" && type && type !== options.applyKind) return [];
347+
if (!frontMatterValue(markdown, "item_snapshot_hash")) return [];
346348
const decision = frontMatterValue(markdown, "decision");
347349
const action = frontMatterValue(markdown, "action_taken");
348350
const confidence = frontMatterValue(markdown, "confidence");
@@ -594,12 +596,16 @@ export function writeApplyCursor(
594596
cursorPath: string,
595597
reportPath: string,
596598
targetRepo: string,
599+
itemNumbers = "",
597600
): Record<string, string> {
598601
const actions = readApplyActions(reportPath);
599602
const processed = actions.flatMap((action) =>
600603
typeof action.number === "number" ? [action.number] : [],
601604
);
602-
const number = processed.at(-1) ?? 0;
605+
const selected = csvItems(itemNumbers)
606+
.map((item) => Number(item))
607+
.filter((number) => Number.isInteger(number) && number > 0);
608+
const number = processed.at(-1) ?? selected.at(-1) ?? 0;
603609
const applyCheckedAt = number > 0 ? applyCheckedAtForItem(targetRepo, number) : "";
604610
fs.mkdirSync(path.dirname(cursorPath), { recursive: true });
605611
fs.writeFileSync(
@@ -610,6 +616,7 @@ export function writeApplyCursor(
610616
next_after_number: number,
611617
next_after_apply_checked_at: applyCheckedAt,
612618
processed_count: processed.length,
619+
selected_count: selected.length,
613620
updated_at: new Date().toISOString(),
614621
},
615622
null,
@@ -618,6 +625,7 @@ export function writeApplyCursor(
618625
);
619626
return {
620627
processed_count: String(processed.length),
628+
selected_count: String(selected.length),
621629
next_cursor_number: String(number),
622630
next_cursor_apply_checked_at: applyCheckedAt,
623631
};

0 commit comments

Comments
 (0)