@@ -123,16 +123,17 @@ const CLOSED_STATS_PAGE_LIMIT = 10;
123123const DEFAULT_CLAWSWEEPER_BOT_LOGINS = [ "clawsweeper[bot]" , "openclaw-clawsweeper[bot]" ] ;
124124const GITHUB_TIMEOUT_MS = 4500 ;
125125const DEFAULT_STALE_QUEUED_WORKFLOW_MS = 6 * 60 * 60 * 1000 ;
126- const DEFAULT_EXACT_REVIEW_QUEUE_MAX_CONCURRENT = 48 ;
127- const DEFAULT_EXACT_REVIEW_TARGET_MAX_CONCURRENT = 44 ;
128- const DEFAULT_EXACT_REVIEW_DISPATCH_LEASE_MS = 10 * 60 * 1000 ;
126+ const DEFAULT_EXACT_REVIEW_QUEUE_MAX_CONCURRENT = 64 ;
127+ const DEFAULT_EXACT_REVIEW_TARGET_MAX_CONCURRENT = 60 ;
128+ const DEFAULT_EXACT_REVIEW_DISPATCH_LEASE_MS = 6 * 60 * 1000 ;
129129const DEFAULT_EXACT_REVIEW_EXECUTION_LEASE_MS = 130 * 60 * 1000 ;
130130const DEFAULT_EXACT_REVIEW_RETRY_MS = 30_000 ;
131131const DEFAULT_EXACT_REVIEW_WORKFLOW_PAUSED_RETRY_MS = 60_000 ;
132132const EXACT_REVIEW_COMPLETION_RETRY_MAX_MS = 2 * 60 * 60 * 1000 ;
133- const EXACT_REVIEW_RECONCILE_RUN_LIMIT = 32 ;
133+ const EXACT_REVIEW_RECONCILE_RUN_LIMIT = 128 ;
134134const EXACT_REVIEW_RECONCILE_CLAIM_MATCH_LIMIT = EXACT_REVIEW_RECONCILE_RUN_LIMIT * 2 ;
135- const EXACT_REVIEW_RECONCILE_CONCURRENCY = 4 ;
135+ const EXACT_REVIEW_RECONCILE_CONCURRENCY = 8 ;
136+ const EXACT_REVIEW_RECONCILE_LIST_PAGE_LIMIT = 3 ;
136137// This is an idempotency policy, not a storage-size control. Receipts live in
137138// individual indexed SQLite rows and are pruned in bounded batches.
138139const EXACT_REVIEW_QUEUE_DELIVERY_TTL_MS = 7 * 24 * 60 * 60 * 1000 ;
@@ -795,33 +796,38 @@ export class ExactReviewQueue {
795796 const body = objectValue ( await request . json ( ) . catch ( ( ) => null ) ) ;
796797 const requestedRuns = exactReviewRequestedRuns ( body . runs ) ;
797798 if ( ! requestedRuns ) return json ( { error : "invalid_requested_runs" } , 400 ) ;
799+ const includeAllClaimed = body . include_all_claimed === true ;
800+ if ( body . include_all_claimed !== undefined && typeof body . include_all_claimed !== "boolean" ) {
801+ return json ( { error : "invalid_include_all_claimed" } , 400 ) ;
802+ }
798803
799- // The workflow_run hook names the exact terminal run. Return at most two matches for
800- // each requested id so a corrupt duplicate remains ambiguous without sampling the first
801- // N unrelated leases. This keeps the response bounded while allowing any live claim in
802- // the durable queue to be reconciled.
804+ // A coalesced workflow_run backstop can scan every live claim. Keep two matches per run
805+ // so corrupt duplicates remain ambiguous, and bound the snapshot to the global worker
806+ // budget so one reconciliation never becomes an unbounded GitHub API fan-out.
803807 const requestedRunIds = new Set ( requestedRuns . map ( ( run ) => run . runId ) ) ;
804808 const matchesByRunId = new Map < string , ExactReviewQueueItem [ ] > ( ) ;
805809 const state = this . readStateSync ( ) ;
806810 for ( const item of Object . values ( state . items ) ) {
807811 if (
808812 item . state !== "leased" ||
809813 ! item . claimedRunId ||
810- ! requestedRunIds . has ( item . claimedRunId )
814+ ( ! includeAllClaimed && ! requestedRunIds . has ( item . claimedRunId ) )
811815 ) {
812816 continue ;
813817 }
814818 const matches = matchesByRunId . get ( item . claimedRunId ) || [ ] ;
815819 if ( matches . length < 2 ) matches . push ( item ) ;
816820 matchesByRunId . set ( item . claimedRunId , matches ) ;
817821 }
818- const runs = [ ...matchesByRunId . values ( ) ] . flatMap ( ( matches ) =>
819- matches . map ( ( item ) => ( {
820- run_id : String ( item . claimedRunId ) ,
821- run_attempt : item . claimedRunAttempt ?? null ,
822- claim_generation : exactReviewClaimGeneration ( item . claimGeneration ) ,
823- } ) ) ,
824- ) ;
822+ const runs = [ ...matchesByRunId . values ( ) ]
823+ . flatMap ( ( matches ) =>
824+ matches . map ( ( item ) => ( {
825+ run_id : String ( item . claimedRunId ) ,
826+ run_attempt : item . claimedRunAttempt ?? null ,
827+ claim_generation : exactReviewClaimGeneration ( item . claimGeneration ) ,
828+ } ) ) ,
829+ )
830+ . slice ( 0 , EXACT_REVIEW_RECONCILE_RUN_LIMIT ) ;
825831 return json ( { runs } ) ;
826832 }
827833
@@ -2213,6 +2219,10 @@ async function authenticatedExactReviewReconcile(request, env) {
22132219 if ( ! body ) return json ( { error : "invalid_json" } , 400 ) ;
22142220 const requestedRuns = exactReviewRequestedRuns ( body . runs ?? body . run_ids ) ;
22152221 if ( ! requestedRuns ) return json ( { error : "invalid_runs" } , 400 ) ;
2222+ const includeAllClaimed = body . include_all_claimed === true ;
2223+ if ( body . include_all_claimed !== undefined && typeof body . include_all_claimed !== "boolean" ) {
2224+ return json ( { error : "invalid_include_all_claimed" } , 400 ) ;
2225+ }
22162226
22172227 const claimedResponse = await exactReviewQueueRequest (
22182228 env ,
@@ -2225,6 +2235,7 @@ async function authenticatedExactReviewReconcile(request, env) {
22252235 run_id : run . runId ,
22262236 ...( run . runAttempt ? { run_attempt : run . runAttempt } : { } ) ,
22272237 } ) ) ,
2238+ ...( includeAllClaimed ? { include_all_claimed : true } : { } ) ,
22282239 } ) ,
22292240 } ) ,
22302241 ) ;
@@ -2233,10 +2244,19 @@ async function authenticatedExactReviewReconcile(request, env) {
22332244 const claimedRuns = exactReviewClaimedRuns ( claimedBody . runs ) ;
22342245 if ( ! claimedRuns ) return json ( { error : "exact_review_queue_unavailable" } , 503 ) ;
22352246 const candidates : Array < ExactReviewClaimedRun & { requestedRunAttempt ?: number } > = [ ] ;
2236- for ( const requested of requestedRuns ) {
2247+ const candidateRequests = includeAllClaimed
2248+ ? [ ...new Set ( claimedRuns . map ( ( claimed ) => claimed . runId ) ) ] . map ( ( runId ) => ( {
2249+ runId,
2250+ runAttempt : undefined ,
2251+ } ) )
2252+ : requestedRuns ;
2253+ for ( const requested of candidateRequests ) {
22372254 const matches = claimedRuns . filter ( ( claimed ) => claimed . runId === requested . runId ) ;
22382255 if ( matches . length !== 1 ) continue ;
2239- candidates . push ( { ...matches [ 0 ] , requestedRunAttempt : requested . runAttempt } ) ;
2256+ candidates . push ( {
2257+ ...matches [ 0 ] ,
2258+ requestedRunAttempt : includeAllClaimed ? matches [ 0 ] . runAttempt : requested . runAttempt ,
2259+ } ) ;
22402260 }
22412261 if ( ! candidates . length ) {
22422262 return json ( {
@@ -2257,17 +2277,19 @@ async function authenticatedExactReviewReconcile(request, env) {
22572277 } catch {
22582278 return json ( { error : "github_run_status_unavailable" } , 502 ) ;
22592279 }
2260- const checked = await mapWithConcurrency (
2261- candidates ,
2262- EXACT_REVIEW_RECONCILE_CONCURRENCY ,
2263- async ( candidate ) => {
2264- try {
2265- return await exactReviewTerminalRun ( token , candidate ) ;
2266- } catch {
2267- return undefined ;
2268- }
2269- } ,
2270- ) ;
2280+ const checked = includeAllClaimed
2281+ ? await exactReviewTerminalRunsFromBatch ( token , candidates )
2282+ : await mapWithConcurrency (
2283+ candidates ,
2284+ EXACT_REVIEW_RECONCILE_CONCURRENCY ,
2285+ async ( candidate ) => {
2286+ try {
2287+ return await exactReviewTerminalRun ( token , candidate ) ;
2288+ } catch {
2289+ return undefined ;
2290+ }
2291+ } ,
2292+ ) ;
22712293 const unavailable = checked . filter ( ( result ) => result === undefined ) . length ;
22722294 const terminalRuns = checked . filter (
22732295 (
@@ -2984,14 +3006,63 @@ async function exactReviewTerminalRun(
29843006 token : string ,
29853007 candidate : ExactReviewClaimedRun & { requestedRunAttempt ?: number } ,
29863008) {
2987- const expectedRunAttempt = candidate . requestedRunAttempt ?? candidate . runAttempt ;
29883009 const latest = await githubTokenJson ( {
29893010 token,
29903011 path : `/repos/${ CLAWSWEEPER_REVIEW_REPO } /actions/runs/${ candidate . runId } ` ,
29913012 method : "GET" ,
29923013 body : undefined ,
29933014 errorLabel : "ClawSweeper run status" ,
29943015 } ) ;
3016+ return exactReviewTerminalRunFromSummary ( token , candidate , latest ) ;
3017+ }
3018+
3019+ async function exactReviewTerminalRunsFromBatch (
3020+ token : string ,
3021+ candidates : Array < ExactReviewClaimedRun & { requestedRunAttempt ?: number } > ,
3022+ ) {
3023+ const runsById = new Map < string , Record < string , unknown > > ( ) ;
3024+ const unresolved = new Set ( candidates . map ( ( candidate ) => candidate . runId ) ) ;
3025+ for ( let page = 1 ; page <= EXACT_REVIEW_RECONCILE_LIST_PAGE_LIMIT ; page += 1 ) {
3026+ let payload ;
3027+ try {
3028+ payload = await githubTokenJson ( {
3029+ token,
3030+ path : `/repos/${ CLAWSWEEPER_REVIEW_REPO } /actions/workflows/sweep.yml/runs?event=repository_dispatch&per_page=100&page=${ page } ` ,
3031+ method : "GET" ,
3032+ body : undefined ,
3033+ errorLabel : "ClawSweeper run batch" ,
3034+ } ) ;
3035+ } catch {
3036+ break ;
3037+ }
3038+ const workflowRuns = Array . isArray ( payload . workflow_runs ) ? payload . workflow_runs : [ ] ;
3039+ for ( const entry of workflowRuns ) {
3040+ const summary = objectValue ( entry ) ;
3041+ const runId = String ( summary . id || "" ) . trim ( ) ;
3042+ if ( ! unresolved . has ( runId ) ) continue ;
3043+ runsById . set ( runId , summary ) ;
3044+ unresolved . delete ( runId ) ;
3045+ }
3046+ if ( ! unresolved . size || workflowRuns . length < 100 ) break ;
3047+ }
3048+ return mapWithConcurrency ( candidates , EXACT_REVIEW_RECONCILE_CONCURRENCY , async ( candidate ) => {
3049+ const summary = runsById . get ( candidate . runId ) ;
3050+ try {
3051+ return summary
3052+ ? await exactReviewTerminalRunFromSummary ( token , candidate , summary )
3053+ : await exactReviewTerminalRun ( token , candidate ) ;
3054+ } catch {
3055+ return undefined ;
3056+ }
3057+ } ) ;
3058+ }
3059+
3060+ async function exactReviewTerminalRunFromSummary (
3061+ token : string ,
3062+ candidate : ExactReviewClaimedRun & { requestedRunAttempt ?: number } ,
3063+ latest : Record < string , unknown > ,
3064+ ) {
3065+ const expectedRunAttempt = candidate . requestedRunAttempt ?? candidate . runAttempt ;
29953066 if ( String ( latest . id || "" ) !== candidate . runId ) {
29963067 throw new Error ( "ClawSweeper run status response id mismatch" ) ;
29973068 }
0 commit comments