next-issue 6.6.96 → 6.6.97

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
@@ -175,7 +175,12 @@ the run handles one issue. For each issue:
175
175
  seconds after the others; a check that shows up in that time counts, and
176
176
  one that shows up later does not. A pending state
177
177
  waits again, up to `checkTimeoutMinutes`. A read that fails is tried three
178
- times. When the checks pass, the harness marks the state file as closing,
178
+ times. When the first read of the checks of a landed change still fails,
179
+ for example on a rate limit or an expired token, the harness hands the
180
+ issue to a person with the reason `checks error` and halts, before the
181
+ next change lands. The comment holds the error and says that the landed
182
+ commit is on the base and its checks were not awaited. The state file
183
+ keeps the commit, so the next run waits for its checks. When the checks pass, the harness marks the state file as closing,
179
184
  sets `status:done` and closes the issue. When a run stops or dies before
180
185
  the close, the next run sees the mark, sets `status:done` and closes the
181
186
  issue, with no new push, revert or hand-over. When a run stops or dies
@@ -282,7 +287,13 @@ and comments the reason on the issue, when:
282
287
  - a step of the run fails with an error. A `gh` call that is safe to repeat,
283
288
  such as a read or a label edit, is tried up to three times first when the
284
289
  network fails. A `gh issue comment` is
285
- tried once, so a lost reply never makes a duplicate.
290
+ tried once, so a lost reply never makes a duplicate. On a resume whose
291
+ state holds a landed commit, or a push or revert that may have reached the
292
+ base, an error before the harness checks the base (for example a failed
293
+ fetch of the base, or a worktree that cannot be made) also halts the run,
294
+ as `push unknown` does. The issue ends in error, the comment says what may
295
+ be on the base and that its checks were not awaited, and the state keeps
296
+ the commits for the next run.
286
297
 
287
298
  After a halt, a running issue that reaches the landing does not land on the
288
299
  broken base branch: it ends `stopped` with the reason `run halted` and keeps
@@ -3,20 +3,26 @@ import { ROUND_CONTINUE } from './job.mjs';
3
3
  import { landApproved, resumeLanding } from './land.mjs';
4
4
  import { reapplyMessage, restoreChange } from './revert.mjs';
5
5
  import { writeState } from './state.mjs';
6
+ import { beforeBaseSettled } from './unsettled.mjs';
6
7
  export async function enterReview(job) {
7
8
  const { context, state } = job;
8
- await settlePush(job);
9
- if (await settleRevert(job)) {
9
+ const reverted = await beforeBaseSettled(state, context.base, async () => {
10
+ await settlePush(job);
11
+ return settleRevert(job);
12
+ });
13
+ if (reverted) {
10
14
  job.mainBroken = true;
11
15
  const { base } = context;
12
16
  return escalateAndFinish(job, `The run stopped during the revert of the change on ${base}. The harness reverted the change on ${base}.`, 'revert stopped');
13
17
  }
14
- await settleSquash(job);
15
18
  const landed = state.landed?.at(-1);
16
- if (landed !== undefined || state.phase === 'approved') {
17
- const { ports } = context;
18
- await ports.discardChanges(job.worktree, await ports.revision(job.worktree), job.branch);
19
- }
19
+ await beforeBaseSettled(state, context.base, async () => {
20
+ await settleSquash(job);
21
+ if (landed !== undefined || state.phase === 'approved') {
22
+ const { ports } = context;
23
+ await ports.discardChanges(job.worktree, await ports.revision(job.worktree), job.branch);
24
+ }
25
+ });
20
26
  if (landed !== undefined) {
21
27
  return resumeLanding(job, landed);
22
28
  }
package/dist/gate.mjs CHANGED
@@ -14,10 +14,10 @@ export async function checkGate(job, sha) {
14
14
  checks = await rerunOnce(job, sha, await waitForChecks(job, sha));
15
15
  }
16
16
  catch (error) {
17
- if (!job.mainBroken) {
18
- throw error;
17
+ if (job.mainBroken) {
18
+ return escalateError(job, error, `The read of the checks on ${base} failed`, 'checks error');
19
19
  }
20
- return escalateError(job, error, `The read of the checks on ${base} failed`, 'checks error');
20
+ return unreadChecks(job, error);
21
21
  }
22
22
  if (checks === 'pass' || checks === 'none') {
23
23
  return GATE_PASSED;
@@ -109,6 +109,15 @@ async function refundStopped(job) {
109
109
  await refundBudget(job, 'ciFixes');
110
110
  }
111
111
  }
112
+ /** A landed commit whose checks cannot be read leaves the base unknown, so the run halts and keeps the commit. */
113
+ async function unreadChecks(job, error) {
114
+ if (runStopped()) {
115
+ throw error;
116
+ }
117
+ const { base } = job.context;
118
+ job.mainBroken = true;
119
+ return escalateAndFinish(job, `The read of the checks on ${base} failed: ${sentence(message(error))} The landed commit is on \`${base}\`, and its checks were not awaited. The run halts, and the next run checks the base again.`, 'checks error');
120
+ }
112
121
  export async function escalateError(job, error, note, reason) {
113
122
  if (runStopped()) {
114
123
  throw error;
package/dist/handover.mjs CHANGED
@@ -8,6 +8,7 @@ import { revertFailedFix } from './revert.mjs';
8
8
  import { logIssueError } from './skip.mjs';
9
9
  import { dropState, writeState } from './state.mjs';
10
10
  import { fitComment } from './text.mjs';
11
+ import { UnsettledBase } from './unsettled.mjs';
11
12
  export async function escalateAndFinish(job, note, reason) {
12
13
  const reverted = await revertFailedFix(job);
13
14
  try {
@@ -169,7 +170,11 @@ class HandOverFailed extends Error {
169
170
  }
170
171
  }
171
172
  function handOverReason(error, reason) {
172
- return error instanceof HandOverFailed ? error.reason : `The run failed: ${reason}`;
173
+ if (error instanceof HandOverFailed) {
174
+ return error.reason;
175
+ }
176
+ const unsettled = error instanceof UnsettledBase ? error.note : '';
177
+ return `The run failed: ${reason}${unsettled}`;
173
178
  }
174
179
  const CUT = '\n\nThe reason was too long for a GitHub comment and was cut.';
175
180
  function handOverComment(reason) {
@@ -187,5 +192,10 @@ export async function claimedError(context, log, issue, state, error, started) {
187
192
  // The issue ends (and the waiting questions go out) only once the hand-over is done.
188
193
  logIssueError(log, error, started);
189
194
  await cleanUp(context, log, state.branch);
190
- return issueReport(issue.number, 'error', state, started, reason);
195
+ const report = issueReport(issue.number, 'error', state, started, reason);
196
+ if (!(error instanceof UnsettledBase)) {
197
+ return report;
198
+ }
199
+ context.halted = true;
200
+ return { ...report, halt: true };
191
201
  }
package/dist/land.mjs CHANGED
@@ -6,12 +6,14 @@ import { escalateAndFinish, finishDone, stop } from './handover.mjs';
6
6
  import { oneAtATime } from './lock.mjs';
7
7
  import { revertFailedFix } from './revert.mjs';
8
8
  import { writeState } from './state.mjs';
9
+ import { beforeBaseSettled } from './unsettled.mjs';
9
10
  export function landApproved(job) {
10
11
  return landing(job, () => landLoop(job));
11
12
  }
12
13
  export function resumeLanding(job, sha) {
13
14
  return landing(job, async () => {
14
- if (await holdsUnlandedFix(job, sha)) {
15
+ const { state, context } = job;
16
+ if (await beforeBaseSettled(state, context.base, () => holdsUnlandedFix(job, sha))) {
15
17
  job.mainBroken = true;
16
18
  job.repairing = true;
17
19
  return landLoop(job);
package/dist/pipeline.mjs CHANGED
@@ -8,6 +8,7 @@ import { reviewRound } from './review.mjs';
8
8
  import { skipReport, unclaimedError } from './skip.mjs';
9
9
  import { hasLabel } from './labels.mjs';
10
10
  import { newState, readState, resetState, } from './state.mjs';
11
+ import { beforeBaseSettled } from './unsettled.mjs';
11
12
  import { setUp } from './worktree-setup.mjs';
12
13
  export async function processIssue(context, issue, claimed = () => undefined) {
13
14
  const { repo } = context;
@@ -67,8 +68,10 @@ function startState(context, issue, saved, handedOver) {
67
68
  return context.reset || handedOver ? resetState(saved) : rest;
68
69
  }
69
70
  async function work(context, issue, log, state, start, handedOver, pending) {
70
- const job = await openJob(context, issue, log, state, start, handedOver, pending);
71
- const setup = await setUp(job);
71
+ const { job, setup } = await beforeBaseSettled(state, context.base, async () => {
72
+ const opened = await openJob(context, issue, log, state, start, handedOver, pending);
73
+ return { job: opened, setup: await setUp(opened) };
74
+ });
72
75
  if (setup.done) {
73
76
  return setup.report;
74
77
  }
@@ -0,0 +1,38 @@
1
+ import { runStopped } from './children.mjs';
2
+ import { message } from './errors.mjs';
3
+ /** What the state holds that is, or may be, on the base branch with checks nobody awaited. */
4
+ export function heldOnBase(state, base) {
5
+ const { landed, pushing, reverting } = state;
6
+ const name = `\`${base}\``;
7
+ return [
8
+ (landed ?? []).length > 0 ? `a landed commit is on ${name}` : '',
9
+ pushing === undefined ? '' : `a push may be on ${name}`,
10
+ reverting === undefined ? '' : `a revert may be on ${name}`,
11
+ ]
12
+ .filter((part) => part !== '')
13
+ .join(', ');
14
+ }
15
+ export function unsettledNote(held, step) {
16
+ return ` ${step} before it checked the base: ${held}, and its checks were not awaited. The run halts, and the next run checks the base again.`;
17
+ }
18
+ /** An error thrown on a resume before it settled the base, while a commit is or may be on it. */
19
+ export class UnsettledBase extends Error {
20
+ note;
21
+ constructor(cause, held) {
22
+ super(message(cause), { cause });
23
+ this.note = unsettledNote(held, 'This resume failed');
24
+ }
25
+ }
26
+ /** Runs a step of a resume that comes before the base is settled; its error halts the run when the state holds a commit on the base. */
27
+ export async function beforeBaseSettled(state, base, step) {
28
+ const held = heldOnBase(state, base);
29
+ try {
30
+ return await step();
31
+ }
32
+ catch (error) {
33
+ if (held === '' || runStopped() || error instanceof UnsettledBase) {
34
+ throw error;
35
+ }
36
+ throw new UnsettledBase(error, held);
37
+ }
38
+ }
@@ -4,6 +4,7 @@ import { succeeded } from './exec.mjs';
4
4
  import { escalateAndFinish } from './handover.mjs';
5
5
  import { ROUND_CONTINUE } from './job.mjs';
6
6
  import { keepTail } from './text.mjs';
7
+ import { heldOnBase, unsettledNote } from './unsettled.mjs';
7
8
  export async function setUp(job) {
8
9
  const { context, log, worktree } = job;
9
10
  const { config, ports } = context;
@@ -31,15 +32,6 @@ async function setupFailed(job, setup) {
31
32
  return escalateAndFinish(job, `${note}${unsettled}`, late ? 'setup timeout' : 'setup failed');
32
33
  }
33
34
  function unsettledBase(job) {
34
- const { landed, pushing, reverting } = job.state;
35
- const base = `\`${job.context.base}\``;
36
- const held = [
37
- (landed ?? []).length > 0 ? `a landed commit is on ${base}` : '',
38
- pushing === undefined ? '' : `a push may be on ${base}`,
39
- reverting === undefined ? '' : `a revert may be on ${base}`,
40
- ].filter((part) => part !== '');
41
- if (held.length === 0) {
42
- return '';
43
- }
44
- return ` This resume ran the setup before it checked the base: ${held.join(', ')}, and its checks were not awaited. The run halts, and the next run checks the base again.`;
35
+ const held = heldOnBase(job.state, job.context.base);
36
+ return held === '' ? '' : unsettledNote(held, 'This resume ran the setup');
45
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.96",
3
+ "version": "6.6.97",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",