Skip to content

Commit 408c283

Browse files
authored
feat(operator): bounded auto-remediation for stuck-queued workflow runs (#1131)
GitHub-side stuck-queued workflow runs have now caused two production incidents: fourteen runs from one Aug-7 window became permanent backend zombies (both cancel APIs return HTTP 500; excluded from health by #1101's ceiling), and six runs from one window tonight sat queued for three hours while their items cycled as oldest-dispatching -- degrading operational health and flapping handoff until manual cancellation cleared everything within minutes. That proven manual playbook is now a bounded remediation stage in the scheduled reconcile lane, replacing the old hourly 24-hour janitor. Selection is strict: queued over 90 minutes AND at least three later runs of the same workflow already started (capacity provably existed -- a global crunch can never trigger it), oldest-first, max 8 workflows inspected and 10 cancellations per pass. Per review, discovery is deadline-bounded at min(start+120s, shared deadline minus 480s), reserving eight minutes so the dead-letter reconciliation stages can never be starved; a stubbed 20-second-per-call provider across 20 workflows stops after one request with full headroom retained. Regular cancel first, force-cancel on 500, 500-500 persists the run as a permanent zombie that is never retried. Cancelled runs re-dispatch through the queue's existing retry machinery -- the mechanism tonight's recovery proved. Proof: the production script driven against a loopback GitHub API cancels exactly the demonstrably-stranded run, leaves the young run untouched, and persists the double-500 zombie with idempotent replay; verified in a Docker-backed Crabbox local-container on the final head with committed receipt.
1 parent 6bf7f48 commit 408c283

12 files changed

Lines changed: 1850 additions & 84 deletions

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ concurrency:
2626
cancel-in-progress: false
2727

2828
permissions:
29+
actions: write
2930
contents: read
3031
issues: read
3132
pull-requests: read
@@ -54,6 +55,46 @@ jobs:
5455
with:
5556
node-version: "24"
5657

58+
- name: Restore permanent queued-run zombie state
59+
env:
60+
GH_TOKEN: ${{ github.token }}
61+
run: |
62+
set -euo pipefail
63+
artifact_dir=.artifacts/exact-review-dlq
64+
mkdir -p "$artifact_dir"
65+
artifact_id="$(gh api -X GET "repos/${GITHUB_REPOSITORY}/actions/artifacts" -F per_page=100 \
66+
--jq '[.artifacts[] | select(.expired == false) | select(.name | startswith("exact-review-dlq-reconcile-"))] | sort_by(.created_at) | reverse | .[0].id // empty')"
67+
if [ -z "$artifact_id" ]; then
68+
echo "no prior reconcile artifact; using checked-in zombie seed"
69+
exit 0
70+
fi
71+
archive="$RUNNER_TEMP/exact-review-dlq-prior.zip"
72+
gh api "repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}/zip" > "$archive"
73+
entry="$(unzip -Z1 "$archive" | awk '/(^|\/)stuck-queued-zombies\.json$/ { print; exit }')"
74+
if [ -z "$entry" ]; then
75+
echo "prior reconcile artifact has no queued-run zombie state; using checked-in seed"
76+
exit 0
77+
fi
78+
unzip -p "$archive" "$entry" > "$artifact_dir/prior-stuck-queued-zombies.json"
79+
echo "restored queued-run zombie state from artifact ${artifact_id}"
80+
81+
- name: Remediate demonstrably stuck queued runs
82+
env:
83+
EXECUTE: ${{ github.event_name == 'schedule' && 'true' || github.event.inputs.execute }}
84+
GITHUB_TOKEN: ${{ github.token }}
85+
run: |
86+
set -euo pipefail
87+
args=(
88+
--repository "$GITHUB_REPOSITORY"
89+
--zombie-state .artifacts/exact-review-dlq/prior-stuck-queued-zombies.json
90+
--zombie-output .artifacts/exact-review-dlq/stuck-queued-zombies.json
91+
--output .artifacts/exact-review-dlq/stuck-queued-runs.json
92+
)
93+
if [[ "$EXECUTE" == "true" ]]; then
94+
args+=(--execute)
95+
fi
96+
node scripts/stuck-queued-run-remediation.mjs "${args[@]}"
97+
5798
- name: Verify live recovery guards
5899
run: |
59100
set -euo pipefail
@@ -120,6 +161,8 @@ jobs:
120161
path: |
121162
.artifacts/exact-review-dlq/inventory.json
122163
.artifacts/exact-review-dlq/parked-reviews.json
164+
.artifacts/exact-review-dlq/stuck-queued-runs.json
165+
.artifacts/exact-review-dlq/stuck-queued-zombies.json
123166
include-hidden-files: true
124167
if-no-files-found: error
125168
retention-days: 14

‎.github/workflows/queued-run-janitor.yml‎

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"schema_version": 1,
3+
"zombies": [
4+
{
5+
"run_id": "29219675461",
6+
"workflow_id": "265487604",
7+
"workflow_path": ".github/workflows/sweep.yml",
8+
"created_at": "2026-07-13T02:31:01Z",
9+
"recorded_at": "2026-08-07T00:00:00Z",
10+
"reason": "cancel_and_force_cancel_http_500"
11+
},
12+
{
13+
"run_id": "29219804812",
14+
"workflow_id": "268202215",
15+
"workflow_path": ".github/workflows/repair-comment-router.yml",
16+
"created_at": "2026-07-13T02:34:43Z",
17+
"recorded_at": "2026-08-07T00:00:00Z",
18+
"reason": "cancel_and_force_cancel_http_500"
19+
},
20+
{
21+
"run_id": "29591086714",
22+
"workflow_id": "268202215",
23+
"workflow_path": ".github/workflows/repair-comment-router.yml",
24+
"created_at": "2026-07-17T15:11:27Z",
25+
"recorded_at": "2026-08-07T00:00:00Z",
26+
"reason": "cancel_and_force_cancel_http_500"
27+
},
28+
{
29+
"run_id": "31164654923",
30+
"workflow_id": "265487604",
31+
"workflow_path": ".github/workflows/sweep.yml",
32+
"created_at": "2026-08-07T09:08:42Z",
33+
"recorded_at": "2026-08-07T09:10:00Z",
34+
"reason": "cancel_and_force_cancel_http_500"
35+
},
36+
{
37+
"run_id": "31164655566",
38+
"workflow_id": "310409655",
39+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
40+
"created_at": "2026-08-07T09:08:43Z",
41+
"recorded_at": "2026-08-07T09:10:00Z",
42+
"reason": "cancel_and_force_cancel_http_500"
43+
},
44+
{
45+
"run_id": "31164659200",
46+
"workflow_id": "274711374",
47+
"workflow_path": ".github/workflows/dashboard-ci.yml",
48+
"created_at": "2026-08-07T09:08:46Z",
49+
"recorded_at": "2026-08-07T09:10:00Z",
50+
"reason": "cancel_and_force_cancel_http_500"
51+
},
52+
{
53+
"run_id": "31164661056",
54+
"workflow_id": "310409655",
55+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
56+
"created_at": "2026-08-07T09:08:48Z",
57+
"recorded_at": "2026-08-07T09:10:00Z",
58+
"reason": "cancel_and_force_cancel_http_500"
59+
},
60+
{
61+
"run_id": "31164662004",
62+
"workflow_id": "265487604",
63+
"workflow_path": ".github/workflows/sweep.yml",
64+
"created_at": "2026-08-07T09:08:49Z",
65+
"recorded_at": "2026-08-07T09:10:00Z",
66+
"reason": "cancel_and_force_cancel_http_500"
67+
},
68+
{
69+
"run_id": "31164663906",
70+
"workflow_id": "310409655",
71+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
72+
"created_at": "2026-08-07T09:08:51Z",
73+
"recorded_at": "2026-08-07T09:10:00Z",
74+
"reason": "cancel_and_force_cancel_http_500"
75+
},
76+
{
77+
"run_id": "31164665677",
78+
"workflow_id": "310409655",
79+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
80+
"created_at": "2026-08-07T09:08:53Z",
81+
"recorded_at": "2026-08-07T09:10:00Z",
82+
"reason": "cancel_and_force_cancel_http_500"
83+
},
84+
{
85+
"run_id": "31164675902",
86+
"workflow_id": "265487604",
87+
"workflow_path": ".github/workflows/sweep.yml",
88+
"created_at": "2026-08-07T09:09:04Z",
89+
"recorded_at": "2026-08-07T09:10:00Z",
90+
"reason": "cancel_and_force_cancel_http_500"
91+
},
92+
{
93+
"run_id": "31164678051",
94+
"workflow_id": "310409655",
95+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
96+
"created_at": "2026-08-07T09:09:05Z",
97+
"recorded_at": "2026-08-07T09:10:00Z",
98+
"reason": "cancel_and_force_cancel_http_500"
99+
},
100+
{
101+
"run_id": "31164678386",
102+
"workflow_id": "265487604",
103+
"workflow_path": ".github/workflows/sweep.yml",
104+
"created_at": "2026-08-07T09:09:06Z",
105+
"recorded_at": "2026-08-07T09:10:00Z",
106+
"reason": "cancel_and_force_cancel_http_500"
107+
},
108+
{
109+
"run_id": "31164680037",
110+
"workflow_id": "310409655",
111+
"workflow_path": ".github/workflows/exact-review-reconcile.yml",
112+
"created_at": "2026-08-07T09:09:08Z",
113+
"recorded_at": "2026-08-07T09:10:00Z",
114+
"reason": "cancel_and_force_cancel_http_500"
115+
},
116+
{
117+
"run_id": "31164688807",
118+
"workflow_id": "265487604",
119+
"workflow_path": ".github/workflows/sweep.yml",
120+
"created_at": "2026-08-07T09:09:15Z",
121+
"recorded_at": "2026-08-07T09:10:00Z",
122+
"reason": "cancel_and_force_cancel_http_500"
123+
},
124+
{
125+
"run_id": "31164690992",
126+
"workflow_id": "265487604",
127+
"workflow_path": ".github/workflows/sweep.yml",
128+
"created_at": "2026-08-07T09:09:16Z",
129+
"recorded_at": "2026-08-07T09:10:00Z",
130+
"reason": "cancel_and_force_cancel_http_500"
131+
},
132+
{
133+
"run_id": "31164698914",
134+
"workflow_id": "265487604",
135+
"workflow_path": ".github/workflows/sweep.yml",
136+
"created_at": "2026-08-07T09:09:21Z",
137+
"recorded_at": "2026-08-07T09:10:00Z",
138+
"reason": "cancel_and_force_cancel_http_500"
139+
}
140+
]
141+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Stuck queued-run remediation proof
2+
3+
The scheduled remediation lane now inspects at most eight distinct stale workflows per pass, oldest queued run first. It also has a two-minute total runtime cap. When the shared `EXACT_REVIEW_RECONCILE_DEADLINE_MS` is present, the effective remediation deadline is the earlier of that cap and the shared deadline minus eight minutes, preserving 480,000 ms for guard verification and both dead-letter stages. Every GitHub request uses the remaining total budget. A partial pass writes `deadline_reached` plus distinct, inspected, and skipped workflow counts to its artifact and step summary.
4+
5+
The timeout regression starts the production script against a loopback history provider that takes 20 seconds per call and exposes 20 distinct stale workflows. With the shared deadline constrained, the script stops after one attempted history request in about 1.5 seconds, reports one inspected and 19 skipped workflows (12 by the eight-workflow cap and seven by deadline), and retains the full eight-minute dead-letter reserve.
6+
7+
`loopback-proof-receipt.json` records the production script's after-fix summary from the Docker-backed Crabbox proof. The loopback GitHub API exposed one two-hour-old queued run with three later same-workflow starts and one ten-minute-old queued run. The script selected and revalidated only the stranded run, posted exactly one regular cancellation, recorded `cancel_requested` with HTTP 202, and left the young run untouched.
8+
9+
The second scenario is recorded in the same receipt. Regular and force cancellation both returned HTTP 500, so the script persisted the run as a permanent zombie. A second production-script pass restored that state, classified the old run as `permanent_zombie`, made no cancellation request, and left the young run untouched. The receipt contains the redacted request traces and all three behavior assertions.
10+
11+
`container-receipt.json` records the current-pushed-head Crabbox run for revision `b46b579b6d12d940cb068b32da20a23e8c39b000`: provider `local-container`, lease `cbx_821f20930574`, slug `amber-shrimp-5247`, and Docker image `node:24-bookworm`. All 71 focused tests, the loopback production-script proof, static policy and documentation checks, formatting, all TypeScript builds, and every lint lane passed. Crabbox stopped the lease automatically.
12+
13+
The earlier live read-only inventory remains in `live-dry-run.json`. It inspected all 18 queued runs returned by GitHub at 2026-08-12T03:39:23.031Z, found one young run plus the 17 seeded permanent zombies, selected nothing, and made no mutation request.
14+
15+
Limits: the after-fix transport is a loopback HTTP fixture rather than live GitHub mutation. It exercises the production CLI, request routing through `GITHUB_API_URL`, selection, live-status revalidation, regular and force cancellation endpoints, summary writing, and restored zombie-state behavior. The host Node 24 `pnpm run check` remains the broad repository gate: 3,345 tests, 3,336 passes, nine platform skips, and zero failures.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"schema_version": 1,
3+
"tested_commit": "b46b579b6d12d940cb068b32da20a23e8c39b000",
4+
"provider": "local-container",
5+
"lease_id": "cbx_821f20930574",
6+
"lease_slug": "amber-shrimp-5247",
7+
"run_id": null,
8+
"machine_type": "node_24-bookworm",
9+
"container_image": "node:24-bookworm",
10+
"fresh_pr": "https://github.com/openclaw/clawsweeper/pull/1131",
11+
"command": "verify pushed HEAD; install with the pinned pnpm; run 71 focused tests; run the loopback production-script scenarios; run check:static, build:all, and lint",
12+
"result": {
13+
"status": "succeeded",
14+
"exit_code": 0,
15+
"focused_tests": {
16+
"total": 71,
17+
"passed": 71,
18+
"failed": 0
19+
},
20+
"loopback_assertions": {
21+
"stranded_cancelled_exactly_once": true,
22+
"young_run_untouched": true,
23+
"zombie_500_500_persisted": true
24+
},
25+
"gates": [
26+
"dependency lockfile and supply-chain policy",
27+
"active-surface, dashboard-boundary, documentation, limits, and formatting checks",
28+
"main, repair, and dashboard TypeScript builds",
29+
"main, repair, dashboard, script, and test lint"
30+
]
31+
},
32+
"timing_ms": {
33+
"sync": 12395,
34+
"command": 18323,
35+
"total": 30800,
36+
"phases": {
37+
"install": 3571,
38+
"focused_tests": 10656,
39+
"loopback_proof": 251,
40+
"static_build_lint_gates": 3634
41+
}
42+
},
43+
"lease_stopped": true,
44+
"limits": [
45+
"The GitHub API was a loopback fixture; no production run was cancelled.",
46+
"The full pnpm run check gate ran in the clean host checkout: 3345 tests, 3336 passes, 9 platform skips, 0 failures."
47+
]
48+
}

0 commit comments

Comments
 (0)