Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
3445b0b
fix(web): terminal output no longer edits a hidden question draft (#2…
juliusmarminge Nov 11, 2026
4d1808d
fix(opencode): show prompts other OpenCode 2 clients send into a T3 s…
juliusmarminge Nov 11, 2026
2a8ec9c
fix(web): single-digit numbered lists no longer clip in wide fonts (#…
juliusmarminge Nov 11, 2026
93c1023
feat(cli): t3 service runs on Windows, so Windows hosts update remote…
t3dotgg Nov 11, 2026
9b98bd0
fix(shared): new chats use the global default when the project defaul…
juliusmarminge Nov 11, 2026
25d2239
fix(web): screen readers hear when a thread is pinned or an action is…
juliusmarminge Nov 11, 2026
6583670
fix(desktop): Linux launches no longer leave an icon copy in /tmp (#2…
juliusmarminge Nov 11, 2026
7315c60
fix(server): a failed Claude wake dispatch no longer drops every late…
juliusmarminge Nov 11, 2026
e5b5da3
fix(web): reopening a guide with many cached diff pages no longer cra…
juliusmarminge Nov 11, 2026
ed57b9b
fix(server): a follow-up to a finished remote task is a new task that…
juliusmarminge Nov 11, 2026
ea3e20a
fix(web): double-clicking another thread in the sidebar renames it in…
juliusmarminge Nov 11, 2026
3ffd240
fix(server): a turn that adds a Git remote shows "Add to another mach…
juliusmarminge Nov 11, 2026
a2a3388
fix(server): keep writes moving while readers pin the WAL (#23496)
juliusmarminge Nov 11, 2026
8851e30
fix(client-runtime): slow foreground probes keep live sessions connec…
juliusmarminge Nov 11, 2026
6e3ada1
fix(server): wake Codex callers when restart cancels commands (#24538)
juliusmarminge Nov 11, 2026
2cd7996
fix(server): list skills from plugins synced from claude.ai (#28633)
juliusmarminge Nov 11, 2026
bd5ed4d
fix(provider-cursor): Cursor sign-in shows why it failed (#25938)
juliusmarminge Nov 11, 2026
52f0988
fix(mobile): iPad sidebar shows new threads after switching tabs (#27…
juliusmarminge Nov 11, 2026
289078a
fix(opencode): wait for a cold directory's scan before caching its sk…
juliusmarminge Nov 11, 2026
962eeef
fix(client-runtime): retry messages after socket loss with the same c…
juliusmarminge Nov 11, 2026
25c5998
fix(provider-core): Nix store provider installs no longer offer an up…
juliusmarminge Nov 11, 2026
4ea32cb
fix(server): load balancing reads container cgroup limits instead of …
juliusmarminge Nov 11, 2026
c8ddb22
fix(desktop): middle-click paste follows gtk-enable-primary-paste on …
juliusmarminge Nov 11, 2026
c501cca
fix(server): PR watch waits for queued GitHub workflow runs (#34624)
juliusmarminge Nov 11, 2026
6e6b6a7
fix(opencode): stopped sessions can fork after a lost end event (#24552)
juliusmarminge Nov 11, 2026
ea6af46
fix(server): @ file search matches paths containing square brackets (…
juliusmarminge Nov 11, 2026
4d52d32
fix(client-runtime): MCP App requests with undefined values reach the…
juliusmarminge Nov 11, 2026
d27d03b
fix(provider-core): recheck a failed sign-in when settings are applie…
juliusmarminge Nov 11, 2026
52ba328
fix(server): avoid reparsing streamed replies from the beginning (#24…
juliusmarminge Nov 11, 2026
50952be
fix(server): No project behind a symlinked scratch folder stays No pr…
juliusmarminge Nov 11, 2026
04be2b3
fix(server): Codex and Pi runs report the model the provider ran (#34…
juliusmarminge Nov 11, 2026
c642c4b
fix(server): settling a Codex thread stops its MCP servers right away…
juliusmarminge Nov 11, 2026
0ad9c9a
fix(server): a full disk no longer crashes the server through a faile…
juliusmarminge Nov 11, 2026
de21fbc
fix(client): a thread whose subscription dies on a defect resubscribe…
juliusmarminge Nov 11, 2026
86e2cb2
fix(server): Claude turns on busy hosts no longer time out registerin…
dw3105 Nov 11, 2026
52da4e5
fix(server): reuse timeline indexes while paging long threads (#24422)
juliusmarminge Nov 11, 2026
aeaf19c
fix(server): a slow or broken hosting CLI is no longer told to instal…
juliusmarminge Nov 11, 2026
1d61dd3
fix(server): recurring tasks keep one queued occurrence while their t…
juliusmarminge Nov 11, 2026
35f5398
fix(server): only offer desktop app updates the desktop can install (…
juliusmarminge Nov 11, 2026
d9805b2
fix(server): closing preview tabs runs beforeunload handlers (#23537)
juliusmarminge Nov 12, 2026
fe565c8
fix(server): storage cleanup keeps edits hidden from git status (#31069)
juliusmarminge Nov 12, 2026
1de5fee
fix(server): price OpenCode Go usage from opencode_go rates (#30683)
juliusmarminge Nov 12, 2026
fdd54b9
fix(server): stop jobs a Claude CLI moved out of its process group wh…
juliusmarminge Nov 12, 2026
cf65084
fix(server): Antigravity install names network failures and 16 KiB-pa…
juliusmarminge Nov 12, 2026
94f7984
fix(web): preserve typed question answers when Stop cancels a turn (#…
juliusmarminge Nov 12, 2026
60ec7fc
fix(desktop): check T3 home ownership before starting the local backe…
juliusmarminge Nov 12, 2026
3af5018
fix(server): open projects in a new VS Code window (#34480)
juliusmarminge Nov 12, 2026
c0b67b7
fix(web): wrap interruption footers as one sentence (#34649)
Yash-Singh1 Nov 12, 2026
2a6b2c8
feat(web): switch the UI language from Settings, with Spanish and Chi…
maria-rcks Nov 12, 2026
afade9b
feat(web): add Brazilian Portuguese translation (#33161)
maria-rcks Nov 12, 2026
93d502f
feat(web): add French translation (#33162)
maria-rcks Nov 12, 2026
d8631c8
feat(web): add German translation (#33163)
maria-rcks Nov 12, 2026
2718951
feat(web): add Japanese translation (#33164)
maria-rcks Nov 12, 2026
fdefab4
feat(web): add Korean translation (#33165)
maria-rcks Nov 12, 2026
13eb5c9
feat(web): add Russian translation (#33166)
maria-rcks Nov 12, 2026
6eef4ac
feat(mobile): switch the settings language (#33169)
maria-rcks Nov 12, 2026
9411a71
fix(web): dismissing the pull request checkout toast stops the handof…
juliusmarminge Nov 12, 2026
f28dc8e
fix(cursor): unified usage plans show one meter (#34506)
juliusmarminge Nov 12, 2026
7271ea0
fix(web): editing a queued message keeps its thread mention chips (#3…
juliusmarminge Nov 12, 2026
2ed69de
fix(desktop): browser snapshots work after relay reconnects (#24829)
juliusmarminge Nov 12, 2026
d749cfd
fix(server): skip Claude interrupts after session teardown (#25159)
juliusmarminge Nov 12, 2026
cacdbb2
fix(desktop): a maximized window reopens on the display it was last u…
juliusmarminge Nov 12, 2026
67d7de8
fix(provider-core): bun-global updates only offer versions bun will i…
juliusmarminge Nov 12, 2026
d21daa7
fix(cli): t3 thread finds the project from inside its git worktrees (…
juliusmarminge Nov 12, 2026
8af1fc1
fix(dev): import seed snapshots with peer preview migrations (#25058)
juliusmarminge Nov 12, 2026
98fd5f2
fix(desktop): AppImage updates no longer leave old runtimes and mount…
juliusmarminge Nov 12, 2026
6d35d09
fix(cli): t3 triage points at the prompt when the agent fails to star…
juliusmarminge Nov 12, 2026
cc62443
fix(web): formatted link labels wrap inside table cells (#27781)
juliusmarminge Nov 12, 2026
2904fea
fix(web): Mod+B toggles bold at a collapsed cursor when the sidebar t…
juliusmarminge Nov 12, 2026
42d645a
fix(web): update Retry stops re-sending servers already on the target…
juliusmarminge Nov 12, 2026
b18fefd
fix(web): switching a cold Claude thread to Codex no longer compacts …
juliusmarminge Nov 12, 2026
a24f7a1
fix(web): code blocks always show their own highlighted source (#34527)
maria-rcks Nov 12, 2026
26f0a62
fix(acp): only approved execute requests let the agent open client te…
maria-rcks Nov 12, 2026
b9d9aab
fix(pi): long tool calls no longer share a session approval with diff…
maria-rcks Nov 12, 2026
35557e6
fix(cli): thread, project, and connect commands skip a server that is…
maria-rcks Nov 12, 2026
9c7f6eb
fix(server): file metadata lookups skip the server's own state files …
maria-rcks Nov 12, 2026
8df455c
fix(acp-registry): ACP Registry installs only change the mode of a co…
maria-rcks Nov 12, 2026
76b3e33
fix(server): MCP tokens still expire after the clock steps back (#34532)
maria-rcks Nov 12, 2026
2bcbdae
fix(server): ChatGPT sign-in keeps listening after a stray callback r…
maria-rcks Nov 12, 2026
3e90486
fix(mobile): show and let users skip compaction before sending to sta…
juliusmarminge Nov 12, 2026
1c65ad0
fix(web): Cmd+A in the rendered Markdown preview selects only the fil…
juliusmarminge Nov 12, 2026
cd8fc91
fix(web): don't offer VS Code on iPad, iPhone and Android browsers (#…
juliusmarminge Nov 12, 2026
1c3d5f7
fix(web): a link to a thread on a linked machine no longer opens a bl…
juliusmarminge Nov 12, 2026
f6b260d
fix(server): self-update moves the t3 command to the new runtime (#14…
JonasFocus Nov 12, 2026
9c96180
fix(server): t3_thread_launch says when its project does not exist (#…
juliusmarminge Nov 12, 2026
fd64128
fix(mobile): iOS web previews keep their flick momentum (#27671)
juliusmarminge Nov 12, 2026
1e25ef9
feat(github): unvouched PRs get an open PR limit, a conflict window, …
maria-rcks Nov 12, 2026
4e69247
fix(web): pasted CRLF text keeps its blank lines and caret in the com…
juliusmarminge Nov 12, 2026
ccc9aaf
fix(server): a cancelled queued Claude continuation no longer drops l…
juliusmarminge Nov 12, 2026
6a03ef6
fix(web): app keybindings on Mod+B, Mod+I and Mod+E win over composer…
juliusmarminge Nov 12, 2026
338e738
fix(web): thread shortcuts work with the narrow sidebar closed (#23568)
juliusmarminge Nov 12, 2026
a6d676f
fix(web): keep background tasks visible during follow-up turns (#24336)
juliusmarminge Nov 12, 2026
6b1d9d5
fix(mobile): the Link a machine sheet scrolls on Android (#34659)
juliusmarminge Nov 12, 2026
cf906e1
feat(web): resolved review conversations fold into avatars on their d…
maria-rcks Nov 12, 2026
7c76c9d
fix(web): mouse back/forward over the right panel no longer moves the…
juliusmarminge Nov 12, 2026
af2421f
fix(github): the PR limits sweep retries a failed read (#34671)
maria-rcks Nov 12, 2026
8214342
fix(web): collapsed PR comments no longer show raw HTML (#32283)
Saikrishna1876 Nov 12, 2026
34e7b66
fix(server): t3_thread_list counts threads waiting on background work…
juliusmarminge Nov 12, 2026
7d71f85
fix(mobile): screen readers hear when the open thread needs you or fi…
shivamhwp Nov 12, 2026
d47f2e0
fix(server): providers keep their saved status until the first check …
juliusmarminge Nov 12, 2026
a21b43f
fix(mobile): choosing a project for a draft whose project is gone kee…
juliusmarminge Nov 12, 2026
d63db06
fix(contracts): side chats open after an abandoned worktree setup (#3…
juliusmarminge Nov 12, 2026
3288254
fix(web): interruption footer label sits on the reason's baseline (#3…
pouyarezvani Nov 12, 2026
4ae66e2
fix(opencode): project-defined models appear in that project's picker…
juliusmarminge Nov 12, 2026
e304dab
fix(server): t3 theme updates a dev server running in the default hom…
juliusmarminge Nov 12, 2026
7462f23
fix(server): preserve delegated results across wake turns (#34568)
Yash-Singh1 Nov 12, 2026
671f854
fix(cli): thread --wait returns once background work the agent waits …
juliusmarminge Nov 12, 2026
489fa8c
fix(cursor): hide duplicate pooled usage limits (#34421)
Yash-Singh1 Nov 12, 2026
afe0528
fix(web): keep git action loading rows at idle height (#34727)
Yash-Singh1 Nov 12, 2026
2248ca8
fix(cursor): steer the live run without reconnecting (#28980)
Jaiminp007 Nov 12, 2026
d9a54ec
fix(web): file breadcrumbs keep backslashes in POSIX folder names (#3…
juliusmarminge Nov 12, 2026
2ab87e1
fix(server): Pi usage and session import read the instance's home (#3…
juliusmarminge Nov 12, 2026
c0c7405
fix(server): t3_thread_list says when its project does not exist (#29…
juliusmarminge Nov 12, 2026
fd033df
fix(web): improve Word document previews (#34722)
Yash-Singh1 Nov 12, 2026
55a94e2
fix(web): voice settings and dictation match the rest of the app (#33…
maria-rcks Nov 12, 2026
c0f85e7
feat(web): reply to an assistant response from its hover actions (#33…
maria-rcks Nov 12, 2026
bc647ed
fix(server): title requests about referenced threads accurately (#34723)
Yash-Singh1 Nov 12, 2026
3a30b01
fix(web): cancelled PR checks show a gray stop sign instead of the fa…
Yash-Singh1 Nov 12, 2026
8c15be9
fix(cursor): recover restarted threads with older runs (#24540)
juliusmarminge Nov 12, 2026
d353fba
fix(desktop): stalled update downloads time out and say why (#26244)
juliusmarminge Nov 12, 2026
8ea4a88
fix(server): Tailscale Serve forwards to the address a specific --hos…
juliusmarminge Nov 12, 2026
9c19aa9
fix(tailscale): serve setup no longer times out on a long success sum…
juliusmarminge Nov 12, 2026
b75f117
fix(server): Rescan finds tools installed after T3 Code started (#23610)
juliusmarminge Nov 12, 2026
a41b882
fix(server): advertise the tailnet name when sshd listens only on the…
juliusmarminge Nov 12, 2026
ea22b5f
fix(web): preview address bar waits for the IME to finish before navi…
juliusmarminge Nov 12, 2026
82465ed
fix(tailscale): Tailscale HTTPS is advertised only when it reaches th…
juliusmarminge Nov 12, 2026
f991781
fix(server,web,mobile): messages from a linked environment name the t…
EtanHey Nov 12, 2026
bb646d2
fix(shared): links to bracketed filenames keep their folder labels (#…
juliusmarminge Nov 12, 2026
1dfc56f
Merge commit 'bb646d2caded23e0942e67b75fd85e1e5e798cea' into fix/cach…
fireboltdude1357 Nov 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 17 additions & 4 deletions .agents/skills/contribution-triage/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ trusted policy and reassess changed submission evidence; neither example grants

Do not automatically close a PR if a maintainer in the trusted `TRIAGE_EXEMPTIONS.td` list has
commented or submitted a review, including on earlier heads, or if `triage:keep-open` is present.
Comments that triage itself posted, such as an earlier notice or question, are not maintainer
involvement, even when they were posted from a maintainer's account on that maintainer's behalf.
Leave protected PRs open for maintainer decision. This does not grant an author exemption,
eligibility, or review approval.

Expand All @@ -126,7 +128,17 @@ comment text but do not write to GitHub. Keep the eligibility finding separate f
This is a routing exception, not a claim that the PR passed eligibility or correctness review.
- **Closure warranted.** The assessment is complete and establishes a specific policy violation.
Prepare a clear explanation under [closure and reconsideration](../../../CONTRIBUTING.md#closure-and-reconsideration),
post it, and close the PR. Verify that the explanation is present and the PR is closed. The comment
post it, then read the repository variable `PR_LIMITS_ENFORCE`
(`gh variable get PR_LIMITS_ENFORCE -R pingdotgg/t3code`). When it prints `true`, apply
`triage:closing` as the last thing you do to the PR, verify that the explanation and the label
are present, and do not close the PR yourself:
[pr-limits.yml](../../../.github/workflows/pr-limits.yml) closes it 72 hours after the label. Any
activity on the PR after the label, including a further comment or label from you, removes the
label; treat an author's reply or push as new evidence, reassess, and apply the label again only
if the finding still holds. When the command prints any other value, or fails saying the variable
was not found, the variable is off and nothing would close a labeled PR: close it yourself and
verify that the explanation is present and the PR is closed. Only another failure, such as a
permission error, means the variable cannot be read; then report the closure as incomplete. The comment
must name the violated rule, cite supporting submission evidence, link the maintained guide section,
and give a concrete remedy. Missing contributor evidence can warrant closure; explain what must be
established. Missing product approval calls for maintainer discussion, not an agent's product decision.
Expand Down Expand Up @@ -173,9 +185,10 @@ description, evidence, approvals, existing triage comments, PR open/closed state
label when relevant. Reassess changes that could invalidate the finding. Reuse an existing explanation
only if it still matches the current finding; avoid duplicate comments, closures, or label applications.

For closure, establish that the required explanation is posted before closing. If posting fails or its
result is ambiguous, read back the comments before retrying or proceeding. If the comment succeeds but
closure fails, preserve the comment and retry only the unfinished closure after checking current state.
For closure, establish that the required explanation is posted before applying `triage:closing` or
closing. If posting fails or its result is ambiguous, read back the comments before retrying or
proceeding. If the comment succeeds but the label or the closure fails, preserve the comment and retry
only that unfinished step after checking current state.
Handle a failed or ambiguous label application the same way: inspect labels before any retry. If access
or state still cannot be verified, report an incomplete action and the step needed to resume. Do not
retry blindly or claim success for an unverified action.
Expand Down
320 changes: 320 additions & 0 deletions .github/scripts/pr-limits.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
const fs = require("node:fs");

const HOUR_MS = 60 * 60 * 1000;
const OPEN_LIMIT = 3;
const CONFLICT_IDLE_MS = 7 * 24 * HOUR_MS;
const NOTICE_MS = 72 * HOUR_MS;
// A first run meets the whole backlog. These keep one run from flooding watchers or GitHub's
// limit on how fast a token may comment.
const MAX_REQUESTS_PER_RUN = 100;
const MAX_CLOSES_PER_RUN = 50;
// A last look that ends in "not today" closes nothing, so the looks need a cap of their own.
const MAX_RECHECKS_PER_RUN = 150;
const WRITE_PAUSE_MS = 1_000;
// Measured here: about two and a half minutes until every open PR has an answer.
const MERGEABLE_WAIT_MS = 150_000;
const READ_ATTEMPTS = 4;
const READ_RETRY_MS = 5_000;
// GitHub stamps a label event and the PR's updatedAt a second or two apart.
const SAME_MOMENT_MS = 15_000;

const REBASE_LABEL = "needs-rebase";
const CLOSING_LABEL = "triage:closing";
const KEEP_OPEN_LABEL = "triage:keep-open";
const UNVOUCHED_LABEL = "vouch:unvouched";
const WRITE_PERMISSIONS = new Set(["admin", "maintain", "write"]);
const EXEMPTIONS_PATH = ".github/TRIAGE_EXEMPTIONS.td";
const VOUCHED_PATH = ".github/VOUCHED.td";
const LOGIN_PATTERN = /^github:([A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38})$/;

// `labels` matches a PR that carries any one of them.
const SWEEP_QUERY = `
query ($owner: String!, $repo: String!, $labels: [String!], $cursor: String) {
repository(owner: $owner, name: $repo) {
pullRequests(states: OPEN, labels: $labels, first: 50, after: $cursor) {
pageInfo { hasNextPage endCursor }
nodes {
number
mergeable
baseRefName
updatedAt
author { login }
labels(first: 100) { nodes { name } }
timelineItems(itemTypes: [LABELED_EVENT], last: 20) {
nodes { ... on LabeledEvent { createdAt label { name } } }
}
}
}
}
}`;

const RECHECK_QUERY = `
query ($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
state
mergeable
updatedAt
labels(first: 100) { nodes { name } }
}
}
}`;

const AUTHOR_OPEN_PRS_QUERY = `
query ($q: String!) {
search(query: $q, type: ISSUE, first: 50) {
nodes { ... on PullRequest { number } }
}
}`;

const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// GitHub answers a heavy list request with a 502 now and then, and one of those must not end the
// run. Only reads go through here: repeating a read is safe, repeating a comment is not.
async function read(github, query, variables) {
for (let attempt = 1; ; attempt += 1) {
try {
return await github.graphql(query, variables);
} catch (error) {
const transient = typeof error.status === "number" && error.status >= 500;
if (attempt === READ_ATTEMPTS || !transient) throw error;
await pause(attempt * READ_RETRY_MS);
}
}
}

// Fails closed: a missing, empty, or malformed list must never read as "nobody is exempt".
function parseExemptions(text) {
const logins = new Set();
for (const raw of text.split("\n")) {
const line = raw.trim();
if (line === "" || line.startsWith("#")) continue;
const match = LOGIN_PATTERN.exec(line);
if (!match) throw new Error(`${EXEMPTIONS_PATH}: malformed entry "${line}"`);
const login = match[1].toLowerCase();
if (logins.has(login)) throw new Error(`${EXEMPTIONS_PATH}: duplicate entry "${line}"`);
logins.add(login);
}
if (logins.size === 0) throw new Error(`${EXEMPTIONS_PATH}: no entries`);
return logins;
}

// VOUCHED.td: one `github:login` per line, `#` comments, and `-github:login reason` to denounce.
function vouchedLogins(text) {
const logins = new Set();
for (const raw of text.split("\n")) {
const entry = raw.trim().split(/\s+/)[0];
if (entry.startsWith("github:")) logins.add(entry.slice("github:".length).toLowerCase());
}
if (logins.size === 0) throw new Error(`${VOUCHED_PATH}: no entries`);
return logins;
}

function labeledAt(pr, name) {
const last = pr.timelineItems.nodes.filter((event) => event.label?.name === name).at(-1);
return last ? Date.parse(last.createdAt) : undefined;
}

// The whole policy for the two windows. Activity is anything that moves the PR's updatedAt: a
// push, a comment, a review, a label. Nobody can set that time, so nothing here trusts the author.
function decide(pr, exemptions, now) {
const labels = new Set(pr.labels.nodes.map((label) => label.name));
if (labels.has(KEEP_OPEN_LABEL)) return "skip";
const updatedAt = Date.parse(pr.updatedAt);

if (labels.has(CLOSING_LABEL)) {
const since = labeledAt(pr, CLOSING_LABEL);
if (since === undefined) return "unknown-notice";
// Any activity after the notice sends the PR back to triage.
if (updatedAt - since > SAME_MOMENT_MS) return "clear-notice";
return now - since >= NOTICE_MS ? "close-notice" : "skip";
}

const exempt = exemptions.has((pr.author?.login ?? "").toLowerCase());
const subject = labels.has(UNVOUCHED_LABEL) && !exempt;
if (labels.has(REBASE_LABEL)) {
if (!subject || pr.mergeable === "MERGEABLE") return "clear-rebase";
// Activity restarts the seven days and keeps the label, so a PR is asked to rebase once.
const idle = now - updatedAt >= CONFLICT_IDLE_MS;
return idle && pr.mergeable === "CONFLICTING" ? "close-conflict" : "skip";
}
return subject && pr.mergeable === "CONFLICTING" ? "request-rebase" : "skip";
}

function guideLink(context, anchor) {
return `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#${anchor}`;
}

async function removeLabel(github, context, number, name) {
try {
await github.rest.issues.removeLabel({ ...context.repo, issue_number: number, name });
} catch (error) {
if (error.status !== 404) throw error;
}
}

async function closeWithComment(github, context, number, body) {
await github.rest.issues.createComment({ ...context.repo, issue_number: number, body });
await github.rest.pulls.update({ ...context.repo, pull_number: number, state: "closed" });
}

async function sweep({ github, context, core, dryRun }) {
const exemptions = parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8"));
const repo = { owner: context.repo.owner, repo: context.repo.repo };

const list = async () => {
const prs = [];
for (let cursor = null; ;) {
const page = (
await read(github, SWEEP_QUERY, {
...repo,
cursor,
labels: [UNVOUCHED_LABEL, REBASE_LABEL, CLOSING_LABEL],
})
).repository.pullRequests;
prs.push(...page.nodes);
if (!page.pageInfo.hasNextPage) return prs;
cursor = page.pageInfo.endCursor;
}
};
// GitHub computes mergeability lazily and forgets it whenever the base moves. Asking starts the
// computation, so ask once more. A PR that is still unknown waits for tomorrow's run.
let prs = await list();
if (prs.some((pr) => pr.mergeable === "UNKNOWN")) {
await pause(MERGEABLE_WAIT_MS);
prs = await list();
}

const now = Date.now();
// Start further down the list each day. The step is no larger than a run's cap, so a cap that
// is reached cannot leave the same PRs waiting behind the same others every day.
const start = (Math.floor(now / (24 * HOUR_MS)) * MAX_RECHECKS_PER_RUN) % (prs.length || 1);
prs = [...prs.slice(start), ...prs.slice(0, start)];
const count = {};
let rechecks = 0;
for (const pr of prs) {
const { number } = pr;
let action = decide(pr, exemptions, now);
if (action === "skip") continue;
if (action === "unknown-notice") {
core.warning(`#${number}: cannot tell when ${CLOSING_LABEL} was applied, leaving it open.`);
continue;
}
if (action === "request-rebase" && (count[action] ?? 0) >= MAX_REQUESTS_PER_RUN) continue;
if (action.startsWith("close")) {
if ((count["close-conflict"] ?? 0) + (count["close-notice"] ?? 0) >= MAX_CLOSES_PER_RUN) {
continue;
}
if (rechecks >= MAX_RECHECKS_PER_RUN) continue;
rechecks += 1;
// The list is minutes old by now. Closing is the one step worth a second look.
const fresh = (await read(github, RECHECK_QUERY, { ...repo, number })).repository.pullRequest;
if (fresh.state !== "OPEN") continue;
// A merge to the base can resolve a conflict without touching the PR, so this is re-read
// too. An answer that is not ready yet reads as "not conflicting" and waits for tomorrow.
action = decide({ ...pr, ...fresh }, exemptions, now);
if (!action.startsWith("close")) continue;
}

count[action] = (count[action] ?? 0) + 1;
core.info(`#${number} ${action}${dryRun ? " (dry run)" : ""}`);
if (dryRun) continue;

if (action === "request-rebase") {
// The request goes first: a label without it would start a clock nobody was told about.
await github.rest.issues.createComment({
...context.repo,
issue_number: number,
body: [
`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.`,
"",
`See the [conflict window](${guideLink(context, "conflict-window")}).`,
].join("\n"),
});
await github.rest.issues.addLabels({
...context.repo,
issue_number: number,
labels: [REBASE_LABEL],
});
} else if (action === "clear-rebase") {
await removeLabel(github, context, number, REBASE_LABEL);
} else if (action === "clear-notice") {
await removeLabel(github, context, number, CLOSING_LABEL);
} else {
const conflict = action === "close-conflict";
await closeWithComment(
github,
context,
number,
conflict
? [
`Closing: this PR still conflicts with \`${pr.baseRefName}\` and has had no activity for 7 days since the rebase request.`,
"",
`To continue, rebase the branch and open a new PR that links this one. See the [conflict window](${guideLink(context, "conflict-window")}).`,
].join("\n")
: [
"Closing: 72 hours have passed since the triage notice above with no activity on this PR.",
"",
`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")}).`,
].join("\n"),
);
// Without this a maintainer's reopen would be closed again by the next run.
await removeLabel(github, context, number, conflict ? REBASE_LABEL : CLOSING_LABEL);
}
await pause(WRITE_PAUSE_MS);
}

const summary = Object.entries(count).map(([action, n]) => `${n} ${action}`);
core.info(
`${dryRun ? "Dry run. " : ""}${prs.length} PRs read: ${summary.join(", ") || "nothing to do"}.`,
);
return count;
}

async function enforceOpenLimit({ github, context, core, dryRun }) {
const pr = context.payload.pull_request;
const author = pr.user.login;
// Who is trusted is decided here rather than by the vouch action, which reports its own failed
// lookups as "not vouched". Every read below throws on failure, and a throw closes nothing.
if (pr.user.type === "Bot") return;
if (parseExemptions(fs.readFileSync(EXEMPTIONS_PATH, "utf8")).has(author.toLowerCase())) return;
if (vouchedLogins(fs.readFileSync(VOUCHED_PATH, "utf8")).has(author.toLowerCase())) return;
const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: author,
});
if (WRITE_PERMISSIONS.has(access.permission)) return;
if (pr.labels.some((label) => label.name === KEEP_OPEN_LABEL)) return;
// Someone else reopening a PR is a maintainer overriding the limit.
const reopened = context.payload.action === "reopened";
if (reopened && context.payload.sender.login.toLowerCase() !== author.toLowerCase()) return;

const q = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open author:${author} sort:created-asc`;
const { search } = await read(github, AUTHOR_OPEN_PRS_QUERY, { q });
// A new PR counts only the older ones, so two opened together cannot close each other.
const others = search.nodes.filter(
(node) => node.number && (reopened ? node.number !== pr.number : node.number < pr.number),
).length;
if (others < OPEN_LIMIT) {
core.info(`PR #${pr.number}: ${author} has ${others} other open PRs.`);
return;
}
if (dryRun) {
core.notice(`Dry run. PR #${pr.number} would close: ${author} has ${others} other open PRs.`);
return;
}

await closeWithComment(
github,
context,
pr.number,
[
`Closing: ${author} already has ${OPEN_LIMIT} or more open PRs here, which is the limit for contributors who are not vouched.`,
"",
`Once one of them is merged or closed, open this again. See the [open PR limit](${guideLink(context, "open-pr-limit")}).`,
].join("\n"),
);
core.info(`PR #${pr.number}: closed, ${author} has ${others} other open PRs.`);
}

module.exports = { decide, enforceOpenLimit, parseExemptions, sweep };
Loading
Loading