Skip to content

Commit f69d9de

Browse files
authored
fix(ci): bound ClawSweeper review fanout (#348)
1 parent ab37a53 commit f69d9de

16 files changed

Lines changed: 222 additions & 98 deletions

‎.github/workflows/sweep.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ on:
7474
shard_count:
7575
description: "Parallel shards (capped by config/automation-limits.json)"
7676
required: false
77-
default: "44"
77+
default: "22"
7878
item_number:
7979
description: "Optional single issue/PR number to review"
8080
required: false

‎README.md‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ source ~/.profile
554554
corepack enable
555555
pnpm install
556556
pnpm run build
557-
pnpm run plan -- --target-repo openclaw/openclaw --batch-size 5 --shard-count 44 --max-pages 250 --codex-model internal --codex-reasoning-effort high
557+
pnpm run plan -- --target-repo openclaw/openclaw --batch-size 5 --shard-count 22 --max-pages 250 --codex-model internal --codex-reasoning-effort high
558558
pnpm run review -- --target-repo openclaw/openclaw --target-dir ../openclaw --batch-size 5 --max-pages 250 --artifact-dir artifacts/reviews --codex-model internal --codex-reasoning-effort high --codex-timeout-ms 600000
559559
pnpm run apply-artifacts -- --target-repo openclaw/openclaw --artifact-dir artifacts/reviews --skip-dashboard
560560
pnpm run audit -- --target-repo openclaw/openclaw --max-pages 250 --sample-limit 25 --update-dashboard
@@ -611,13 +611,13 @@ default, subject to the selected repository profile; pass `target_repo`,
611611
`apply_kind=issue`, or `apply_kind=pull_request` to narrow a manual run.
612612

613613
Scheduled runs cover the configured product profiles. `openclaw/openclaw` runs
614-
normal backfill every 5 minutes with up to 24 review shards when the system is
614+
normal backfill every 5 minutes with up to 12 review shards when the system is
615615
quiet; `openclaw/clawhub` runs on offset review/apply/audit crons so its reports
616616
live under `records/openclaw-clawhub/` without colliding with default repo
617617
records. `openclaw/clawsweeper` has a scheduled read-only audit row and is
618618
available for manual and event self-review smoke tests. Broad hot-intake sweeps
619-
cap scheduled fan-out at 22 one-item shards per run when quiet; manual normal
620-
backfill can use up to 44 shards, while exact event reviews still use one shard.
619+
cap scheduled fan-out at 11 one-item shards per run when quiet; manual normal
620+
backfill can use up to 22 shards, while exact event reviews still use one shard.
621621
Normal review, hot intake, and commit review are
622622
background lanes, so they shrink automatically while repair or exact-item work
623623
is active. Throughput defaults live in
@@ -626,17 +626,18 @@ is active. Throughput defaults live in
626626
### Worker Budget
627627

628628
ClawSweeper has one main capacity knob:
629-
`config/automation-limits.json` -> `workers.max`. The current value is `64`.
630-
Lane limits are derived from that number: normal review defaults to 44 shards
631-
for manual/backstop runs, scheduled normal review gets up to 24 after reserves,
632-
hot intake up to 22 shards, commit review 3 commits per page, and existing
633-
repair/issue implementation lanes use 40% of `workers.max`, currently 25 live
629+
`config/automation-limits.json` -> `workers.max`. The current value is `32`.
630+
Lane limits are derived from that number: normal review defaults to 22 shards
631+
for manual/backstop runs, scheduled normal review gets up to 12 after reserves,
632+
hot intake up to 11 shards, commit review 1 commit per page, and existing
633+
repair/issue implementation lanes use 40% of `workers.max`, currently 12 live
634634
workers. Imported gitcrawl cluster repair allows 2 live workers by default.
635635
Exact-item review, repair, and issue implementation are priority work; normal
636636
review, hot intake, and commit review are background work and automatically
637637
yield when priority work is active. Exact-item runs use a durable Worker queue
638-
that coalesces item deliveries and leases at most 8 concurrent reviews. Other
639-
lanes retain the existing global 64-worker scheduling model.
638+
that coalesces item deliveries, leases at most 4 concurrent reviews, and admits
639+
at most one active exact review per target repository. Other lanes retain the
640+
checked-in 32-worker scheduling model.
640641
Use `workers.max` first when turning total Codex usage up or down; use
641642
`lanes.repair.cluster_max_live_runs` to tune the imported legacy cluster-repair
642643
lane separately, and individual environment overrides only for temporary

‎config/automation-limits.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"workers": {
3-
"max": 64,
4-
"reserve_for_interactive": 16,
5-
"expansion_reserve": 24,
6-
"minimum_background": 8
3+
"max": 32,
4+
"reserve_for_interactive": 8,
5+
"expansion_reserve": 12,
6+
"minimum_background": 4
77
},
88
"lanes": {
99
"exact_review": {
10-
"max_concurrent": 8
10+
"max_concurrent": 4
1111
},
1212
"assist": {
1313
"max": 10

‎dashboard/worker.ts‎

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const CLOSED_STATS_PAGE_LIMIT = 10;
7171
const DEFAULT_CLAWSWEEPER_BOT_LOGINS = ["clawsweeper[bot]", "openclaw-clawsweeper[bot]"];
7272
const GITHUB_TIMEOUT_MS = 4500;
7373
const DEFAULT_STALE_QUEUED_WORKFLOW_MS = 6 * 60 * 60 * 1000;
74-
const DEFAULT_EXACT_REVIEW_QUEUE_MAX_CONCURRENT = 8;
74+
const DEFAULT_EXACT_REVIEW_QUEUE_MAX_CONCURRENT = 4;
75+
const DEFAULT_EXACT_REVIEW_TARGET_MAX_CONCURRENT = 1;
7576
const DEFAULT_EXACT_REVIEW_DISPATCH_LEASE_MS = 10 * 60 * 1000;
7677
const DEFAULT_EXACT_REVIEW_EXECUTION_LEASE_MS = 130 * 60 * 1000;
7778
const DEFAULT_EXACT_REVIEW_RETRY_MS = 30_000;
@@ -444,10 +445,24 @@ export class ExactReviewQueue {
444445
let changed = reclaimExpiredExactReviewLeases(state, now);
445446
const capacity = exactReviewQueueCapacity(this.env);
446447
const slots = Math.max(0, capacity - exactReviewQueueActiveCount(state));
447-
const admitted = Object.values(state.items)
448+
const activeTargets = new Map<string, number>();
449+
for (const item of Object.values(state.items)) {
450+
if (item.state !== "dispatching" && item.state !== "leased") continue;
451+
const target = item.decision.targetRepo;
452+
activeTargets.set(target, (activeTargets.get(target) || 0) + 1);
453+
}
454+
const admitted: ExactReviewQueueItem[] = [];
455+
const pending = Object.values(state.items)
448456
.filter((item) => item.state === "pending" && item.nextAttemptAt <= now)
449-
.sort((left, right) => left.createdAt - right.createdAt || left.key.localeCompare(right.key))
450-
.slice(0, slots);
457+
.sort((left, right) => left.createdAt - right.createdAt || left.key.localeCompare(right.key));
458+
for (const item of pending) {
459+
if (admitted.length >= slots) break;
460+
const target = item.decision.targetRepo;
461+
const active = activeTargets.get(target) || 0;
462+
if (active >= DEFAULT_EXACT_REVIEW_TARGET_MAX_CONCURRENT) continue;
463+
activeTargets.set(target, active + 1);
464+
admitted.push(item);
465+
}
451466

452467
for (const item of admitted) {
453468
item.state = "dispatching";
@@ -501,7 +516,7 @@ export class ExactReviewQueue {
501516
}
502517

503518
private async scheduleNext(state: ExactReviewQueueState, now: number) {
504-
const next = exactReviewQueueNextWakeAt(state, now);
519+
const next = exactReviewQueueNextWakeAt(state, now, exactReviewQueueCapacity(this.env));
505520
if (next === null) {
506521
await this.storage.deleteAlarm();
507522
return;
@@ -1169,11 +1184,44 @@ function exactReviewQueueStats(state: ExactReviewQueueState) {
11691184
};
11701185
}
11711186

1172-
function exactReviewQueueNextWakeAt(state: ExactReviewQueueState, now: number) {
1187+
function exactReviewQueueNextWakeAt(
1188+
state: ExactReviewQueueState,
1189+
now: number,
1190+
capacity = Number.POSITIVE_INFINITY,
1191+
) {
11731192
const items = Object.values(state.items);
11741193
if (!items.length) return null;
1194+
const activeItems = items.filter(
1195+
(item) => item.state === "dispatching" || item.state === "leased",
1196+
);
1197+
const activeLeaseWakeAt = activeItems
1198+
.map((item) => item.leaseExpiresAt)
1199+
.filter((value): value is number => Boolean(value && value > now));
1200+
if (activeItems.some((item) => !item.leaseExpiresAt || item.leaseExpiresAt <= now)) {
1201+
return now + 1_000;
1202+
}
1203+
if (activeItems.length >= capacity && activeLeaseWakeAt.length) {
1204+
return Math.max(now + 1_000, Math.min(...activeLeaseWakeAt));
1205+
}
1206+
const activeTargetWakeAt = new Map<string, number>();
1207+
for (const item of items) {
1208+
if (
1209+
(item.state === "dispatching" || item.state === "leased") &&
1210+
item.leaseExpiresAt &&
1211+
item.leaseExpiresAt > now
1212+
) {
1213+
const current = activeTargetWakeAt.get(item.decision.targetRepo);
1214+
activeTargetWakeAt.set(
1215+
item.decision.targetRepo,
1216+
current === undefined ? item.leaseExpiresAt : Math.min(current, item.leaseExpiresAt),
1217+
);
1218+
}
1219+
}
11751220
const times = items.flatMap((item) => {
1176-
if (item.state === "pending") return [item.nextAttemptAt];
1221+
if (item.state === "pending") {
1222+
const blockedUntil = activeTargetWakeAt.get(item.decision.targetRepo);
1223+
return [blockedUntil ?? item.nextAttemptAt];
1224+
}
11771225
return item.leaseExpiresAt ? [item.leaseExpiresAt] : [];
11781226
});
11791227
if (!times.length) return now + DEFAULT_EXACT_REVIEW_RETRY_MS;
@@ -1192,7 +1240,7 @@ export function exactReviewQueueCapacity(env) {
11921240
return Math.max(
11931241
1,
11941242
Math.min(
1195-
64,
1243+
32,
11961244
numberFrom(env.EXACT_REVIEW_QUEUE_MAX_CONCURRENT, DEFAULT_EXACT_REVIEW_QUEUE_MAX_CONCURRENT),
11971245
),
11981246
);
@@ -1585,7 +1633,7 @@ async function statusSnapshot(env) {
15851633
.split(",")
15861634
.map((value) => value.trim())
15871635
.filter(Boolean);
1588-
const budget = numberFrom(env.WORKER_BUDGET, 64);
1636+
const budget = numberFrom(env.WORKER_BUDGET, 32);
15891637
const [runs, completedRuns, filteredActiveRuns] = await Promise.all([
15901638
githubJson(env, `/repos/${repo}/actions/runs?per_page=100`).catch((error) => {
15911639
errors.push(`workflow runs: ${error.message}`);

‎dashboard/wrangler.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CLAWSWEEPER_REPO = "openclaw/clawsweeper"
2929
CLAWSWEEPER_APP_CLIENT_ID = "Iv23liOECG0slfuhz093"
3030
CLAWSWEEPER_CRABFLEET_URL = "https://crabfleet.openclaw.ai"
3131
TARGET_REPOS = "openclaw/openclaw,openclaw/clawhub,openclaw/clawsweeper,openclaw/fs-safe"
32-
WORKER_BUDGET = "64"
32+
WORKER_BUDGET = "32"
3333
WORKER_DETAIL_RUN_LIMIT = "128"
3434
WORKER_JOB_FETCH_CONCURRENCY = "12"
3535
WORKER_JOB_CACHE_TTL_SECONDS = "60"
@@ -39,6 +39,6 @@ AUTOMERGE_CACHE_TTL_SECONDS = "300"
3939
RECENT_CLOSED_CACHE_TTL_SECONDS = "300"
4040
CACHE_TTL_SECONDS = "20"
4141
INCLUDE_CI_STATUS = "1"
42-
EXACT_REVIEW_QUEUE_MAX_CONCURRENT = "8"
42+
EXACT_REVIEW_QUEUE_MAX_CONCURRENT = "4"
4343
EXACT_REVIEW_DISPATCH_LEASE_MS = "600000"
4444
EXACT_REVIEW_EXECUTION_LEASE_MS = "7800000"

‎docs/commit-dispatcher.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ CLAWSWEEPER_COMMIT_REVIEW_SETTLE_SECONDS=60
107107
Use `0` for settled manual backfills or a larger value during GitHub event
108108
lag incidents.
109109

110-
Commit review is a background lane. It defaults to 3 commits per workflow page
110+
Commit review is a background lane. It defaults to 1 commit per workflow page
111111
when the system is quiet, but the receiver asks the central worker scheduler for
112112
capacity before each page. Active repair, exact-item review, and sweep work can
113113
lower the page size so commit review does not consume capacity needed by
@@ -116,10 +116,10 @@ maintainer-visible work. The checked-in default comes from
116116
`openclaw/clawsweeper` only when the org has enough rate-limit headroom:
117117

118118
```text
119-
CLAWSWEEPER_COMMIT_REVIEW_PAGE_SIZE=3
119+
CLAWSWEEPER_COMMIT_REVIEW_PAGE_SIZE=1
120120
```
121121

122-
The receiver clamps this between 1 and 64. Setting the variable bypasses the
122+
The receiver clamps this between 1 and 32. Setting the variable bypasses the
123123
dynamic default for that run; leave it unset when the central scheduler should
124124
decide. Large push ranges continue in later workflow pages.
125125

‎docs/commit-sweeper.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ by SHA/range rather than detaching the whole target repository at the commit.
8989

9090
## Scaling
9191

92-
Commit Sweeper is background work. It defaults to 3 commits per workflow page
92+
Commit Sweeper is background work. It defaults to 1 commit per workflow page
9393
when the system is quiet, but the receiver asks the central worker scheduler for
9494
the effective page size before dispatching the matrix. Active repair,
9595
exact-item review, and sweep work can lower commit review to keep capacity
9696
available for maintainer-visible work. The checked-in default lives in
9797
`config/automation-limits.json`. The receiver clamps
98-
`CLAWSWEEPER_COMMIT_REVIEW_PAGE_SIZE` between 1 and 64, then pages large ranges:
98+
`CLAWSWEEPER_COMMIT_REVIEW_PAGE_SIZE` between 1 and 32, then pages large ranges:
9999

100100
- select up to the configured page size
101101
- classify them cheaply

‎docs/limits.md‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,40 @@ The mental model:
3333

3434
| Name | Current | Meaning |
3535
| --- | ---: | --- |
36-
| `workers.max` | 64 | Maximum global Codex worker budget used to derive lane limits. |
37-
| `workers.reserve_for_interactive` | 16 | Worker slots background lanes leave open for exact/manual/urgent work. |
38-
| `workers.expansion_reserve` | 24 | Extra slots background lanes leave open for independently planned matrix expansion. |
39-
| `workers.minimum_background` | 8 | Target floor for background progress when enough global capacity is available. |
40-
| `lanes.exact_review.max_concurrent` | 8 | Maximum concurrent exact-item review workflow runs admitted to Codex. |
36+
| `workers.max` | 32 | Maximum global Codex worker budget used to derive lane limits. |
37+
| `workers.reserve_for_interactive` | 8 | Worker slots background lanes leave open for exact/manual/urgent work. |
38+
| `workers.expansion_reserve` | 12 | Extra slots background lanes leave open for independently planned matrix expansion. |
39+
| `workers.minimum_background` | 4 | Target floor for background progress when enough global capacity is available. |
40+
| `lanes.exact_review.max_concurrent` | 4 | Maximum concurrent exact-item review workflow runs admitted to Codex. |
4141
| `lanes.assist.max` | 10 | Maximum concurrent lightweight assist jobs. |
4242
| `lanes.repair.cluster_max_live_runs` | 2 | Default live repair workflow cap for imported gitcrawl cluster dispatches. |
4343

4444
## Derived Limits
4545

4646
Review, commit, and existing repair limits are intentionally percentages of
4747
`workers.max`; imported cluster repair has its own lane knob. With
48-
`workers.max = 64`, normal review can use 44 workers, hot intake can use 22,
49-
commit review can use 3 commits per page, existing repair lanes dispatch 25
48+
`workers.max = 32`, normal review can use 22 workers, hot intake can use 11,
49+
commit review can use 1 commit per page, existing repair lanes dispatch 12
5050
live workers by default, and imported cluster repair dispatches two live workers
5151
by default.
5252

5353
| Name | Current | Meaning |
5454
| --- | ---: | --- |
55-
| `exact_review.concurrent_max` | 8 | Exact-item review admission cap, clamped to `workers.max`. |
55+
| `exact_review.concurrent_max` | 4 | Exact-item review admission cap, clamped to `workers.max`. |
5656
| `assist.default` | 10 | Maintainer assist job cap. |
57-
| `review_shards.normal_default` | 44 | Quiet-system normal review shard ceiling. |
58-
| `review_shards.normal_active_floor` | 19 | Minimum active normal review shards to keep queued for `openclaw/openclaw`. |
59-
| `review_shards.hot_intake_default` | 22 | Quiet-system broad hot-intake review shard ceiling. |
57+
| `review_shards.normal_default` | 22 | Quiet-system normal review shard ceiling. |
58+
| `review_shards.normal_active_floor` | 9 | Minimum active normal review shards to keep queued for `openclaw/openclaw`. |
59+
| `review_shards.hot_intake_default` | 11 | Quiet-system broad hot-intake review shard ceiling. |
6060
| `review_shards.exact_item_default` | 1 | Exact-item hot-intake shard count. |
61-
| `review_shards.hard_cap` | 64 | Maximum accepted review shard count. |
62-
| `commit_review.page_size_default` | 3 | Commits selected per commit-review page. |
63-
| `commit_review.page_size_hard_cap` | 64 | Maximum commit-review page size. |
64-
| `repair_live_runs.default` | 25 | Default live repair workflow run cap for manual dispatch/requeue/self-heal. |
65-
| `repair_live_runs.hard_cap` | 64 | Absolute live repair run cap accepted by explicit CLI/env overrides with this config. |
66-
| `repair_live_runs.automerge_default` | 25 | Live repair run cap for automerge comment-router dispatches. |
67-
| `repair_live_runs.issue_implementation_default` | 25 | Live repair run cap for issue-to-PR implementation intake. |
61+
| `review_shards.hard_cap` | 32 | Maximum accepted review shard count. |
62+
| `commit_review.page_size_default` | 1 | Commits selected per commit-review page. |
63+
| `commit_review.page_size_hard_cap` | 32 | Maximum commit-review page size. |
64+
| `repair_live_runs.default` | 12 | Default live repair workflow run cap for manual dispatch/requeue/self-heal. |
65+
| `repair_live_runs.hard_cap` | 32 | Absolute live repair run cap accepted by explicit CLI/env overrides with this config. |
66+
| `repair_live_runs.automerge_default` | 12 | Live repair run cap for automerge comment-router dispatches. |
67+
| `repair_live_runs.issue_implementation_default` | 12 | Live repair run cap for issue-to-PR implementation intake. |
6868
| `repair_live_runs.cluster_default` | 2 | Live repair run cap for imported gitcrawl cluster dispatches. |
69-
| `issue_implementation.dispatches_per_sweep_default` | 2 | Maximum implementation intake jobs queued from one review publish run. |
69+
| `issue_implementation.dispatches_per_sweep_default` | 1 | Maximum implementation intake jobs queued from one review publish run. |
7070

7171
Formula summary:
7272

@@ -114,7 +114,7 @@ Exact-item webhooks are admitted by the dashboard Worker's durable
114114
deliveries by repository and item number, so a new webhook updates the latest
115115
desired review rather than consuming another runner. Only
116116
`EXACT_REVIEW_QUEUE_MAX_CONCURRENT` leased items may dispatch an exact-review
117-
workflow at once; the default is 8.
117+
workflow at once; the default is 4.
118118

119119
Each dispatched workflow claims its opaque lease before checkout. Duplicate
120120
dispatches and stale workflows cannot claim the same lease, and a completion
@@ -124,13 +124,13 @@ keeps capacity waiting and retry state out of GitHub Actions runners.
124124

125125
Examples with the current config:
126126

127-
- Quiet system: manual normal review can request 44 shards; scheduled normal
128-
review gets 24 after reserving 16 slots for exact/manual/urgent work and 24
127+
- Quiet system: manual normal review can request 22 shards; scheduled normal
128+
review gets 12 after reserving 8 slots for exact/manual/urgent work and 12
129129
slots for in-flight matrix expansion.
130-
- 4 active repair workers and 20 active background workers: normal review gets
131-
1 because `64 - 16 interactive reserve - 24 expansion reserve - 4 priority
132-
- 20 background = 0`, and enabled background lanes keep one slow-progress worker.
133-
- 48 active priority workers: commit review gets 1, so commit review yields but
130+
- 4 active repair workers and 8 active background workers: normal review gets
131+
1 because `32 - 8 interactive reserve - 12 expansion reserve - 4 priority
132+
- 8 background = 0`, and enabled background lanes keep one slow-progress worker.
133+
- 24 active priority workers: commit review gets 1, so commit review yields but
134134
does not fully stall.
135135

136136
Use these commands to inspect the effective values from a checkout:
@@ -143,8 +143,8 @@ pnpm run --silent workflow -- worker-limit commit_review --active-critical 88
143143
```
144144

145145
Change `workers.max` first when tuning review-side rate-limit pressure. For
146-
example, setting `workers.max` to `90` automatically makes normal review `63`,
147-
hot intake `31`, and commit review `4`. Existing repair lanes keep their
146+
example, setting `workers.max` to `40` automatically makes normal review `28`,
147+
hot intake `14`, and commit review `2`. Existing repair lanes keep their
148148
40% derived caps, while imported cluster repair remains separately bounded until
149149
`lanes.repair.cluster_max_live_runs` is raised.
150150

‎docs/live-dashboard.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ The Worker fetches job details only for the bounded active-run set, limits that
130130
GitHub fanout to 12 concurrent requests, and caches each run's jobs for 60
131131
seconds. It separately samples 20 recent completed worker runs with ten-way
132132
fanout and caches error/recovery telemetry for 120 seconds. This bounds
133-
telemetry pressure without reducing the 64-worker fleet budget. Worker details
134-
paginate up to 300 jobs per workflow run so 44-shard runs remain fully visible,
133+
telemetry pressure without exceeding the 32-worker fleet budget. Worker details
134+
paginate up to 300 jobs per workflow run so 22-shard runs remain fully visible,
135135
then finish before optional pipeline CI and historical
136136
enrichment begin, so those secondary lookups do not compete with active worker
137137
telemetry. If GitHub job telemetry is unavailable, the API and UI retain the

0 commit comments

Comments
 (0)