next-issue 12.0.0 → 12.0.2
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 +4 -4
- package/dist/implement.mjs +8 -2
- package/dist/loop.mjs +69 -36
- package/dist/worker-run.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,12 +40,12 @@ 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.
|
|
47
47
|
3. Fetch the remote, fast-forward the local copy of the default branch when that is safe, then add a git worktree at `.worktrees/<n>` in the repository root on the `<n>` branch. An issue that resumes from saved state keeps the branch name that the state holds, and a worktree that holds that branch already stays in use. A branch that exists on the remote is the start, and a local branch that fell behind the remote is fast-forwarded; a local branch that cannot be fast-forwarded stays as it is and the harness writes a `branch.behind` event. The fetch prunes remote branches, so a remote branch that was deleted does not count. A local branch that the remote does not hold and that has no commits of its own starts again from the remote base. An issue with no saved state does not reuse a local `<n>` branch: it resets that branch, and any worktree that holds it, to the remote branch, or to the remote base when there is none. A worktree at `.worktrees/<n>` left on a detached HEAD, for example by a crash, is removed, but its uncommitted files are first committed on a `<n>-detached-<sha>` branch, so they are kept. The main worktree of the repository is never used, reset or cleaned: when it has the branch of the issue checked out, the issue fails and is handed over, and the reason asks you to check out another branch there. A fast-forward of the base that is not safe leaves the local base branch as it is and writes a `base.behind` event. A new branch then starts from the remote base.
|
|
48
|
-
4. Let the implementer agent do the work, then commit it. For a behaviour change, the implementer writes the test first and quotes its failing output in its reply. The harness keeps that reply in the state file for the reviewer. The branch is not pushed. When a git hook stops a commit, the agent that made the change gets the hook output, fixes it, and the harness commits again. A `commit:` line in the reply of the agent replaces the subject, so a hook that rejects the subject can pass. The harness drops each GitHub closing keyword (`close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, `resolve`, `resolves`, `resolved`) that names an issue from the subject, so a push to the base never closes an issue: the issue closes only after its checks pass. The budget is `maxCommitFixes`. Any other git failure in the commit stops the run with an error. An implementer that makes no change hands the issue to a person, unless the branch is already ahead of the base, for example when an issue resumes from saved state in phase `claimed`, or when the remote holds branch `<n>`: the run then carries on with the commits on the branch, and the newest of them gives the subject of the landed commit. A lost state file does not count, since an issue with no saved state resets its local branch (step 3). When the base already does all that the issue asks, the implementer makes no change and ends its reply with a `done: <evidence>` line. If the branch is not ahead of the base, a reviewer then checks that claim against the base. The harness puts the branch back after this reviewer as it does after the reviewer of step 5, also when it times out, fails or the run stops. When it raises no blocking finding, the harness comments `### next-issue · Worker: already done` with the evidence and the summary of the reviewer, adds `status:done` and closes the issue as completed, and the issue ends as `done`. Otherwise it hands the issue to a person with the reason `already done disputed`, and the comment holds the evidence and the findings of the reviewer. A reply with a `question:` line asks the questions instead. To close a parent issue once its sub-issues land, mark it as blocked by each sub-issue and give it the `status:todo` label: it waits while a sub-issue is open (step 1), then the implementer finds it already done and the harness closes it. The implementer checks the issue first. When the scope, the expected behaviour or the acceptance criteria are ambiguous, it makes no change and asks instead of guessing, with each question on its own `question: <n>. <question>` line, its options labelled by letters and one option recommended. A reply with at least one `question:` line makes the harness drop any change in the worktree, commit nothing and hand the issue to a person with the reason `questions`. The hand-over comment lists the questions in order, numbered by the harness. The harness reads the issue again and adds the questions after any text under its `Open questions` heading, or adds that heading at the end of the body when it has none. When that read or body edit fails, the harness records a `questions.body-failed` event in the run log and still hands the issue over with the questions in the comment. It also keeps the questions in the state of the issue, so the implementer of the run that resumes the issue finds them next to the answer of a person, not in the issue body.
|
|
48
|
+
4. Let the implementer agent do the work, then commit it. For a behaviour change, the implementer writes the test first and quotes its failing output in its reply. The harness keeps that reply in the state file for the reviewer. The branch is not pushed. When a git hook stops a commit, the agent that made the change gets the hook output, fixes it, and the harness commits again. A `commit:` line in the reply of the agent replaces the subject, so a hook that rejects the subject can pass. The harness drops each GitHub closing keyword (`close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, `resolve`, `resolves`, `resolved`) that names an issue from the subject, so a push to the base never closes an issue: the issue closes only after its checks pass. The budget is `maxCommitFixes`. Any other git failure in the commit stops the run with an error. An implementer that makes no change hands the issue to a person, unless the branch is already ahead of the base, for example when an issue resumes from saved state in phase `claimed`, or when the remote holds branch `<n>`: the run then carries on with the commits on the branch, and the newest of them gives the subject of the landed commit. A lost state file does not count, since an issue with no saved state resets its local branch (step 3). When the base already does all that the issue asks, the implementer makes no change and ends its reply with a `done: <evidence>` line. If the branch is not ahead of the base, a reviewer then checks that claim against the base. The harness puts the branch back after this reviewer as it does after the reviewer of step 5, also when it times out, fails or the run stops. When it raises no blocking finding, the harness comments `### next-issue · Worker: already done` with the evidence and the summary of the reviewer, adds `status:done` and closes the issue as completed, and the issue ends as `done`. Otherwise it hands the issue to a person with the reason `already done disputed`, and the comment holds the evidence and the findings of the reviewer. A reply with a `question:` line asks the questions instead. To close a parent issue once its sub-issues land, mark it as blocked by each sub-issue and give it the `status:todo` label: it waits while a sub-issue is open (step 1), then the implementer finds it already done and the harness closes it. The implementer checks the issue first. When the scope, the expected behaviour or the acceptance criteria are ambiguous, it makes no change and asks instead of guessing, with each question on its own `question: <n>. <question>` line, its options labelled by letters and one option recommended. A reply with at least one `question:` line makes the harness drop any change in the worktree, commit nothing and hand the issue to a person with the reason `questions`. The hand-over comment lists the questions in order, numbered by the harness. The harness reads the issue again and adds the questions after any text under its `Open questions` heading, or adds that heading at the end of the body when it has none. When that read or body edit fails, the harness records a `questions.body-failed` event in the run log and still hands the issue over with the questions in the comment. When a person without write access last changed the body, the harness leaves the body as it is, records a `questions.body-untrusted` event and does the same (see [Safety](#safety)). It also keeps the questions in the state of the issue, so the implementer of the run that resumes the issue finds them next to the answer of a person, not in the issue body.
|
|
49
49
|
5. Let the reviewer agent judge the diff, at most `diffMaxChars` of it. The reviewer reads files and runs commands in the worktree, so it can prove a finding with the tests or the type check. The harness then throws away every change that the reviewer left in the worktree, so no such change can reach a later commit. When the reviewer left another branch or a detached `HEAD` checked out, the harness checks out the issue branch again at its commit from before the review. It does the same when the reviewer times out or fails. The state file keeps that commit while the reviewer runs, so when the run stops during the review, the next run that resumes the issue first puts the issue branch back at that commit, before the setup command, and the diff it reads holds no reviewer commit. A commit that a person adds to the branch after a hand-over stays on it. The first reviewer also gets the reply of the implementer, and raises a finding when a behaviour change has no failing run of its test. A later reviewer gets the reply of the last review fixer instead, who quotes the failing run of a test for a behaviour change. The reviewer ends its last message with its verdict as a json block: a summary and one entry per finding, each rated `blocking` or `minor`. A reply without a valid block hands the issue to a person. The findings are the only ground truth. The reviewer gives no approve or reject field, because such a field can contradict the findings. The harness puts the result on the issue. A result longer than a GitHub comment (65536 characters) is cut to fit, with a last line that says so.
|
|
50
50
|
6. An open finding is any finding, blocking or minor, while a review round is left. In the last round, only a blocking finding stays open: a minor finding there goes on the issue but starts no fix, because a fix in the last round gets no review. Thus `maxReviewRounds` of `1` never fixes a minor finding.
|
|
51
51
|
7. No open finding means approval: the change lands on the base branch. Approved changes land one at a time, so the next one waits, without a slot, until the checks of the last one end, and other issues go on meanwhile. The harness fetches the remote base, merges it into the branch and makes the change one commit on top of it, with the subject of the implementer's commit. A review fix keeps that subject, but a commit fix for the implementer's commit replaces it, and a fix for failed checks after the landing lands under the fixer's own subject. The reapply commit after a revert uses the subject of the change. When git merges the base cleanly, no agent runs. When a conflicted file holds no conflict marker, for example a file that one side deletes and the other changes, a renamed file or a binary file that both sides change, no agent runs: the harness undoes the merge and hands the issue to a person with the reason `merge conflict`, since git leaves only one side in the file. When git reports conflicted files, the fixer gets the list from the check budget, `maxCiFixes`, removes the conflict markers, and the harness commits the merge. A merge that the fixer commits itself counts only when the branch then holds the base commit that was merged and the listed files hold no conflict marker. With the budget used up, or when the fixer leaves a conflict marker or the merge unresolved, aborts the merge, or fails, the harness undoes the merge and hands the issue to a person with the reason `merge conflict`. When `checks` lists commands, the harness then runs the setup command again in the worktree, so the checks use the dependencies of the merged base. It runs the setup after it makes the change one commit, and commits what the setup writes, unless git ignores it, on top of that commit without hooks. Every check runs on that setup commit. After the checks, the harness puts the branch back at the change commit, so what this setup writes does not land on the base; after a stop or kill during the checks, the next run puts the branch back first. What the first setup writes, before the implementer, is part of the implementer's commit and lands. When this setup rewrites such a file, for example a lock file, the checks run on the rewritten file, but the base gets the file of the change. A change that the base already holds is an `empty change` before the setup runs. A setup that fails or does not finish in `setupTimeoutMinutes` keeps the merged commit, stops the landing before the push and hands the issue to a person with the reason `setup failed` or `setup timeout`. The harness then runs each command in `checks` in the worktree, in order, with `bash -c` and stderr merged into stdout, each for at most `checksTimeoutMinutes`. Their output goes to the run log (`check.output`, and `check.fail` for a failure). After each command, the harness resets the worktree to the commit it checked and removes untracked files that git does not ignore, so a file that a command writes never lands on the base. A command that fails or does not finish stops the landing before the push: the fixer gets the command and the tail of its output (at most `logMaxChars`) from the check budget, `maxCiFixes`, and its fix is squashed into the change, which keeps its subject. The harness then merges the base again and runs every command again, so nothing lands until all pass. When the budget runs out, the harness hands the issue to a person with the reason `local checks failed: <command>` and the tail of the output in the comment; a fixer that adds no commit or calls the failure unrelated hands it over too, as for the checks on the base. Nothing of the change reaches the base. A run that stops while a command runs keeps the budget, and the next run merges and runs every command again before any push. The state file keeps the merged commit from the squash until the push, so the next run that resumes the issue first puts the issue branch back at that commit, before the setup command. A commit that a person adds to the branch after a hand-over stays on it. The harness then pushes the commit to the base branch, without force. When the push fails, the harness fetches the base first, and treats the push as landed when the base holds the commit, for example after a timeout. When the base moved, for example because someone else pushed first, the harness starts the rebase again, three times at most. When the base did not move, for example on a missing permission or a branch protection rule, the harness hands the issue to a person at once with the reason `push failed`, without running the checks again. Each `push failed` comment holds the tail of the last error of git. When that fetch fails too, the harness hands the issue to a person with the reason `push unknown` and halts, even when the hand-over fails. The state file holds the commit during the push, so a run stopped meanwhile, or the resume after that hand-over (once a person answers or takes the label off), checks the base and waits for the checks of the commit when it landed. Until then, no run lands another change (see below). Once the commit lands, the harness fetches the remote and fast-forwards the local base branch to it when that is safe. A fetch that fails or a fast-forward that is not safe leaves the local base branch as it is and writes a `base.behind` event, and the landing goes on. The harness then waits for the checks of the pushed commit on the base branch: the GitHub Actions workflow runs that a `push` of the base branch started on it, its commit statuses and the check runs of every other GitHub App, so checks from another CI service count too. It leaves out the check runs of the GitHub Actions app, since it judges GitHub Actions by its workflow runs. It leaves out workflow runs that any other event (such as `issues`, `issue_comment` or `schedule`) started, since GitHub gives such a run the tip of the default branch as its commit. It also leaves out the `push` runs that a push of a tag or of another branch started on the same commit, such as a release or a deploy. It leaves out every GitHub Actions job, check run and commit status whose name is in `ignoredChecks`: it does not wait for it, its result does not fail the checks and its logs do not go to the fixer. With `ignoredChecks` set, the harness judges each workflow run by its other jobs, so a run whose only failed job is ignored passes when every other job passes. A run that GitHub concludes `success` passes as it is, so a failed job with `continue-on-error: true` does not fail the checks. When an ignored job fails and GitHub cancels another job of the same run, for example through the default `strategy.fail-fast` of a matrix, that job never finished: the harness hands the issue to a person with the reason `main checks cut short` and halts, and the issue stays open. Set `fail-fast: false` on a matrix with an ignored job to avoid this. The same goes when an ignored job fails and another job of the same run ends `skipped`, for example because it `needs` the ignored job; a skipped job in a run with no failed job still passes. A failed or errored commit status, or a workflow run or check run that ends with `failure`, `timed_out` or `action_required`, fails the checks. The harness does not rerun a workflow run that ends `action_required`, since it waits for a person to approve it. When any check ends `cancelled`, for example because a later push cancelled the workflow run, that check never finished, even when another check (such as a release workflow) ends `success`: the harness hands the issue to a person with the reason `main checks cancelled` and halts, and the issue stays open. A repository that reports no check keeps asking for `checkGraceSeconds`. When every check passes, the harness keeps asking until `checkGraceSeconds` have gone by since it first read the checks, since GitHub can add a check a few seconds after the others; a check that shows up in that time counts, and one that shows up later does not. A pending state waits again, up to `checkTimeoutMinutes`. A read that fails is tried three times. When the first read of the checks of a landed change still fails, for example on a rate limit or an expired token, the harness hands the issue to a person with the reason `checks error` and halts, before the next change lands. The comment holds the error and says that the landed commit is on the base and its checks were not awaited. The state file keeps the commit, so the resume after a person answers or takes the label off waits for its checks, and until then no run lands another change (see below). When the checks pass, the harness marks the state file as closing, sets `status:done` and closes the issue. When a run stops or dies before the close, the next run sees the mark, sets `status:done` and closes the issue, with no new push, revert or hand-over. A hand-over clears the mark, so an issue taken back after a failed label edit or close is resumed, not closed, by later runs. When a run stops or dies after the close, before the state file goes away, the next run finds the closed issue through its state file and removes the worktree, the local branches and the state file, with no new push, revert, label, close or hand-over. A label or close that fails for another reason hands the issue over, and it then waits for a person like any other hand-over. Then the worktree, the local branch and the state file go away. When the checks fail, the harness reruns the failed jobs of each failed GitHub Actions workflow run once with `gh run rerun <id> --failed`, records a `ci-checks.rerun` event and waits again once the runs restart. A failed run whose failed jobs were already rerun (its attempt on GitHub is above 1) is not rerun again, so a resumed run reruns only the runs not rerun yet. A failure that gets a rerun ends the wait at once; any other failure (a run that was rerun, a run that waits for approval, a check from another CI service) waits until every check has finished, so a workflow run that fails later, even after the first rerun started, still gets its own rerun before any fixer. A workflow run whose kept job failed while a job in `ignoredChecks` still runs gets its rerun only once the whole run has finished on GitHub, as GitHub refuses to rerun a running run. A rerun that GitHub refuses because the run is already running counts as started. When at least one run restarted and a later rerun or read fails, the event carries the error and the harness still waits for the checks again, counting each restarted run as running until a later attempt of it completes, so the fixer never runs while a rerun is queued or in progress. When the rerun cannot start (no run restarted, a `ci-checks.rerun-failed` event), or the checks fail again with no run left to rerun, the fixer gets their logs from the check budget (for a check from another CI service, only its name and link), and its fix lands the same way. When the fixer cannot fix them, its fix cannot land, an error stops the fix, or the budget runs out, the harness reverts every commit of the change on the base branch, pushes the revert and hands the issue to a person. When the push of the fix ends as `push unknown`, the harness does not revert: it hands the issue over and halts as for any other `push unknown`. A revert push that the remote refuses, for example because the base moved, makes the revert again on the new base, three times at most. A failed revert push that the base holds after a fetch counts as landed. Once the revert lands, the harness fast-forwards the local base branch to it, as after a landed commit. When that fetch fails too, the revert may be on the base with checks nobody awaited: the harness reports it so, saves the halt and blocks later landings. The state file holds the revert commit during the push, so a run stopped meanwhile checks the base on resume. When the base holds the revert, the harness puts the change back on the branch on top of the revert, as after a revert that completes (an unlanded fix commit is dropped), drops the landed commits from the state, waits for no checks, does not revert again, hands the issue to a person with the reason `revert stopped` and halts. A resume that stopped while the checks of a landed commit ran waits for them again, even when more commits landed on the base since, and a fix that was committed but not landed lands first. Before that, the resume drops any change left in the worktree, including a merge of the base that a stopped fix landing left in progress, so the fix merges the current base again from the start. A problem that the reviewer leaves out of the findings thus gets an approval: only the findings count.
|
|
@@ -123,7 +123,7 @@ The harness runs all git and `gh` commands itself. The commit holds all the chan
|
|
|
123
123
|
|
|
124
124
|
Every agent can run a shell command. The implementer and the fixer run with the permission checks off; the reviewer runs with a smaller tool set, but its shell has no limit on the commands. They all start in the worktree, but nothing holds them there: they can run any command, with your rights, anywhere on the machine. The prompt holds the title and the body of the issue, which come from GitHub. It also holds the comments of the issue, but only those by users with write or admin access to the repository. The harness leaves out every other comment and writes a `comment.skip` event with its author to the run log. If an access check fails for a reason other than a 404, the issue stops with an error.
|
|
125
125
|
|
|
126
|
-
After the setup, and before any agent runs, the harness finds the last person to change the body (the author when nobody edited it) and the last person to change the title (the author when nobody renamed it). When either has no write or admin access, no agent gets the issue: the harness hands it to a person with the reason `untrusted editor`, and the comment names each such person. The agent gets the title and body read in the same query as their editors, so an edit made after the harness listed the issue is never sent unchecked. A writer who checks the text and then changes the named title or body makes the issue go on after the answer. This matters most on a public repository: anyone can open an issue there, and its author can edit the body after a maintainer adds the ready label, before the harness claims it. An issue opened by a person without write access thus always waits for a writer to change it.
|
|
126
|
+
After the setup, and before any agent runs, the harness finds the last person to change the body (the author when nobody edited it) and the last person to change the title (the author when nobody renamed it). When either has no write or admin access, no agent gets the issue: the harness hands it to a person with the reason `untrusted editor`, and the comment names each such person. The agent gets the title and body read in the same query as their editors, so an edit made after the harness listed the issue is never sent unchecked. A writer who checks the text and then changes the named title or body makes the issue go on after the answer. This matters most on a public repository: anyone can open an issue there, and its author can edit the body after a maintainer adds the ready label, before the harness claims it. An issue opened by a person without write access thus always waits for a writer to change it. When the implementer asks questions, the harness writes them into the body only when a writer last changed it; otherwise the body edit would make the harness its last editor and pass the unchecked text. It hands the issue over with the questions in the comment instead, and the run that resumes it after the answer hands it over again with the reason `untrusted editor`.
|
|
127
127
|
|
|
128
128
|
The prompt puts the body of the issue, check logs, hook output, the diff and the replies of other agents inside `untrusted` fences, each longer than any backtick run in its text, and tells the agent to treat that text as data, not instructions. The comments of writers, and a writer's answer to a hand-over, stay outside the fences.
|
|
129
129
|
|
|
@@ -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/implement.mjs
CHANGED
|
@@ -36,8 +36,14 @@ async function askQuestions(job, before, questions) {
|
|
|
36
36
|
const { repo, ports } = context;
|
|
37
37
|
await ports.discardChanges(worktree, before, branch);
|
|
38
38
|
try {
|
|
39
|
-
const fresh = await ports.
|
|
40
|
-
await ports.
|
|
39
|
+
const fresh = await ports.issueEditors(repo, issue.number);
|
|
40
|
+
if (await ports.canWrite(repo, fresh.editors.body)) {
|
|
41
|
+
await ports.editIssueBody(repo, issue.number, withOpenQuestions(fresh.body, questions));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
log.event('questions.body-untrusted', { editor: fresh.editors.body });
|
|
45
|
+
state.unpostedQuestions = questions;
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
catch (error) {
|
|
43
49
|
log.event('questions.body-failed', { error: message(error) });
|
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;
|