next-issue 17.2.7 → 17.2.9

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.
@@ -3,12 +3,21 @@ const groups = new Set();
3
3
  const stoppers = new Set();
4
4
  const undos = new Set();
5
5
  const current = new AsyncLocalStorage();
6
+ const runs = new Set();
6
7
  const STOP_GRACE_MS = 10_000;
7
8
  export function runChildren() {
8
9
  return { groups: new Set(), stoppers: new Set(), stopped: false };
9
10
  }
10
11
  export function withRunChildren(children, body) {
11
- return current.run(children, body);
12
+ return current.run(children, async () => {
13
+ runs.add(children);
14
+ try {
15
+ return await body();
16
+ }
17
+ finally {
18
+ runs.delete(children);
19
+ }
20
+ });
12
21
  }
13
22
  function stopAll(children, signal) {
14
23
  for (const stopper of children.stoppers) {
@@ -29,9 +38,10 @@ export function stopRunChildren(children) {
29
38
  stopAll(children, 'SIGINT');
30
39
  escalate(running, ['SIGTERM', 'SIGKILL']);
31
40
  }
32
- function escalate(running, signals) {
41
+ function escalate(running, signals, ended) {
33
42
  const [signal, ...later] = signals;
34
43
  if (signal === undefined || running.length === 0) {
44
+ ended?.();
35
45
  return;
36
46
  }
37
47
  setTimeout(() => {
@@ -42,7 +52,7 @@ function escalate(running, signals) {
42
52
  }
43
53
  catch { }
44
54
  }
45
- escalate(left, later);
55
+ escalate(left, later, ended);
46
56
  }, STOP_GRACE_MS).unref();
47
57
  }
48
58
  export function runStopped() {
@@ -74,8 +84,13 @@ export function onKill(undo) {
74
84
  undos.delete(undo);
75
85
  };
76
86
  }
87
+ let ending;
77
88
  export function stopChildren(signal) {
78
- stopAll({ groups, stoppers }, signal);
89
+ for (const children of runs) {
90
+ children.stopped = true;
91
+ }
92
+ const running = [...groups];
93
+ stopAll({ groups: new Set(running), stoppers }, signal);
79
94
  for (const undo of undos) {
80
95
  try {
81
96
  undo();
@@ -85,7 +100,19 @@ export function stopChildren(signal) {
85
100
  undos.clear();
86
101
  process.off('SIGTERM', onTerminate);
87
102
  process.off('SIGHUP', onHangUp);
88
- process.kill(process.pid, signal);
103
+ const exit = () => {
104
+ if (ending === exitOnceEnded) {
105
+ ending = undefined;
106
+ process.kill(process.pid, signal);
107
+ }
108
+ };
109
+ const exitOnceEnded = () => {
110
+ if (running.every((pid) => !groups.has(pid))) {
111
+ exit();
112
+ }
113
+ };
114
+ ending = exitOnceEnded;
115
+ escalate(running, ['SIGTERM', 'SIGKILL'], exit);
89
116
  }
90
117
  const onTerminate = () => stopChildren('SIGTERM');
91
118
  const onHangUp = () => stopChildren('SIGHUP');
@@ -121,6 +148,7 @@ export function watch(pid) {
121
148
  function unwatch(pid) {
122
149
  groups.delete(pid);
123
150
  unguard();
151
+ ending?.();
124
152
  }
125
153
  export function killTree(child) {
126
154
  if (child.pid === undefined) {
@@ -34,6 +34,7 @@ export async function startWorker(options) {
34
34
  const runs = new Map();
35
35
  let restart;
36
36
  let successor;
37
+ let closing = false;
37
38
  const server = createServer();
38
39
  const sockets = new WebSocketServer({ server });
39
40
  const busy = () => [...runs.values()].some(active);
@@ -54,6 +55,7 @@ export async function startWorker(options) {
54
55
  await shutdown(server, sockets, owned, listening);
55
56
  };
56
57
  const { closed, close } = closer(async () => {
58
+ closing = true;
57
59
  clearTimeout(idleTimer);
58
60
  const run = runs.get(options.root);
59
61
  if (successor !== undefined && run !== undefined && upgradedRun(run)) {
@@ -114,7 +116,7 @@ export async function startWorker(options) {
114
116
  joinGoing(socket, refuse, going, argv, id);
115
117
  return;
116
118
  }
117
- const refusal = startRefusal(going, restart !== undefined);
119
+ const refusal = startRefusal(going, restart !== undefined, closing);
118
120
  if (refusal !== undefined) {
119
121
  if (!resume) {
120
122
  refuse(refusal);
@@ -151,6 +153,9 @@ export async function startWorker(options) {
151
153
  summary = ended;
152
154
  },
153
155
  }))
156
+ .finally(() => {
157
+ closing = true;
158
+ })
154
159
  .then((code) => {
155
160
  update({ ...run.progress, status: endStatus(run) });
156
161
  return sendAllSent(sockets, {
@@ -21,10 +21,13 @@ export function endStatus(run) {
21
21
  }
22
22
  return run.stop === undefined ? 'finished' : 'stopped';
23
23
  }
24
- export function startRefusal(run, restart) {
24
+ export function startRefusal(run, restart, closing) {
25
25
  if (restart) {
26
26
  return 'the worker is restarting, try again soon';
27
27
  }
28
+ if (closing) {
29
+ return 'the worker is shutting down, try again soon';
30
+ }
28
31
  if (active(run)) {
29
32
  return 'a run is going in this repository already';
30
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "17.2.7",
3
+ "version": "17.2.9",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",