next-issue 8.7.0 → 8.8.0

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
@@ -1043,7 +1043,14 @@ affect another. The worker:
1043
1043
  - waits up to 5 seconds for the lock when a worker that is closing still
1044
1044
  holds it;
1045
1045
  - closes once no run is going when a client with a newer version connects, so
1046
- that the client can start the newer worker;
1046
+ that the client can start the newer worker. A run that watches is stopped
1047
+ between issues for that, as `stop` with `issue` does: it claims nothing new,
1048
+ and its running issues and its current hunt finish. Its progress then holds
1049
+ `"upgrade": { "from": "<worker version>", "to": "<client version>" }`. A
1050
+ stop by a person drops that field, so no client starts the run again. A run
1051
+ that does not watch is left alone. Meanwhile the worker refuses every start
1052
+ with `the worker is restarting, try again soon`. A `start` with
1053
+ `"resume": true` gets no error when the worker refuses it;
1047
1054
  - stops every agent and command and exits on `SIGTERM`, `SIGHUP` or `SIGINT`, and
1048
1055
  removes its socket and lock files;
1049
1056
  - keeps `.next-issue/worker.log`, where the extension writes the output of
package/dist/serve.mjs CHANGED
@@ -14,7 +14,7 @@ import { runRepo } from './run.mjs';
14
14
  import { packageVersion } from './version.mjs';
15
15
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
16
16
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
17
- import { active, endStatus, newRun, requestRefresh, requestStop, runControls, runsMessage, setHunting, setWatching, startRefusal, stopPoint, switchRefusal, } from './worker-run.mjs';
17
+ import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stopPoint, switchRefusal, } from './worker-run.mjs';
18
18
  import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
19
19
  const LOCK_WAIT_MS = 5_000;
20
20
  const IDLE_MS = 30_000;
@@ -32,7 +32,7 @@ export async function startWorker(options) {
32
32
  socket: '',
33
33
  };
34
34
  const runs = new Map();
35
- let restart = false;
35
+ let restart;
36
36
  const server = createServer();
37
37
  const sockets = new WebSocketServer({ server });
38
38
  const sendQuestions = questionSender(options.questions);
@@ -46,14 +46,21 @@ export async function startWorker(options) {
46
46
  await shutdown(server, sockets, owned);
47
47
  });
48
48
  const closeWhenIdle = () => {
49
- if ((restart || sockets.clients.size === 0) && !busy()) {
49
+ if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
50
50
  void close();
51
51
  }
52
52
  };
53
- const start = (socket, root, argv) => {
54
- const refusal = startRefusal(runs.get(root), restart);
53
+ const upgradeBetweenIssues = (run) => {
54
+ if (restart !== undefined && requestUpgrade(run, { from: options.version, to: restart })) {
55
+ broadcast(sockets, runs);
56
+ }
57
+ };
58
+ const start = (socket, root, argv, resume) => {
59
+ const refusal = startRefusal(runs.get(root), restart !== undefined);
55
60
  if (refusal !== undefined) {
56
- send(socket, { type: 'error', root, message: refusal });
61
+ if (!resume) {
62
+ send(socket, { type: 'error', root, message: refusal });
63
+ }
57
64
  return;
58
65
  }
59
66
  let args;
@@ -79,8 +86,11 @@ export async function startWorker(options) {
79
86
  const point = stopPoint(after);
80
87
  if (point === undefined) {
81
88
  send(socket, { type: 'error', root, message: `stop does not take --after ${String(after)}` });
89
+ return;
82
90
  }
83
- else if (requestStop(runs.get(root), point)) {
91
+ const run = runs.get(root);
92
+ const dropped = dropUpgrade(run);
93
+ if (requestStop(run, point) || dropped) {
84
94
  broadcast(sockets, runs);
85
95
  }
86
96
  };
@@ -93,6 +103,7 @@ export async function startWorker(options) {
93
103
  }
94
104
  set(run, on);
95
105
  broadcast(sockets, runs);
106
+ upgradeBetweenIssues(run);
96
107
  };
97
108
  const receive = (socket, value) => {
98
109
  if (value.type === 'hello') {
@@ -100,7 +111,8 @@ export async function startWorker(options) {
100
111
  throw new Error('a hello message needs its version as a string');
101
112
  }
102
113
  if (isNewer(value.version, options.version)) {
103
- restart = true;
114
+ restart ??= value.version;
115
+ runs.forEach(upgradeBetweenIssues);
104
116
  closeWhenIdle();
105
117
  }
106
118
  }
@@ -112,7 +124,7 @@ export async function startWorker(options) {
112
124
  });
113
125
  }
114
126
  else if (value.type === 'start') {
115
- start(socket, value.root, value.args ?? []);
127
+ start(socket, value.root, value.args ?? [], value.resume === true);
116
128
  }
117
129
  else if (value.type === 'stop') {
118
130
  stop(socket, value.root, value.after);
@@ -2,7 +2,7 @@ import { runChildren, stopRunChildren } from './children.mjs';
2
2
  import { wakeableSleep } from './durations.mjs';
3
3
  import { onOff } from './switch.mjs';
4
4
  import { applyEvent } from './progress.mjs';
5
- import { STOP_POINTS } from './protocol.mjs';
5
+ import { STOP_POINTS, } from './protocol.mjs';
6
6
  import { refresher } from './refresh.mjs';
7
7
  export function newRun(progress) {
8
8
  return {
@@ -58,6 +58,20 @@ export function requestStop(run, after) {
58
58
  run.progress = { ...run.progress, status: 'stopping' };
59
59
  return true;
60
60
  }
61
+ export function requestUpgrade(run, upgrade) {
62
+ if (!run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
63
+ return false;
64
+ }
65
+ run.progress = { ...run.progress, upgrade };
66
+ return true;
67
+ }
68
+ export function dropUpgrade(run) {
69
+ if (run?.progress.upgrade === undefined) {
70
+ return false;
71
+ }
72
+ run.progress = { ...run.progress, upgrade: undefined };
73
+ return true;
74
+ }
61
75
  export function switchRefusal(run) {
62
76
  return active(run) ? undefined : 'no run is going in this repository';
63
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "8.7.0",
3
+ "version": "8.8.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",