Skip to content

Commit 7d99189

Browse files
committed
fix: defer comment router throttles safely
1 parent 4d41d3d commit 7d99189

10 files changed

Lines changed: 826 additions & 5 deletions

File tree

‎.github/workflows/repair-comment-router.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ jobs:
103103
results
104104
schema/clawsweeper-pr-close-coverage-proof.schema.json
105105
scripts/hydrate-state.ts
106+
scripts/comment-router-runner.mjs
107+
scripts/operator-skip-reasons.mjs
106108
scripts/prepare-worker-record-cache.ts
107109
scripts/worker-blobs.ts
108110
scripts/worker-records.ts
@@ -320,10 +322,12 @@ jobs:
320322
exit 0
321323
fi
322324
jobs_changed=0
325+
cursor_changed="$(jq -r '.routing_cursor_changed == true' results/comment-router-latest.json 2>/dev/null || true)"
323326
if ! git diff --no-index --quiet -- "$CLAWSWEEPER_STATE_DIR/jobs" jobs; then
324327
jobs_changed=1
325328
fi
326329
if [ "$jobs_changed" = "0" ] &&
330+
[ "$cursor_changed" != "true" ] &&
327331
jq -e '((.ledger_claimed // 0) + (.ledger_changed // 0)) == 0' results/comment-router-latest.json >/dev/null 2>&1; then
328332
echo "No durable router state changed; skipping state publication."
329333
exit 0
@@ -338,6 +342,9 @@ jobs:
338342
if [ "$jobs_changed" = "1" ]; then
339343
publish_args+=(--path jobs)
340344
fi
345+
if [ "$cursor_changed" = "true" ]; then
346+
publish_args+=(--path "results/comment-router-cursors/${{ steps.target.outputs.target_slug }}.json")
347+
fi
341348
pnpm run repair:publish-main -- "${publish_args[@]}"
342349
343350
- name: Detect waiting repair dispatches
@@ -476,10 +483,12 @@ jobs:
476483
# The initial publish copies every published path back into the state
477484
# checkout, making it the baseline for retry-only job mutations.
478485
jobs_changed=0
486+
cursor_changed="$(jq -r '.routing_cursor_changed == true' results/comment-router-latest.json 2>/dev/null || true)"
479487
if ! git diff --no-index --quiet -- "$CLAWSWEEPER_STATE_DIR/jobs" jobs; then
480488
jobs_changed=1
481489
fi
482490
if [ "$jobs_changed" = "0" ] &&
491+
[ "$cursor_changed" != "true" ] &&
483492
jq -e '((.ledger_claimed // 0) + (.ledger_changed // 0)) == 0' results/comment-router-latest.json >/dev/null 2>&1; then
484493
echo "No durable router retry state changed; skipping state publication."
485494
exit 0
@@ -493,6 +502,9 @@ jobs:
493502
if [ "$jobs_changed" = "1" ]; then
494503
publish_args+=(--path jobs)
495504
fi
505+
if [ "$cursor_changed" = "true" ]; then
506+
publish_args+=(--path "results/comment-router-cursors/${{ steps.target.outputs.target_slug }}.json")
507+
fi
496508
pnpm run repair:publish-main -- "${publish_args[@]}"
497509
498510
- name: Finalize command action ledger
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Router throttle resilience behavior contract
2+
3+
## User-visible goal
4+
5+
The repair comment router must defer GitHub installation or abuse throttles
6+
without losing its scheduled scan position, while still surfacing unrelated
7+
errors as failures.
8+
9+
## Target
10+
11+
- Type: operator CLI and scheduled-workflow state artifact.
12+
- Launch or access: `node scripts/e2e/comment-router-throttle-loopback.mjs`.
13+
- Allowed fixtures and credential source: deterministic loopback HTTP selected
14+
through `GITHUB_API_URL` and a synthetic placeholder token; no live secret.
15+
16+
## User tasks
17+
18+
1. Route an exact comment while its issue-comment history returns GitHub's real
19+
installation-rate-limit 403 body.
20+
2. Route a bounded broad batch containing one throttled issue and one issue
21+
whose context is already available.
22+
3. Retry the broad scan after GitHub recovers.
23+
4. Route the same exact comment when GitHub returns a non-throttle client error.
24+
25+
## Expected observable behavior
26+
27+
- Installation 403, abuse 403, and 429 responses produce a structured
28+
`github_throttled` skip and exit 0.
29+
- The throttled command is retained as waiting, already-routable work completes,
30+
and the cursor remains byte-for-byte unchanged.
31+
- The recovered broad scan requests comments oldest-first with
32+
`since=<cursor watermark>`, skips ids already handled at that timestamp, and
33+
advances only after success.
34+
- The non-throttle error exits nonzero.
35+
36+
## Anti-cheat probes
37+
38+
- Vary the throttle response between installation 403, abuse 403, and 429.
39+
- Include two comments with the same cursor timestamp and prove the saved id is
40+
not reprocessed.
41+
- Replace the throttle with a 422 response and require a failing exit.
42+
- Inspect the persisted cursor before defer and after successful retry.
43+
44+
## Evidence required
45+
46+
- Parsed CLI exit statuses and structured skip output.
47+
- Loopback request paths showing the incremental query.
48+
- Before/defer/retry cursor JSON summaries.
49+
- Git commit and tree ids resolved by Git in the validation container and
50+
checked with `git cat-file`.
51+
52+
## Out of scope
53+
54+
Live GitHub quota consumption, production workflow dispatch, GitHub mutation,
55+
and changes to the historical-comment semantics used by source-revision and
56+
status-comment guards.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
repo_root="$(git rev-parse --show-toplevel)"
5+
cd "$repo_root"
6+
output_dir="${ROUTER_THROTTLE_PROOF_OUTPUT:-.artifacts/router-throttle-resilience}"
7+
mkdir -p "$output_dir"
8+
9+
head_sha="$(git rev-parse HEAD)"
10+
head_tree="$(git rev-parse "${head_sha}^{tree}")"
11+
base_sha="$(git rev-parse origin/main)"
12+
git cat-file -e "${head_sha}^{commit}"
13+
git cat-file -e "${head_tree}^{tree}"
14+
git cat-file -e "${base_sha}^{commit}"
15+
16+
node scripts/e2e/comment-router-throttle-loopback.mjs > "$output_dir/behavior-result.json"
17+
jq -e '
18+
.ok == true and
19+
.transport == "loopback HTTP via GITHUB_API_URL" and
20+
(.assertions | all(.[]; . == true)) and
21+
any(.requests[]; contains("issues/comments?since=") and contains("sort=updated") and contains("direction=asc"))
22+
' "$output_dir/behavior-result.json" >/dev/null
23+
24+
node --test \
25+
test/repair/comment-router-throttle-resilience.test.ts \
26+
test/repair/comment-router-action-ledger.test.ts \
27+
test/repair/github-cli.test.ts \
28+
> "$output_dir/focused-tests.tap"
29+
30+
jq -n \
31+
--arg head_sha "$head_sha" \
32+
--arg head_tree "$head_tree" \
33+
--arg base_sha "$base_sha" \
34+
--arg node_version "$(node --version)" \
35+
--arg pnpm_version "$(pnpm --version)" \
36+
--slurpfile behavior "$output_dir/behavior-result.json" \
37+
'{
38+
schema_version: 1,
39+
head_sha: $head_sha,
40+
head_tree: $head_tree,
41+
base_sha: $base_sha,
42+
cat_file_cross_check: {
43+
head_commit: true,
44+
head_tree: true,
45+
base_commit: true
46+
},
47+
runtime: {
48+
node: $node_version,
49+
pnpm: $pnpm_version,
50+
transport: $behavior[0].transport
51+
},
52+
assertions: $behavior[0].assertions,
53+
request_count: ($behavior[0].requests | length),
54+
focused_tests_tap: "focused-tests.tap",
55+
limits: "Loopback GitHub API with synthetic credentials; no live GitHub mutation or production workflow dispatch."
56+
}' > "$output_dir/container-receipt.json"
57+
58+
jq -e '
59+
.schema_version == 1 and
60+
(.head_sha | test("^[0-9a-f]{40}$")) and
61+
(.head_tree | test("^[0-9a-f]{40}$")) and
62+
(.base_sha | test("^[0-9a-f]{40}$")) and
63+
.cat_file_cross_check == {head_commit:true, head_tree:true, base_commit:true} and
64+
(.assertions | all(.[]; . == true))
65+
' "$output_dir/container-receipt.json" >/dev/null
66+
67+
cat "$output_dir/container-receipt.json"

‎docs/repair/operations.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ it classifies the command, so the visible reply is available as soon as the
329329
target dispatcher starts. Exact comment dispatches scan only the source comment
330330
and use per-comment receiver concurrency; the scheduled sweep remains a
331331
five-minute fallback.
332+
The scheduled sweep persists a per-repository `updated_at` watermark and the
333+
comment ids already inspected at that exact timestamp. It reads repository
334+
comments oldest-first from that watermark and advances it only after the router
335+
process completes successfully. A GitHub installation rate limit, abuse-limit
336+
403, or 429 therefore emits a structured `github_throttled` defer and exits
337+
successfully without moving the watermark; the next sweep repeats the
338+
uncompleted interval. Other failures remain fatal. Exact-comment and exact-item
339+
dispatches never advance the scheduled watermark.
332340
The status comment itself uses one compact badge: `🦞👀` for acknowledgement,
333341
`🦞🧹` for review, `🦞🔧` for repair/build/fix work, and `🦞✅` for completed or
334342
paused work.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"repair:post-flight": "node dist/repair/post-flight.js",
4848
"repair:finalize-open-prs": "node dist/repair/finalize-open-prs.js",
4949
"repair:cleanup-replacement-labels": "node dist/repair/cleanup-replacement-labels.js",
50-
"repair:comment-router": "node dist/repair/comment-router.js",
50+
"repair:comment-router": "node scripts/comment-router-runner.mjs",
5151
"repair:action-ledger": "node dist/repair/action-ledger-cli.js",
5252
"repair:comment-webhook": "node dist/repair/comment-webhook.js",
5353
"repair:issue-implementation-intake": "node dist/repair/issue-implementation-intake.js",

0 commit comments

Comments
 (0)