Skip to content

Commit a52b852

Browse files
steipetebrokemac79
andauthored
feat: adapt apply scan window (#406)
Expand skip-heavy zero-close scans without changing close or worker limits, preserve close-health telemetry across comment sync, and extract apply helpers so GitHub can validate the workflow. Co-authored-by: brokemac79 <[email protected]>
1 parent 26ccb0e commit a52b852

9 files changed

Lines changed: 446 additions & 91 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,7 @@ jobs:
23102310
run: |
23112311
set -euo pipefail
23122312
test -n "$GH_TOKEN"
2313+
source scripts/apply-workflow-helpers.sh
23132314
limit="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_limit || '20' }}"
23142315
min_age_days="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_min_age_days || '0' }}"
23152316
min_age_minutes="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_min_age_minutes || '' }}"
@@ -2320,7 +2321,12 @@ jobs:
23202321
progress_every="10"
23212322
checkpoint_size="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_checkpoint_size || '20' }}"
23222323
comment_sync_processed_limit=1000
2323-
close_processed_limit=300
2324+
base_close_processed_limit=300
2325+
# Consumed by the sourced workflow helpers.
2326+
# shellcheck disable=SC2034
2327+
max_close_processed_limit=900
2328+
close_processed_limit="$base_close_processed_limit"
2329+
adaptive_apply_scan_reason="base_window"
23242330
sync_batch_size="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.apply_limit || '25' }}"
23252331
item_numbers="${{ github.event_name == 'repository_dispatch' && github.event.client_payload.item_number || github.event.inputs.apply_item_numbers || '' }}"
23262332
sync_open_pr_batch="${{ github.event_name == 'schedule' && github.event.schedule == '6,21,36,51 * * * *' && 'true' || 'false' }}"
@@ -2368,84 +2374,14 @@ jobs:
23682374
echo "Capping apply checkpoint size at 20 to keep each GitHub App token within its lifetime."
23692375
checkpoint_size=20
23702376
fi
2371-
candidate_quality_summary="not evaluated"
2372-
candidate_quality_detail=""
2377+
select_adaptive_apply_batch
23732378
mkdir -p .artifacts/apply-reports
2374-
publish_changes() {
2375-
message="$1"
2376-
shift
2377-
publish_args=(--message "$message" --rebase-strategy apply-records)
2378-
for path in "$@"; do
2379-
publish_args+=(--path "$path")
2380-
done
2381-
pnpm run repair:publish-main -- "${publish_args[@]}"
2382-
}
2383-
publish_status() {
2384-
message="$1"
2385-
if ! publish_changes "$message" results/sweep-status; then
2386-
echo "Best-effort status update failed: $message"
2387-
git restore results/sweep-status || true
2388-
fi
2389-
}
2390-
write_apply_health() {
2391-
report_path="$1"
2392-
output_path="$2"
2393-
health_mode="$3"
2394-
health_processed_limit="$4"
2395-
health_cursor_path="${5:-}"
2396-
health_cursor_required="${6:-false}"
2397-
health_candidate_count="${7:-}"
2398-
health_scheduled_interval_minutes="${8:-}"
2399-
health_cursor_advance_count="${9:-}"
2400-
health_args=(
2401-
--target-repo "$TARGET_REPO"
2402-
--report "$report_path"
2403-
--mode "$health_mode"
2404-
--processed-limit "$health_processed_limit"
2405-
--close-limit "$limit"
2406-
)
2407-
if [ -n "$health_cursor_path" ]; then
2408-
health_args+=(--cursor-path "$health_cursor_path")
2409-
fi
2410-
if [ "$health_cursor_required" = "true" ]; then
2411-
health_args+=(--cursor-required true)
2412-
fi
2413-
if [ -n "$health_candidate_count" ]; then
2414-
health_args+=(--candidate-count "$health_candidate_count")
2415-
fi
2416-
if [ -n "$health_scheduled_interval_minutes" ]; then
2417-
health_args+=(--scheduled-interval-minutes "$health_scheduled_interval_minutes")
2418-
fi
2419-
if [ -n "$health_cursor_advance_count" ]; then
2420-
health_args+=(--cursor-advance-count "$health_cursor_advance_count")
2421-
fi
2422-
pnpm run --silent workflow -- summarize-apply-report "${health_args[@]}" > "$output_path"
2423-
}
24242379
reconcile_args=(--target-repo "$TARGET_REPO" --skip-closed-at)
24252380
if [ -n "$item_numbers" ]; then
24262381
reconcile_args+=(--item-numbers "$item_numbers")
24272382
fi
24282383
pnpm run reconcile -- "${reconcile_args[@]}"
2429-
if [ "$sync_comments_only" != "true" ]; then
2430-
quality_args=(
2431-
--target-repo "$TARGET_REPO"
2432-
--apply-kind "$apply_kind"
2433-
--apply-close-reasons "$apply_close_reasons"
2434-
--stale-min-age-days "$stale_min_age_days"
2435-
--min-age-days "$min_age_days"
2436-
--min-age-minutes "$min_age_minutes"
2437-
)
2438-
if [ -n "$item_numbers" ]; then
2439-
quality_args+=(--item-numbers "$item_numbers")
2440-
else
2441-
quality_args+=(--batch-size "$close_processed_limit" --cursor-path "$apply_cursor_path")
2442-
fi
2443-
candidate_quality_env=".artifacts/apply-candidate-quality.env"
2444-
pnpm run --silent workflow -- proposed-item-quality-summary "${quality_args[@]}" > "$candidate_quality_env"
2445-
cat "$candidate_quality_env"
2446-
candidate_quality_summary="$(awk -F= '$1 == "candidate_quality_summary" { print $2 }' "$candidate_quality_env")"
2447-
candidate_quality_detail=" Close candidate mix: $candidate_quality_summary."
2448-
fi
2384+
summarize_apply_candidate_quality
24492385
if [ "$sync_open_pr_batch" = "true" ] && [ -z "$item_numbers" ]; then
24502386
batch_env=".artifacts/comment-sync-batch.env"
24512387
pnpm run --silent workflow -- comment-sync-batch \
@@ -2509,7 +2445,7 @@ jobs:
25092445
if [ "$proposed_count" -lt "$limit" ]; then
25102446
limit="$proposed_count"
25112447
fi
2512-
echo "Auto-selected $proposed_count proposed close candidate(s) from apply cursor window: $item_numbers; apply-ready count: ${apply_ready_count:-unknown}"
2448+
echo "Auto-selected $proposed_count proposed close candidate(s) from $close_processed_limit-record apply cursor window ($adaptive_apply_scan_reason): $item_numbers; apply-ready count: ${apply_ready_count:-unknown}"
25132449
fi
25142450
fi
25152451
item_numbers_arg=()
@@ -2545,7 +2481,7 @@ jobs:
25452481
pnpm run status -- \
25462482
--target-repo "$TARGET_REPO" \
25472483
--state "Apply in progress" \
2548-
--detail "Starting apply/comment-sync run for up to $limit fresh $apply_kind closes. Close reasons: $apply_close_reasons.$candidate_quality_detail Existing Codex automated review comments are updated in place when closing or when comment-only sync is stale by ${comment_sync_min_age_days} day(s); checkpoints commit every $checkpoint_size fresh closes; close delay is ${close_delay_ms}ms; sync-comments-only=$sync_comments_only; item numbers=${item_numbers:-all}." \
2484+
--detail "Starting apply/comment-sync run for up to $limit fresh $apply_kind closes. Close reasons: $apply_close_reasons.$candidate_quality_detail Scan window: $close_processed_limit records ($adaptive_apply_scan_reason). Existing Codex automated review comments are updated in place when closing or when comment-only sync is stale by ${comment_sync_min_age_days} day(s); checkpoints commit every $checkpoint_size fresh closes; close delay is ${close_delay_ms}ms; sync-comments-only=$sync_comments_only; item numbers=${item_numbers:-all}." \
25492485
--run-url "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
25502486
if ! publish_changes "chore: mark sweep apply in progress" records results/sweep-status; then
25512487
echo "Best-effort apply start status update failed"
@@ -2738,6 +2674,8 @@ jobs:
27382674
echo "APPLY_SYNC_OPEN_PR_BATCH=$sync_open_pr_batch"
27392675
echo "APPLY_AUTO_SELECTED_BATCH=$auto_selected_apply_batch"
27402676
echo "APPLY_COMMENT_SYNC_MIN_AGE_DAYS=$comment_sync_min_age_days"
2677+
echo "APPLY_CLOSE_PROCESSED_LIMIT=$close_processed_limit"
2678+
echo "APPLY_ADAPTIVE_SCAN_REASON=$adaptive_apply_scan_reason"
27412679
echo "APPLY_CANDIDATE_QUALITY_SUMMARY=$candidate_quality_summary"
27422680
} >> "$GITHUB_ENV"
27432681

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ checkpoint, and status-only commits are intentionally omitted.
1818

1919
### Changed
2020

21+
- Expanded untargeted close-apply scans from 300 toward a capped 900 records after skip-heavy zero-close windows without changing close or worker limits. Thanks @brokemac79.
2122
- Made ClawHub diversion comments a practical self-serve handoff with package-shape, manifest, configuration, documentation, usage, and smoke-proof guidance. Thanks @brokemac79.
2223
- Reduced duplicate GitHub API reads in each live-dashboard status snapshot and batched recent automerge hydration into one GraphQL request with a REST fallback. Thanks @brokemac79.
2324
- Raised the apply-existing close limit and checkpoint size from 5 to 20 fresh closes per run so continuation chains drain the proposal queue faster while each GitHub App token stays within its lifetime.
@@ -26,6 +27,7 @@ checkpoint, and status-only commits are intentionally omitted.
2627

2728
### Fixed
2829

30+
- Split apply workflow helpers out of the oversized inline expression so GitHub can validate and start sweep runs again.
2931
- Bounded apply-existing checkpoints to five fresh closes, renewed the GitHub
3032
App token between continuation runs, and stopped zero-progress scans from
3133
chaining indefinitely.

‎docs/scheduler.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ continuation with a fresh GitHub App token after any checkpoint that closes at
459459
least one item. A saturated scan that closes nothing stops without chaining so
460460
the same records cannot create an unbounded runner loop.
461461

462+
Untargeted cursor-based close apply starts with a 300-record scan window. If
463+
the previous cursor window was a full close-mode scan, closed nothing, skipped
464+
at least 80% of processed records, and did not hit a live-fetch, runtime-budget,
465+
or missing-cursor failure, the next automatic window expands to inspect more
466+
records, capped at 900. This changes only the deterministic scan window:
467+
`apply_limit`, checkpoint size, close gates, live-state checks, and maintainer
468+
policy gates stay unchanged. The workflow logs and sweep status detail include
469+
the selected scan window and reason.
470+
462471
Before a close-mode apply run starts, the workflow summarizes the selected close
463472
candidate mix by quality bucket in the status detail. Buckets such as
464473
implemented-on-main, duplicate/superseded, needs PR close proof,

‎scripts/apply-workflow-helpers.sh‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
3+
# Shared by the apply workflow step. The caller supplies the current apply
4+
# settings as shell variables before sourcing this file.
5+
# shellcheck disable=SC2034,SC2154
6+
7+
publish_changes() {
8+
local message="$1"
9+
shift
10+
local publish_args=(--message "$message" --rebase-strategy apply-records)
11+
local path
12+
for path in "$@"; do
13+
publish_args+=(--path "$path")
14+
done
15+
pnpm run repair:publish-main -- "${publish_args[@]}"
16+
}
17+
18+
publish_status() {
19+
local message="$1"
20+
if ! publish_changes "$message" results/sweep-status; then
21+
echo "Best-effort status update failed: $message"
22+
git restore results/sweep-status || true
23+
fi
24+
}
25+
26+
write_apply_health() {
27+
local report_path="$1"
28+
local output_path="$2"
29+
local health_mode="$3"
30+
local health_processed_limit="$4"
31+
local health_cursor_path="${5:-}"
32+
local health_cursor_required="${6:-false}"
33+
local health_candidate_count="${7:-}"
34+
local health_scheduled_interval_minutes="${8:-}"
35+
local health_cursor_advance_count="${9:-}"
36+
local health_args=(
37+
--target-repo "$TARGET_REPO"
38+
--report "$report_path"
39+
--mode "$health_mode"
40+
--processed-limit "$health_processed_limit"
41+
--close-limit "$limit"
42+
)
43+
if [ -n "$health_cursor_path" ]; then
44+
health_args+=(--cursor-path "$health_cursor_path")
45+
fi
46+
if [ "$health_cursor_required" = "true" ]; then
47+
health_args+=(--cursor-required true)
48+
fi
49+
if [ -n "$health_candidate_count" ]; then
50+
health_args+=(--candidate-count "$health_candidate_count")
51+
fi
52+
if [ -n "$health_scheduled_interval_minutes" ]; then
53+
health_args+=(--scheduled-interval-minutes "$health_scheduled_interval_minutes")
54+
fi
55+
if [ -n "$health_cursor_advance_count" ]; then
56+
health_args+=(--cursor-advance-count "$health_cursor_advance_count")
57+
fi
58+
pnpm run --silent workflow -- summarize-apply-report "${health_args[@]}" > "$output_path"
59+
}
60+
61+
select_adaptive_apply_batch() {
62+
if [ "$sync_comments_only" = "true" ] || [ -n "$item_numbers" ]; then
63+
return
64+
fi
65+
mkdir -p .artifacts
66+
local adaptive_batch_env=".artifacts/apply-adaptive-batch.env"
67+
pnpm run --silent workflow -- adaptive-apply-batch-size \
68+
--status-path "results/sweep-status/${target_slug}.json" \
69+
--base-size "$base_close_processed_limit" \
70+
--max-size "$max_close_processed_limit" > "$adaptive_batch_env"
71+
cat "$adaptive_batch_env"
72+
close_processed_limit="$(awk -F= '$1 == "close_processed_limit" { print $2 }' "$adaptive_batch_env")"
73+
adaptive_apply_scan_reason="$(awk -F= '$1 == "adaptive_apply_scan_reason" { print $2 }' "$adaptive_batch_env")"
74+
}
75+
76+
summarize_apply_candidate_quality() {
77+
candidate_quality_summary="not evaluated"
78+
candidate_quality_detail=""
79+
if [ "$sync_comments_only" = "true" ]; then
80+
return
81+
fi
82+
local quality_args=(
83+
--target-repo "$TARGET_REPO"
84+
--apply-kind "$apply_kind"
85+
--apply-close-reasons "$apply_close_reasons"
86+
--stale-min-age-days "$stale_min_age_days"
87+
--min-age-days "$min_age_days"
88+
--min-age-minutes "$min_age_minutes"
89+
)
90+
if [ -n "$item_numbers" ]; then
91+
quality_args+=(--item-numbers "$item_numbers")
92+
else
93+
quality_args+=(--batch-size "$close_processed_limit" --cursor-path "$apply_cursor_path")
94+
fi
95+
local candidate_quality_env=".artifacts/apply-candidate-quality.env"
96+
pnpm run --silent workflow -- proposed-item-quality-summary "${quality_args[@]}" > "$candidate_quality_env"
97+
cat "$candidate_quality_env"
98+
candidate_quality_summary="$(awk -F= '$1 == "candidate_quality_summary" { print $2 }' "$candidate_quality_env")"
99+
candidate_quality_detail=" Close candidate mix: $candidate_quality_summary."
100+
}

‎src/clawsweeper.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ interface WorkflowStatusSummary {
788788
detail: string;
789789
runUrl: string | undefined;
790790
applyHealth: Record<string, unknown> | undefined;
791+
lastCloseApplyHealth: Record<string, unknown> | undefined;
791792
plannedCount: number | undefined;
792793
plannedCapacity: number | undefined;
793794
plannedShards: number | undefined;
@@ -1954,10 +1955,14 @@ function writeSweepStatus(options: {
19541955
}): void {
19551956
const profile = options.profile ?? targetProfile();
19561957
const updatedAt = new Date().toISOString();
1958+
const previousStatus = readSweepStatusSummary(profile);
19571959
const applyHealth =
1958-
options.applyHealth === undefined
1959-
? readSweepStatusSummary(profile)?.applyHealth
1960-
: options.applyHealth;
1960+
options.applyHealth === undefined ? previousStatus?.applyHealth : options.applyHealth;
1961+
const previousCloseApplyHealth =
1962+
previousStatus?.lastCloseApplyHealth ??
1963+
(previousStatus?.applyHealth?.mode === "close" ? previousStatus.applyHealth : undefined);
1964+
const lastCloseApplyHealth =
1965+
applyHealth && applyHealth.mode === "close" ? applyHealth : previousCloseApplyHealth;
19611966
const payload = {
19621967
schema_version: 1,
19631968
slug: profile.slug,
@@ -1980,6 +1985,7 @@ function writeSweepStatus(options: {
19801985
bot_owned_proof_decisions_requested: options.botOwnedProofDecisionsRequested ?? null,
19811986
bot_owned_proof_dispatches: options.botOwnedProofDispatches ?? null,
19821987
apply_health: applyHealth ?? null,
1988+
last_close_apply_health: lastCloseApplyHealth ?? null,
19831989
updated_at: updatedAt,
19841990
};
19851991
const outputPath = sweepStatusPath(profile);
@@ -8265,6 +8271,7 @@ function readSweepStatusSummary(profile = targetProfile()): WorkflowStatusSummar
82658271
detail: stringOrUndefined(parsed.detail) ?? "No workflow status has been published yet.",
82668272
runUrl: stringOrUndefined(parsed.run_url),
82678273
applyHealth: recordOrUndefined(parsed.apply_health),
8274+
lastCloseApplyHealth: recordOrUndefined(parsed.last_close_apply_health),
82688275
plannedCount: numberOrUndefined(parsed.planned_count),
82698276
plannedCapacity: numberOrUndefined(parsed.planned_capacity),
82708277
plannedShards: numberOrUndefined(parsed.planned_shards),
@@ -8359,6 +8366,7 @@ function workflowStatusSummary(block: string): WorkflowStatusSummary {
83598366
detail,
83608367
runUrl,
83618368
applyHealth: undefined,
8369+
lastCloseApplyHealth: undefined,
83628370
plannedCount: numberOrUndefined(planMatch?.[1]),
83638371
plannedShards: numberOrUndefined(planMatch?.[2]),
83648372
plannedCapacity: numberOrUndefined(planMatch?.[3]),

0 commit comments

Comments
 (0)