Skip to content

Commit 98fae30

Browse files
committed
fix(reconcile): skip throttled queued-run remediation
1 parent e0dc544 commit 98fae30

10 files changed

Lines changed: 531 additions & 66 deletions

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
echo "restored queued-run zombie state from artifact ${artifact_id}"
8080
8181
- name: Remediate demonstrably stuck queued runs
82+
id: remediate
83+
continue-on-error: true
8284
env:
8385
EXECUTE: ${{ github.event_name == 'schedule' && 'true' || github.event.inputs.execute }}
8486
GITHUB_TOKEN: ${{ github.token }}
@@ -153,6 +155,12 @@ jobs:
153155
fi
154156
node scripts/exact-review-dead-letter-operator.mjs "${args[@]}"
155157
158+
- name: Fail if queued-run remediation failed
159+
if: ${{ always() && steps.remediate.outcome == 'failure' }}
160+
run: |
161+
echo "Queued-run remediation failed after dead-letter reconciliation completed" >&2
162+
exit 1
163+
156164
- name: Upload sanitized inventory
157165
if: always()
158166
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
@@ -164,5 +172,5 @@ jobs:
164172
.artifacts/exact-review-dlq/stuck-queued-runs.json
165173
.artifacts/exact-review-dlq/stuck-queued-zombies.json
166174
include-hidden-files: true
167-
if-no-files-found: error
175+
if-no-files-found: ignore
168176
retention-days: 14
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Remediation throttle skip proof
2+
3+
- Status: historical proof
4+
- Owner: ClawSweeper maintainers
5+
- Source of truth: `scripts/stuck-queued-run-remediation.mjs`, `scripts/operator-skip-reasons.mjs`, and `.github/workflows/exact-review-dead-letter-reconcile.yml`
6+
- Base revision: `openclaw/clawsweeper@e0dc54438e6562f144623fcde2263b3b839fe28d`
7+
- Update when: the remediation throttle contract, dead-letter workflow ordering, or focused loopback fixtures change
8+
9+
The proof claim is that GitHub rate-limit and abuse throttles are an operator-visible graceful skip for opportunistic queued-run remediation, including after earlier cancellations, while persistent 5xx and authorization failures remain hard failures. The exercised surface is the production CLI routed through its real `GITHUB_API_URL` seam to loopback HTTP listeners, plus the parsed production workflow.
10+
11+
[`red-green-transcript.txt`](red-green-transcript.txt) records the red test-only run against the base production script and the green focused run. The fixtures cover a 403 installation rate-limit body, a 429 secondary-rate-limit response after one successful cancellation, a non-throttle 403, persistent 503 responses with three attempts, an invalid inventory shape, and the workflow sequencing/upload contract. No live credentials or external mutations are used.
12+
13+
The source-blind behavior contract is in [`behavior-contract.md`](behavior-contract.md). All five clauses passed through the operator CLI/workflow artifact surfaces. Anti-cheat probes varied both status and body, distinguished authorization from throttling, retained a completed mutation before the mid-run skip, and verified the persistent failure path.
14+
15+
OpenClaw Bay is unaffected: this changes only an internal housekeeping CLI and workflow sequencing, with no dashboard data contract or observer surface change. No dashboard files were touched, so the requested scripts/workflow proof replaces a Crabbox real-Worker receipt.
16+
17+
Limits: the transport is loopback HTTP rather than live GitHub, and workflow behavior is validated structurally rather than by dispatching the production schedule. Full repository gates provide the broader integration check.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Behavior Contract
2+
3+
## User-Visible Goal
4+
5+
Opportunistic stuck-run remediation must yield to GitHub throttling without preventing the scheduled dead-letter reconcile cycle, while authentication failures, persistent server failures, and malformed responses remain hard failures.
6+
7+
## Target
8+
9+
- Type: operator CLI and GitHub Actions workflow artifact
10+
- Launch or access: `node scripts/stuck-queued-run-remediation.mjs` through the focused loopback test and parsed `.github/workflows/exact-review-dead-letter-reconcile.yml`
11+
- Allowed fixtures and credential source: loopback HTTP listeners through `GITHUB_API_URL`; synthetic placeholder token only
12+
13+
## User Tasks
14+
15+
1. Run discovery when GitHub returns a rate-limit 403.
16+
2. Run discovery when GitHub returns a persistent 503 or a non-throttle 403.
17+
3. Run execute mode when one cancellation succeeds and the next request is throttled.
18+
4. Inspect the workflow ordering and artifact-upload policy.
19+
20+
## Expected Observable Behavior
21+
22+
- A discovery throttle exits 0 and emits one JSON line with `skip_reasons.github_throttled`, phase, and request path.
23+
- Persistent 5xx retries three times and exits 1; a non-throttle 403 exits 1 without retry.
24+
- A throttle after a successful cancellation retains that action, stops further remediation, emits the skip reason, and exits 0.
25+
- The workflow lets both dead-letter reconcile stages run after a remediation failure, then fails honestly; absent inventory files do not create a second upload failure.
26+
27+
## Anti-Cheat Probes
28+
29+
- Vary the throttle signal between a 403 rate-limit body and HTTP 429 secondary-rate-limit response.
30+
- Replace the throttle body with an authorization error and verify it does not skip.
31+
- Replace the throttle response with persistent 503 and verify the bounded retry plus hard failure.
32+
- Exercise throttling after a prior mutation rather than only on the first request.
33+
34+
## Evidence Required
35+
36+
- Red/green Node test transcript showing exit status and named scenarios.
37+
- Focused workflow-shape assertion in the green run.
38+
- Secret scan of the committed transcript.
39+
40+
## Out Of Scope
41+
42+
- Live GitHub cancellation mutations.
43+
- Cloudflare Worker, dashboard, or OpenClaw Bay behavior.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Remediation throttle skip red/green transcript
2+
Base: openclaw/clawsweeper@e0dc54438e6562f144623fcde2263b3b839fe28d
3+
Environment: Node v24.19.0, macOS, loopback HTTP via GITHUB_API_URL
4+
5+
RED (test-only patch; production script still at base behavior)
6+
$ node --test --test-name-pattern='discovery GitHub throttling' test/stuck-queued-run-remediation.test.ts
7+
exit_code=1
8+
not ok - discovery GitHub throttling exits successfully with a structured skip reason
9+
AssertionError [ERR_ASSERTION]: GET /actions/runs?status=queued&per_page=100&page=1 returned 403: {"message":"API rate limit exceeded for installation"}
10+
1 !== 0
11+
tests 1
12+
pass 0
13+
fail 1
14+
15+
GREEN (implementation plus workflow isolation)
16+
$ node --test --test-name-pattern='discovery GitHub throttling|persistent discovery 5xx|non-throttle discovery 403|unexpected discovery response shape|mid-remediation throttling|queued workflow remediation' test/stuck-queued-run-remediation.test.ts test/review-reliability-workflow.test.ts
17+
exit_code=0
18+
ok - queued workflow remediation shares the guarded dead-letter cadence
19+
ok - discovery GitHub throttling exits successfully with a structured skip reason
20+
ok - persistent discovery 5xx still exits unsuccessfully after bounded retry
21+
ok - a non-throttle discovery 403 remains a hard failure
22+
ok - an unexpected discovery response shape remains a hard failure
23+
ok - mid-remediation throttling stops after completed actions and exits successfully
24+
tests 6
25+
pass 6
26+
fail 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schema": "clawsweeper-proof-secret-scan/v1",
3+
"scanner": "trufflehog 3.96.0",
4+
"command": "trufflehog filesystem docs/proof/remediation-throttle-skip/red-green-transcript.txt --results=verified,unknown --json",
5+
"source": {
6+
"path": "docs/proof/remediation-throttle-skip/red-green-transcript.txt",
7+
"bytes": 1447,
8+
"sha256": "3ac36e6b3bebba57c7064966eb04715f85276a6759912dbee5b335f4a3cac38d"
9+
},
10+
"result": {
11+
"exit_code": 0,
12+
"verified_secrets": 0,
13+
"unverified_secrets": 0
14+
}
15+
}

‎scripts/exact-review-dead-letter-operator.mjs‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mkdir, writeFile } from "node:fs/promises";
55
import { dirname, resolve } from "node:path";
66
import process from "node:process";
77
import { parseArgs as parseNodeArgs } from "node:util";
8+
import { classifyOperatorSkipReason } from "./operator-skip-reasons.mjs";
89

910
const DEFAULT_OUTPUT = ".artifacts/exact-review-dlq/inventory.json";
1011
const MAX_SELECTED_IDS = 2;
@@ -1368,7 +1369,7 @@ function countBy(rows, keyFor) {
13681369
function recordInspectionSkips(summary, targets, error) {
13691370
if (targets.length === 0) return;
13701371
const reason = sanitizeSkipReason(error);
1371-
const reasonClass = classifySkipReason(reason);
1372+
const reasonClass = classifyOperatorSkipReason(reason);
13721373
recordSkipReasonCount(summary, reasonClass, targets.length);
13731374
for (const target of targets) {
13741375
if (summary.skip_samples.length >= MAX_SKIP_SAMPLES) break;
@@ -1419,33 +1420,6 @@ function sanitizeSkipReason(error) {
14191420
return (sanitized || "unknown inspection failure").slice(0, MAX_SKIP_REASON_LENGTH);
14201421
}
14211422

1422-
function classifySkipReason(reason) {
1423-
const normalized = reason.toLowerCase();
1424-
if (normalized.includes("not inspected because canonical discovery aborted")) {
1425-
return "not_inspected_abort";
1426-
}
1427-
if (normalized.includes("inspected but reconciliation aborted")) {
1428-
return "inspected_before_abort";
1429-
}
1430-
if (normalized.includes("missing from an existing repository")) {
1431-
return "missing_from_existing_repository";
1432-
}
1433-
if (
1434-
normalized.includes("invalid identity") ||
1435-
normalized.includes("invalid canonical identity")
1436-
) {
1437-
return "invalid_identity";
1438-
}
1439-
if (/\b(timeout|timed out|aborterror|timeouterror)\b/.test(normalized)) return "timeout";
1440-
const status = /(?:\bwith|\breturned|\()\s*([1-5]\d{2})\)?\b/.exec(normalized)?.[1];
1441-
if (status === "403") return "http_403";
1442-
if (status === "429") return "http_429";
1443-
if (status?.startsWith("5")) return "http_5xx";
1444-
if (status?.startsWith("4")) return "http_4xx";
1445-
if (status?.startsWith("3")) return "http_3xx";
1446-
return "other";
1447-
}
1448-
14491423
async function signedPost({
14501424
queueUrl,
14511425
secret,

‎scripts/operator-skip-reasons.mjs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function failureText(value) {
2+
return value instanceof Error ? value.message : String(value ?? "");
3+
}
4+
5+
function failureStatus(value, text) {
6+
if (Number.isInteger(value?.status)) return String(value.status);
7+
return /(?:\bwith|\breturned|\()\s*([1-5]\d{2})\)?\b/.exec(text)?.[1] ?? null;
8+
}
9+
10+
export function isGitHubThrottleFailure(value) {
11+
const text = failureText(value);
12+
const status = failureStatus(value, text);
13+
if (status === "429") return true;
14+
if (status !== "403") return false;
15+
return /api[\s-]+rate[\s-]+limit exceeded|secondary[\s-]+rate[\s-]+limit|abuse detection|rate[\s-]+limited|too many requests|was submitted too quickly/i.test(
16+
text,
17+
);
18+
}
19+
20+
export function classifyOperatorSkipReason(value) {
21+
const reason = failureText(value);
22+
const normalized = reason.toLowerCase();
23+
if (normalized.includes("not inspected because canonical discovery aborted")) {
24+
return "not_inspected_abort";
25+
}
26+
if (normalized.includes("inspected but reconciliation aborted")) {
27+
return "inspected_before_abort";
28+
}
29+
if (normalized.includes("missing from an existing repository")) {
30+
return "missing_from_existing_repository";
31+
}
32+
if (
33+
normalized.includes("invalid identity") ||
34+
normalized.includes("invalid canonical identity")
35+
) {
36+
return "invalid_identity";
37+
}
38+
if (/\b(timeout|timed out|aborterror|timeouterror)\b/.test(normalized)) return "timeout";
39+
if (isGitHubThrottleFailure(value)) return "github_throttled";
40+
const status = failureStatus(value, reason);
41+
if (status === "403") return "http_403";
42+
if (status === "429") return "http_429";
43+
if (status?.startsWith("5")) return "http_5xx";
44+
if (status?.startsWith("4")) return "http_4xx";
45+
if (status?.startsWith("3")) return "http_3xx";
46+
return "other";
47+
}

0 commit comments

Comments
 (0)