next-issue 6.6.113 → 6.6.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ npx -y next-issue@latest
9
9
 
10
10
  ## Overview
11
11
 
12
- The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit. On a red build the harness reruns the failed jobs once, and only a second red build goes to the fixer, whose fix lands the same way. When the checks pass, the issue is closed and gets `status:done`. When a budget runs out or the work cannot go on, the issue gets `status:needs-human` and goes to a person. Then the harness takes the next issue.
12
+ The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit. On a red build the harness reruns the failed jobs of each failed workflow run once, and only a run that fails again goes to the fixer, whose fix lands the same way. When the checks pass, the issue is closed and gets `status:done`. When a budget runs out or the work cannot go on, the issue gets `status:needs-human` and goes to a person. Then the harness takes the next issue.
13
13
 
14
14
  ```mermaid
15
15
  flowchart TD
@@ -201,17 +201,23 @@ the run handles one issue. For each issue:
201
201
  file go away. A fetch that fails or a fast-forward that is
202
202
  not safe leaves the local base branch as it is and writes a `base.behind`
203
203
  event, and the issue is still done. When the checks fail, the harness
204
- reruns the failed GitHub Actions jobs once with
205
- `gh run rerun <id> --failed`, records a
206
- `main-checks.rerun` event, saves the rerun in the state file and waits
207
- again once the runs restart. A rerun that GitHub refuses because the run
204
+ reruns the failed jobs of each failed GitHub Actions workflow run once
205
+ with `gh run rerun <id> --failed`, records a `main-checks.rerun` event
206
+ and waits again once the runs restart. A failed run whose failed jobs
207
+ were already rerun (its attempt on GitHub is above 1) is not rerun
208
+ again, so a resumed run reruns only the runs not rerun yet. A failure
209
+ that gets a rerun ends the wait at once; any other failure (a run that
210
+ was rerun, a run that waits for approval, a check from another CI
211
+ service) waits until every check has finished, so a workflow run that
212
+ fails later, even after the first rerun started, still gets its own
213
+ rerun before any fixer. A rerun that GitHub refuses because the run
208
214
  is already running counts as started. When at least one run restarted
209
215
  and a later rerun or read fails, the event carries the error and the
210
216
  harness still waits for the checks again, counting each restarted run as
211
217
  running until a later attempt of it completes, so the fixer never runs
212
218
  while a rerun is queued or in progress. When the rerun cannot start (no
213
219
  run restarted, a `main-checks.rerun-failed` event), or the checks
214
- fail again, the fixer gets their logs from the check budget (for a check
220
+ fail again with no run left to rerun, the fixer gets their logs from the check budget (for a check
215
221
  from another CI service, only its name and link), and its fix
216
222
  lands the same way. When the fixer cannot fix them, its fix cannot land,
217
223
  an error stops the fix, or the budget runs out, the harness reverts every
@@ -48,39 +48,54 @@ async function baseChecks(repo, sha, branch, restarted) {
48
48
  ]);
49
49
  // A rerun run counts as running until a later attempt of it completes, so its old failure never ends the wait.
50
50
  const rerunning = restarted.some((entry) => !runs.some((run) => run.databaseId === entry.id && run.attempt > entry.attempt && run.status === 'completed'));
51
- return { checks: [...runs.map((entry) => ({ ...entry, url: '' })), ...external], rerunning };
51
+ return { runs, external, rerunning };
52
52
  }
53
53
  function failedRun(entry) {
54
54
  return entry.status === 'completed' && FAILED_CONCLUSIONS.has(entry.conclusion);
55
55
  }
56
- function baseState(runs) {
57
- if (runs.some(failedRun)) {
56
+ /** A failed workflow run whose failed jobs were not rerun yet; one that waits for approval cannot be rerun. */
57
+ function rerunnable(entry) {
58
+ return failedRun(entry) && entry.conclusion !== AWAITS_APPROVAL && !(entry.attempt > 1);
59
+ }
60
+ function baseState(runs, external) {
61
+ // A failure that gets a rerun ends the wait at once; any other failure waits for every check, so no run that fails later misses its rerun.
62
+ if (runs.some(rerunnable)) {
58
63
  return 'fail';
59
64
  }
60
- if (!runs.every((entry) => entry.status === 'completed')) {
65
+ const checks = [...runs, ...external];
66
+ if (!checks.every((entry) => entry.status === 'completed')) {
61
67
  return 'pending';
62
68
  }
63
- return runs.some((entry) => entry.conclusion === 'cancelled') ? 'cancelled' : 'pass';
69
+ if (checks.some(failedRun)) {
70
+ return 'fail';
71
+ }
72
+ return checks.some((entry) => entry.conclusion === 'cancelled') ? 'cancelled' : 'pass';
64
73
  }
65
74
  export function waitForBaseChecks(repo, sha, branch, options, restarted = []) {
66
- let read = { checks: [], rerunning: false };
75
+ let read = {
76
+ runs: [],
77
+ external: [],
78
+ rerunning: false,
79
+ };
67
80
  return pollChecks({
68
81
  head: async () => sha,
69
82
  lags: async () => true,
70
83
  list: async () => {
71
84
  read = await baseChecks(repo, sha, branch, restarted);
72
- return read.checks.length === 0 && !read.rerunning ? 'none' : 'some';
85
+ return read.runs.length + read.external.length === 0 && !read.rerunning ? 'none' : 'some';
73
86
  },
74
- watch: async () => (read.rerunning ? 'pending' : baseState(read.checks)),
87
+ watch: async () => (read.rerunning ? 'pending' : baseState(read.runs, read.external)),
75
88
  }, options);
76
89
  }
77
90
  export async function rerunFailedBase(repo, sha, branch, started = () => { }) {
78
- const failed = (await baseRuns(repo, sha, branch)).filter((entry) => failedRun(entry) && entry.conclusion !== AWAITS_APPROVAL);
91
+ const failed = (await baseRuns(repo, sha, branch)).filter(rerunnable);
79
92
  for (const entry of failed) {
80
93
  await rerun(repo, entry.databaseId);
81
94
  started({ id: entry.databaseId, attempt: entry.attempt });
82
95
  }
83
- await waitForRestart(repo, sha, branch, failed);
96
+ if (failed.length > 0) {
97
+ await waitForRestart(repo, sha, branch, failed);
98
+ }
84
99
  return failed.map((entry) => String(entry.databaseId));
85
100
  }
86
101
  async function rerun(repo, id) {
package/dist/gate.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { budgetUse, refundBudget, refundOnKill } from './budget.mjs';
2
2
  import { checkWaiting } from './check-poll.mjs';
3
- import { onKill, runStopped } from './children.mjs';
3
+ import { runStopped } from './children.mjs';
4
4
  import { asError, message } from './errors.mjs';
5
5
  import { escalateCheckFix, fixRound } from './fix.mjs';
6
6
  import { escalateAndFinish } from './handover.mjs';
7
7
  import { GATE_FIXED, GATE_PASSED } from './job.mjs';
8
8
  import { revertOrReport, sentence } from './revert.mjs';
9
- import { writeState, writeStateNow } from './state.mjs';
9
+ import { writeState } from './state.mjs';
10
10
  import { HALT_NOTE } from './unsettled.mjs';
11
11
  export async function checkGate(job, sha) {
12
12
  const { base } = job.context;
@@ -45,40 +45,38 @@ async function waitForChecks(job, sha, fields = {}, restarted = []) {
45
45
  log.event('main-checks.state', { state: checks, ...fields });
46
46
  return checks;
47
47
  }
48
+ /** Reruns the failed jobs of each failed workflow run once; GitHub keeps the attempts, so a resume reruns only runs not rerun yet. */
48
49
  async function rerunOnce(job, sha, checks) {
49
- const { context, log, state } = job;
50
- if (checks !== 'fail' || state.rerun === sha) {
51
- return checks;
50
+ let state = checks;
51
+ while (state === 'fail') {
52
+ const restarted = await rerunFailed(job, sha);
53
+ if (restarted.length === 0) {
54
+ return state;
55
+ }
56
+ state = await waitForChecks(job, sha, { rerun: true }, restarted).catch((error) => {
57
+ job.mainBroken = true;
58
+ throw error;
59
+ });
52
60
  }
53
- const before = state.rerun;
54
- state.rerun = sha;
55
- await writeState(context.repo, state);
61
+ return state;
62
+ }
63
+ async function rerunFailed(job, sha) {
64
+ const { context, log } = job;
56
65
  const restarted = [];
57
- const forget = onKill(() => {
58
- state.rerun = before;
59
- writeStateNow(context.repo, state);
60
- });
61
66
  try {
62
67
  const runs = await context.ports.rerunFailedBase(context.repo, sha, context.base, (run) => {
63
- forget();
64
68
  restarted.push(run);
65
69
  });
66
- forget();
70
+ // An empty list tells why the fixer starts with no rerun: no failed workflow run is left to rerun.
67
71
  log.event('main-checks.rerun', { sha, runs });
68
72
  }
69
73
  catch (error) {
70
- forget();
71
74
  if (runStopped()) {
72
- if (restarted.length > 0) {
73
- throw error;
74
- }
75
- state.rerun = before;
76
- await writeState(context.repo, state);
77
75
  throw error;
78
76
  }
79
77
  if (restarted.length === 0) {
80
78
  log.event('main-checks.rerun-failed', { sha, error: asError(error).message });
81
- return checks;
79
+ return restarted;
82
80
  }
83
81
  // Some runs restarted, so the fixer waits for them rather than getting a failure with no log.
84
82
  log.event('main-checks.rerun', {
@@ -87,10 +85,7 @@ async function rerunOnce(job, sha, checks) {
87
85
  error: asError(error).message,
88
86
  });
89
87
  }
90
- return waitForChecks(job, sha, { rerun: true }, restarted).catch((error) => {
91
- job.mainBroken = true;
92
- throw error;
93
- });
88
+ return restarted;
94
89
  }
95
90
  async function failedChecksFix(job, sha) {
96
91
  const { context, log, state } = job;
package/dist/state.mjs CHANGED
@@ -66,7 +66,6 @@ function isState(value) {
66
66
  isOptional(value.pushing, 'string') &&
67
67
  isOptional(value.reverting, 'string') &&
68
68
  isOptional(value.squashing, 'string') &&
69
- isOptional(value.rerun, 'string') &&
70
69
  isOptional(value.reviewing, 'string') &&
71
70
  typeof value.reviewRounds === 'number' &&
72
71
  Array.isArray(value.reviewLog) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.113",
3
+ "version": "6.6.114",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",