Skip to content

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.

fix(tools): keep dry-run triage out of the real autofix state

Zhuowei Wang041d9b84a599
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.md
index c5348da..18ffd2b 100644
--- a/tools/linear-autofix/README.md
+++ b/tools/linear-autofix/README.md
@@ -104,10 +104,15 @@ First run, by hand, before scheduling anything:
```sh
cd ~/code/ego-lite/tools/linear-autofix && source ~/.config/linear-autofix/env
AUTOFIX_DRY_RUN=1 node src/cli.mjs tick # triages everything, writes nothing
-node src/cli.mjs status
+AUTOFIX_DRY_RUN=1 node src/cli.mjs status # what the dry run decided
AUTOFIX_ISSUE=CITRO-2908 node src/cli.mjs tick # one real ticket end to end
```
+A dry run only triages, and keeps its records under `dry-run/` in the state
+dir, so a real tick still triages every ticket and posts the result. It does
+not see the real STOP file or usage pause, and `implement`, `review`, `publish`
+and `reset` refuse to run in it. Delete `dry-run/` to triage again from scratch.
+
Watch that PR through a full review loop (`node src/cli.mjs status`, the tick
log comments on the log ticket), then keep it running. Two options.
@@ -203,7 +208,7 @@ the ticket stays readable. Set `AUTOFIX_LOG_ISSUE=` (empty) to disable.
| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |
| `AUTOFIX_E2E_KNOWN_FAILURES` | (empty) | E2E cases the bot leaves out of its run and its comments |
| `AUTOFIX_LOG_ISSUE` | `CITRO-4786` | Linear ticket that receives one comment per active tick |
-| `AUTOFIX_DRY_RUN` | unset | `1`: no Linear/GitHub writes, no push |
+| `AUTOFIX_DRY_RUN` | unset | `1`: triage only, separate state, no writes |
| `AUTOFIX_ISSUE` | unset | restrict a tick to one identifier |
## What counts as review feedback
diff --git a/tools/linear-autofix/src/cli.mjs b/tools/linear-autofix/src/cli.mjs
index 3be3310..3add173 100755
--- a/tools/linear-autofix/src/cli.mjs
+++ b/tools/linear-autofix/src/cli.mjs
@@ -152,7 +152,14 @@ function status() {
console.log(`\n${records.length} tracked · state dir ${config.stateDir}`);
}
+/** These act on real branches, worktrees and PRs, which a dry run must not touch. */
+const NOT_IN_DRY_RUN = ["implement", "review", "publish", "reset"];
+
async function main([command, arg]) {
+ if (config.dryRun && NOT_IN_DRY_RUN.includes(command))
+ throw new Error(
+ `${command} is not available with AUTOFIX_DRY_RUN=1: a dry run only triages`,
+ );
switch (command) {
case "tick":
timestampLogs();
diff --git a/tools/linear-autofix/src/config.mjs b/tools/linear-autofix/src/config.mjs
index f432bb9..45277c6 100644
--- a/tools/linear-autofix/src/config.mjs
+++ b/tools/linear-autofix/src/config.mjs
@@ -18,12 +18,22 @@ function list(name, fallback) {
return (raw ? raw.split(",") : fallback).map((s) => s.trim()).filter(Boolean);
}
+/**
+ * Where records, runs, worktrees, the lock and STOP live. A dry run gets its
+ * own directory: Linear and GitHub never hear about its verdicts, so a record
+ * saved in the real state would stop the bot from ever triaging that ticket for
+ * real. Pure.
+ */
+export function resolveStateDir(env, home) {
+ const base =
+ env.AUTOFIX_STATE_DIR ?? path.join(home, ".local/state/linear-autofix");
+ return env.AUTOFIX_DRY_RUN === "1" ? path.join(base, "dry-run") : base;
+}
+
export const config = Object.freeze({
// The ego-lite checkout this tool lives in. Worktrees are created from it.
repoRoot: process.env.AUTOFIX_REPO ?? path.resolve(here, "../../.."),
- stateDir:
- process.env.AUTOFIX_STATE_DIR ??
- path.join(os.homedir(), ".local/state/linear-autofix"),
+ stateDir: resolveStateDir(process.env, os.homedir()),
linearApiKey: process.env.LINEAR_API_KEY ?? "",
linearStates: list("AUTOFIX_LINEAR_STATES", [
@@ -76,8 +86,8 @@ export const config = Object.freeze({
codexMarker: "<!-- codex-review -->",
codexCleanLine: "No issues found that require changes.",
- // AUTOFIX_DRY_RUN=1: read everything, run Claude, but never write to
- // Linear or GitHub and never push.
+ // AUTOFIX_DRY_RUN=1: triage only, with state in its own directory. Never
+ // writes to Linear or GitHub, never pushes, never creates a branch.
dryRun: process.env.AUTOFIX_DRY_RUN === "1",
// AUTOFIX_ISSUE=CITRO-1234 restricts a tick to one issue.
onlyIssue: process.env.AUTOFIX_ISSUE ?? "",
diff --git a/tools/linear-autofix/src/dry-run.test.mjs b/tools/linear-autofix/src/dry-run.test.mjs
new file mode 100644
index 0000000..0111827
--- /dev/null
+++ b/tools/linear-autofix/src/dry-run.test.mjs
@@ -0,0 +1,141 @@
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { test } from "node:test";
+
+const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "linear-autofix-dry-"));
+const base = path.join(tmp, "state");
+const calls = path.join(tmp, "calls.log");
+
+function fakeBin(name, output) {
+ const file = path.join(tmp, name);
+ fs.writeFileSync(
+ file,
+ `#!/bin/sh\necho "${name} $*" >> '${calls}'\ncat > /dev/null\ncat <<'OUT'\n${output}\nOUT\n`,
+ );
+ fs.chmodSync(file, 0o755);
+ return file;
+}
+
+const verdict = {
+ verdict: "fix",
+ confidence: 0.9,
+ reason: "evident in the code",
+ needs_windows: false,
+ size: "S",
+ affected_paths: [],
+ repro_plan: "a test",
+ comment: "fixable",
+};
+fakeBin("gh", "[]");
+Object.assign(process.env, {
+ PATH: `${tmp}${path.delimiter}${process.env.PATH}`,
+ AUTOFIX_CLAUDE_BIN: fakeBin(
+ "claude",
+ JSON.stringify({ type: "result", structured_output: verdict }),
+ ),
+ // Not a git repository: a regression fails here instead of branching in ours.
+ AUTOFIX_REPO: tmp,
+ AUTOFIX_STATE_DIR: base,
+ AUTOFIX_DRY_RUN: "1",
+ AUTOFIX_LOG_ISSUE: "",
+ LINEAR_API_KEY: "lin_api_test",
+});
+
+const { config, resolveStateDir } = await import("./config.mjs");
+const { tick } = await import("./tick.mjs");
+
+const issue = (identifier) => ({
+ id: `uuid-${identifier}`,
+ identifier,
+ title: "t",
+ url: "https://linear.app/x",
+ branchName: `zhuoweiwang/${identifier.toLowerCase()}`,
+ updatedAt: "2026-11-01T00:00:00Z",
+ team: { id: "team", key: "CITRO" },
+ state: { name: "Todo" },
+ labels: { nodes: [] },
+ comments: { nodes: [] },
+});
+
+test("the state dir of a dry run is separate from the real one", () => {
+ const home = "/home/bot";
+ const real = "/home/bot/.local/state/linear-autofix";
+ assert.equal(resolveStateDir({}, home), real);
+ assert.equal(
+ resolveStateDir({ AUTOFIX_DRY_RUN: "1" }, home),
+ `${real}/dry-run`,
+ );
+ assert.equal(resolveStateDir({ AUTOFIX_STATE_DIR: "/s" }, home), "/s");
+ assert.equal(
+ resolveStateDir({ AUTOFIX_STATE_DIR: "/s", AUTOFIX_DRY_RUN: "1" }, home),
+ "/s/dry-run",
+ );
+});
+
+test("a dry-run tick triages without touching the real state, Linear or a PR", async () => {
+ const issuesDir = path.join(config.stateDir, "issues");
+ fs.mkdirSync(issuesDir, { recursive: true });
+ // Would be reviewed by a real tick.
+ fs.writeFileSync(
+ path.join(issuesDir, "CITRO-2.json"),
+ JSON.stringify({ identifier: "CITRO-2", stage: "in_review", history: [] }),
+ );
+
+ const queries = [];
+ const realFetch = globalThis.fetch;
+ globalThis.fetch = async (_url, init) => {
+ const { query } = JSON.parse(init.body);
+ queries.push(query);
+ return new Response(
+ JSON.stringify({
+ data: {
+ issues: {
+ nodes: [issue("CITRO-1"), issue("CITRO-2")],
+ pageInfo: { hasNextPage: false },
+ },
+ },
+ }),
+ );
+ };
+ try {
+ await tick();
+ } finally {
+ globalThis.fetch = realFetch;
+ }
+
+ const read = (id) =>
+ JSON.parse(fs.readFileSync(path.join(issuesDir, `${id}.json`), "utf8"));
+ assert.equal(read("CITRO-1").stage, "triaged");
+ assert.equal(read("CITRO-1").triage.verdict, "fix");
+ assert.equal(read("CITRO-2").stage, "in_review");
+
+ assert.equal(
+ fs.existsSync(path.join(base, "issues")),
+ false,
+ "nothing is recorded in the real state",
+ );
+ assert.deepEqual(fs.readdirSync(path.join(config.stateDir, "worktrees")), []);
+ assert.equal(queries.length, 1, "Linear is only read");
+
+ const log = fs.readFileSync(calls, "utf8").trim().split("\n");
+ assert.equal(log.filter((l) => l.startsWith("claude ")).length, 1);
+ assert.equal(log.filter((l) => l.startsWith("gh ")).length, 1);
+ assert.match(
+ log.find((l) => l.startsWith("gh ")),
+ /citro-1 /,
+ );
+});
+
+for (const command of ["implement", "review", "publish", "reset"]) {
+ test(`${command} refuses to run in a dry run`, () => {
+ const cli = new URL("./cli.mjs", import.meta.url).pathname;
+ const res = spawnSync(process.execPath, [cli, command, "CITRO-1"], {
+ encoding: "utf8",
+ });
+ assert.equal(res.status, 1);
+ assert.match(res.stderr, /not available with AUTOFIX_DRY_RUN=1/);
+ });
+}
diff --git a/tools/linear-autofix/src/tick.mjs b/tools/linear-autofix/src/tick.mjs
index 53a4d3f..cddffd7 100644
--- a/tools/linear-autofix/src/tick.mjs
+++ b/tools/linear-autofix/src/tick.mjs
@@ -101,7 +101,9 @@ export async function tick() {
return;
}
if (config.dryRun)
- console.log("[dry-run] no writes to Linear or GitHub, no push");
+ console.log(
+ `[dry-run] triage only, state in ${config.stateDir}; no writes to Linear or GitHub, no push`,
+ );
let issues = await linear.fetchAssignedIssues();
if (config.onlyIssue)
@@ -118,18 +120,20 @@ export async function tick() {
}));
console.log(`stages: ${stageCounts(work.map((w) => w.record))}`);
- // 0. Finished PRs that are still open: a human comment reopens the loop.
- for (const { record } of work.filter((w) => w.record.stage === "done")) {
- if (stopRequested()) return;
- await guarded(record, () => watchDone(record));
- }
+ if (!config.dryRun) {
+ // 0. Finished PRs that are still open: a human comment reopens the loop.
+ for (const { record } of work.filter((w) => w.record.stage === "done")) {
+ if (stopRequested()) return;
+ await guarded(record, () => watchDone(record));
+ }
- // 1. Review loops first: cheap checks that may finish a PR.
- for (const { issue, record } of work.filter(
- (w) => w.record.stage === "in_review",
- )) {
- if (stopRequested()) return;
- await guarded(record, () => review(issue, record));
+ // 1. Review loops first: cheap checks that may finish a PR.
+ for (const { issue, record } of work.filter(
+ (w) => w.record.stage === "in_review",
+ )) {
+ if (stopRequested()) return;
+ await guarded(record, () => review(issue, record));
+ }
}
const pausedUntil = usagePausedUntil();
@@ -166,6 +170,10 @@ export async function tick() {
});
}
+ // A dry run ends here: an implementation would leave a local branch checked
+ // out in the dry-run worktree, which blocks the real run on that ticket.
+ if (config.dryRun) return;
+
// 3. Implement, bounded by the number of bot PRs already in review.
const open = () => loadAll().filter((r) => r.stage === "in_review").length;
for (const { issue, record } of work.filter(