next-issue 6.6.5 → 6.6.7
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 +21 -12
- package/dist/enter-review.mjs +14 -0
- package/dist/git.mjs +3 -0
- package/dist/land.mjs +18 -2
- package/dist/lock.mjs +73 -24
- package/dist/ports.mjs +2 -1
- package/dist/serve.mjs +20 -9
- package/dist/state.mjs +1 -0
- package/dist/worker-server.mjs +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,17 +110,23 @@ the run handles one issue. For each issue:
|
|
|
110
110
|
and hands the issue to a person with the reason `merge conflict`. The
|
|
111
111
|
harness then pushes the commit to the base branch, without force. A push
|
|
112
112
|
that the remote refuses, for example because the base moved, starts the
|
|
113
|
-
rebase again, three times at most.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
rebase again, three times at most. When the push fails, the harness
|
|
114
|
+
fetches the base first, and treats the push as landed when the base holds
|
|
115
|
+
the commit, for example after a timeout. When that fetch fails too, the
|
|
116
|
+
harness hands the issue to a person with the reason `push unknown` and
|
|
117
|
+
halts. The state file holds the commit during the push, so a run stopped
|
|
118
|
+
meanwhile, or the next run after that hand-over, checks the base on resume
|
|
119
|
+
and waits for the checks of the commit when it landed. The harness then
|
|
120
|
+
waits for the checks of the pushed commit on the base branch. A repository
|
|
121
|
+
that reports no check keeps asking for `checkGraceSeconds`. A pending state
|
|
122
|
+
waits again, up to `checkTimeoutMinutes`. A read that fails is tried three
|
|
123
|
+
times. When the checks pass, the harness closes the issue and sets
|
|
124
|
+
`status:done`, fetches the remote and fast-forwards the local base branch
|
|
125
|
+
to the landed commit when that is safe, and the worktree, the local branch
|
|
126
|
+
and the state file go away. A fetch that fails or a fast-forward that is
|
|
127
|
+
not safe leaves the local base branch as it is and writes a `base.behind`
|
|
128
|
+
event, and the issue is still done. When the checks fail, the harness
|
|
129
|
+
reruns the failed jobs once with `gh run rerun <id> --failed`, records a
|
|
124
130
|
`main-checks.rerun` event, saves the rerun in the state file and waits
|
|
125
131
|
again once the runs restart. When the rerun cannot start, or the checks
|
|
126
132
|
fail again, the fixer gets their logs from the check budget, and its fix lands
|
|
@@ -550,7 +556,10 @@ affect another. The worker:
|
|
|
550
556
|
with that id started at another time, for example because the system gave
|
|
551
557
|
the id of a worker that was killed or lost in a reboot to another process.
|
|
552
558
|
A lock without a start time, from an older version, is stale too. A worker
|
|
553
|
-
that cannot read its own start time exits with an error and takes no lock
|
|
559
|
+
that cannot read its own start time exits with an error and takes no lock.
|
|
560
|
+
When several workers start at once, one takes the lock and the others exit
|
|
561
|
+
with `another worker is running`. A worker that stops removes the socket
|
|
562
|
+
and lock files only while it still holds the lock;
|
|
554
563
|
- refuses a `start`, `stop` or `questions` message whose `root` is not
|
|
555
564
|
the exact path of its repository with an `error` message, and starts or
|
|
556
565
|
stops nothing;
|
package/dist/enter-review.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { resumeLanding } from './land.mjs';
|
|
|
3
3
|
import { writeState } from './state.mjs';
|
|
4
4
|
export async function enterReview(job) {
|
|
5
5
|
const { context, state } = job;
|
|
6
|
+
await settlePush(job);
|
|
6
7
|
const landed = state.landed?.at(-1);
|
|
7
8
|
if (landed !== undefined) {
|
|
8
9
|
return resumeLanding(job, landed);
|
|
@@ -11,3 +12,16 @@ export async function enterReview(job) {
|
|
|
11
12
|
await writeState(context.repo, state);
|
|
12
13
|
return ROUND_CONTINUE;
|
|
13
14
|
}
|
|
15
|
+
async function settlePush(job) {
|
|
16
|
+
const { context, state, worktree } = job;
|
|
17
|
+
const { repo, config, ports, base } = context;
|
|
18
|
+
const sha = state.pushing;
|
|
19
|
+
if (sha === undefined) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (await ports.isOnBase(worktree, base, config.remote, sha)) {
|
|
23
|
+
state.landed = [...(state.landed ?? []), sha];
|
|
24
|
+
}
|
|
25
|
+
state.pushing = undefined;
|
|
26
|
+
await writeState(repo, state);
|
|
27
|
+
}
|
package/dist/git.mjs
CHANGED
|
@@ -98,6 +98,9 @@ export async function isAncestor(cwd, ancestor, descendant) {
|
|
|
98
98
|
export async function isLanded(cwd, base, remote) {
|
|
99
99
|
return isAncestor(cwd, 'HEAD', remoteRef(remote, base));
|
|
100
100
|
}
|
|
101
|
+
export async function isOnBase(cwd, base, remote, sha) {
|
|
102
|
+
return isAncestor(cwd, sha, await fetchBase(cwd, base, remote));
|
|
103
|
+
}
|
|
101
104
|
export async function deleteBranch(repo, branch) {
|
|
102
105
|
return succeeds(repo.root, ['branch', '-D', branch]);
|
|
103
106
|
}
|
package/dist/land.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runStopped } from './children.mjs';
|
|
1
2
|
import { rebase } from './conflict.mjs';
|
|
2
3
|
import { checkGate } from './gate.mjs';
|
|
3
4
|
import { PUSH_TRIES } from './git-land.mjs';
|
|
@@ -60,10 +61,25 @@ async function pushChange(job) {
|
|
|
60
61
|
return rebased;
|
|
61
62
|
}
|
|
62
63
|
const sha = await ports.revision(worktree);
|
|
63
|
-
|
|
64
|
+
state.pushing = sha;
|
|
65
|
+
await writeState(repo, state);
|
|
66
|
+
const pushed = await log.step('land', { base, sha }, async () => (await ports.pushToBase(worktree, config.remote, base)) ||
|
|
67
|
+
ports.isOnBase(worktree, base, config.remote, sha).catch((error) => {
|
|
68
|
+
if (runStopped()) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}));
|
|
73
|
+
if (pushed === undefined) {
|
|
74
|
+
job.mainBroken = true;
|
|
75
|
+
return escalateAndFinish(job, `The push to ${base} failed and the fetch of ${base} failed too, so the harness cannot tell whether the commit landed.`, 'push unknown');
|
|
76
|
+
}
|
|
77
|
+
state.pushing = undefined;
|
|
64
78
|
if (pushed) {
|
|
65
79
|
state.landed = [...(state.landed ?? []), sha];
|
|
66
|
-
|
|
80
|
+
}
|
|
81
|
+
await writeState(repo, state);
|
|
82
|
+
if (pushed) {
|
|
67
83
|
job.repairing = false;
|
|
68
84
|
return sha;
|
|
69
85
|
}
|
package/dist/lock.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
4
|
+
import { link, rm, writeFile } from 'node:fs/promises';
|
|
3
5
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
6
|
import { promisify } from 'node:util';
|
|
5
7
|
import { hasCode } from './errors.mjs';
|
|
6
|
-
import { readTextOrEmpty } from './files.mjs';
|
|
8
|
+
import { readTextIfPresent, readTextOrEmpty } from './files.mjs';
|
|
7
9
|
const LOCK_POLL_MS = 100;
|
|
8
10
|
const worktreeQueues = new Map();
|
|
9
11
|
export function oneAtATime(root, work) {
|
|
@@ -26,8 +28,8 @@ export async function processStart(pid) {
|
|
|
26
28
|
return undefined;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
async function
|
|
30
|
-
const [first = '', ...rest] =
|
|
31
|
+
async function holderOf(text) {
|
|
32
|
+
const [first = '', ...rest] = text.trim().split(' ');
|
|
31
33
|
const pid = Number(first);
|
|
32
34
|
const started = rest.join(' ');
|
|
33
35
|
if (!(pid > 0) || started === '') {
|
|
@@ -35,6 +37,13 @@ async function holder(lockPath) {
|
|
|
35
37
|
}
|
|
36
38
|
return (await processStart(pid)) === started ? pid : undefined;
|
|
37
39
|
}
|
|
40
|
+
async function holder(lockPath) {
|
|
41
|
+
return holderOf(await readTextOrEmpty(lockPath));
|
|
42
|
+
}
|
|
43
|
+
async function isStale(lockPath) {
|
|
44
|
+
const text = await readTextIfPresent(lockPath);
|
|
45
|
+
return text !== undefined && (await holderOf(text)) === undefined;
|
|
46
|
+
}
|
|
38
47
|
export async function stopWorker(lockPath) {
|
|
39
48
|
const pid = await holder(lockPath);
|
|
40
49
|
if (pid !== undefined) {
|
|
@@ -42,33 +51,73 @@ export async function stopWorker(lockPath) {
|
|
|
42
51
|
}
|
|
43
52
|
return pid;
|
|
44
53
|
}
|
|
54
|
+
function inode(path) {
|
|
55
|
+
return statSync(path, { throwIfNoEntry: false })?.ino;
|
|
56
|
+
}
|
|
57
|
+
function textOf(path) {
|
|
58
|
+
try {
|
|
59
|
+
return readFileSync(path, 'utf8');
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function linked(source, target) {
|
|
66
|
+
try {
|
|
67
|
+
await link(source, target);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (hasCode(error, 'EEXIST')) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function removeStale(path, filled) {
|
|
78
|
+
const breakPath = `${path}.break`;
|
|
79
|
+
if (!(await linked(filled, breakPath))) {
|
|
80
|
+
if (await isStale(breakPath)) {
|
|
81
|
+
await rm(breakPath, { force: true });
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
if (await isStale(path)) {
|
|
87
|
+
await rm(path, { force: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
await rm(breakPath, { force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
45
94
|
export async function lock(path, waitMs, readStart = processStart) {
|
|
46
95
|
const started = await readStart(process.pid);
|
|
47
96
|
if (started === undefined) {
|
|
48
97
|
throw new Error('next-issue: cannot read the start time of the worker process');
|
|
49
98
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
99
|
+
const filled = `${path}.${randomUUID()}`;
|
|
100
|
+
const text = `${process.pid} ${started}\n`;
|
|
101
|
+
await writeFile(filled, text, { flag: 'wx', mode: 0o600 });
|
|
102
|
+
try {
|
|
103
|
+
const deadline = Date.now() + waitMs;
|
|
104
|
+
for (;;) {
|
|
105
|
+
if (await linked(filled, path)) {
|
|
106
|
+
const held = inode(path);
|
|
107
|
+
return {
|
|
108
|
+
owns: () => held !== undefined && inode(path) === held && textOf(path) === text,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if ((await holder(path)) === undefined) {
|
|
112
|
+
await removeStale(path, filled);
|
|
113
|
+
}
|
|
114
|
+
else if (Date.now() >= deadline) {
|
|
115
|
+
return undefined;
|
|
62
116
|
}
|
|
63
|
-
}
|
|
64
|
-
if ((await holder(path)) === undefined) {
|
|
65
|
-
await rm(path, { force: true });
|
|
66
|
-
}
|
|
67
|
-
else if (Date.now() >= deadline) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
117
|
await delay(LOCK_POLL_MS);
|
|
72
118
|
}
|
|
73
119
|
}
|
|
120
|
+
finally {
|
|
121
|
+
await rm(filled, { force: true });
|
|
122
|
+
}
|
|
74
123
|
}
|
package/dist/ports.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { run } from './exec.mjs';
|
|
|
4
4
|
import { commitAll } from './git-commit.mjs';
|
|
5
5
|
import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
|
|
6
6
|
import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
7
|
-
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
7
|
+
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, isOnBase, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
8
8
|
import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
|
|
9
9
|
import { huntWorktree } from './hunt.mjs';
|
|
10
10
|
import { ensureLabel, setLabel } from './labels.mjs';
|
|
@@ -33,6 +33,7 @@ export const PORTS = {
|
|
|
33
33
|
huntWorktree,
|
|
34
34
|
isDirty,
|
|
35
35
|
isLanded,
|
|
36
|
+
isOnBase,
|
|
36
37
|
issueComments,
|
|
37
38
|
latestSubject,
|
|
38
39
|
openBlockers,
|
package/dist/serve.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
|
-
import { mkdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
|
-
import { dirname } from 'node:path';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
5
|
import { WebSocketServer } from 'ws';
|
|
6
6
|
import { parseStartArgs } from './args.mjs';
|
|
7
7
|
import { stopChildren, withRunChildren } from './children.mjs';
|
|
8
8
|
import { message } from './errors.mjs';
|
|
9
|
+
import { listOrEmpty } from './files.mjs';
|
|
9
10
|
import { lock } from './lock.mjs';
|
|
10
11
|
import { startProgress } from './progress.mjs';
|
|
11
12
|
import { isNewer } from './protocol.mjs';
|
|
@@ -20,10 +21,17 @@ const IDLE_MS = 30_000;
|
|
|
20
21
|
export async function startWorker(options) {
|
|
21
22
|
checkSocketPath(options.socketPath);
|
|
22
23
|
await mkdir(dirname(options.lockPath), { recursive: true });
|
|
23
|
-
|
|
24
|
+
const held = await lock(options.lockPath, options.lockWaitMs ?? LOCK_WAIT_MS);
|
|
25
|
+
if (held === undefined) {
|
|
24
26
|
return undefined;
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
const stateDir = dirname(options.socketPath);
|
|
29
|
+
const bindPath = join(stateDir, `s${process.pid}`);
|
|
30
|
+
for (const name of await listOrEmpty(stateDir)) {
|
|
31
|
+
if (/^s\d+$/.test(name)) {
|
|
32
|
+
await rm(join(stateDir, name), { force: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
const runs = new Map();
|
|
28
36
|
let restart = false;
|
|
29
37
|
const server = createServer();
|
|
@@ -33,7 +41,7 @@ export async function startWorker(options) {
|
|
|
33
41
|
let idleTimer;
|
|
34
42
|
const { closed, close } = closer(async () => {
|
|
35
43
|
clearTimeout(idleTimer);
|
|
36
|
-
await shutdown(server, sockets, options);
|
|
44
|
+
await shutdown(server, sockets, options, held);
|
|
37
45
|
});
|
|
38
46
|
const closeWhenIdle = () => {
|
|
39
47
|
if ((restart || sockets.clients.size === 0) && !busy()) {
|
|
@@ -120,9 +128,10 @@ export async function startWorker(options) {
|
|
|
120
128
|
}
|
|
121
129
|
});
|
|
122
130
|
});
|
|
123
|
-
await listen(server,
|
|
131
|
+
await listen(server, bindPath);
|
|
132
|
+
await rename(bindPath, options.socketPath);
|
|
124
133
|
idleTimer = setTimeout(closeWhenIdle, options.idleMs ?? IDLE_MS);
|
|
125
|
-
return { closed, close };
|
|
134
|
+
return { closed, close, lock: held };
|
|
126
135
|
}
|
|
127
136
|
export async function serve(root) {
|
|
128
137
|
const paths = workerPaths(root);
|
|
@@ -140,8 +149,10 @@ export async function serve(root) {
|
|
|
140
149
|
const end = (signal) => {
|
|
141
150
|
process.off('SIGTERM', onTerminate);
|
|
142
151
|
process.off('SIGINT', onInterrupt);
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
if (worker.lock.owns()) {
|
|
153
|
+
rmSync(paths.socketPath, { force: true });
|
|
154
|
+
rmSync(paths.lockPath, { force: true });
|
|
155
|
+
}
|
|
145
156
|
stopChildren(signal);
|
|
146
157
|
};
|
|
147
158
|
const onTerminate = () => end('SIGTERM');
|
package/dist/state.mjs
CHANGED
|
@@ -56,6 +56,7 @@ function isState(value) {
|
|
|
56
56
|
typeof value.ciFixes === 'number' &&
|
|
57
57
|
isOptional(value.commitFixes, 'number') &&
|
|
58
58
|
(value.landed === undefined || isLanded(value.landed)) &&
|
|
59
|
+
isOptional(value.pushing, 'string') &&
|
|
59
60
|
isOptional(value.rerun, 'string') &&
|
|
60
61
|
typeof value.reviewRounds === 'number' &&
|
|
61
62
|
Array.isArray(value.reviewLog) &&
|
package/dist/worker-server.mjs
CHANGED
|
@@ -56,14 +56,16 @@ export function listen(server, path) {
|
|
|
56
56
|
function whenClosed(close) {
|
|
57
57
|
return new Promise((resolve) => close(() => resolve()));
|
|
58
58
|
}
|
|
59
|
-
export async function shutdown(server, sockets, paths) {
|
|
59
|
+
export async function shutdown(server, sockets, paths, held) {
|
|
60
60
|
for (const socket of sockets.clients) {
|
|
61
61
|
socket.terminate();
|
|
62
62
|
}
|
|
63
63
|
await whenClosed((done) => sockets.close(done));
|
|
64
64
|
await whenClosed((done) => server.close(done));
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (held.owns()) {
|
|
66
|
+
await rm(paths.socketPath, { force: true });
|
|
67
|
+
await rm(paths.lockPath, { force: true });
|
|
68
|
+
}
|
|
67
69
|
}
|
|
68
70
|
export function closer(stop) {
|
|
69
71
|
let finish = () => undefined;
|