The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
feat(github): unvouched PRs get an open PR limit, a conflict window, and a 72 hour close notice (#34555)
maria committed
Nov 12, 2026 at 00:47 UTC
1e25ef9e5747c321af91b81ab3492b22c65a91da
5 files changed
+414
-6
.agents/skills/contribution-triage/SKILL.md
+17
-4
@@ -111,6 +111,8 @@ trusted policy and reassess changed submission evidence; neither example grants
111
112
Do not automatically close a PR if a maintainer in the trusted `TRIAGE_EXEMPTIONS.td` list has
113
commented or submitted a review, including on earlier heads, or if `triage:keep-open` is present.
114
+Comments that triage itself posted, such as an earlier notice or question, are not maintainer
115
+involvement, even when they were posted from a maintainer's account on that maintainer's behalf.
116
Leave protected PRs open for maintainer decision. This does not grant an author exemption,
117
eligibility, or review approval.
118
@@ -126,7 +128,17 @@ comment text but do not write to GitHub. Keep the eligibility finding separate f
128
This is a routing exception, not a claim that the PR passed eligibility or correctness review.
129
- **Closure warranted.** The assessment is complete and establishes a specific policy violation.
130
Prepare a clear explanation under [closure and reconsideration](../../../CONTRIBUTING.md#closure-and-reconsideration),
129
- post it, and close the PR. Verify that the explanation is present and the PR is closed. The comment
131
+ post it, then read the repository variable `PR_LIMITS_ENFORCE`
132
+ (`gh variable get PR_LIMITS_ENFORCE -R pingdotgg/t3code`). When it prints `true`, apply
133
+ `triage:closing` as the last thing you do to the PR, verify that the explanation and the label
134
+ are present, and do not close the PR yourself:
135
+ [pr-limits.yml](../../../.github/workflows/pr-limits.yml) closes it 72 hours after the label. Any
136
+ activity on the PR after the label, including a further comment or label from you, removes the
137
+ label; treat an author's reply or push as new evidence, reassess, and apply the label again only
138
+ if the finding still holds. When the command prints any other value, or fails saying the variable
139
+ was not found, the variable is off and nothing would close a labeled PR: close it yourself and
140
+ verify that the explanation is present and the PR is closed. Only another failure, such as a
141
+ permission error, means the variable cannot be read; then report the closure as incomplete. The comment
142
must name the violated rule, cite supporting submission evidence, link the maintained guide section,
143
and give a concrete remedy. Missing contributor evidence can warrant closure; explain what must be
144
established. Missing product approval calls for maintainer discussion, not an agent's product decision.
@@ -173,9 +185,10 @@ description, evidence, approvals, existing triage comments, PR open/closed state
185
label when relevant. Reassess changes that could invalidate the finding. Reuse an existing explanation
186
only if it still matches the current finding; avoid duplicate comments, closures, or label applications.
187
176
-For closure, establish that the required explanation is posted before closing. If posting fails or its
177
-result is ambiguous, read back the comments before retrying or proceeding. If the comment succeeds but
178
-closure fails, preserve the comment and retry only the unfinished closure after checking current state.
188
+For closure, establish that the required explanation is posted before applying `triage:closing` or
189
+closing. If posting fails or its result is ambiguous, read back the comments before retrying or
190
+proceeding. If the comment succeeds but the label or the closure fails, preserve the comment and retry
191
+only that unfinished step after checking current state.
192
Handle a failed or ambiguous label application the same way: inspect labels before any retry. If access
193
or state still cannot be verified, report an incomplete action and the step needed to resume. Do not
194
retry blindly or claim success for an unverified action.
.github/scripts/pr-limits.cjs
new
+295
@@ -0,0 +1,295 @@
1
+const fs = require("node:fs");
2
+
3
+const HOUR_MS = 60 * 60 * 1000;
4
+const OPEN_LIMIT = 3;
5
+const CONFLICT_IDLE_MS = 7 * 24 * HOUR_MS;
6
+const NOTICE_MS = 72 * HOUR_MS;
7
+// A first run meets the whole backlog. These keep one run from flooding watchers or GitHub's
8
+// limit on how fast a token may comment.
9
+const MAX_REQUESTS_PER_RUN = 100;
10
+const MAX_CLOSES_PER_RUN = 50;
11
+const WRITE_PAUSE_MS = 1_000;
12
+// Measured here: about two and a half minutes until every open PR has an answer.
13
+const MERGEABLE_WAIT_MS = 150_000;
14
+// GitHub stamps a label event and the PR's updatedAt a second or two apart.
15
+const SAME_MOMENT_MS = 15_000;
16
+
17
+const REBASE_LABEL = "needs-rebase";
18
+const CLOSING_LABEL = "triage:closing";
19
+const KEEP_OPEN_LABEL = "triage:keep-open";
20
+const UNVOUCHED_LABEL = "vouch:unvouched";
21
+const WRITE_PERMISSIONS = new Set(["admin", "maintain", "write"]);
22
+const EXEMPTIONS_PATH = ".github/TRIAGE_EXEMPTIONS.td";
23
+const VOUCHED_PATH = ".github/VOUCHED.td";
24
+const LOGIN_PATTERN = /^github:([A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38})$/;
25
+
26
+// `labels` matches a PR that carries any one of them.
27
+const SWEEP_QUERY = `
28
+ query ($owner: String!, $repo: String!, $labels: [String!], $cursor: String) {
29
+ repository(owner: $owner, name: $repo) {
30
+ pullRequests(states: OPEN, labels: $labels, first: 100, after: $cursor) {
31
+ pageInfo { hasNextPage endCursor }
32
+ nodes {
33
+ number
34
+ mergeable
35
+ baseRefName
36
+ updatedAt
37
+ author { login }
38
+ labels(first: 100) { nodes { name } }
39
+ timelineItems(itemTypes: [LABELED_EVENT], last: 20) {
40
+ nodes { ... on LabeledEvent { createdAt label { name } } }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }`;
46
+
47
+const RECHECK_QUERY = `
48
+ query ($owner: String!, $repo: String!, $number: Int!) {
49
+ repository(owner: $owner, name: $repo) {
50
+ pullRequest(number: $number) {
51
+ state
52
+ mergeable
53
+ updatedAt
54
+ labels(first: 100) { nodes { name } }
55
+ }
56
+ }
57
+ }`;
58
+
59
+const AUTHOR_OPEN_PRS_QUERY = `
60
+ query ($q: String!) {
61
+ search(query: $q, type: ISSUE, first: 50) {
62
+ nodes { ... on PullRequest { number } }
63
+ }
64
+ }`;
65
+
66
+// Fails closed: a missing, empty, or malformed list must never read as "nobody is exempt".
67
+function parseExemptions(text) {
68
+ const logins = new Set();
69
+ for (const raw of text.split("\n")) {
70
+ const line = raw.trim();
71
+ if (line === "" || line.startsWith("#")) continue;
72
+ const match = LOGIN_PATTERN.exec(line);
73
+ if (!match) throw new Error(`${EXEMPTIONS_PATH}: malformed entry "${line}"`);
74
+ const login = match[1].toLowerCase();
75
+ if (logins.has(login)) throw new Error(`${EXEMPTIONS_PATH}: duplicate entry "${line}"`);
76
+ logins.add(login);
77
+ }
78
+ if (logins.size === 0) throw new Error(`${EXEMPTIONS_PATH}: no entries`);
79
+ return logins;
80
+}
81
+
82
+// VOUCHED.td: one `github:login` per line, `#` comments, and `-github:login reason` to denounce.
83
+function vouchedLogins(text) {
84
+ const logins = new Set();
85
+ for (const raw of text.split("\n")) {
86
+ const entry = raw.trim().split(/\s+/)[0];
87
+ if (entry.startsWith("github:")) logins.add(entry.slice("github:".length).toLowerCase());
88
+ }
89
+ if (logins.size === 0) throw new Error(`${VOUCHED_PATH}: no entries`);
90
+ return logins;
91
+}
92
+
93
+function labeledAt(pr, name) {
94
+ const last = pr.timelineItems.nodes.filter((event) => event.label?.name === name).at(-1);
95
+ return last ? Date.parse(last.createdAt) : undefined;
96
+}
97
+
98
+// The whole policy for the two windows. Activity is anything that moves the PR's updatedAt: a
99
+// push, a comment, a review, a label. Nobody can set that time, so nothing here trusts the author.
100
+function decide(pr, exemptions, now) {
101
+ const labels = new Set(pr.labels.nodes.map((label) => label.name));
102
+ if (labels.has(KEEP_OPEN_LABEL)) return "skip";
103
+ const updatedAt = Date.parse(pr.updatedAt);
104
+
105
+ if (labels.has(CLOSING_LABEL)) {
106
+ const since = labeledAt(pr, CLOSING_LABEL);
107
+ if (since === undefined) return "unknown-notice";
108
+ // Any activity after the notice sends the PR back to triage.
109
+ if (updatedAt - since > SAME_MOMENT_MS) return "clear-notice";
110
+ return now - since >= NOTICE_MS ? "close-notice" : "skip";
111
+ }
112
+
113
+ const exempt = exemptions.has((pr.author?.login ?? "").toLowerCase());
114
+ const subject = labels.has(UNVOUCHED_LABEL) && !exempt;
115
+ if (labels.has(REBASE_LABEL)) {
116
+ if (!subject || pr.mergeable === "MERGEABLE") return "clear-rebase";
117
+ // Activity restarts the seven days and keeps the label, so a PR is asked to rebase once.
118
+ const idle = now - updatedAt >= CONFLICT_IDLE_MS;
119
+ return idle && pr.mergeable === "CONFLICTING" ? "close-conflict" : "skip";
120
+ }
121
+ return subject && pr.mergeable === "CONFLICTING" ? "request-rebase" : "skip";
122
+}
123
+
124
+function guideLink(context, anchor) {
125
+ return `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#${anchor}`;
126
+}
127
+
128
+async function removeLabel(github, context, number, name) {
129
+ try {
130
+ await github.rest.issues.removeLabel({ ...context.repo, issue_number: number, name });
131
+ } catch (error) {
132
+ if (error.status !== 404) throw error;
133
+ }
134
+}
135
+
136
+async function closeWithComment(github, context, number, body) {
137
+ await github.rest.issues.createComment({ ...context.repo, issue_number: number, body });
138
+ await github.rest.pulls.update({ ...context.repo, pull_number: number, state: "closed" });
139
+}
140
+
141
+async function sweep({ github, context, core, dryRun }) {
142
+ const exemptions = parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8"));
143
+ const repo = { owner: context.repo.owner, repo: context.repo.repo };
144
+ const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
145
+
146
+ const list = async () => {
147
+ const prs = [];
148
+ for (let cursor = null; ;) {
149
+ const page = (
150
+ await github.graphql(SWEEP_QUERY, {
151
+ ...repo,
152
+ cursor,
153
+ labels: [UNVOUCHED_LABEL, REBASE_LABEL, CLOSING_LABEL],
154
+ })
155
+ ).repository.pullRequests;
156
+ prs.push(...page.nodes);
157
+ if (!page.pageInfo.hasNextPage) return prs;
158
+ cursor = page.pageInfo.endCursor;
159
+ }
160
+ };
161
+ // GitHub computes mergeability lazily and forgets it whenever the base moves. Asking starts the
162
+ // computation, so ask once more. A PR that is still unknown waits for tomorrow's run.
163
+ let prs = await list();
164
+ if (prs.some((pr) => pr.mergeable === "UNKNOWN")) {
165
+ await pause(MERGEABLE_WAIT_MS);
166
+ prs = await list();
167
+ }
168
+
169
+ const now = Date.now();
170
+ const count = {};
171
+ for (const pr of prs) {
172
+ const { number } = pr;
173
+ let action = decide(pr, exemptions, now);
174
+ if (action === "skip") continue;
175
+ if (action === "unknown-notice") {
176
+ core.warning(`#${number}: cannot tell when ${CLOSING_LABEL} was applied, leaving it open.`);
177
+ continue;
178
+ }
179
+ if (action === "request-rebase" && (count[action] ?? 0) >= MAX_REQUESTS_PER_RUN) continue;
180
+ if (action.startsWith("close")) {
181
+ if ((count["close-conflict"] ?? 0) + (count["close-notice"] ?? 0) >= MAX_CLOSES_PER_RUN) {
182
+ continue;
183
+ }
184
+ // The list is minutes old by now. Closing is the one step worth a second look.
185
+ const fresh = (await github.graphql(RECHECK_QUERY, { ...repo, number })).repository
186
+ .pullRequest;
187
+ if (fresh.state !== "OPEN") continue;
188
+ // A merge to the base can resolve a conflict without touching the PR, so this is re-read
189
+ // too. An answer that is not ready yet reads as "not conflicting" and waits for tomorrow.
190
+ action = decide({ ...pr, ...fresh }, exemptions, now);
191
+ if (!action.startsWith("close")) continue;
192
+ }
193
+
194
+ count[action] = (count[action] ?? 0) + 1;
195
+ core.info(`#${number} ${action}${dryRun ? " (dry run)" : ""}`);
196
+ if (dryRun) continue;
197
+
198
+ if (action === "request-rebase") {
199
+ // The request goes first: a label without it would start a clock nobody was told about.
200
+ await github.rest.issues.createComment({
201
+ ...context.repo,
202
+ issue_number: number,
203
+ body: [
204
+ `This PR conflicts with \`${pr.baseRefName}\`. Rebase it or merge \`${pr.baseRefName}\` into it. If it still conflicts after 7 days with no activity, it will be closed automatically.`,
205
+ "",
206
+ `See the [conflict window](${guideLink(context, "conflict-window")}).`,
207
+ ].join("\n"),
208
+ });
209
+ await github.rest.issues.addLabels({
210
+ ...context.repo,
211
+ issue_number: number,
212
+ labels: [REBASE_LABEL],
213
+ });
214
+ } else if (action === "clear-rebase") {
215
+ await removeLabel(github, context, number, REBASE_LABEL);
216
+ } else if (action === "clear-notice") {
217
+ await removeLabel(github, context, number, CLOSING_LABEL);
218
+ } else {
219
+ const conflict = action === "close-conflict";
220
+ await closeWithComment(
221
+ github,
222
+ context,
223
+ number,
224
+ conflict
225
+ ? [
226
+ `Closing: this PR still conflicts with \`${pr.baseRefName}\` and has had no activity for 7 days since the rebase request.`,
227
+ "",
228
+ `To continue, rebase the branch and open a new PR that links this one. See the [conflict window](${guideLink(context, "conflict-window")}).`,
229
+ ].join("\n")
230
+ : [
231
+ "Closing: 72 hours have passed since the triage notice above with no activity on this PR.",
232
+ "",
233
+ `To ask for reconsideration, address the notice and comment here, or open a focused replacement PR that links this one. See [closure and reconsideration](${guideLink(context, "closure-and-reconsideration")}).`,
234
+ ].join("\n"),
235
+ );
236
+ // Without this a maintainer's reopen would be closed again by the next run.
237
+ await removeLabel(github, context, number, conflict ? REBASE_LABEL : CLOSING_LABEL);
238
+ }
239
+ await pause(WRITE_PAUSE_MS);
240
+ }
241
+
242
+ const summary = Object.entries(count).map(([action, n]) => `${n} ${action}`);
243
+ core.info(
244
+ `${dryRun ? "Dry run. " : ""}${prs.length} PRs read: ${summary.join(", ") || "nothing to do"}.`,
245
+ );
246
+ return count;
247
+}
248
+
249
+async function enforceOpenLimit({ github, context, core, dryRun }) {
250
+ const pr = context.payload.pull_request;
251
+ const author = pr.user.login;
252
+ // Who is trusted is decided here rather than by the vouch action, which reports its own failed
253
+ // lookups as "not vouched". Every read below throws on failure, and a throw closes nothing.
254
+ if (pr.user.type === "Bot") return;
255
+ if (parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8")).has(author.toLowerCase())) return;
256
+ if (vouchedLogins(fs.readFileSync(VOUCHED_PATH, "utf8")).has(author.toLowerCase())) return;
257
+ const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({
258
+ ...context.repo,
259
+ username: author,
260
+ });
261
+ if (WRITE_PERMISSIONS.has(access.permission)) return;
262
+ if (pr.labels.some((label) => label.name === KEEP_OPEN_LABEL)) return;
263
+ // Someone else reopening a PR is a maintainer overriding the limit.
264
+ const reopened = context.payload.action === "reopened";
265
+ if (reopened && context.payload.sender.login.toLowerCase() !== author.toLowerCase()) return;
266
+
267
+ const q = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open author:${author} sort:created-asc`;
268
+ const { search } = await github.graphql(AUTHOR_OPEN_PRS_QUERY, { q });
269
+ // A new PR counts only the older ones, so two opened together cannot close each other.
270
+ const others = search.nodes.filter(
271
+ (node) => node.number && (reopened ? node.number !== pr.number : node.number < pr.number),
272
+ ).length;
273
+ if (others < OPEN_LIMIT) {
274
+ core.info(`PR #${pr.number}: ${author} has ${others} other open PRs.`);
275
+ return;
276
+ }
277
+ if (dryRun) {
278
+ core.notice(`Dry run. PR #${pr.number} would close: ${author} has ${others} other open PRs.`);
279
+ return;
280
+ }
281
+
282
+ await closeWithComment(
283
+ github,
284
+ context,
285
+ pr.number,
286
+ [
287
+ `Closing: ${author} already has ${OPEN_LIMIT} or more open PRs here, which is the limit for contributors who are not vouched.`,
288
+ "",
289
+ `Once one of them is merged or closed, open this again. See the [open PR limit](${guideLink(context, "open-pr-limit")}).`,
290
+ ].join("\n"),
291
+ );
292
+ core.info(`PR #${pr.number}: closed, ${author} has ${others} other open PRs.`);
293
+}
294
+
295
+module.exports = { decide, enforceOpenLimit, parseExemptions, sweep };
.github/workflows/pr-limits.yml
new
+72
@@ -0,0 +1,72 @@
1
+name: PR Limits
2
+
3
+# Deterministic PR rules from CONTRIBUTING.md: the open PR limit, the conflict
4
+# window, and the 72 hour close window that follows a triage notice.
5
+#
6
+# Nothing is labeled, commented on, or closed until the repository variable
7
+# PR_LIMITS_ENFORCE is "true". Until then every run logs what it would do. A
8
+# sweep reads the variable once when it starts; to stop one, cancel the run.
9
+
10
+on:
11
+ pull_request_target:
12
+ types: [opened, reopened]
13
+ schedule:
14
+ - cron: "23 5 * * *"
15
+ workflow_dispatch:
16
+ inputs:
17
+ dry_run:
18
+ description: Log what the sweep would do without labeling, commenting, or closing.
19
+ type: boolean
20
+ default: true
21
+
22
+permissions:
23
+ contents: read
24
+ issues: write
25
+ pull-requests: write
26
+
27
+jobs:
28
+ open-limit:
29
+ name: Open PR limit
30
+ if: github.event_name == 'pull_request_target'
31
+ runs-on: ubuntu-24.04
32
+ steps:
33
+ # pull_request_target has a write token. Load the script from the default
34
+ # branch and never run PR code. Cone mode also checks out the files beside
35
+ # .github/scripts, which is where TRIAGE_EXEMPTIONS.td and VOUCHED.td live.
36
+ - name: Checkout trusted scripts
37
+ uses: actions/checkout@v6
38
+ with:
39
+ ref: ${{ github.event.repository.default_branch }}
40
+ sparse-checkout: .github/scripts
41
+
42
+ - name: Close PRs over the limit
43
+ uses: actions/github-script@v8
44
+ env:
45
+ DRY_RUN: ${{ vars.PR_LIMITS_ENFORCE != 'true' }}
46
+ with:
47
+ script: |
48
+ const limits = require("./.github/scripts/pr-limits.cjs");
49
+ await limits.enforceOpenLimit({ github, context, core, dryRun: process.env.DRY_RUN === "true" });
50
+
51
+ sweep:
52
+ name: Conflict and close windows
53
+ if: github.event_name != 'pull_request_target'
54
+ runs-on: ubuntu-24.04
55
+ concurrency:
56
+ group: pr-limits-sweep
57
+ cancel-in-progress: false
58
+ steps:
59
+ - name: Checkout trusted scripts
60
+ uses: actions/checkout@v6
61
+ with:
62
+ ref: ${{ github.event.repository.default_branch }}
63
+ sparse-checkout: .github/scripts
64
+
65
+ - name: Request rebases and close what went unanswered
66
+ uses: actions/github-script@v8
67
+ env:
68
+ DRY_RUN: ${{ vars.PR_LIMITS_ENFORCE != 'true' || (github.event_name == 'workflow_dispatch' && inputs.dry_run) }}
69
+ with:
70
+ script: |
71
+ const limits = require("./.github/scripts/pr-limits.cjs");
72
+ await limits.sweep({ github, context, core, dryRun: process.env.DRY_RUN === "true" });
CONTRIBUTING.md
+29
-2
@@ -141,14 +141,41 @@ supported event fetches current full PR state and assesses cumulative changes; u
141
not wired and there is no periodic sweep. This guide does not announce a deployed automation or change
142
existing review settings. Neither triage nor a Macroscope review authorizes merging.
143
144
+<a id="open-pr-limit"></a>
145
+
146
+## Open PR limit and conflict window
147
+
148
+Two rules run without triage, in [pr-limits.yml](.github/workflows/pr-limits.yml). Neither applies
149
+to vouched contributors, to maintainers in [TRIAGE_EXEMPTIONS.td](.github/TRIAGE_EXEMPTIONS.td), or to
150
+a PR labeled `triage:keep-open`. They do not assess eligibility. They and the closure notice below are
151
+enforced only while the repository variable `PR_LIMITS_ENFORCE` is `true`; until then triage closes
152
+PRs directly.
153
+
154
+A contributor who is not vouched can have 3 open PRs. A further PR is closed when it is opened. Get
155
+one of the open PRs merged or closed, then open it again. A maintainer who reopens a PR overrides the
156
+limit for that PR.
157
+
158
+<a id="conflict-window"></a>
159
+
160
+A PR labeled `vouch:unvouched` that conflicts with its base branch gets a request to rebase and the
161
+`needs-rebase` label. The label comes off once the PR no longer conflicts. A PR that still conflicts
162
+after 7 days with no activity is closed. Any activity on the PR, such as a push, a comment, or a
163
+review from anyone, restarts the 7 days.
164
+
165
<a id="closure-and-reconsideration"></a>
166
167
## Closure and reconsideration
168
169
Automated triage leaves a PR open for maintainer decision if someone in the trusted
170
[TRIAGE_EXEMPTIONS.td](.github/TRIAGE_EXEMPTIONS.td) list has commented or submitted a review,
150
-including on an earlier head, or if `triage:keep-open` is present. This protection does not imply
151
-eligibility or review approval.
171
+including on an earlier head, or if `triage:keep-open` is present. Comments that triage itself
172
+posted, such as an earlier notice, do not count, even when they came from a maintainer's account.
173
+This protection does not imply eligibility or review approval.
174
+
175
+A policy-based closure starts with a notice. Triage posts the explanation and applies
176
+`triage:closing`, and the PR closes 72 hours later. Any activity on the PR within that time, such as
177
+a reply, a push, or a maintainer's comment, removes the label and sends the PR back to triage, which
178
+reassesses it with the new evidence.
179
180
PRs that violate these requirements can be closed before deeper review. Multiple independent fixes
181
require splitting. Missing approval requires maintainer discussion or issue triage, as applicable.
knip.jsonc
+1
@@ -12,6 +12,7 @@
12
// CodeRabbit loads its configuration by filename.
13
".coderabbit.config.ts",
14
".github/scripts/thread-transfer-report.cjs",
15
+ ".github/scripts/pr-limits.cjs",
16
],
17
"vite": { "entry": [".github/**/*.test.cjs"] },
18
"vitest": { "entry": [".github/**/*.test.cjs"] },