The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
fix(tools): keep bot-answered threads unresolved, require a Codex review for done, paginate threads
Zhuowei Wang73441dce86a9
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.mdindex 6ccac43..e46c633 100644--- a/tools/linear-autofix/README.md+++ b/tools/linear-autofix/README.md@@ -180,9 +180,14 @@ the ticket stays readable. Set `AUTOFIX_LOG_ISSUE=` (empty) to disable.## Review-loop termination-A PR is finished when, for its current head commit, CI is green, the Codex-review comment (tagged `<!-- codex-review -->` with the 8-char SHA) says+A PR is finished when, for its current head commit, CI reported success, the+Codex review comment (tagged `<!-- codex-review -->` with the 8-char SHA) says`No issues found that require changes.`, and no review thread is unresolved.+A thread the bot answered without resolving still counts as unresolved: it+blocks `done` and waits for a human, but does not trigger another fix round.+If CI or the Codex review has not reported for a head within two hours the+ticket escalates rather than finishing, since both run on every PR here.+Codex skips draft PRs, so a draft (Windows ticket) with green CI and no threadsis reported on Linear as _ready for Windows verification_ and waits for a humanto mark it ready; the loop then resumes.diff --git a/tools/linear-autofix/src/actions.mjs b/tools/linear-autofix/src/actions.mjsindex 569da5d..85d1371 100644--- a/tools/linear-autofix/src/actions.mjs+++ b/tools/linear-autofix/src/actions.mjs@@ -1,6 +1,6 @@import { config } from "./config.mjs";import * as linear from "./linear.mjs";-import { note, transition } from "./state.mjs";+import { note, save, transition } from "./state.mjs";export const FOOTER = `_Generated by linear-autofix. Add the \`${config.labels.optOut}\` label to stop the bot on this ticket._`;@@ -28,5 +28,6 @@ export async function recordError(record, err) {export function clearErrors(record) {if (record.consecutiveErrors) {record.consecutiveErrors = 0;+ save(record);}}diff --git a/tools/linear-autofix/src/github.mjs b/tools/linear-autofix/src/github.mjsindex 4d9c635..ea24bbb 100644--- a/tools/linear-autofix/src/github.mjs+++ b/tools/linear-autofix/src/github.mjs@@ -106,28 +106,40 @@ export async function checksText(number) {return (stdout || stderr).trim();}+/** Every review thread of the PR, following the connection's pages. */export async function reviewThreads(number) {const [owner, name] = (await repoNameWithOwner()).split("/");- const data = await ghJson([- "api",- "graphql",- "-f",- `query=query($owner:String!,$name:String!,$number:Int!){- repository(owner:$owner,name:$name){ pullRequest(number:$number){- reviewThreads(first:100){ nodes{- id isResolved isOutdated path line- comments(first:50){ nodes{ id body createdAt author{ login } } }+ const threads = [];+ let after = null;+ for (;;) {+ const data = await ghJson([+ "api",+ "graphql",+ "-f",+ `query=query($owner:String!,$name:String!,$number:Int!,$after:String){+ repository(owner:$owner,name:$name){ pullRequest(number:$number){+ reviewThreads(first:100, after:$after){+ pageInfo{ hasNextPage endCursor }+ nodes{+ id isResolved isOutdated path line+ comments(first:50){ nodes{ id body createdAt author{ login } } }+ }+ }} }- } }- }`,- "-f",- `owner=${owner}`,- "-f",- `name=${name}`,- "-F",- `number=${number}`,- ]);- return data.data.repository.pullRequest.reviewThreads.nodes;+ }`,+ "-f",+ `owner=${owner}`,+ "-f",+ `name=${name}`,+ "-F",+ `number=${number}`,+ ...(after ? ["-f", `after=${after}`] : []),+ ]);+ const page = data.data.repository.pullRequest.reviewThreads;+ threads.push(...page.nodes);+ if (!page.pageInfo.hasNextPage) return threads;+ after = page.pageInfo.endCursor;+ }}export async function replyToThread(threadId, body) {diff --git a/tools/linear-autofix/src/linear.mjs b/tools/linear-autofix/src/linear.mjsindex ca7c96d..2431426 100644--- a/tools/linear-autofix/src/linear.mjs+++ b/tools/linear-autofix/src/linear.mjs@@ -33,6 +33,8 @@ const ISSUE_FIELDS = `labels { nodes { id name } }attachments { nodes { title url } }comments(first: 50) { nodes { id body createdAt user { name displayName } } }+ # Linear returns the newest comments first; re-triage of needs_info tickets+ # keys on the newest createdAt among them (see state.upsertFromIssue).`;/** Every issue assigned to the API key's user in the configured states. */diff --git a/tools/linear-autofix/src/review.mjs b/tools/linear-autofix/src/review.mjsindex f44cc32..fa26f7d 100644--- a/tools/linear-autofix/src/review.mjs+++ b/tools/linear-autofix/src/review.mjs@@ -11,7 +11,7 @@ import * as git from "./git.mjs";import * as github from "./github.mjs";import * as linear from "./linear.mjs";import { note, runDir, transition, worktreePath } from "./state.mjs";-import { actionableThreads, renderThreads } from "./threads.mjs";+import { renderThreads, splitThreads } from "./threads.mjs";import { escalate, FOOTER } from "./actions.mjs";import { CODE_TOOLS, readJson } from "./implement.mjs";import { gatedPush } from "./e2e.mjs";@@ -24,15 +24,18 @@ const CODEX_WAIT_MS = 2 * 60 * 60_000;* Decide what the review loop should do for the PR's current head. Pure.* Returns { action: 'wait' | 'done' | 'draft_ready' | 'fix' | 'escalate', problems, why }.*- * `done` requires CI to have reported success. A head with no checks at all- * (`none`) is treated as not reported yet; after the wait window it escalates- * instead of finishing, since this repository runs CI on every PR.+ * `done` needs all of: CI reported success, a clean Codex review of this head,+ * no unresolved review thread (neither fresh ones nor ones the bot answered+ * and a human has yet to resolve). A head with no checks reported (`none`) or+ * no Codex review is "not reported yet"; after the wait window that escalates+ * instead of finishing, since this repository runs both on every PR.*/export function assessHead({pr,codex,ci,threads,+ awaitingHuman = [],headSeenAt,now = Date.now(),}) {@@ -54,14 +57,21 @@ export function assessHead({why: "no CI result was reported for this head within the wait window",};}+ if (awaitingHuman.length) {+ return {+ action: "wait",+ problems,+ why: `${awaitingHuman.length} thread(s) answered by the bot await a human`,+ };+ }if (pr.isDraft) return { action: "draft_ready", problems };if (!codex) {if (waited < CODEX_WAIT_MS)return { action: "wait", problems, why: "waiting for the Codex review" };return {- action: "done",+ action: "escalate",problems,- why: "no Codex review arrived; CI green and no open threads",+ why: "no Codex review arrived for this head within the wait window",};}return {@@ -89,19 +99,22 @@ export async function review(issue, record) {record.review.headSeenAt = new Date().toISOString();}const ci = github.ciStatus(pr.statusCheckRollup);- const threads = actionableThreads(await github.reviewThreads(pr.number));+ const { fresh: threads, awaitingHuman } = splitThreads(+ await github.reviewThreads(pr.number),+ );const codex = pr.isDraft ? null : findCodexReview(pr.comments, sha);const verdict = assessHead({pr,codex,ci,threads,+ awaitingHuman,headSeenAt: record.review.headSeenAt,});note(record,`review check ${sha.slice(0, 8)}`,- `ci=${ci} codex=${codex ? (isCleanReview(codex.body) ? "clean" : "findings") : "none"} threads=${threads.length} -> ${verdict.action}`,+ `ci=${ci} codex=${codex ? (isCleanReview(codex.body) ? "clean" : "findings") : "none"} threads=${threads.length}+${awaitingHuman.length} -> ${verdict.action}`,);if (verdict.action === "wait") return;diff --git a/tools/linear-autofix/src/review.test.mjs b/tools/linear-autofix/src/review.test.mjsindex 0dfdad4..1caf12a 100644--- a/tools/linear-autofix/src/review.test.mjs+++ b/tools/linear-autofix/src/review.test.mjs@@ -43,23 +43,32 @@ test("waits while CI runs, has not reported, or while the Codex review is pendin);});-test("finishes only when CI reported success", () => {+test("finishes only with green CI, a clean Codex review and no unresolved threads", () => {assert.equal(assessHead({ pr: ready, codex: clean, ci: "success", threads: [], now }).action,"done",);- assert.equal(- assessHead({- pr: ready,- codex: null,- ci: "success",- threads: [],- headSeenAt: old,- now,- }).action,- "done",- );+ const noCodex = assessHead({+ pr: ready,+ codex: null,+ ci: "success",+ threads: [],+ headSeenAt: old,+ now,+ });+ assert.equal(noCodex.action, "escalate");+ assert.match(noCodex.why, /no Codex review/);+ const answered = assessHead({+ pr: ready,+ codex: clean,+ ci: "success",+ threads: [],+ awaitingHuman: [{ id: "t" }],+ now,+ });+ assert.equal(answered.action, "wait");+ assert.match(answered.why, /await a human/);const noCi = assessHead({pr: ready,codex: clean,diff --git a/tools/linear-autofix/src/state.mjs b/tools/linear-autofix/src/state.mjsindex 4e4f06b..87de7df 100644--- a/tools/linear-autofix/src/state.mjs+++ b/tools/linear-autofix/src/state.mjs@@ -113,12 +113,19 @@ export function upsertFromIssue(issue) {base.linearState = issue.state?.name;base.linearUpdatedAt = issue.updatedAt;base.labels = (issue.labels?.nodes ?? []).map((l) => l.name);- const commentCount = issue.comments?.nodes?.length ?? 0;- base.lastSeenCommentCount ??= commentCount;- base.commentCount = commentCount;+ base.latestCommentAt = latestCommentAt(issue);+ base.lastSeenCommentAt ??= base.latestCommentAt;return save(base);}+/** Newest comment timestamp on the issue, or null. Pure. */+export function latestCommentAt(issue) {+ const stamps = (issue.comments?.nodes ?? [])+ .map((c) => c.createdAt)+ .filter(Boolean);+ return stamps.length ? stamps.sort().at(-1) : null;+}+export function acquireLock() {ensureStateDir();try {diff --git a/tools/linear-autofix/src/threads.mjs b/tools/linear-autofix/src/threads.mjsindex 06c8adf..6924204 100644--- a/tools/linear-autofix/src/threads.mjs+++ b/tools/linear-autofix/src/threads.mjs@@ -1,18 +1,29 @@import { config } from "./config.mjs";/**- * Unresolved review threads whose latest comment is not a bot reply. Human+ * Split the unresolved review threads into the ones that need the bot's+ * attention (`fresh`: the latest comment is not a bot reply) and the ones the+ * bot already answered without resolving (`awaitingHuman`). Both kinds keep+ * the PR from being done; only `fresh` ones trigger a fix round. Human* comments made from the bot's own GitHub account are indistinguishable by* author, so bot replies are recognized by the marker they carry.*/-export function actionableThreads(threads, marker = config.botMarker) {- return (threads ?? []).filter((t) => {- if (t.isResolved) return false;+export function splitThreads(threads, marker = config.botMarker) {+ const fresh = [];+ const awaitingHuman = [];+ for (const t of threads ?? []) {+ if (t.isResolved) continue;const comments = t.comments?.nodes ?? [];- if (!comments.length) return false;+ if (!comments.length) continue;const last = comments[comments.length - 1];- return !String(last.body ?? "").includes(marker);- });+ (String(last.body ?? "").includes(marker) ? awaitingHuman : fresh).push(t);+ }+ return { fresh, awaitingHuman };+}++/** Unresolved threads that need the bot's attention. */+export function actionableThreads(threads, marker = config.botMarker) {+ return splitThreads(threads, marker).fresh;}export function renderThreads(threads) {diff --git a/tools/linear-autofix/src/threads.test.mjs b/tools/linear-autofix/src/threads.test.mjsindex ff8d3c2..5889cae 100644--- a/tools/linear-autofix/src/threads.test.mjs+++ b/tools/linear-autofix/src/threads.test.mjs@@ -1,6 +1,6 @@import assert from "node:assert/strict";import { test } from "node:test";-import { actionableThreads, renderThreads } from "./threads.mjs";+import { actionableThreads, renderThreads, splitThreads } from "./threads.mjs";const thread = (id,@@ -38,6 +38,25 @@ test("actionableThreads keeps unresolved threads the bot has not answered", () =);});+test("splitThreads keeps bot-answered unresolved threads apart instead of dropping them", () => {+ const { fresh, awaitingHuman } = splitThreads([+ thread("t1"),+ thread("t2", { resolved: true }),+ thread("t3", {+ last: "<!-- linear-autofix -->\nDone in abc123",+ author: "joway",+ }),+ ]);+ assert.deepEqual(+ fresh.map((t) => t.id),+ ["t1"],+ );+ assert.deepEqual(+ awaitingHuman.map((t) => t.id),+ ["t3"],+ );+});+test("renderThreads includes the thread id, location and quoted comments", () => {const text = renderThreads([thread("PRRT_abc")]);assert.match(text, /Thread `PRRT_abc`/);diff --git a/tools/linear-autofix/src/tick.mjs b/tools/linear-autofix/src/tick.mjsindex 8a06f37..85c8a10 100644--- a/tools/linear-autofix/src/tick.mjs+++ b/tools/linear-autofix/src/tick.mjs@@ -36,7 +36,7 @@ export function reconcile(record, issue) {if (record.stage === "skipped" &&record.triage?.verdict === "needs_info" &&- record.commentCount > record.lastSeenCommentCount+ (record.latestCommentAt ?? "") > (record.lastSeenCommentAt ?? "")) {transition(record,diff --git a/tools/linear-autofix/src/tick.test.mjs b/tools/linear-autofix/src/tick.test.mjsindex 1f6e4b6..c369cc0 100644--- a/tools/linear-autofix/src/tick.test.mjs+++ b/tools/linear-autofix/src/tick.test.mjs@@ -64,11 +64,13 @@ test("reconcile honors the opt-out label, retries crashed runs and re-triages neconst info = state.upsertFromIssue(issue("CITRO-4"));info.triage = { verdict: "needs_info" };- info.lastSeenCommentCount = 0;+ info.lastSeenCommentAt = "2026-11-01T00:00:00Z";state.transition(info, "skipped");assert.equal(reconcile(info, issue("CITRO-4")).stage, "skipped");const commented = issue("CITRO-4", {- comments: { nodes: [{ body: "here is the repro" }] },+ comments: {+ nodes: [{ body: "here is the repro", createdAt: "2026-11-02T00:00:00Z" }],+ },});assert.equal(reconcile(state.upsertFromIssue(commented), commented).stage,diff --git a/tools/linear-autofix/src/triage.mjs b/tools/linear-autofix/src/triage.mjsindex 8b8602a..6db9b10 100644--- a/tools/linear-autofix/src/triage.mjs+++ b/tools/linear-autofix/src/triage.mjs@@ -128,7 +128,9 @@ export async function triage(issue, record) {transition(record, "triaged");} else {await linear.addLabel(record, config.labels.skipped);- record.lastSeenCommentCount = record.commentCount;+ // The triage comment just posted is newer than anything fetched; a human+ // comment after this moment re-triages a needs_info ticket.+ record.lastSeenCommentAt = new Date().toISOString();transition(record, "skipped", triageResult.verdict);}return triageResult;