next-issue 17.2.8 → 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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "17.2.8",
3
+ "version": "17.2.9",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",