@@ -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,18 +2277,32 @@ 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 ;
2294+ const requiredUnavailable = checked . filter ( ( result , index ) => {
2295+ const candidate = candidates [ index ] ;
2296+ return (
2297+ result === undefined &&
2298+ ( ! includeAllClaimed ||
2299+ requestedRuns . some (
2300+ ( requested ) =>
2301+ requested . runId === candidate ?. runId &&
2302+ ( requested . runAttempt === undefined || requested . runAttempt === candidate . runAttempt ) ,
2303+ ) )
2304+ ) ;
2305+ } ) . length ;
22722306 const terminalRuns = checked . filter (
22732307 (
22742308 result ,
@@ -2301,14 +2335,14 @@ async function authenticatedExactReviewReconcile(request, env) {
23012335 }
23022336 return json (
23032337 {
2304- ok : unavailable === 0 ,
2338+ ok : requiredUnavailable === 0 ,
23052339 requested : requestedRuns . length ,
23062340 claimed : candidates . length ,
23072341 terminal : terminalRuns . length ,
23082342 unavailable,
23092343 ...reconciliation ,
23102344 } ,
2311- unavailable ? 502 : 200 ,
2345+ requiredUnavailable ? 502 : 200 ,
23122346 ) ;
23132347}
23142348
@@ -2984,14 +3018,63 @@ async function exactReviewTerminalRun(
29843018 token : string ,
29853019 candidate : ExactReviewClaimedRun & { requestedRunAttempt ?: number } ,
29863020) {
2987- const expectedRunAttempt = candidate . requestedRunAttempt ?? candidate . runAttempt ;
29883021 const latest = await githubTokenJson ( {
29893022 token,
29903023 path : `/repos/${ CLAWSWEEPER_REVIEW_REPO } /actions/runs/${ candidate . runId } ` ,
29913024 method : "GET" ,
29923025 body : undefined ,
29933026 errorLabel : "ClawSweeper run status" ,
29943027 } ) ;
3028+ return exactReviewTerminalRunFromSummary ( token , candidate , latest ) ;
3029+ }
3030+
3031+ async function exactReviewTerminalRunsFromBatch (
3032+ token : string ,
3033+ candidates : Array < ExactReviewClaimedRun & { requestedRunAttempt ?: number } > ,
3034+ ) {
3035+ const runsById = new Map < string , Record < string , unknown > > ( ) ;
3036+ const unresolved = new Set ( candidates . map ( ( candidate ) => candidate . runId ) ) ;
3037+ for ( let page = 1 ; page <= EXACT_REVIEW_RECONCILE_LIST_PAGE_LIMIT ; page += 1 ) {
3038+ let payload ;
3039+ try {
3040+ payload = await githubTokenJson ( {
3041+ token,
3042+ path : `/repos/${ CLAWSWEEPER_REVIEW_REPO } /actions/workflows/sweep.yml/runs?event=repository_dispatch&per_page=100&page=${ page } ` ,
3043+ method : "GET" ,
3044+ body : undefined ,
3045+ errorLabel : "ClawSweeper run batch" ,
3046+ } ) ;
3047+ } catch {
3048+ break ;
3049+ }
3050+ const workflowRuns = Array . isArray ( payload . workflow_runs ) ? payload . workflow_runs : [ ] ;
3051+ for ( const entry of workflowRuns ) {
3052+ const summary = objectValue ( entry ) ;
3053+ const runId = String ( summary . id || "" ) . trim ( ) ;
3054+ if ( ! unresolved . has ( runId ) ) continue ;
3055+ runsById . set ( runId , summary ) ;
3056+ unresolved . delete ( runId ) ;
3057+ }
3058+ if ( ! unresolved . size || workflowRuns . length < 100 ) break ;
3059+ }
3060+ return mapWithConcurrency ( candidates , EXACT_REVIEW_RECONCILE_CONCURRENCY , async ( candidate ) => {
3061+ const summary = runsById . get ( candidate . runId ) ;
3062+ try {
3063+ return summary
3064+ ? await exactReviewTerminalRunFromSummary ( token , candidate , summary )
3065+ : await exactReviewTerminalRun ( token , candidate ) ;
3066+ } catch {
3067+ return undefined ;
3068+ }
3069+ } ) ;
3070+ }
3071+
3072+ async function exactReviewTerminalRunFromSummary (
3073+ token : string ,
3074+ candidate : ExactReviewClaimedRun & { requestedRunAttempt ?: number } ,
3075+ latest : Record < string , unknown > ,
3076+ ) {
3077+ const expectedRunAttempt = candidate . requestedRunAttempt ?? candidate . runAttempt ;
29953078 if ( String ( latest . id || "" ) !== candidate . runId ) {
29963079 throw new Error ( "ClawSweeper run status response id mismatch" ) ;
29973080 }
0 commit comments