next-issue 12.0.0 → 12.0.1
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 +2 -2
- package/dist/loop.mjs +69 -36
- package/dist/worker-run.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Only one worker goes at a time in a repository. It holds the lock `.next-issue/w
|
|
|
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
|
|
|
43
|
-
A run works on up to `concurrency` issues with an agent at the same time, 1 by default. Each claimed issue takes a slot. An approved issue frees its slot while it waits to land, while it lands and while it waits for the checks on the base, so the next issue's agents never wait for CI. When such an issue needs an agent again, for example the fixer for a conflict or for failed checks, it waits for a free slot, takes it before any new issue is claimed and frees it once the agent ends. So no more than `concurrency` agents run at once. When a slot frees up, the run claims the oldest unseen issue for it, and fetches the open issues again only when the last fetch left an unseen issue unclaimed or an issue has ended since. The run ends only once every issue has ended, including those waiting to land. Each issue has its own worktree and branch. Step 3 below and the removal of a worktree or branch run for one issue at a time, so two issues never change the git refs or worktrees of the repository at once. An issue skipped as blocked is tried again in that run once another issue is done, so an issue blocked by one that waits to land is claimed once its blocker closes. For each issue:
|
|
43
|
+
A run works on up to `concurrency` issues with an agent at the same time, 1 by default. Each claimed issue takes a slot. An approved issue frees its slot while it waits to land, while it lands and while it waits for the checks on the base, so the next issue's agents never wait for CI. When such an issue needs an agent again, for example the fixer for a conflict or for failed checks, it waits for a free slot, takes it before any new issue is claimed and frees it once the agent ends. So no more than `concurrency` agents run at once. When a slot frees up, the run claims the oldest unseen issue for it, and fetches the open issues again only when the last fetch left an unseen issue unclaimed or an issue has ended since. When an issue ends while every slot is taken, the run still reads the open issues again, so the open-issue count stays current, but claims nothing until a slot frees up. The run ends only once every issue has ended, including those waiting to land. Each issue has its own worktree and branch. Step 3 below and the removal of a worktree or branch run for one issue at a time, so two issues never change the git refs or worktrees of the repository at once. An issue skipped as blocked is tried again in that run once another issue is done, so an issue blocked by one that waits to land is claimed once its blocker closes. For each issue:
|
|
44
44
|
|
|
45
45
|
1. Claim the issue only when it holds the `status:todo` label and holds no `status:in-progress` or `status:in-review` label. A `status:done`, `status:needs-human` or `status:blocked` label always stops the claim, a resume too, except a `status:needs-human` issue with an answer to its hand-over that the run made, and except an issue whose finish a stop cut short and that was not handed over (see step 7 below). An issue that GitHub lists as blocked by an open issue waits, because its blocker closes only when the change of the blocker lands. An issue with saved state under `.next-issue/` resumes instead, whatever its other labels and blockers.
|
|
46
46
|
2. Add `status:in-progress` to the issue.
|
|
@@ -366,7 +366,7 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
|
|
|
366
366
|
- stops a run when a client sends `{ "type": "stop", "root": "<path>", "after": "issue" | "round" | "now" }`. With no `after`, it stops after `issue`. `issue` works like a first `Ctrl-C`: no new claim or hunt, and the held issues and a going hunt finish. `round` works like a second `Ctrl-C`: each running issue stops after its current round, with the state kept, and a going hunt ends first. `now` stops every agent, command and hunt of the run at once, and each running issue ends as `stopped` with its state and labels kept; the worker keeps running. A later point than one already asked for changes nothing, and an earlier one replaces it. An unknown `after` gets an `error` message. While a run is going, the client that sent the stop gets `{ "type": "stopping", "root": "<path>", "waiting": <bool>, "hunting": <bool> }`, with the `id` of the stop when it has one: `waiting` is `true` when the run waited between passes, and `hunting` is `true` when a hunt was going then. `next-issue start` picks its note from it;
|
|
367
367
|
- switches watching of a run on or off when a client sends `{ "type": "watch", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. A run starts with watching on, unless it was started with `--watch off`. On keeps the run going after the current pass, as with `--watch on`. Off ends the run after the current pass, or at once when it waits between passes, and also turns hunting off. With no run going, the message gets an `error` and starts nothing;
|
|
368
368
|
- switches hunting of a run on or off when a client sends `{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. Every run of the worker has a hunter: a run started with `--hunt on` starts with hunting on, and any other run with it off. Off lets a hunt that is going finish, so the issues it files stay, and starts no new hunt. On wakes the hunter at once, with no back-off wait, and also turns watching on. With no run going, the message gets an `error` and starts nothing. The settings last for the run only: a new run takes them from its own flags. The progress of each run carries `hunting`, `true` while hunting is on, and `watching`, `true` when the run watches for issues;
|
|
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.
|
|
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. While a pass runs, the run reads the open issues again, so its open-issue count is current, and claims a new issue only when a slot is free. A refresh 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
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;
|
package/dist/loop.mjs
CHANGED
|
@@ -8,50 +8,83 @@ export async function runIssues(loop, seen = new Set()) {
|
|
|
8
8
|
let crash;
|
|
9
9
|
let claiming = true;
|
|
10
10
|
let unclaimed = true;
|
|
11
|
+
let recount = false;
|
|
12
|
+
const ended = new AbortController();
|
|
13
|
+
let refresh = refreshes(loop, ended.signal);
|
|
11
14
|
const tried = { ended: new Set(), labels: new Map(), blocked: new Set() };
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
try {
|
|
16
|
+
for (;;) {
|
|
17
|
+
if (claiming && (recount || (unclaimed && slots.open()))) {
|
|
18
|
+
recount = false;
|
|
19
|
+
refresh = refreshes(loop, ended.signal, refresh);
|
|
20
|
+
try {
|
|
21
|
+
({ claiming, unclaimed } = await claimIssues(loop, seen, tried, { running, slots }));
|
|
22
|
+
}
|
|
23
|
+
catch (failure) {
|
|
24
|
+
error = failure;
|
|
25
|
+
claiming = false;
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
if (running.size === 0) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const settled = await Promise.race([...running.values(), slots.freed(), refresh.asked]);
|
|
32
|
+
if (settled === 'refresh') {
|
|
33
|
+
recount = true;
|
|
34
|
+
refresh = refreshes(loop, ended.signal, refresh);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (settled === undefined) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const { issue, slot, report, failure } = settled;
|
|
41
|
+
running.delete(issue);
|
|
42
|
+
slot.free();
|
|
43
|
+
unclaimed = true;
|
|
44
|
+
recount = true;
|
|
45
|
+
if (report === undefined) {
|
|
46
|
+
crash ??= { failure };
|
|
47
|
+
claiming = false;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
reports.push(report);
|
|
51
|
+
if (retryable(report)) {
|
|
52
|
+
tried.ended.add(issue);
|
|
53
|
+
}
|
|
54
|
+
if (report.blocked === true) {
|
|
55
|
+
tried.blocked.add(issue);
|
|
56
|
+
}
|
|
57
|
+
if (report.outcome === 'done') {
|
|
58
|
+
readmitBlocked(seen, tried);
|
|
59
|
+
}
|
|
60
|
+
if (claiming && (loop.stop() || report.halt === true)) {
|
|
61
|
+
stoppedAt = issue;
|
|
19
62
|
claiming = false;
|
|
20
63
|
}
|
|
21
64
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const settled = await Promise.race([...running.values(), slots.freed()]);
|
|
26
|
-
if (settled === undefined) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const { issue, slot, report, failure } = settled;
|
|
30
|
-
running.delete(issue);
|
|
31
|
-
slot.free();
|
|
32
|
-
unclaimed = true;
|
|
33
|
-
if (report === undefined) {
|
|
34
|
-
crash ??= { failure };
|
|
35
|
-
claiming = false;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
reports.push(report);
|
|
39
|
-
if (retryable(report)) {
|
|
40
|
-
tried.ended.add(issue);
|
|
41
|
-
}
|
|
42
|
-
if (report.blocked === true) {
|
|
43
|
-
tried.blocked.add(issue);
|
|
44
|
-
}
|
|
45
|
-
if (report.outcome === 'done') {
|
|
46
|
-
readmitBlocked(seen, tried);
|
|
47
|
-
}
|
|
48
|
-
if (claiming && (loop.stop() || report.halt === true)) {
|
|
49
|
-
stoppedAt = issue;
|
|
50
|
-
claiming = false;
|
|
51
|
-
}
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
ended.abort();
|
|
52
68
|
}
|
|
53
69
|
return loopResult(reports, stoppedAt, error, crash);
|
|
54
70
|
}
|
|
71
|
+
function refreshes(loop, ended, previous) {
|
|
72
|
+
const signal = loop.refreshed?.();
|
|
73
|
+
if (previous !== undefined && previous.signal === signal) {
|
|
74
|
+
return previous;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
signal,
|
|
78
|
+
asked: new Promise((resolve) => {
|
|
79
|
+
if (signal?.aborted === true) {
|
|
80
|
+
resolve('refresh');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
signal?.addEventListener('abort', () => resolve('refresh'), { once: true, signal: ended });
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
55
88
|
function loopResult(reports, stoppedAt, error, crash) {
|
|
56
89
|
return {
|
|
57
90
|
reports,
|
package/dist/worker-run.mjs
CHANGED
|
@@ -86,7 +86,7 @@ export function dropUpgrade(run) {
|
|
|
86
86
|
export function switchRefusal(run) {
|
|
87
87
|
return active(run) ? undefined : 'no run is going in this repository';
|
|
88
88
|
}
|
|
89
|
-
// Only a running watch run refreshes
|
|
89
|
+
// Only a running watch run refreshes: it wakes the wait between passes, or reads the open issues again during a pass.
|
|
90
90
|
export function requestRefresh(run) {
|
|
91
91
|
if (run?.progress.status !== 'running' || !run.watching.on() || run.stop !== undefined) {
|
|
92
92
|
return false;
|