next-issue 10.7.1 → 10.7.3

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
@@ -34,9 +34,9 @@ flowchart TD
34
34
 
35
35
  Before each issue, fetch the open issues again and take the oldest one not yet seen in this run. An issue seen once in a run is not tried again in that run while its labels stay as the first fetch after its attempt found them. When its labels change, for example once a person answers a hand-over or makes a skipped issue ready, the next fetch claims it again in the usual order. An issue that is done, or that failed with an error and was not handed over, is not tried again in that run. The run ends when no unseen issue is left. When the fetch fails, the run claims no new issue, ends once the running issues end, writes the summary of the issues it handled and exits with code 1.
36
36
 
37
- `next-issue start` runs the work in the worker of the repository, see [Worker](#worker). It connects to the worker, or starts one in the background (`next-issue serve` of the same version, with its output in `.next-issue/worker.log`) when none answers, and then starts the run there with its flags. It prints the output of the run on standard error and the summary on standard output, and exits with the exit code of the run. When the terminal closes or the command ends some other way, the run keeps going in the worker, and pi and `next-issue logs` still show it. pi shows the run in `/next-issue` and the dashboard, and its Stop, Watch, Hunt and Refresh work on it. When the worker is older than `start` and no run is going, it closes and `start` starts a new one. When a run is going in the worker already, `start` exits with code 1 and the error `a run is going in this repository already`, and leaves that run alone: it does not tell an older worker its version, so the worker does not stop a watching run for an upgrade. `start` ignores `--force`, as before.
37
+ `next-issue start` runs the work in the worker of the repository, see [Worker](#worker). It connects to the worker, or starts one in the background (`next-issue serve` of the same version, with its output in `.next-issue/worker.log`) when none answers, and then starts the run there with its flags. It prints the output of the run on standard error and the summary on standard output, and exits with the exit code of the run. When the terminal closes or the command ends some other way, the run keeps going in the worker, and pi and `next-issue logs` still show it. pi shows the run in `/next-issue` and the dashboard, and its Stop, Watch, Hunt and Refresh work on it. When the worker is older than `start` and no run is going, it closes and `start` starts a new one. When a newer client, such as a newer pi, connects while a run of `start` goes, the worker does not stop that run for an upgrade, even when it watches: the run keeps its flags (`--max`, `--verbose`, `--quiet`), `start` follows it to its end, and the worker upgrades once it ends. When a run is going in the worker already, `start` exits with code 1 and the error `a run is going in this repository already`, and leaves that run alone: it does not tell an older worker its version, so the worker does not stop a watching run for an upgrade. `start` ignores `--force`, as before.
38
38
 
39
- Only one worker goes at a time in a repository. It holds the lock `.next-issue/worker.lock`, with the process id and the start time of that process, for its whole life. A run that the worker starts takes no lock of its own, since the worker runs at most one run at a time. When a process that does not take connections on the worker socket holds the lock, for example a command-line run of an older version, `start` claims no issue and exits with code 1 and the error `another next-issue worker or run (process id <n>) is going in this repository`. A lock whose process is gone, or started at another time, is stale and taken over.
39
+ Only one worker goes at a time in a repository. It holds the lock `.next-issue/worker.lock`, with the process id and the start time of that process, for its whole life. A run that the worker starts takes no lock of its own, since the worker runs at most one run at a time. When a process that does not take connections on the worker socket holds the lock for more than 2 seconds, `start` starts a worker anyway, which exits with `another worker is running`, so `start` claims no issue and exits with code 1 and the error `the next-issue worker exited before it listened: exit code 1 (see .next-issue/worker.log)`. A lock whose process is gone, or started at another time, is stale and taken over.
40
40
 
41
41
  Every command uses the main worktree of the repository as its root, the first one that `git worktree list` shows, even when it runs in a linked worktree. So `.next-issue/`, with the config, the locks, the worker socket, the saved state and the notes, and `.worktrees/` are always in the main worktree, and a run or worker started from a linked worktree gets the same refusal as one started from the main worktree.
42
42
 
@@ -353,7 +353,7 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
353
353
  `next-issue serve` runs one worker for the repository it is run in. The [`@ravshansbox/pi-next-issue`](../pi-next-issue) extension and `next-issue start` start it and talk to it. `serve` takes no flags apart from `--help` and refuses any other with an error, because runs start from a client, not from `serve`. Each repository has its own worker, so the runs, restarts and upgrades of one repository never affect another. The worker:
354
354
 
355
355
  - listens with WebSocket on the socket file `.next-issue/worker.sock` in the repository. Only your user can open the file. It works on macOS and Linux. When the path of the socket file is too long for the system, about 103 bytes on macOS and 107 on Linux, it exits with an error that says so;
356
- - holds `.next-issue/worker.lock` in the repository, with its process id and the start time of that process, so only one worker or command-line run goes per repository. A worker that starts while a command-line run holds the lock exits with `another worker is running`. A lock is stale, and is taken over, when no process has that id or the process with that id started at another time, for example because the system gave the id of a worker that was killed or lost in a reboot to another process. A lock without a start time, from an older version, is held while a process with that id is alive, and stale otherwise. A worker that cannot read its own start time exits with an error and takes no lock. When several workers start at once, one takes the lock and the others exit with `another worker is running`. A worker that stops removes the lock file only while it still holds the lock, and the socket file only while it is still the socket it bound;
356
+ - holds `.next-issue/worker.lock` in the repository, with its process id and the start time of that process, so only one worker goes per repository. A worker that starts while another process holds the lock exits with `another worker is running`. A lock is stale, and is taken over, when no process has that id or the process with that id started at another time, for example because the system gave the id of a worker that was killed or lost in a reboot to another process. A lock without a start time, from an older version, is held while a process with that id is alive, and stale otherwise. A worker that cannot read its own start time exits with an error and takes no lock. When several workers start at once, one takes the lock and the others exit with `another worker is running`. A worker that stops removes the lock file only while it still holds the lock, and the socket file only while it is still the socket it bound;
357
357
  - refuses a `start`, `stop`, `watch`, `hunt`, `questions` or `upcoming` message whose `root` is not the exact path of its repository with an `error` message, and starts or stops nothing;
358
358
  - sends each `error` as `{ "type": "error", "root": "<path>", "message": "<text>" }`. When a `start`, `stop`, `watch`, `hunt` or `refresh` message carries an `"id"`, the `error` that refuses it carries the same `id`;
359
359
  - runs at most one run at a time. A client starts it with `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like `next-issue start` with those args, or with none when `args` is left out (the pi extension sends none). It takes `--max <n>`, `--watch`, `--hunt`, `--reset`, `--verbose` and `--quiet`, and refuses a command (`start` too), `--json`, `--force`, `--help` or an unknown argument with an `error` message;
@@ -369,11 +369,11 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
369
369
  - asks a watching run to check for new issues now when a client sends `{ "type": "refresh", "root": "<path>" }`. A run that waits between passes starts a new pass at once, and its next wait starts again at 1 minute; a waiting hunter checks the ready count again. A refresh while a pass runs, for a run that is stopping or does not watch, or with no run going, changes nothing and gets no answer;
370
370
  - exits, and removes its socket and lock files, when no run is going and no client is connected, or when no client connects in the 30 seconds after it starts;
371
371
  - waits up to 5 seconds for the lock when a worker that is closing still holds it;
372
- - closes once no run is going when a client with a newer version connects, so that the client can start the newer worker. A run that watches is stopped between issues for that, as `stop` with `issue` does: it claims nothing new, and its running issues and its current hunt finish. Its progress then holds `"upgrade": { "from": "<worker version>", "to": "<client version>" }`. A stop by a person, or turning watching off, drops that field, so no client starts the run again. A run that does not watch is left alone. Meanwhile the worker refuses every start with `the worker is restarting, try again soon`. A `start` with `"resume": true` gets no error when the worker refuses it;
372
+ - closes once no run is going when a client with a newer version connects, so that the client can start the newer worker. A run that watches is stopped between issues for that, as `stop` with `issue` does: it claims nothing new, and its running issues and its current hunt finish. Its progress then holds `"upgrade": { "from": "<worker version>", "to": "<client version>" }`. A stop by a person, or turning watching off, drops that field, so no client starts the run again. A run that does not watch, or that `next-issue start` started, is left alone. Meanwhile the worker refuses every start with `the worker is restarting, try again soon`. A `start` with `"resume": true` gets no error when the worker refuses it;
373
373
  - stops every agent and command and exits on `SIGTERM`, `SIGHUP` or `SIGINT`, and removes its socket and lock files;
374
374
  - keeps `.next-issue/worker.log`, where the extension writes the output of the worker, within 10 MiB: when it starts and once a minute while it runs, it cuts a log of more than 10 MiB to its newest 5 MiB, from the start of a line. It skips the cut while a command that writes to the log runs. The run logs under `.next-issue/runs/` hold the same events.
375
375
 
376
- Stop the worker of a repository with `next-issue stop` in that repository. Workers of other repositories carry on. This sends `SIGTERM` to the process in the lock file when the lock is not stale and the worker socket file takes a connection, so the worker stops at once and a run that is going resumes from its saved state next time. When no worker is running, the command says so and exits with 0. When a command-line run of an older version holds the lock, the command sends no signal, says `no worker is running; a command-line run (process id <n>) is going, press Ctrl-C there to stop it` and exits with 0.
376
+ Stop the worker of a repository with `next-issue stop` in that repository. Workers of other repositories carry on. This sends `SIGTERM` to the process in the lock file when the lock is not stale, and for a lock without a start time only when the socket of the worker takes a connection, so the worker stops at once and a run that is going resumes from its saved state next time. When no worker is running, the command says so and exits with 0.
377
377
 
378
378
  Versions before one worker per repository ran one worker for the machine, with `next-issue.sock`, `next-issue.lock` and `next-issue.roots.json` in `~/.pi/agent`, or in the folder that `PI_CODING_AGENT_DIR` names. That worker does not stop by itself, `next-issue stop` does not reach it, and a run in it can claim issues alongside the new worker of the same repository. Stop it once after you upgrade:
379
379
 
package/dist/cli.mjs CHANGED
@@ -51,7 +51,6 @@ function run(root, args, argv) {
51
51
  }
52
52
  const STOPPED = {
53
53
  none: () => 'next-issue: no worker is running\n',
54
- run: (pid) => `next-issue: no worker is running; a command-line run (process id ${pid}) is going, press Ctrl-C there to stop it\n`,
55
54
  worker: (pid) => `next-issue: stopped the worker with process id ${pid}\n`,
56
55
  };
57
56
  async function stop(root) {
package/dist/lock.mjs CHANGED
@@ -147,7 +147,7 @@ async function removeDeadDrafts(path) {
147
147
  }
148
148
  }
149
149
  }
150
- function listening(socketPath) {
150
+ function takesConnection(socketPath) {
151
151
  return new Promise((resolve) => {
152
152
  const socket = createConnection(socketPath);
153
153
  socket.once('connect', () => {
@@ -158,13 +158,12 @@ function listening(socketPath) {
158
158
  });
159
159
  }
160
160
  export async function stopWorker(paths) {
161
- const pid = await lockHolder(paths.lockPath);
162
- if (pid === undefined) {
161
+ const text = await readTextOrEmpty(paths.lockPath);
162
+ const pid = await holderOf(text);
163
+ const unverified = text.trim().split(' ').length === 1;
164
+ if (pid === undefined || (unverified && !(await takesConnection(paths.socketPath)))) {
163
165
  return { stopped: 'none' };
164
166
  }
165
- if (!(await listening(paths.socketPath))) {
166
- return { stopped: 'run', pid };
167
- }
168
167
  process.kill(pid, 'SIGTERM');
169
168
  return { stopped: 'worker', pid };
170
169
  }
package/dist/loop.mjs CHANGED
@@ -89,6 +89,7 @@ function readmitChanged(issues, seen, tried) {
89
89
  for (const [number, labels] of tried.labels) {
90
90
  if (listed.has(number) && listed.get(number) !== labels) {
91
91
  tried.labels.delete(number);
92
+ tried.blocked.delete(number);
92
93
  seen.delete(number);
93
94
  }
94
95
  }
package/dist/run.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import { mkdir, rm } from 'node:fs/promises';
2
- import { dirname } from 'node:path';
3
1
  import { recordCommands } from './command-records.mjs';
4
2
  import { loadConfig } from './config.mjs';
5
3
  import { minutesToMs } from './durations.mjs';
@@ -12,7 +10,6 @@ import { checkGitVersion } from './git-version.mjs';
12
10
  import { defaultBranch } from './github.mjs';
13
11
  import { hunter } from './hunt.mjs';
14
12
  import { onOff } from './switch.mjs';
15
- import { lock, lockHolder } from './lock.mjs';
16
13
  import { exitCode, runIssues } from './loop.mjs';
17
14
  import { Recorder } from './observe.mjs';
18
15
  import { pendingIssues } from './pending.mjs';
@@ -22,24 +19,6 @@ import { pruneRuns } from './prune-runs.mjs';
22
19
  import { count } from './summary.mjs';
23
20
  import { packageVersion } from './version.mjs';
24
21
  import { watchIssues } from './watch.mjs';
25
- import { workerPaths } from './worker-paths.mjs';
26
- export async function runLocked(root, args, controls) {
27
- const path = workerPaths(root).lockPath;
28
- await mkdir(dirname(path), { recursive: true });
29
- const held = await lock(path, 0);
30
- if (held === undefined) {
31
- const pid = await lockHolder(path);
32
- throw new Error(`another next-issue worker or run (process id ${pid ?? 'unknown'}) is going in this repository`);
33
- }
34
- try {
35
- return await runRepo(root, args, controls);
36
- }
37
- finally {
38
- if (held.owns()) {
39
- await rm(path, { force: true });
40
- }
41
- }
42
- }
43
22
  export async function runRepo(root, args, controls) {
44
23
  const config = await loadConfig(root, { sortFile: true });
45
24
  return withDefaultTimeout(minutesToMs(config.commandTimeoutMinutes), () => runWithConfig(root, args, controls, config));
package/dist/serve.mjs CHANGED
@@ -56,7 +56,7 @@ export async function startWorker(options) {
56
56
  broadcast(sockets, runs);
57
57
  }
58
58
  };
59
- const start = (refuse, root, argv, resume) => {
59
+ const start = (refuse, root, argv, resume, command) => {
60
60
  const refusal = startRefusal(runs.get(root), restart !== undefined);
61
61
  if (refusal !== undefined) {
62
62
  if (!resume) {
@@ -72,7 +72,7 @@ export async function startWorker(options) {
72
72
  refuse(message(error));
73
73
  return;
74
74
  }
75
- const run = newRun({ ...startProgress(args.hunt), watching: args.watch });
75
+ const run = newRun({ ...startProgress(args.hunt), watching: args.watch }, command);
76
76
  runs.set(root, run);
77
77
  const update = (next) => {
78
78
  run.progress = next;
@@ -148,7 +148,7 @@ export async function startWorker(options) {
148
148
  refuse(`the worker serves ${options.root} only`);
149
149
  }
150
150
  else if (value.type === 'start') {
151
- start(refuse, value.root, value.args ?? [], value.resume === true);
151
+ start(refuse, value.root, value.args ?? [], value.resume === true, value.command === true);
152
152
  }
153
153
  else if (value.type === 'stop') {
154
154
  stop(socket, refuse, value.root, value.after, value.id);
package/dist/start.mjs CHANGED
@@ -90,6 +90,6 @@ function follow(connection, root, args, argv, out) {
90
90
  }
91
91
  });
92
92
  void connection.closed.then(() => fail(CLOSED));
93
- connection.send({ type: 'start', root, args: argv, id });
93
+ connection.send({ type: 'start', root, args: argv, command: true, id });
94
94
  });
95
95
  }
@@ -21,9 +21,6 @@ class SilentWorker extends Error {
21
21
  export function going(progress) {
22
22
  return progress?.status === 'running' || progress?.status === 'stopping';
23
23
  }
24
- function runGoing(pid) {
25
- return new Error(`another next-issue worker or run (process id ${pid}) is going in this repository`);
26
- }
27
24
  function parse(text) {
28
25
  try {
29
26
  return JSON.parse(text);
@@ -105,13 +102,9 @@ async function tryOpen(socketPath, version) {
105
102
  async function waitForHolder(paths, version) {
106
103
  const deadline = Date.now() + HOLDER_GRACE_MS;
107
104
  for (;;) {
108
- const pid = await lockHolder(paths.lockPath);
109
- if (pid === undefined) {
105
+ if ((await lockHolder(paths.lockPath)) === undefined || Date.now() >= deadline) {
110
106
  return undefined;
111
107
  }
112
- if (Date.now() >= deadline) {
113
- throw runGoing(pid);
114
- }
115
108
  await delay(POLL_MS);
116
109
  const opened = await tryOpen(paths.socketPath, version);
117
110
  if (opened !== undefined) {
@@ -129,10 +122,7 @@ async function waitForStart(paths, version, exited) {
129
122
  return opened;
130
123
  }
131
124
  if (reason !== undefined) {
132
- const pid = await lockHolder(paths.lockPath);
133
- throw pid === undefined
134
- ? new Error(`the next-issue worker exited before it listened: ${reason}`)
135
- : runGoing(pid);
125
+ throw new Error(`the next-issue worker exited before it listened: ${reason}`);
136
126
  }
137
127
  if (Date.now() >= deadline) {
138
128
  throw new Error('the next-issue worker did not start (see .next-issue/worker.log)');
@@ -4,9 +4,10 @@ import { onOff } from './switch.mjs';
4
4
  import { applyEvent } from './progress.mjs';
5
5
  import { STOP_POINTS, } from './protocol.mjs';
6
6
  import { refresher } from './refresh.mjs';
7
- export function newRun(progress) {
7
+ export function newRun(progress, command = false) {
8
8
  return {
9
9
  progress,
10
+ command,
10
11
  children: runChildren(),
11
12
  watching: onOff(progress.watching === true),
12
13
  hunting: onOff(progress.hunting),
@@ -69,7 +70,7 @@ export function stoppingMessage(root, run, id) {
69
70
  };
70
71
  }
71
72
  export function requestUpgrade(run, upgrade) {
72
- if (!run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
73
+ if (run.command || !run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
73
74
  return false;
74
75
  }
75
76
  run.progress = { ...run.progress, upgrade };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "10.7.1",
3
+ "version": "10.7.3",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",