next-issue 6.6.103 → 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
@@ -372,16 +372,23 @@ Press `Ctrl-C` to stop the run step by step:
372
372
  starts, so the reviewer sees only the commits of the branch. Files that
373
373
  git ignores, such as build output, stay. When it
374
374
  resumes before the first commit, the implementer runs again and the
375
- commit holds them. A review round or a check fix whose reviewer or
376
- fixer this press kills does not count, so the next run runs that step
377
- again with the same budget.
378
-
379
- When the reviewer approved the change and the run stopped before its
380
- commit reached the base branch, the next run drops those edits and any
381
- unfinished merge of the base branch, then lands the change with no new
382
- review round. A hand-over of the issue cancels that approval, so the
383
- issue resumes in review. A revert of the landed change cancels it too,
384
- 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.
385
392
 
386
393
  Signals that arrive within 100 ms of the last counted one count as one press,
387
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/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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.103",
3
+ "version": "6.6.104",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",