Skip to content

Commit a397ae0

Browse files
brokemac79steipete
andauthored
feat: report apply cycle estimates (#398)
* feat: report apply cycle estimates * test: cover apply cycle telemetry wiring --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent baf9ddb commit a397ae0

7 files changed

Lines changed: 320 additions & 18 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,8 @@ jobs:
22922292
cursor_path="results/comment-sync-cursors/${target_slug}.json"
22932293
apply_cursor_path="results/apply-cursors/${target_slug}.json"
22942294
next_cursor=""
2295+
apply_ready_count=""
2296+
cursor_advance_count=""
22952297
if [ "$sync_open_pr_batch" = "true" ]; then
22962298
sync_comments_only="true"
22972299
apply_kind="pull_request"
@@ -2333,6 +2335,9 @@ jobs:
23332335
health_processed_limit="$4"
23342336
health_cursor_path="${5:-}"
23352337
health_cursor_required="${6:-false}"
2338+
health_candidate_count="${7:-}"
2339+
health_scheduled_interval_minutes="${8:-}"
2340+
health_cursor_advance_count="${9:-}"
23362341
health_args=(
23372342
--target-repo "$TARGET_REPO"
23382343
--report "$report_path"
@@ -2346,6 +2351,15 @@ jobs:
23462351
if [ "$health_cursor_required" = "true" ]; then
23472352
health_args+=(--cursor-required true)
23482353
fi
2354+
if [ -n "$health_candidate_count" ]; then
2355+
health_args+=(--candidate-count "$health_candidate_count")
2356+
fi
2357+
if [ -n "$health_scheduled_interval_minutes" ]; then
2358+
health_args+=(--scheduled-interval-minutes "$health_scheduled_interval_minutes")
2359+
fi
2360+
if [ -n "$health_cursor_advance_count" ]; then
2361+
health_args+=(--cursor-advance-count "$health_cursor_advance_count")
2362+
fi
23492363
pnpm run --silent workflow -- summarize-apply-report "${health_args[@]}" > "$output_path"
23502364
}
23512365
reconcile_args=(--target-repo "$TARGET_REPO" --skip-closed-at)
@@ -2406,10 +2420,17 @@ jobs:
24062420
if [ -n "$item_numbers" ]; then
24072421
auto_selected_apply_batch=true
24082422
proposed_count="$(pnpm run --silent workflow -- count-csv --items "$item_numbers")"
2423+
apply_ready_count="$(pnpm run --silent workflow -- proposed-item-count \
2424+
--target-repo "$TARGET_REPO" \
2425+
--apply-kind "$apply_kind" \
2426+
--apply-close-reasons "$apply_close_reasons" \
2427+
--stale-min-age-days "$stale_min_age_days" \
2428+
--min-age-days "$min_age_days" \
2429+
--min-age-minutes "$min_age_minutes")"
24092430
if [ "$proposed_count" -lt "$limit" ]; then
24102431
limit="$proposed_count"
24112432
fi
2412-
echo "Auto-selected $proposed_count proposed close candidate(s) from apply cursor window: $item_numbers"
2433+
echo "Auto-selected $proposed_count proposed close candidate(s) from apply cursor window: $item_numbers; apply-ready count: ${apply_ready_count:-unknown}"
24132434
fi
24142435
fi
24152436
item_numbers_arg=()
@@ -2491,7 +2512,7 @@ jobs:
24912512
comment_sync_health_cursor_required="true"
24922513
comment_sync_health_processed_limit="$sync_batch_size"
24932514
fi
2494-
write_apply_health ".artifacts/apply-reports/apply-report-$checkpoint.json" ".artifacts/apply-health-$checkpoint.json" "comment_sync" "$comment_sync_health_processed_limit" "$comment_sync_health_cursor_path" "$comment_sync_health_cursor_required"
2515+
write_apply_health ".artifacts/apply-reports/apply-report-$checkpoint.json" ".artifacts/apply-health-$checkpoint.json" "comment_sync" "$comment_sync_health_processed_limit" "$comment_sync_health_cursor_path" "$comment_sync_health_cursor_required" "" "" ""
24952516
pnpm run status -- \
24962517
--target-repo "$TARGET_REPO" \
24972518
--state "Apply comments synced" \
@@ -2541,14 +2562,17 @@ jobs:
25412562
--report ".artifacts/apply-reports/apply-report-$checkpoint.json" \
25422563
--target-repo "$TARGET_REPO" \
25432564
--item-numbers "$item_numbers"
2565+
cursor_advance_count="$(pnpm run --silent workflow -- apply-cursor-advance-count \
2566+
--report ".artifacts/apply-reports/apply-report-$checkpoint.json" \
2567+
--item-numbers "$item_numbers")"
25442568
apply_publish_paths+=(results/apply-cursors)
25452569
fi
25462570
publish_changes "chore: apply sweep decisions checkpoint $checkpoint" "${apply_publish_paths[@]}"
25472571
close_health_cursor_path=""
25482572
if [ "$auto_selected_apply_batch" = "true" ]; then
25492573
close_health_cursor_path="$apply_cursor_path"
25502574
fi
2551-
write_apply_health ".artifacts/apply-reports/apply-report-$checkpoint.json" ".artifacts/apply-health-$checkpoint.json" "close" "$close_processed_limit" "$close_health_cursor_path" "$auto_selected_apply_batch"
2575+
write_apply_health ".artifacts/apply-reports/apply-report-$checkpoint.json" ".artifacts/apply-health-$checkpoint.json" "close" "$close_processed_limit" "$close_health_cursor_path" "$auto_selected_apply_batch" "$apply_ready_count" "15" "$cursor_advance_count"
25522576
pnpm run status -- \
25532577
--target-repo "$TARGET_REPO" \
25542578
--state "Apply in progress" \
@@ -2583,20 +2607,29 @@ jobs:
25832607
final_health_processed_limit="$close_processed_limit"
25842608
final_health_cursor_path=""
25852609
final_health_cursor_required="$auto_selected_apply_batch"
2610+
final_health_candidate_count=""
2611+
final_health_scheduled_interval_minutes=""
2612+
final_health_cursor_advance_count=""
25862613
if [ "$auto_selected_apply_batch" = "true" ]; then
25872614
final_health_cursor_path="$apply_cursor_path"
2615+
final_health_candidate_count="$apply_ready_count"
2616+
final_health_scheduled_interval_minutes="15"
2617+
final_health_cursor_advance_count="$cursor_advance_count"
25882618
fi
25892619
if [ "$sync_comments_only" = "true" ]; then
25902620
final_health_mode="comment_sync"
25912621
final_health_processed_limit="$comment_sync_processed_limit"
25922622
final_health_cursor_required="false"
2623+
final_health_candidate_count=""
2624+
final_health_scheduled_interval_minutes=""
2625+
final_health_cursor_advance_count=""
25932626
if [ "$sync_open_pr_batch" = "true" ]; then
25942627
final_health_cursor_path="$cursor_path"
25952628
final_health_cursor_required="true"
25962629
final_health_processed_limit="$sync_batch_size"
25972630
fi
25982631
fi
2599-
write_apply_health "apply-report.json" ".artifacts/apply-health-final.json" "$final_health_mode" "$final_health_processed_limit" "$final_health_cursor_path" "$final_health_cursor_required"
2632+
write_apply_health "apply-report.json" ".artifacts/apply-health-final.json" "$final_health_mode" "$final_health_processed_limit" "$final_health_cursor_path" "$final_health_cursor_required" "$final_health_candidate_count" "$final_health_scheduled_interval_minutes" "$final_health_cursor_advance_count"
26002633
pnpm run status -- \
26012634
--target-repo "$TARGET_REPO" \
26022635
--state "Apply finished" \

‎dashboard/worker.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,7 @@ async function readApplyHealthMarker(env, targetRepo) {
35843584
lanes: applyHealthLanes(health.lanes),
35853585
next_actions: nextActions,
35863586
next_action_buckets: numericRecord(health.next_action_buckets),
3587+
cycle: applyHealthCycle(health.cycle),
35873588
attention_reasons: Array.isArray(health.attention_reasons)
35883589
? health.attention_reasons
35893590
.map((reason) => String(reason))
@@ -3620,6 +3621,7 @@ async function readApplyHealthMarker(env, targetRepo) {
36203621
lanes: emptyApplyHealthLanes(),
36213622
next_actions: [],
36223623
next_action_buckets: {},
3624+
cycle: emptyApplyHealthCycle(),
36233625
attention_reasons: [],
36243626
cursor: null,
36253627
};
@@ -3638,6 +3640,7 @@ function emptyApplyHealthStatus(targetRepos) {
36383640
lanes: emptyApplyHealthLanes(),
36393641
next_actions: [],
36403642
next_action_buckets: {},
3643+
cycle: emptyApplyHealthCycle(),
36413644
attention_reasons: [],
36423645
cursor: null,
36433646
})),
@@ -3699,6 +3702,31 @@ function applyHealthNextActions(value) {
36993702
.filter(Boolean)
37003703
.slice(0, 12);
37013704
}
3705+
3706+
function applyHealthCycle(value) {
3707+
const source = objectValue(value);
3708+
return {
3709+
basis: nullableString(source.basis),
3710+
apply_ready_count: optionalNumber(source.apply_ready_count),
3711+
window_size: optionalNumber(source.window_size),
3712+
estimated_full_cycle_windows: optionalNumber(source.estimated_full_cycle_windows),
3713+
estimated_full_cycle_minutes: optionalNumber(source.estimated_full_cycle_minutes),
3714+
scheduled_interval_minutes: optionalNumber(source.scheduled_interval_minutes),
3715+
label: nullableString(source.label),
3716+
};
3717+
}
3718+
3719+
function emptyApplyHealthCycle() {
3720+
return {
3721+
basis: null,
3722+
apply_ready_count: null,
3723+
window_size: null,
3724+
estimated_full_cycle_windows: null,
3725+
estimated_full_cycle_minutes: null,
3726+
scheduled_interval_minutes: null,
3727+
label: null,
3728+
};
3729+
}
37023730
function latestIso(values) {
37033731
const timestamps = values
37043732
.map((value) => Date.parse(value || ""))
@@ -4763,6 +4791,11 @@ function numberOrNull(value) {
47634791
return Number.isFinite(number) ? number : null;
47644792
}
47654793

4794+
function optionalNumber(value) {
4795+
if (value === null || value === undefined || value === "") return null;
4796+
return numberOrNull(value);
4797+
}
4798+
47664799
function numberFrom(value, fallback) {
47674800
const number = Number(value);
47684801
return Number.isFinite(number) ? number : fallback;
@@ -6890,14 +6923,23 @@ function renderApplyHealth(data) {
68906923
const syncProcessed = Number.isFinite(item.lanes?.comment_sync?.processed) ? fmt.format(item.lanes.comment_sync.processed) : processed;
68916924
const closureSynced = Number.isFinite(item.lanes?.closure?.comment_synced) ? fmt.format(item.lanes.closure.comment_synced) : "0";
68926925
const syncLaneSynced = Number.isFinite(item.lanes?.comment_sync?.comment_synced) ? fmt.format(item.lanes.comment_sync.comment_synced) : "0";
6926+
const cycle = applyHealthCyclePill(item.cycle);
68936927
return '<div class="apply-health-alert" role="status" title="' + esc(topInfo.summary + " Next: " + topInfo.action) + '">' +
68946928
'<div class="apply-health-heading"><strong>Pruning sweep ' + esc(applyHealthStatusLabel(item.status)) + " - " + esc(item.target_repo || "target repo") + '</strong><span class="pill" title="' + esc("Latest " + applyHealthModeLabel(item.mode) + " status from the sweep-status marker.") + '">' + esc(applyHealthModeLabel(item.mode)) + '</span></div>' +
68956929
'<p>' + esc(applyHealthOperatorSummary(item, topInfo)) + '</p>' +
68966930
'<p class="apply-health-next"><strong>Next check:</strong> ' + esc(topInfo.action) + '</p>' +
68976931
applyHealthActionHtml(action) +
6898-
'<div class="apply-health-meta"><span class="pill" title="Records checked in this pruning window.">' + esc(processed) + ' processed</span><span class="pill" title="' + esc("Closure lane: " + closureProcessed + " records processed; " + closed + " closed.") + '">' + esc(closed) + ' closed</span><span class="pill" title="' + esc("Durable review comments refreshed across lanes: " + synced + ". Closure lane refreshed " + closureSynced + "; comment-sync lane refreshed " + syncLaneSynced + " from " + syncProcessed + " records.") + '">' + esc(synced) + ' comments synced</span>' + cursorPill + reasons + buckets + linkClass(item.run_url, "workflow run", "pill run-link") + '</div></div>';
6932+
'<div class="apply-health-meta"><span class="pill" title="Records checked in this pruning window.">' + esc(processed) + ' processed</span><span class="pill" title="' + esc("Closure lane: " + closureProcessed + " records processed; " + closed + " closed.") + '">' + esc(closed) + ' closed</span><span class="pill" title="' + esc("Durable review comments refreshed across lanes: " + synced + ". Closure lane refreshed " + closureSynced + "; comment-sync lane refreshed " + syncLaneSynced + " from " + syncProcessed + " records.") + '">' + esc(synced) + ' comments synced</span>' + cycle + cursorPill + reasons + buckets + linkClass(item.run_url, "workflow run", "pill run-link") + '</div></div>';
68996933
}).join("");
69006934
}
6935+
function applyHealthCyclePill(cycle) {
6936+
if (!cycle || cycle.basis !== "scheduled_close_cursor") return "";
6937+
const windows = Number(cycle.estimated_full_cycle_windows);
6938+
const label = Number.isFinite(windows)
6939+
? "revisit ~" + fmt.format(windows) + " window" + (windows === 1 ? "" : "s")
6940+
: "revisit estimate";
6941+
return '<span class="pill" title="' + esc(cycle.label || "Estimated time to revisit the current apply-ready close queue.") + '">' + esc(label) + '</span>';
6942+
}
69016943
function applyHealthNeedsAttention(status) {
69026944
return ["attention", "blocked", "degraded", "failed", "needs_attention", "warning"].includes(String(status || "").toLowerCase());
69036945
}

‎docs/live-dashboard.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ is absent or a cache event lands in another Cloudflare colo.
134134
- skip next-action buckets in apply health JSON so stale reviews, missing close
135135
proof, protected labels, stable skips, invalid reports, and open closing PRs
136136
are discoverable without reading individual item records
137+
- scheduled close-cycle telemetry in apply-health JSON, including current
138+
apply-ready candidate count and an estimated number of cursor windows to
139+
revisit the close queue; scheduled cadence time is explanatory only because
140+
successful windows can dispatch immediate continuations
137141

138142
The Worker fetches job details only for the bounded active-run set, limits that
139143
GitHub fanout to 12 concurrent requests, and caches each run's jobs for 60

0 commit comments

Comments
 (0)