Skip to content

Commit dc17440

Browse files
committed
fix: restore exact-review throughput
1 parent 97e8237 commit dc17440

13 files changed

Lines changed: 181 additions & 70 deletions

‎.github/workflows/exact-review-reconcile.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ env:
1212
CLAWSWEEPER_APP_CLIENT_ID: Iv23liOECG0slfuhz093
1313

1414
concurrency:
15-
group: exact-review-reconcile-${{ github.event.workflow_run.id }}
15+
# Exact-review completions share one pending slot. Each surviving run scans all
16+
# live claims, so GitHub may safely coalesce a burst without losing a terminal run.
17+
group: exact-review-reconcile-${{ github.event.workflow_run.event == 'repository_dispatch' && startsWith(github.event.workflow_run.display_title, 'Review event item ') && 'queue' || github.event.workflow_run.id }}
1618
cancel-in-progress: false
1719

1820
jobs:

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ checkpoint, and status-only commits are intentionally omitted.
5858

5959
### Changed
6060

61+
- Raised exact-review capacity from 48/44 global/per-target workers to 64/60, shortened unclaimed dispatch recovery from ten to six minutes, and coalesced terminal-run reconciliation bursts into one bounded aggregate claim scan.
6162
- Expanded exact-review backlog capacity while making background review yield, released exact-review leases before ledger publication, and aggregated healthy retry scans into one bounded ledger summary.
6263
- Accepted package-manager argument separators in the action-ledger CLI and
6364
allowed proven zero-command router runs to finish without empty publication.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,8 @@ workers. Imported gitcrawl cluster repair allows 2 live workers by default.
759759
Exact-item review, repair, and issue implementation are priority work; normal
760760
review, hot intake, and commit review are background work and automatically
761761
yield when priority work is active. Exact-item runs use a durable Worker queue
762-
that coalesces item deliveries, leases at most 48 concurrent reviews, and admits
763-
up to 44 active exact reviews per target repository. Other lanes retain the
762+
that coalesces item deliveries, leases at most 64 concurrent reviews, and admits
763+
up to 60 active exact reviews per target repository. Other lanes retain the
764764
checked-in 128-worker scheduling model.
765765
Use `workers.max` first when turning total Codex usage up or down; use
766766
`lanes.repair.cluster_max_live_runs` to tune the imported legacy cluster-repair

‎config/automation-limits.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
},
88
"lanes": {
99
"exact_review": {
10-
"max_concurrent": 48,
11-
"target_max_concurrent": 44
10+
"max_concurrent": 64,
11+
"target_max_concurrent": 60
1212
},
1313
"assist": {
1414
"max": 10

‎dashboard/worker.ts‎

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,17 @@ const CLOSED_STATS_PAGE_LIMIT = 10;
123123
const DEFAULT_CLAWSWEEPER_BOT_LOGINS = ["clawsweeper[bot]", "openclaw-clawsweeper[bot]"];
124124
const GITHUB_TIMEOUT_MS = 4500;
125125
const 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;
129129
const DEFAULT_EXACT_REVIEW_EXECUTION_LEASE_MS = 130 * 60 * 1000;
130130
const DEFAULT_EXACT_REVIEW_RETRY_MS = 30_000;
131131
const DEFAULT_EXACT_REVIEW_WORKFLOW_PAUSED_RETRY_MS = 60_000;
132132
const 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;
134134
const 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.
138139
const 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
}

‎dashboard/wrangler.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ AUTOMERGE_CACHE_TTL_SECONDS = "300"
4141
RECENT_CLOSED_CACHE_TTL_SECONDS = "300"
4242
CACHE_TTL_SECONDS = "20"
4343
INCLUDE_CI_STATUS = "1"
44-
EXACT_REVIEW_QUEUE_MAX_CONCURRENT = "48"
45-
EXACT_REVIEW_TARGET_MAX_CONCURRENT = "44"
46-
EXACT_REVIEW_DISPATCH_LEASE_MS = "600000"
44+
EXACT_REVIEW_QUEUE_MAX_CONCURRENT = "64"
45+
EXACT_REVIEW_TARGET_MAX_CONCURRENT = "60"
46+
EXACT_REVIEW_DISPATCH_LEASE_MS = "360000"
4747
EXACT_REVIEW_EXECUTION_LEASE_MS = "7800000"
4848
EXACT_REVIEW_WORKFLOW_PAUSED_RETRY_MS = "60000"

‎docs/limits.md‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ The mental model:
3737
| `workers.reserve_for_interactive` | 16 | Worker slots background lanes leave open for exact/manual/urgent work. |
3838
| `workers.expansion_reserve` | 8 | Extra slots background lanes leave open for independently planned matrix expansion. |
3939
| `workers.minimum_background` | 16 | Target floor for background progress when enough global capacity is available. |
40-
| `lanes.exact_review.max_concurrent` | 48 | Maximum concurrent exact-item review workflow runs admitted to Codex. |
41-
| `lanes.exact_review.target_max_concurrent` | 44 | Maximum concurrent exact-item review workflow runs one target repository may consume. |
40+
| `lanes.exact_review.max_concurrent` | 64 | Maximum concurrent exact-item review workflow runs admitted to Codex. |
41+
| `lanes.exact_review.target_max_concurrent` | 60 | Maximum concurrent exact-item review workflow runs one target repository may consume. |
4242
| `lanes.assist.max` | 10 | Maximum concurrent lightweight assist jobs. |
4343
| `lanes.repair.cluster_max_live_runs` | 2 | Default live repair workflow cap for imported gitcrawl cluster dispatches. |
4444

@@ -53,8 +53,8 @@ by default.
5353

5454
| Name | Current | Meaning |
5555
| --------------------------------------------------- | ------: | ------------------------------------------------------------------------------------- |
56-
| `exact_review.concurrent_max` | 48 | Exact-item review admission cap, clamped to `workers.max`. |
57-
| `exact_review.target_concurrent_max` | 44 | Exact-item per-target admission cap, clamped to global exact-review capacity. |
56+
| `exact_review.concurrent_max` | 64 | Exact-item review admission cap, clamped to `workers.max`. |
57+
| `exact_review.target_concurrent_max` | 60 | Exact-item per-target admission cap, clamped to global exact-review capacity. |
5858
| `assist.default` | 10 | Maintainer assist job cap. |
5959
| `review_shards.normal_default` | 89 | Quiet-system normal review shard ceiling. |
6060
| `review_shards.normal_active_floor` | 38 | Minimum active normal review shards to keep queued for `openclaw/openclaw`. |
@@ -117,9 +117,9 @@ Exact-item webhooks are admitted by the dashboard Worker's durable
117117
deliveries by repository and item number, so a new webhook updates the latest
118118
desired review rather than consuming another runner. Only
119119
`EXACT_REVIEW_QUEUE_MAX_CONCURRENT` leased items may dispatch an exact-review
120-
workflow at once; the default is 48. `EXACT_REVIEW_TARGET_MAX_CONCURRENT` bounds
120+
workflow at once; the default is 64. `EXACT_REVIEW_TARGET_MAX_CONCURRENT` bounds
121121
how many of those slots one target repository may consume; production sets it
122-
to 44 so other target repositories retain four global slots during an OpenClaw
122+
to 60 so other target repositories retain four global slots during an OpenClaw
123123
backlog drain. Exact capacity is consumed only while queue work is pending. As
124124
those priority workers start, normal, hot-intake, and commit-review planners
125125
count them and reduce their next background wave.
@@ -134,7 +134,14 @@ immediately schedules a known newer revision. Failed and cancelled executors
134134
requeue their item with bounded retry backoff. Successful finalizer reports stay
135135
leased until a signed terminal-run reconciliation backstop confirms that exact
136136
GitHub attempt completed successfully; this backstop can also recover terminal
137-
failed or cancelled runs before lease expiry.
137+
failed or cancelled runs before lease expiry. Completion triggers share one
138+
running and one pending reconciler; each surviving run inspects every live claim
139+
against bounded workflow-run pages, then verifies only matching terminal attempts.
140+
Candidates absent from those pages fall back to exact run lookup. This keeps
141+
steady-state GitHub API work constant without losing an older claim, while a
142+
terminal burst does not consume one Actions runner per review. Unclaimed
143+
dispatches expire after six minutes and receive a new opaque lease; delayed
144+
workflows holding the expired lease cannot claim it.
138145
Run-attempt binding and a per-claim generation check keep delayed terminal
139146
decisions from releasing a later rerun; queued and in-progress runs are never
140147
released. If a workflow never claims or completes, the Durable Object reclaims

‎docs/live-dashboard.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Do not move these into the dashboard:
175175

176176
The dashboard Worker owns durable exact-review admission only: it deduplicates
177177
webhook deliveries, coalesces each repository/item pair, and leases at most
178-
48 Actions executors, with up to 44 active leases per target repository. It does
178+
64 Actions executors, with up to 60 active leases per target repository. It does
179179
not decide review outcomes or perform target repository mutations. For
180180
command-triggered reviews, the queue retains the bounded review prompt and
181181
command-status identifiers so the leased GitHub Actions executor can update the

‎docs/target-dispatcher.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ endpoint is `/github/webhook`; the local equivalent is
239239
target installation token for acknowledgement/comment reactions, mints the
240240
`openclaw/clawsweeper` installation token for repository dispatch, and queues
241241
exact `clawsweeper_comment` or `clawsweeper_item` work. The durable Worker
242-
queue dispatches at most 48 leased exact-review executors, with up to 44 active
242+
queue dispatches at most 64 leased exact-review executors, with up to 60 active
243243
reviews per target repository. Keep the Actions
244244
dispatcher installed as a compatibility fallback; its legacy dispatch is
245245
bridged into the same queue before Codex starts.

‎src/repair/exact-review-action-ledger.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function runExactReviewQueueCommand(
3838
const fetchImpl = dependencies.fetch ?? fetch;
3939
const sleep = dependencies.sleep ?? defaultSleep;
4040
const attempts = dependencies.attempts ?? 3;
41-
const timeoutMs = dependencies.timeoutMs ?? 20_000;
41+
const timeoutMs = dependencies.timeoutMs ?? (command === "reconcile" ? 120_000 : 20_000);
4242
if (!Number.isSafeInteger(attempts) || attempts < 1 || attempts > 10) {
4343
throw new Error("exact-review request attempt count is invalid");
4444
}
@@ -260,6 +260,7 @@ function reconcileRequest(env: NodeJS.ProcessEnv): ExactReviewQueueRequest {
260260
run_attempt: sourceRunAttempt,
261261
},
262262
],
263+
include_all_claimed: true,
263264
};
264265
const repository = normalizedRepository(env.GITHUB_REPOSITORY ?? "openclaw/clawsweeper");
265266
return signedRequest("reconcile", env, payload, repository, null, {

0 commit comments

Comments
 (0)