Skip to content

Commit dc6fc0b

Browse files
authored
fix(webhook): grant pull request fast-ack tokens pull_requests write (#1082)
* fix(webhook): grant pull request fast-ack tokens pull_requests write The PR receipt fast ack minted its installation token with pull_requests: read, but posting a comment on a pull request through the issues API requires pull_requests: write for App tokens. GitHub answered 403 Resource not accessible by integration, the ack threw, and between PR #1078 and #1079 that uncaught throw returned HTTP 500 to every pull_request opened/ready_for_review webhook delivery (outage window 2026-08-09 04:12-04:52Z); after #1079 the same failure was swallowed silently, so no PR ever received its receipt comment. Also mint App installation tokens with the documented repositories parameter instead of repository_names, which GitHub ignores - tokens were silently granted installation-wide repository_selection=all instead of being scoped to the named repository. Log swallowed fast-ack failures so the next regression is visible in wrangler tail. * docs: reference PR number in changelog entries
1 parent 6971afb commit dc6fc0b

6 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎CHANGELOG.md‎

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

4242
### Fixed
4343

44+
- Restored pull request 🦞👀 receipt comments by granting fast-ack tokens `pull_requests: write`. (#1082)
45+
- Scoped GitHub App tokens to their named repositories via the documented `repositories` parameter. (#1082)
4446
- Legacy reports with canonical proof or rating keys outside the apparent leading front-matter block now fail closed, with a read-only workflow to inventory affected canonical records. (#1049)
4547
- Prevented model-authored report prose and body-shaped front matter from spoofing proof or rating sections, keeping unproven external pull requests in human review instead of routing them into automated repair. (#951)
4648

‎dashboard/exact-review-queue.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13093,7 +13093,7 @@ export async function createGithubAppTokenFor({
1309313093
{
1309413094
method: "POST",
1309513095
body: JSON.stringify({
13096-
repository_names: repositories.filter(Boolean),
13096+
repositories: repositories.filter(Boolean),
1309713097
permissions,
1309813098
}),
1309913099
errorLabel: `GitHub App token for ${label}`,

‎dashboard/worker.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,10 @@ async function githubWebhook(request, env, ctx) {
11991199
const deliveryId = request.headers.get("x-github-delivery") || "";
12001200
let itemDecision = decision as ExactReviewDecision & { installationId?: number };
12011201
if (itemDecision.itemKind === "pull_request") {
1202-
await acknowledgePullRequestReceipt({ env, ctx, decision: itemDecision }).catch(
1203-
() => undefined,
1204-
);
1202+
await acknowledgePullRequestReceipt({ env, ctx, decision: itemDecision }).catch((error) => {
1203+
console.error(`ClawSweeper pull request fast ack failed: ${error?.message || error}`);
1204+
return undefined;
1205+
});
12051206
}
12061207
itemDecision = await withPullRequestEditContentRevision({
12071208
event,
@@ -2466,7 +2467,7 @@ async function acknowledgePullRequestReceipt({ env, ctx, decision }) {
24662467
installationId: decision.installationId,
24672468
label: decision.targetRepo,
24682469
repositories: [repoName(decision.targetRepo)],
2469-
permissions: { issues: "write", pull_requests: "read" },
2470+
permissions: { issues: "write", pull_requests: "write" },
24702471
});
24712472
const ackMarker = pullRequestFastAckMarker(decision.itemNumber, decision.sourceAction);
24722473
const statusCommentId = await createFastAckCommentOnce({

‎src/repair/comment-webhook.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ async function createInstallationToken({
466466
path: `/app/installations/${installationId}/access_tokens`,
467467
method: "POST",
468468
body: {
469-
repository_names: repositories.filter(Boolean),
469+
repositories: repositories.filter(Boolean),
470470
permissions,
471471
},
472472
authScheme: "Bearer",

‎test/dashboard-worker.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25951,6 +25951,10 @@ test("hosted pull request receipt fast acks precede verification and stay idempo
2595125951
globalThis.fetch = async (input, init) => {
2595225952
const url = new URL(String(input));
2595325953
if (url.pathname === "/app/installations/123/access_tokens") {
25954+
assert.deepEqual(JSON.parse(String(init?.body)), {
25955+
repositories: ["gogcli"],
25956+
permissions: { issues: "write", pull_requests: "write" },
25957+
});
2595425958
return jsonResponse({ token: "target-token" });
2595525959
}
2595625960
const pullMatch = /^\/repos\/openclaw\/gogcli\/pulls\/(\d+)$/.exec(url.pathname);
@@ -25978,7 +25982,12 @@ test("hosted pull request receipt fast acks precede verification and stay idempo
2597825982
if (commentMatch && init?.method === "POST") {
2597925983
const itemNumber = Number(commentMatch[1]);
2598025984
fastAckPostAttempts.set(itemNumber, (fastAckPostAttempts.get(itemNumber) || 0) + 1);
25981-
if (itemNumber === 601) throw new Error("GitHub comment write failed");
25985+
if (itemNumber === 601) {
25986+
return new Response(JSON.stringify({ message: "Resource not accessible by integration" }), {
25987+
status: 403,
25988+
headers: { "content-type": "application/json" },
25989+
});
25990+
}
2598225991
const body = JSON.parse(String(init.body || "{}"));
2598325992
const comment = {
2598425993
id: 9000 + itemNumber,

‎test/exact-review-publication-batches.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ test("rollout dispatches one full batch workflow without admitting legacy publis
17091709
if (url.pathname === "/app/installations/1000/access_tokens") {
17101710
const body = JSON.parse(String(init?.body));
17111711
assert.deepEqual(body, {
1712-
repository_names: ["openclaw"],
1712+
repositories: ["openclaw"],
17131713
permissions: { issues: "read", pull_requests: "read" },
17141714
});
17151715
return new Response(JSON.stringify({ token: "target-token" }), {

0 commit comments

Comments
 (0)