next-issue 6.6.3 → 6.6.4

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
@@ -544,9 +544,12 @@ affect another. The worker:
544
544
  repository. Only your user can open the file. It works on macOS and Linux.
545
545
  When the path of the socket file is too long for the system, about 103
546
546
  bytes on macOS and 107 on Linux, it exits with an error that says so;
547
- - holds `.next-issue/worker.lock` in the repository, with its process id, so
548
- only one worker runs per repository. A lock whose process is no longer alive
549
- is taken over;
547
+ - holds `.next-issue/worker.lock` in the repository, with its process id and
548
+ the start time of that process, so only one worker runs per repository. A
549
+ lock is stale, and is taken over, when no process has that id or the process
550
+ with that id started at another time, for example because the system gave
551
+ the id of a worker that was killed or lost in a reboot to another process.
552
+ A lock without a start time, from an older version, is stale too;
550
553
  - refuses a `start`, `stop` or `questions` message whose `root` is not
551
554
  the exact path of its repository with an `error` message, and starts or
552
555
  stops nothing;
@@ -595,9 +598,9 @@ affect another. The worker:
595
598
 
596
599
  Stop the worker of a repository with `next-issue stop` in that repository.
597
600
  Workers of other repositories carry on. This sends `SIGTERM` to the process in
598
- the lock file, so the worker stops at once and a run that is going resumes from
599
- its saved state next time. When no worker is running, the command says so and
600
- exits with 0.
601
+ the lock file when the lock is not stale, so the worker stops at once and a
602
+ run that is going resumes from its saved state next time. When no worker is
603
+ running, the command says so and exits with 0.
601
604
 
602
605
  Versions before one worker per repository ran one worker for the machine,
603
606
  with `next-issue.sock`, `next-issue.lock` and `next-issue.roots.json` in
package/dist/lock.mjs CHANGED
@@ -1,5 +1,7 @@
1
+ import { execFile } from 'node:child_process';
1
2
  import { rm, writeFile } from 'node:fs/promises';
2
3
  import { setTimeout as delay } from 'node:timers/promises';
4
+ import { promisify } from 'node:util';
3
5
  import { hasCode } from './errors.mjs';
4
6
  import { readTextOrEmpty } from './files.mjs';
5
7
  const LOCK_POLL_MS = 100;
@@ -9,18 +11,29 @@ export function oneAtATime(root, work) {
9
11
  worktreeQueues.set(root, result.catch(() => undefined));
10
12
  return result;
11
13
  }
12
- function alive(pid) {
14
+ export async function processStart(pid) {
15
+ const stat = await readTextOrEmpty(`/proc/${pid}/stat`);
16
+ if (stat !== '') {
17
+ return stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19];
18
+ }
13
19
  try {
14
- process.kill(pid, 0);
15
- return true;
20
+ const { stdout } = await promisify(execFile)('ps', ['-o', 'lstart=', '-p', String(pid)], {
21
+ env: { ...process.env, LC_ALL: 'C' },
22
+ });
23
+ return stdout.trim() || undefined;
16
24
  }
17
- catch (error) {
18
- return hasCode(error, 'EPERM');
25
+ catch {
26
+ return undefined;
19
27
  }
20
28
  }
21
29
  async function holder(lockPath) {
22
- const pid = Number((await readTextOrEmpty(lockPath)).trim());
23
- return pid > 0 && alive(pid) ? pid : undefined;
30
+ const [first = '', ...rest] = (await readTextOrEmpty(lockPath)).trim().split(' ');
31
+ const pid = Number(first);
32
+ const started = rest.join(' ');
33
+ if (!(pid > 0) || started === '') {
34
+ return undefined;
35
+ }
36
+ return (await processStart(pid)) === started ? pid : undefined;
24
37
  }
25
38
  export async function stopWorker(lockPath) {
26
39
  const pid = await holder(lockPath);
@@ -33,7 +46,10 @@ export async function lock(path, waitMs) {
33
46
  const deadline = Date.now() + waitMs;
34
47
  for (;;) {
35
48
  try {
36
- await writeFile(path, `${process.pid}\n`, { flag: 'wx', mode: 0o600 });
49
+ await writeFile(path, `${process.pid} ${await processStart(process.pid)}\n`, {
50
+ flag: 'wx',
51
+ mode: 0o600,
52
+ });
37
53
  return true;
38
54
  }
39
55
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.3",
3
+ "version": "6.6.4",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",