Skip to content

Commit cbae4b0

Browse files
committed
fix: classify apply recovery actions
1 parent 9836fc7 commit cbae4b0

3 files changed

Lines changed: 171 additions & 135 deletions

File tree

‎dashboard/worker.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,6 +6958,7 @@ function applyHealthBucketLabel(bucket) {
69586958
const labels = {
69596959
already_resolved: "already resolved",
69606960
close_coverage_proof: "needs close proof",
6961+
conversation_unlock: "unlock conversation",
69616962
defer_until_closing_pr: "defer for PR state",
69626963
inspect: "inspect skips",
69636964
live_state_recovery: "live check recovery",

‎src/repair/workflow-utils.ts‎

Lines changed: 139 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type ApplySkipNextAction = {
6767
bucket:
6868
| "review_refresh"
6969
| "close_coverage_proof"
70+
| "conversation_unlock"
7071
| "maintainer_review"
7172
| "stable_skip"
7273
| "report_quality_repair"
@@ -81,6 +82,8 @@ type ApplySkipNextAction = {
8182
summary: string;
8283
next_step: string;
8384
};
85+
86+
type ApplySkipNextActionDetail = Omit<ApplySkipNextAction, "reason" | "count">;
8487
const args = parseArgs(process.argv.slice(2));
8588

8689
function runCli(): void {
@@ -490,151 +493,155 @@ function applyNextActionBucketRank(bucket: ApplySkipNextAction["bucket"]): numbe
490493
"close_coverage_proof",
491494
"report_quality_repair",
492495
"defer_until_closing_pr",
496+
"conversation_unlock",
493497
"maintainer_review",
494498
"stable_skip",
495499
"already_resolved",
496500
"inspect",
497501
].indexOf(bucket);
498502
}
499503

504+
const APPLY_SKIP_NEXT_ACTION_DETAILS: Record<string, ApplySkipNextActionDetail> = {
505+
skipped_changed_since_review: {
506+
bucket: "review_refresh",
507+
owner: "clawsweeper",
508+
retryable: true,
509+
label: "Refresh review",
510+
summary: "The item changed after the review that proposed closing it.",
511+
next_step: "Queue a fresh ClawSweeper review before any close retry.",
512+
},
513+
skipped_stale_review_comment_sync: {
514+
bucket: "review_refresh",
515+
owner: "clawsweeper",
516+
retryable: true,
517+
label: "Refresh review state",
518+
summary: "The durable review comment is newer than the local review report.",
519+
next_step: "Queue a fresh review instead of overwriting the newer durable comment.",
520+
},
521+
skipped_pr_close_coverage_proof: {
522+
bucket: "close_coverage_proof",
523+
owner: "clawsweeper",
524+
retryable: true,
525+
label: "Add close proof",
526+
summary: "The PR close proposal needs positive coverage proof before apply can close it.",
527+
next_step: "Run or refresh close-coverage proof for the canonical and covered PR pair.",
528+
},
529+
retry_pr_close_coverage_proof: {
530+
bucket: "close_coverage_proof",
531+
owner: "clawsweeper",
532+
retryable: true,
533+
label: "Retry close proof",
534+
summary: "The close-coverage proof check failed transiently before reaching a decision.",
535+
next_step: "Inspect the proof failure, then retry after model and GitHub access recover.",
536+
},
537+
skipped_protected_label: maintainerDecisionAction(),
538+
skipped_policy_exempt: maintainerDecisionAction(),
539+
skipped_maintainer_authored: {
540+
bucket: "maintainer_review",
541+
owner: "maintainer",
542+
retryable: false,
543+
label: "Maintainer-authored",
544+
summary: "Automation does not close maintainer-authored items without human judgement.",
545+
next_step: "Route to maintainer review or close manually if the owner agrees.",
546+
},
547+
skipped_locked_conversation: {
548+
bucket: "conversation_unlock",
549+
owner: "maintainer",
550+
retryable: false,
551+
label: "Conversation locked",
552+
summary: "GitHub blocked the durable comment write because the conversation is locked.",
553+
next_step: "Unlock the conversation before retrying comment sync, or leave it unchanged.",
554+
},
555+
skipped_same_author_pair: {
556+
bucket: "stable_skip",
557+
owner: "none",
558+
retryable: false,
559+
label: "Stable skip",
560+
summary:
561+
"The source and canonical items have the same author, so automated duplicate close is intentionally conservative.",
562+
next_step: "Leave as a stable skip unless maintainers change the same-author close policy.",
563+
},
564+
skipped_invalid_decision: reportRepairAction(),
565+
skipped_missing_record: reportRepairAction(),
566+
skipped_open_closing_pr: {
567+
bucket: "defer_until_closing_pr",
568+
owner: "github",
569+
retryable: false,
570+
label: "Wait for closing PR",
571+
summary: "The item appears covered by a pull request that is still open.",
572+
next_step: "Defer until the linked closing PR merges, closes, or changes state.",
573+
},
574+
skipped_runtime_budget: {
575+
bucket: "run_budget",
576+
owner: "clawsweeper",
577+
retryable: true,
578+
label: "Runtime budget",
579+
summary: "The apply lane stopped because it reached its bounded runtime.",
580+
next_step: "Let the next scheduled run continue; tune runtime or batch size if this repeats.",
581+
},
582+
skipped_live_fetch_failed: {
583+
bucket: "live_state_recovery",
584+
owner: "github",
585+
retryable: true,
586+
label: "Recover live check",
587+
summary: "ClawSweeper could not confirm live GitHub state before mutating.",
588+
next_step: "Inspect auth, API, or rate-limit failures and retry after live checks recover.",
589+
},
590+
skipped_comment_auth: {
591+
bucket: "live_state_recovery",
592+
owner: "clawsweeper",
593+
retryable: true,
594+
label: "Repair comment auth",
595+
summary: "GitHub rejected the durable review comment write as unauthenticated.",
596+
next_step: "Repair the GitHub App write token before retrying comment sync.",
597+
},
598+
skipped_not_open: alreadyResolvedAction(),
599+
skipped_already_closed: alreadyResolvedAction(),
600+
skipped_closed: alreadyResolvedAction(),
601+
};
602+
500603
function applySkipNextAction(reason: string, count: number): ApplySkipNextAction {
501-
if (reason === "skipped_changed_since_review") {
502-
return {
503-
reason,
504-
count,
505-
bucket: "review_refresh",
506-
owner: "clawsweeper",
507-
retryable: true,
508-
label: "Refresh review",
509-
summary: "The item changed after the review that proposed closing it.",
510-
next_step: "Queue a fresh ClawSweeper review before any close retry.",
511-
};
512-
}
513-
if (reason === "skipped_pr_close_coverage_proof") {
514-
return {
515-
reason,
516-
count,
517-
bucket: "close_coverage_proof",
518-
owner: "clawsweeper",
519-
retryable: true,
520-
label: "Add close proof",
521-
summary: "The PR close proposal needs coverage proof before it can be applied.",
522-
next_step: "Run or refresh close-coverage proof for the canonical/covered PR pair.",
523-
};
524-
}
525-
if (reason === "skipped_protected_label" || reason === "skipped_policy_exempt") {
526-
return {
527-
reason,
528-
count,
529-
bucket: "maintainer_review",
530-
owner: "maintainer",
531-
retryable: false,
532-
label: "Maintainer decision",
533-
summary: "A protected label or policy exemption blocks automated pruning.",
534-
next_step: "Have a maintainer confirm the label/policy should remain or close manually.",
535-
};
536-
}
537-
if (reason === "skipped_maintainer_authored") {
538-
return {
539-
reason,
540-
count,
541-
bucket: "maintainer_review",
542-
owner: "maintainer",
543-
retryable: false,
544-
label: "Maintainer-authored",
545-
summary: "Automation does not close maintainer-authored items without human judgement.",
546-
next_step: "Route to maintainer review or close manually if the owner agrees.",
547-
};
548-
}
549-
if (reason === "skipped_same_author_pair") {
550-
return {
551-
reason,
552-
count,
553-
bucket: "stable_skip",
554-
owner: "none",
555-
retryable: false,
556-
label: "Stable skip",
557-
summary:
558-
"The source and canonical items have the same author, so automated duplicate close is intentionally conservative.",
559-
next_step: "Leave as a stable skip unless maintainers change the same-author close policy.",
560-
};
561-
}
562-
if (reason === "skipped_invalid_decision") {
563-
return {
564-
reason,
565-
count,
566-
bucket: "report_quality_repair",
567-
owner: "clawsweeper",
568-
retryable: true,
569-
label: "Repair review report",
570-
summary: "The durable review decision was incomplete or invalid for apply.",
571-
next_step: "Queue report-quality repair or re-review so the close decision becomes valid.",
572-
};
573-
}
574-
if (reason === "skipped_open_closing_pr") {
575-
return {
576-
reason,
577-
count,
578-
bucket: "defer_until_closing_pr",
579-
owner: "github",
580-
retryable: false,
581-
label: "Wait for closing PR",
582-
summary: "The item appears covered by a pull request that is still open.",
583-
next_step: "Defer until the linked closing PR merges, closes, or changes state.",
584-
};
585-
}
586-
if (reason === "skipped_runtime_budget") {
587-
return {
588-
reason,
589-
count,
590-
bucket: "run_budget",
591-
owner: "clawsweeper",
592-
retryable: true,
593-
label: "Runtime budget",
594-
summary: "The apply lane stopped because it reached its bounded runtime.",
595-
next_step: "Let the next scheduled run continue; tune runtime or batch size if this repeats.",
596-
};
597-
}
598-
if (reason === "skipped_live_fetch_failed") {
599-
return {
600-
reason,
601-
count,
602-
bucket: "live_state_recovery",
603-
owner: "github",
604-
retryable: true,
605-
label: "Recover live check",
606-
summary: "ClawSweeper could not confirm live GitHub state before mutating.",
607-
next_step:
608-
"Inspect auth, API, or rate-limit failures and retry only after live checks recover.",
609-
};
610-
}
611-
if (
612-
reason === "skipped_not_open" ||
613-
reason === "skipped_already_closed" ||
614-
reason === "skipped_closed"
615-
) {
616-
return {
617-
reason,
618-
count,
619-
bucket: "already_resolved",
620-
owner: "none",
621-
retryable: false,
622-
label: "Already resolved",
623-
summary: "The item was not open by the time apply checked it.",
624-
next_step:
625-
"No action is normally needed; investigate only if this bucket dominates repeated runs.",
626-
};
627-
}
628-
return {
629-
reason,
630-
count,
604+
const detail = APPLY_SKIP_NEXT_ACTION_DETAILS[reason] ?? {
631605
bucket: "inspect",
632606
owner: "maintainer",
633607
retryable: false,
634608
label: "Inspect skip",
635609
summary: "Apply reported an unmapped skip bucket.",
636-
next_step:
637-
"Inspect the workflow run and add a deterministic next-action mapping if this repeats.",
610+
next_step: "Inspect the workflow run and add a deterministic mapping if this repeats.",
611+
};
612+
return { reason, count, ...detail };
613+
}
614+
615+
function maintainerDecisionAction(): ApplySkipNextActionDetail {
616+
return {
617+
bucket: "maintainer_review",
618+
owner: "maintainer",
619+
retryable: false,
620+
label: "Maintainer decision",
621+
summary: "A protected label or policy exemption blocks automated pruning.",
622+
next_step: "Confirm the policy should remain, or close manually if it should not.",
623+
};
624+
}
625+
626+
function reportRepairAction(): ApplySkipNextActionDetail {
627+
return {
628+
bucket: "report_quality_repair",
629+
owner: "clawsweeper",
630+
retryable: true,
631+
label: "Repair review report",
632+
summary: "The durable review record is missing or invalid for apply.",
633+
next_step: "Queue a fresh review so apply receives a complete, valid decision.",
634+
};
635+
}
636+
637+
function alreadyResolvedAction(): ApplySkipNextActionDetail {
638+
return {
639+
bucket: "already_resolved",
640+
owner: "none",
641+
retryable: false,
642+
label: "Already resolved",
643+
summary: "The item was not open by the time apply checked it.",
644+
next_step: "No action is needed unless this bucket dominates repeated runs.",
638645
};
639646
}
640647
function applyReportHealthSummary(options: {

‎test/repair/workflow-utils.test.ts‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ test("workflow utilities summarize apply health with skip buckets and cursor", (
243243
skipped_locked_conversation: 1,
244244
},
245245
});
246+
assert.deepEqual(summary.next_action_buckets, {
247+
conversation_unlock: 1,
248+
live_state_recovery: 1,
249+
review_refresh: 2,
250+
});
251+
assert.equal(
252+
summary.next_actions.find((action) => action.reason === "skipped_comment_auth")?.next_step,
253+
"Repair the GitHub App write token before retrying comment sync.",
254+
);
246255
assert.equal(summary.cursor?.next_after_number, 40);
247256
});
248257

@@ -288,6 +297,15 @@ test("workflow utilities summarize comment-sync apply reports separately from cl
288297
skipped_stale_review_comment_sync: 1,
289298
},
290299
});
300+
assert.deepEqual(summary.next_action_buckets, {
301+
close_coverage_proof: 1,
302+
review_refresh: 1,
303+
});
304+
assert.equal(
305+
summary.next_actions.find((action) => action.reason === "skipped_stale_review_comment_sync")
306+
?.label,
307+
"Refresh review state",
308+
);
291309
});
292310

293311
test("workflow utilities classify common apply skip reasons into next actions", () => {
@@ -302,6 +320,8 @@ test("workflow utilities classify common apply skip reasons into next actions",
302320
{ number: 40, action: "skipped_invalid_decision" },
303321
{ number: 50, action: "skipped_open_closing_pr" },
304322
{ number: 60, action: "skipped_maintainer_authored" },
323+
{ number: 70, action: "retry_pr_close_coverage_proof" },
324+
{ number: 80, action: "skipped_missing_record" },
305325
]),
306326
);
307327

@@ -316,16 +336,16 @@ test("workflow utilities classify common apply skip reasons into next actions",
316336
});
317337

318338
assert.deepEqual(summary.next_action_buckets, {
319-
close_coverage_proof: 1,
339+
close_coverage_proof: 2,
320340
defer_until_closing_pr: 1,
321341
maintainer_review: 2,
322-
report_quality_repair: 1,
342+
report_quality_repair: 2,
323343
stable_skip: 1,
324344
});
325345
assert.equal(
326346
summary.next_actions.find((action) => action.reason === "skipped_pr_close_coverage_proof")
327347
?.next_step,
328-
"Run or refresh close-coverage proof for the canonical/covered PR pair.",
348+
"Run or refresh close-coverage proof for the canonical and covered PR pair.",
329349
);
330350
assert.equal(
331351
summary.next_actions.find((action) => action.reason === "skipped_open_closing_pr")?.bucket,
@@ -339,6 +359,14 @@ test("workflow utilities classify common apply skip reasons into next actions",
339359
summary.next_actions.find((action) => action.reason === "skipped_invalid_decision")?.owner,
340360
"clawsweeper",
341361
);
362+
assert.equal(
363+
summary.next_actions.find((action) => action.reason === "retry_pr_close_coverage_proof")?.label,
364+
"Retry close proof",
365+
);
366+
assert.equal(
367+
summary.next_actions.find((action) => action.reason === "skipped_missing_record")?.bucket,
368+
"report_quality_repair",
369+
);
342370
});
343371

344372
test("workflow utilities flag full-window close scans without the required cursor", () => {

0 commit comments

Comments
 (0)