next-issue 6.6.102 → 6.6.104

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
@@ -328,7 +328,12 @@ reaches the landing first does not keep it from checking the base. Once a person
328
328
  takes the label off, the issue resumes, checks the base and waits for the
329
329
  checks of its commit; when those are known (the issue is done, or its
330
330
  commits are reverted or found not on the base), the next run lands the
331
- held issues again. Such a resume is not held back
331
+ held issues again. A person who gives such an issue up instead (the `skip`
332
+ label, which **Give up** in pi adds) releases the block: the next run skips
333
+ the issue, drops its halt from the state and logs a `land.released` event,
334
+ so other issues land again on a base whose last checks nobody read. The state
335
+ keeps the commits, so taking the `skip` label off later resumes the issue
336
+ and checks them. Such a resume is not held back
332
337
  by another halted issue while it only checks its commit already on the
333
338
  base; a fix it has to land waits like any other change. The hand-over
334
339
  comment says so.
@@ -367,16 +372,23 @@ Press `Ctrl-C` to stop the run step by step:
367
372
  starts, so the reviewer sees only the commits of the branch. Files that
368
373
  git ignores, such as build output, stay. When it
369
374
  resumes before the first commit, the implementer runs again and the
370
- commit holds them. A review round or a check fix whose reviewer or
371
- fixer this press kills does not count, so the next run runs that step
372
- again with the same budget.
373
-
374
- When the reviewer approved the change and the run stopped before its
375
- commit reached the base branch, the next run drops those edits and any
376
- unfinished merge of the base branch, then lands the change with no new
377
- review round. A hand-over of the issue cancels that approval, so the
378
- issue resumes in review. A revert of the landed change cancels it too,
379
- even when the hand-over after it does not finish.
375
+ commit holds them. A review round or a check fix whose reviewer,
376
+ fixer or read of the failed logs this press kills does not count, so the next run runs that step
377
+ again with the same budget. A rerun of the failed jobs on the base
378
+ branch that this press kills before any job restarted runs again in the
379
+ next run, before any fixer.
380
+
381
+ `SIGTERM` to a command-line run while a command runs, and `SIGTERM` or
382
+ `SIGINT` to the worker (as `next-issue stop` sends), act like the third
383
+ press: they give back the review round, the check fix and the rerun in the
384
+ same way.
385
+
386
+ When the reviewer approved the change and the run stopped before its
387
+ commit reached the base branch, the next run drops those edits and any
388
+ unfinished merge of the base branch, then lands the change with no new
389
+ review round. A hand-over of the issue cancels that approval, so the
390
+ issue resumes in review. A revert of the landed change cancels it too,
391
+ even when the hand-over after it does not finish.
380
392
 
381
393
  Signals that arrive within 100 ms of the last counted one count as one press,
382
394
  because `npx` and `npm exec` pass on a press as a second signal.
package/dist/budget.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ import { onKill } from './children.mjs';
1
2
  import { escalateAndFinish } from './handover.mjs';
2
- import { writeState } from './state.mjs';
3
+ import { writeState, writeStateNow } from './state.mjs';
3
4
  const LIMITS = { ciFixes: 'maxCiFixes', reviewRounds: 'maxReviewRounds' };
4
5
  export function budgetUse(job, budget) {
5
6
  return { round: job.state[budget], limit: job.context.config[LIMITS[budget]] };
@@ -20,3 +21,17 @@ export async function refundBudget(job, budget) {
20
21
  state[budget] = Math.max(0, state[budget] - 1);
21
22
  await writeState(context.repo, state);
22
23
  }
24
+ /** Gives the spent budget back if the process is killed (third Ctrl-C) while `body` runs. */
25
+ export async function refundOnKill(job, budget, body) {
26
+ const { context, state } = job;
27
+ const forget = onKill(() => {
28
+ state[budget] = Math.max(0, state[budget] - 1);
29
+ writeStateNow(context.repo, state);
30
+ });
31
+ try {
32
+ return await body();
33
+ }
34
+ finally {
35
+ forget();
36
+ }
37
+ }
package/dist/children.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  const groups = new Set();
3
3
  const stoppers = new Set();
4
+ const undos = new Set();
4
5
  const current = new AsyncLocalStorage();
5
6
  export function runChildren() {
6
7
  return { groups: new Set(), stoppers: new Set(), stopped: false };
@@ -45,8 +46,22 @@ export function onStop(stopper) {
45
46
  children?.stoppers.delete(stopper);
46
47
  };
47
48
  }
49
+ /** Runs `undo` (synchronously) if the process is killed, for a step the kill leaves unsettled. */
50
+ export function onKill(undo) {
51
+ undos.add(undo);
52
+ return () => {
53
+ undos.delete(undo);
54
+ };
55
+ }
48
56
  export function stopChildren(signal) {
49
57
  stopAll({ groups, stoppers }, signal);
58
+ for (const undo of undos) {
59
+ try {
60
+ undo();
61
+ }
62
+ catch { }
63
+ }
64
+ undos.clear();
50
65
  process.off('SIGTERM', onTerminate);
51
66
  process.kill(process.pid, signal);
52
67
  }
package/dist/conflict.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { parseCommitSubject } from './agent-reply.mjs';
2
- import { refundBudget, spendBudget } from './budget.mjs';
2
+ import { refundBudget, refundOnKill, spendBudget } from './budget.mjs';
3
3
  import { runStopped } from './children.mjs';
4
4
  import { commitWork, runFixer } from './fix.mjs';
5
5
  import { escalateAndFinish } from './handover.mjs';
@@ -66,9 +66,12 @@ async function resolve(job, merge) {
66
66
  const { before, files } = merge;
67
67
  const { config, ports } = context;
68
68
  try {
69
- const text = files.length > 0 ? await fixConflict(job, files) : '';
70
- const subject = parseCommitSubject(text, `chore: merge ${config.remote}/${context.base}`);
71
- return await commitWork(job, before, subject, 'fixer', (cwd, message) => ports.commitMerge(cwd, merge, message));
69
+ const fixAndCommit = async () => {
70
+ const text = files.length > 0 ? await fixConflict(job, files) : '';
71
+ const subject = parseCommitSubject(text, `chore: merge ${config.remote}/${context.base}`);
72
+ return commitWork(job, before, subject, 'fixer', (cwd, message) => ports.commitMerge(cwd, merge, message));
73
+ };
74
+ return await (files.length > 0 ? refundOnKill(job, 'ciFixes', fixAndCommit) : fixAndCommit());
72
75
  }
73
76
  catch (error) {
74
77
  if (files.length > 0 && runStopped()) {
package/dist/files.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { dirname } from 'node:path';
2
4
  import { readdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
5
  import { hasCode } from './errors.mjs';
4
6
  export function readTextOrEmpty(path) {
@@ -24,6 +26,19 @@ export async function replaceJson(path, value) {
24
26
  throw error;
25
27
  }
26
28
  }
29
+ /** The synchronous `replaceJson`, for a write that must land before the process dies. */
30
+ export function replaceJsonNow(path, value) {
31
+ const draft = `${path}.${process.pid}.${randomUUID()}.tmp`;
32
+ try {
33
+ mkdirSync(dirname(path), { recursive: true });
34
+ writeFileSync(draft, prettyJson(value));
35
+ renameSync(draft, path);
36
+ }
37
+ catch (error) {
38
+ rmSync(draft, { force: true });
39
+ throw error;
40
+ }
41
+ }
27
42
  export async function unlessMissing(read) {
28
43
  try {
29
44
  return await read();
package/dist/gate.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { budgetUse, refundBudget } from './budget.mjs';
1
+ import { budgetUse, refundBudget, refundOnKill } from './budget.mjs';
2
2
  import { checkWaiting } from './check-poll.mjs';
3
- import { runStopped } from './children.mjs';
3
+ import { onKill, 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 } from './state.mjs';
9
+ import { writeState, writeStateNow } 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;
@@ -52,13 +52,20 @@ async function rerunOnce(job, sha, checks) {
52
52
  state.rerun = sha;
53
53
  await writeState(context.repo, state);
54
54
  const restarted = [];
55
+ const forget = onKill(() => {
56
+ state.rerun = before;
57
+ writeStateNow(context.repo, state);
58
+ });
55
59
  try {
56
60
  const runs = await context.ports.rerunFailedBase(context.repo, sha, context.base, (run) => {
61
+ forget();
57
62
  restarted.push(run);
58
63
  });
64
+ forget();
59
65
  log.event('main-checks.rerun', { sha, runs });
60
66
  }
61
67
  catch (error) {
68
+ forget();
62
69
  if (runStopped()) {
63
70
  if (restarted.length > 0) {
64
71
  throw error;
@@ -95,7 +102,7 @@ async function failedChecksFix(job, sha) {
95
102
  await writeState(repo, state);
96
103
  let logs;
97
104
  try {
98
- logs = await ports.failedBaseLogs(repo, sha, base, config.logMaxChars);
105
+ logs = await refundOnKill(job, 'ciFixes', () => ports.failedBaseLogs(repo, sha, base, config.logMaxChars));
99
106
  }
100
107
  catch (error) {
101
108
  await refundStopped(job);
@@ -104,7 +111,7 @@ async function failedChecksFix(job, sha) {
104
111
  log.event('main-checks.logs', { chars: logs.length });
105
112
  let fix;
106
113
  try {
107
- fix = await fixRound(job, `The checks on ${base} failed after the change landed there.`, logs, [], 'checks');
114
+ fix = await refundOnKill(job, 'ciFixes', () => fixRound(job, `The checks on ${base} failed after the change landed there.`, logs, [], 'checks'));
108
115
  }
109
116
  catch (error) {
110
117
  await refundStopped(job);
package/dist/review.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { REVIEWING } from './agents.mjs';
2
2
  import { runStopped } from './children.mjs';
3
- import { budgetUse, refundBudget, spendBudget } from './budget.mjs';
3
+ import { budgetUse, refundBudget, refundOnKill, spendBudget } from './budget.mjs';
4
4
  import { message } from './errors.mjs';
5
5
  import { fixRound } from './fix.mjs';
6
6
  import { escalateAndFinish } from './handover.mjs';
@@ -21,8 +21,10 @@ export async function reviewRound(job) {
21
21
  const earlier = history(state.reviewLog);
22
22
  let text;
23
23
  try {
24
- await setStatus(context, issue.number, config.labels.inReview);
25
- text = await runReviewer(job, earlier);
24
+ text = await refundOnKill(job, 'reviewRounds', async () => {
25
+ await setStatus(context, issue.number, config.labels.inReview);
26
+ return runReviewer(job, earlier);
27
+ });
26
28
  }
27
29
  catch (error) {
28
30
  if (runStopped()) {
package/dist/skip.mjs CHANGED
@@ -4,6 +4,8 @@ import { message } from './errors.mjs';
4
4
  import { handOverReply } from './hand-over-comments.mjs';
5
5
  import { stopNow } from './handover.mjs';
6
6
  import { hasLabel } from './labels.mjs';
7
+ import { writeState } from './state.mjs';
8
+ import { heldOnBase } from './unsettled.mjs';
7
9
  export function skipReason(issue, config, resuming, answered = false) {
8
10
  const has = (name) => hasLabel(issue.labels, name);
9
11
  const names = config.labels;
@@ -33,6 +35,14 @@ export async function skipReport(context, log, issue, saved, started) {
33
35
  const skip = skipReason(issue, context.config, saved !== undefined, answered);
34
36
  if (skip !== undefined) {
35
37
  log.event('issue.skip', { title: issue.title, reason: skip });
38
+ if (saved?.halted === true && hasLabel(issue.labels, context.config.labels.skip)) {
39
+ try {
40
+ await release(context, log, saved);
41
+ }
42
+ catch (error) {
43
+ return readError(log, issue, saved, error, started);
44
+ }
45
+ }
36
46
  return skipped(issue);
37
47
  }
38
48
  if (saved !== undefined) {
@@ -51,6 +61,15 @@ export async function skipReport(context, log, issue, saved, started) {
51
61
  }
52
62
  return undefined;
53
63
  }
64
+ /**
65
+ * A person gave up on a halted issue: it never resumes to check the base while it has the skip label, so its halt
66
+ * stops blocking the landings of other issues. The state keeps what is on the base for a later resume.
67
+ */
68
+ async function release(context, log, saved) {
69
+ delete saved.halted;
70
+ await writeState(context.repo, saved);
71
+ log.event('land.released', { held: heldOnBase(saved, context.base) });
72
+ }
54
73
  async function hasAnswer(context, issue, saved) {
55
74
  if (!hasLabel(issue.labels, context.config.labels.needsHuman)) {
56
75
  return false;
package/dist/state.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mkdir, readdir, rm } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { parseJson } from './errors.mjs';
4
- import { readTextIfPresent, replaceJson, unlessMissing } from './files.mjs';
4
+ import { readTextIfPresent, replaceJson, replaceJsonNow, unlessMissing } from './files.mjs';
5
5
  import { isRecord } from './records.mjs';
6
6
  export const STATE_DIR = '.next-issue';
7
7
  export function stateDir(root) {
@@ -95,6 +95,10 @@ export async function writeState(repo, state) {
95
95
  await mkdir(stateDir(repo.root), { recursive: true });
96
96
  await replaceJson(file(repo, state.issue), state);
97
97
  }
98
+ /** Writes the state synchronously, from a kill of the process. */
99
+ export function writeStateNow(repo, state) {
100
+ replaceJsonNow(file(repo, state.issue), state);
101
+ }
98
102
  export async function dropState(repo, issue) {
99
103
  await rm(file(repo, issue), { force: true });
100
104
  }
@@ -13,7 +13,7 @@ export function heldOnBase(state, base) {
13
13
  .join(', ');
14
14
  }
15
15
  /** What a halt with an unchecked commit on the base means for the next runs. */
16
- export const HALT_NOTE = 'The run halts, and no run lands another change until this issue resumes (after an answer or once the label is off) and checks the base.';
16
+ export const HALT_NOTE = 'The run halts, and no run lands another change until this issue resumes (after an answer or once the label is off) and checks the base, or a person gives it up with the skip label.';
17
17
  /** Whether this state keeps every run from landing: it halted with a commit on the base whose checks are still unknown. */
18
18
  export function blocksLanding(state, base) {
19
19
  return state.halted === true && state.closing !== true && heldOnBase(state, base) !== '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.102",
3
+ "version": "6.6.104",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",