@@ -110,7 +110,7 @@ interface ApplyCloseExecutionOptions {
110110 canStartPairedIssueClose : ( number : number , kind : Item [ "kind" ] ) => boolean ;
111111 pairedIssueMarkdown : ( number : number ) => string | null ;
112112 pairedIssueReviewUpdatedAt : ( number : number ) => string | null ;
113- pairedIssueOwnedReviewCommentUpdatedAt : ( number : number ) => string | null ;
113+ pairedIssueDurableReviewCommentUpdatedAt : ( number : number ) => string | null ;
114114 pairedIssueCanonicalProvenanceBlock : ( number : number ) => string | null ;
115115 closeDelayMs : number ;
116116 closeLimitReached : boolean ;
@@ -122,7 +122,9 @@ interface ApplyCloseExecutionOptions {
122122 currentObsoleteFixPrBlockReason : ( ) => string | null ;
123123 currentPrCloseCoverageProofGateBlock : ( ) => PrCloseCoverageProofGateBlock | null ;
124124 currentStaleVersionBugBlockReason : ( ) => string | null ;
125+ currentDurableReviewCommentUpdatedAt : ( ) => string | null ;
125126 dryRun : boolean ;
127+ deferPairedIssueForThisRun : ( number : number ) => void ;
126128 examinedItemNumbers : number [ ] ;
127129 getMarkdown : ( ) => string ;
128130 isRetryableSkippedClose : boolean ;
@@ -137,7 +139,7 @@ interface ApplyCloseExecutionOptions {
137139 onClosed : ( result : ApplyResult , dryRun : boolean ) => boolean ;
138140 onPairedIssueClosed : ( result : ApplyResult , dryRun : boolean ) => boolean ;
139141 postProofCoveringPrFreshnessBlock : ( ) => PrCloseCoverageProofGateBlock | null ;
140- postProofFreshnessBlock : ( ) => ReviewFreshnessBlock | null ;
142+ postProofFreshnessBlock : ( options ?: { force ?: boolean } ) => ReviewFreshnessBlock | null ;
141143 proofResult : ( ) => PrCloseCoverageProofGateResult | undefined ;
142144 recordApplySkipped : ( action : ActionTaken , reason : string ) => boolean ;
143145 recordMutation : ( parentEventId ?: string | null ) => void ;
@@ -205,7 +207,7 @@ export function executeApplyClose(
205207 canStartPairedIssueClose,
206208 pairedIssueMarkdown,
207209 pairedIssueReviewUpdatedAt,
208- pairedIssueOwnedReviewCommentUpdatedAt ,
210+ pairedIssueDurableReviewCommentUpdatedAt ,
209211 pairedIssueCanonicalProvenanceBlock,
210212 closeDelayMs,
211213 closeLimitReached,
@@ -216,7 +218,9 @@ export function executeApplyClose(
216218 currentObsoleteFixPrBlockReason,
217219 currentPrCloseCoverageProofGateBlock,
218220 currentStaleVersionBugBlockReason,
221+ currentDurableReviewCommentUpdatedAt,
219222 dryRun,
223+ deferPairedIssueForThisRun,
220224 emitEventApplyProof,
221225 examinedItemNumbers,
222226 getMarkdown,
@@ -302,7 +306,8 @@ export function executeApplyClose(
302306 if (
303307 CLAWSWEEPER_BOT_AUTHORS . has ( login ) &&
304308 ( body . includes ( closeAppliedMarker ) ||
305- body . includes ( `<!-- clawsweeper-review item=${ issueNumber } ` ) )
309+ body . includes ( `<!-- clawsweeper-review item=${ issueNumber } ` ) ||
310+ body . includes ( `<!-- clawsweeper-review-lease item=${ issueNumber } ` ) )
306311 ) {
307312 continue ;
308313 }
@@ -339,6 +344,9 @@ export function executeApplyClose(
339344 const implementationBasedPrClose =
340345 item . kind === "pull_request" &&
341346 [ "implemented_on_main" , "mostly_implemented_on_main" ] . includes ( closeReason ) ;
347+ const implementationBasedIssueClose =
348+ item . kind === "issue" &&
349+ [ "implemented_on_main" , "mostly_implemented_on_main" ] . includes ( closeReason ) ;
342350 const parsedLinkedIssueNumbers = implementationBasedPrClose
343351 ? ( ( ) => {
344352 const livePull = ghJson < { body ?: unknown } > ( [
@@ -474,12 +482,27 @@ export function executeApplyClose(
474482 }
475483 }
476484 const linkedIssuesToClose = linkedItems . filter ( ( liveIssue ) => liveIssue . state === "open" ) ;
485+ if ( ! dryRun && implementationBasedIssueClose && ! currentDurableReviewCommentUpdatedAt ( ) ) {
486+ return skip (
487+ "kept_open" ,
488+ "implemented-on-main issue close requires an exact current durable review comment for its report" ,
489+ ) ;
490+ }
477491 if ( linkedIssuesToClose . length > 0 && ! pairedIssueCloseCapacityAvailable ) {
478492 return skip (
479493 "kept_open" ,
480494 "implemented-on-main paired closeout exceeds the remaining close or processed-item limit" ,
481495 ) ;
482496 }
497+ for ( const liveIssue of linkedIssuesToClose ) {
498+ if ( ! pairedIssueMarkdown ( liveIssue . item . number ) ) continue ;
499+ if ( pairedIssueDurableReviewCommentUpdatedAt ( liveIssue . item . number ) ) continue ;
500+ deferPairedIssueForThisRun ( liveIssue . item . number ) ;
501+ return skip (
502+ "kept_open" ,
503+ "implemented-on-main paired closeout requires an exact current durable review comment for the linked issue report" ,
504+ ) ;
505+ }
483506 if (
484507 linkedIssuesToClose . length > 0 &&
485508 ( applyKind !== "all" || ! canStartPairedIssueClose ( linkedIssuesToClose [ 0 ] ! . item . number , "issue" ) )
@@ -499,10 +522,21 @@ export function executeApplyClose(
499522 "implemented-on-main paired closeout requires an independently reviewed linked issue report" ,
500523 ) ;
501524 }
525+ const pairedDurableReviewUpdatedAt = pairedIssueDurableReviewCommentUpdatedAt (
526+ liveIssue . item . number ,
527+ ) ;
528+ if ( ! pairedDurableReviewUpdatedAt ) {
529+ deferPairedIssueForThisRun ( liveIssue . item . number ) ;
530+ return skip (
531+ "kept_open" ,
532+ "implemented-on-main paired closeout requires an exact current durable review comment for the linked issue report" ,
533+ ) ;
534+ }
502535 if (
503536 pairedIssueReviewUpdatedAt ( liveIssue . item . number ) !== liveIssue . item . updatedAt &&
504- pairedIssueOwnedReviewCommentUpdatedAt ( liveIssue . item . number ) !== liveIssue . item . updatedAt
537+ pairedDurableReviewUpdatedAt !== liveIssue . item . updatedAt
505538 ) {
539+ deferPairedIssueForThisRun ( liveIssue . item . number ) ;
506540 return skip (
507541 "kept_open" ,
508542 "implemented-on-main paired closeout requires the linked issue to remain unchanged since its independent review" ,
@@ -550,7 +584,7 @@ export function executeApplyClose(
550584 dryRun,
551585 } )
552586 : null ;
553- const stop = onClosed (
587+ let stop = onClosed (
554588 {
555589 number,
556590 action : "closed" ,
@@ -565,14 +599,15 @@ export function executeApplyClose(
565599 ) ;
566600 for ( const liveIssue of linkedIssuesToClose ) {
567601 archivePairedIssue ( liveIssue . item . number ) ;
568- onPairedIssueClosed (
569- {
570- number : liveIssue . item . number ,
571- action : "closed" ,
572- reason : `dry-run: would close as ${ closeReasonText ( linkedIssueCloseReason ) } ` ,
573- } ,
574- true ,
575- ) ;
602+ stop =
603+ onPairedIssueClosed (
604+ {
605+ number : liveIssue . item . number ,
606+ action : "closed" ,
607+ reason : `dry-run: would close as ${ closeReasonText ( linkedIssueCloseReason ) } ` ,
608+ } ,
609+ true ,
610+ ) || stop ;
576611 }
577612 return stop ? "stop" : "next" ;
578613 }
@@ -607,10 +642,13 @@ export function executeApplyClose(
607642 }
608643 throw error ;
609644 }
610- if ( / ^ (?: p o s t e d | u p d a t e d ) c l o s e - a p p l i e d c o m m e n t $ / . test ( closeAppliedCommentReason ?? "" ) ) {
611- // The comment updates the PR's activity timestamp. Admit only this verified
612- // self-mutation before the final freshness guard; it still rejects any
613- // intervening contributor activity or source/head drift.
645+ if (
646+ / ^ (?: p o s t e d | u p d a t e d ) c l o s e - a p p l i e d c o m m e n t $ / . test ( closeAppliedCommentReason ?? "" ) ||
647+ implementationBasedPrClose
648+ ) {
649+ // Bind the final close to an immediate structural receipt. This admits
650+ // verified automation mutations while still rejecting source or human
651+ // activity drift, including when a matching closeout marker preexisted.
614652 if (
615653 ! rememberSelfMutationUpdatedAt ( {
616654 postReviewActivityStartedAtMs : closeoutActivityBaselineMs ,
@@ -624,7 +662,7 @@ export function executeApplyClose(
624662 : "next" ;
625663 }
626664 }
627- const finalFreshnessBlock = postProofFreshnessBlock ( ) ;
665+ const finalFreshnessBlock = postProofFreshnessBlock ( { force : implementationBasedPrClose } ) ;
628666 if ( finalFreshnessBlock ) return markChangedSinceReview ( finalFreshnessBlock ) ? "stop" : "next" ;
629667 const finalCoveringPrFreshnessBlock = postProofCoveringPrFreshnessBlock ( ) ;
630668 if ( finalCoveringPrFreshnessBlock ) {
@@ -830,21 +868,63 @@ export function executeApplyClose(
830868 `implemented-on-main paired closeout requires linked issue #${ pairedIssue . number } to remain unchanged, unlocked, and free of new activity before closing the parent PR` ,
831869 ) ;
832870 }
833- withPairedIssueMutationLease (
834- pairedIssue . number ,
835- ( ) =>
836- closeItem ( { number : pairedIssue . number , kind : "issue" , reason : linkedIssueCloseReason } ) ,
837- {
838- onOperationCompleted : ( ) => {
839- archivePairedIssue ( pairedIssue . number ) ;
840- pairedStop ||= onPairedIssueClosed (
841- { number : pairedIssue . number , action : "closed" , reason : pairedIssue . reason } ,
842- false ,
871+ const finalProvenanceRevoked = new Error ( "final canonical provenance revoked" ) ;
872+ let finalProvenanceBlock : string | null = null ;
873+ try {
874+ withPairedIssueMutationLease (
875+ pairedIssue . number ,
876+ ( ) => {
877+ const postLeasePairedIssue = fetchItem ( pairedIssue . number , {
878+ bypassGenerationCache : true ,
879+ } ) ;
880+ const postLeasePairedIssueSource = pairedIssueSourceSnapshot ( pairedIssue . number ) ;
881+ const postLeasePairedIssueActivity = pairedIssueRecentNonSelfCommentBlockReasonSafe (
882+ pairedIssue . number ,
883+ pairedIssue . reviewedAtMs ,
843884 ) ;
844- logProgress ( `linked issue #${ pairedIssue . number } : ${ pairedIssue . reason } ` ) ;
885+ if (
886+ postLeasePairedIssue . state !== "open" ||
887+ postLeasePairedIssue . item . kind !== "issue" ||
888+ postLeasePairedIssue . item . locked ||
889+ postLeasePairedIssueSource !== preClosePairedIssueSource ||
890+ postLeasePairedIssueActivity
891+ ) {
892+ finalProvenanceBlock = `implemented-on-main paired closeout requires linked issue #${ pairedIssue . number } to remain unchanged, unlocked, and free of new activity after acquiring its mutation lease` ;
893+ throw finalProvenanceRevoked ;
894+ }
895+ finalProvenanceBlock = implementedOnMainPullRequestProvenanceApplyBlock (
896+ getMarkdown ( ) ,
897+ item ,
898+ closeReason ,
899+ pairedIssue . number ,
900+ ) ;
901+ if ( finalProvenanceBlock ) throw finalProvenanceRevoked ;
902+ closeItem ( {
903+ number : pairedIssue . number ,
904+ kind : "issue" ,
905+ reason : linkedIssueCloseReason ,
906+ } ) ;
845907 } ,
846- } ,
847- ) ;
908+ {
909+ onOperationCompleted : ( ) => {
910+ archivePairedIssue ( pairedIssue . number ) ;
911+ pairedStop ||= onPairedIssueClosed (
912+ { number : pairedIssue . number , action : "closed" , reason : pairedIssue . reason } ,
913+ false ,
914+ ) ;
915+ logProgress ( `linked issue #${ pairedIssue . number } : ${ pairedIssue . reason } ` ) ;
916+ } ,
917+ } ,
918+ ) ;
919+ } catch ( error ) {
920+ if ( error !== finalProvenanceRevoked ) throw error ;
921+ deferPairedIssueForThisRun ( pairedIssue . number ) ;
922+ return skip (
923+ "kept_open" ,
924+ finalProvenanceBlock ??
925+ "implemented-on-main close could not revalidate current GitHub provenance" ,
926+ ) ;
927+ }
848928 }
849929 let stop = false ;
850930 let finalParentGuardFlow : ApplyCloseFlow | null = null ;
0 commit comments