@jesdi/skills 0.0.52 → 0.0.54

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jesdi/skills",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,7 +19,7 @@ A comment in the code is for a line that looks wrong or removable without it.
19
19
  | `driver_report.py` | Validation of one agent report against its schema, git and the agent's log |
20
20
  | `driver_review.py` | The locked-file check of a ticket's own tests, the routing of findings, mutation proofs |
21
21
  | `driver_merge.py` | Merges by git plumbing, the locked-file check of a landing, the move of the PR ref |
22
- | `driver_gate.py` | One run of the gate command and its record |
22
+ | `driver_gate.py` | One gate of a commit: the command, once more when a signal ended it, and its record |
23
23
  | `driver_slots.py` | The worktrees that tickets run in, and the `git` helper |
24
24
  | `driver_state.py` | `state.json` (the resume contract) and the kernel lock |
25
25
  | `driver_names.py` | The names of one run: its ticket branches, its recovery ref and its lock file |
@@ -138,6 +138,10 @@ and do not know about the run, except `driver_run.py`, which the three deciding
138
138
  - No test-writer correction runs after round 4 (`driver_fixloop._act_on`): its findings become `finding` questions
139
139
  with the others. A correction there would add red locked tests that no fix round makes green, and `accept` could
140
140
  not merge the ticket.
141
+ - A correction that does not close its findings (the next review finds one again, or the driver rejects its
142
+ report) asks a `locked-test-again` question. `correct-again` and `accept` send the ticket back to `review`, and
143
+ `driver_decisions.corrections` reads the answers from `state.json`: the count of `correct-again` stops bounds the
144
+ extra corrections (`AGAIN`), and an `accept` stop closes the ticket's locked-test findings in `_act_on`.
141
145
 
142
146
  ### Questions
143
147
 
@@ -57,7 +57,7 @@ Default timeouts in minutes: explorer 30, test-writer 30, implementer 90, review
57
57
  |---|---|
58
58
  | 0 | Done: every ticket is merged and no question is open. Also the end of a valid `--dry-run`. In local mode without `--push`, nothing is pushed. |
59
59
  | 1 | A ticket is BLOCKED, or the end of run is BLOCKED. The other tickets ran as far as they could. |
60
- | 2 | Parked: a question of kind `locked-test` or `final-finding` is open. Exit 2 wins over exit 1. |
60
+ | 2 | Parked: a question of kind `locked-test`, `locked-test-again` or `final-finding` is open. Exit 2 wins over exit 1. |
61
61
  | 3 | Invalid input or a failed precondition: a usage error, a ticket error, a model error, an uncommitted change, a slot that cannot be made, another driver that runs on the same PR branch. No agent starts. The one exception: a review page that cannot be written gives exit 3 at the end of a run, after agents ran. |
62
62
  | 4 | Stopped: the CLI of an agent failed two times and wrote no report (for example, the account cannot use the model). The driver starts no other agent and lets the running agents end. No ticket is BLOCKED by it: fix the CLI or the model entry, then run the same command again to resume. |
63
63
  | 130 | The operator interrupted the run. The driver stops each agent. The work stays in the slots for the next run. |
@@ -83,7 +83,7 @@ Everything is under `.agent/`, which is never committed.
83
83
  | `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
84
84
  | `.agent/implement/<NN>/` | One folder for each ticket. |
85
85
  | `.agent/implement/<NN>/<role>-<K>.json`, `.log`, `.prompt.md` | The report, the log and the prompt of one agent. K is the fix round. |
86
- | `.agent/implement/<NN>/gate-<sha7>.log` | One gate record: start, commit, status, command, output, exit, the state after the command, end. |
86
+ | `.agent/implement/<NN>/gate-<sha7>.log` | One gate record: start, commit, status, command, output, exit, the state after the command, end. A command that a signal ended, with the tree clean and HEAD unmoved, did not judge the commit: the driver runs it once more, that run overwrites the record, and the ledger says the gate was killed by the signal and runs again. A signal ended the command when its exit is negative, or when it is 128+N for N in SIGHUP (1), SIGINT (2), SIGKILL (9) or SIGTERM (15): the gate runs in `/bin/sh -c`, and a shell that does not exec the command, as Ubuntu's dash does not, outlives its killed child and exits with 128+N. Any other exit, 142 (128+SIGALRM) among them, is a red record with no second run. A second signal leaves the record red. |
87
87
  | `.agent/implement/<NN>/findings-<K>.json` | The merged findings of the review after fix round K, or the red gate of round K. |
88
88
  | `.agent/implement/final/` | The same files for the end of run, and `pr-body.md`: the pr-writer's body, then the facts of the run. |
89
89
  | `.agent/implement/pycache/` | Compiled Python of the gate, kept out of the slots. |
@@ -109,6 +109,7 @@ A ticket is ready when each ticket in its **Blocked by** line is merged and no r
109
109
  Rules for each agent:
110
110
 
111
111
  - A call blocks until the agent ends. The driver does not poll.
112
+ - An agent stops only the processes it started and their child processes, by PID, and never kills a process it did not start, nor uses `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. A process it did not start that blocks it goes into its concerns.
112
113
  - An agent gets one rerun: after a rejected report, after a timeout, or after it left the ticket branch. The rerun prompt is the first prompt plus the reason.
113
114
  - A report with status `BLOCKED` or `NEEDS_CONTEXT` blocks the ticket.
114
115
  - A BLOCKED ticket stops the tickets that it blocks. All other tickets run on.
@@ -117,7 +118,7 @@ Rules for each agent:
117
118
 
118
119
  | Finding | What the driver does |
119
120
  |---|---|
120
- | kind `fixture`, any severity, or kind `test`, `critical` or `important`, on a locked file of the ticket | One test-writer correction, outside the fix rounds. The fixer may not edit a locked file, so a fix round cannot close a `test` finding there. The corrected files are the new locked versions, and the next review is a full review. A finding that the correction reports in `not_addressed` (it needs a production change first) becomes a finding of kind `code`, with the reason as its evidence, and goes to a fix round at once; the ledger says it was not corrected. A finding of this kind that is open after the correction blocks the ticket. No correction runs after round 4. |
121
+ | kind `fixture`, any severity, or kind `test`, `critical` or `important`, on a locked file of the ticket | One test-writer correction, outside the fix rounds. The fixer may not edit a locked file, so a fix round cannot close a `test` finding there. The corrected files are the new locked versions, and the next review is a full review. A finding that the correction reports in `not_addressed` (it needs a production change first) becomes a finding of kind `code`, with the reason as its evidence, and goes to a fix round at once; the ledger says it was not corrected. A finding of this kind that is open in the review after the correction, or a correction that the driver rejects, blocks the ticket with a `locked-test-again` question. No correction runs after round 4. |
121
122
  | `critical` or `important` | One fix round. |
122
123
  | `minor` | It stays in the ledger and in the findings file. The final reviewer gets the list. |
123
124
 
@@ -196,6 +197,7 @@ A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` h
196
197
  |---|---|---|---|---|
197
198
  | `locked-test` | `<NN>-locked-test-<n>` | An implementer or a fixer reports BLOCKED with a concern that starts with `locked test contradicts spec:`. | 2 | `overrule-test`: the test-writer corrects the test from that report, then the implementer runs again, and the fix rounds count from 0: the corrected tests are a new contract. `overrule-implementer` (recommended): the implementer runs again. |
198
199
  | `finding` | `<NN>-finding-<n>` | A finding is open after fix round 4. One question for each finding. | 1 | `accept`: close the finding; the ticket merges when each of its findings is accepted. `split` (recommended) and `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. |
200
+ | `locked-test-again` | `<NN>-locked-test-again-<n>` | A finding for a test-writer correction is open in the review right after a correction, or the driver rejects the correction's report (for example, it changes a file that it does not list in `locked`). One question for each finding. | 2 | `correct-again` (recommended): the ticket resumes from the review, and that review's findings get one more correction. `accept`: no more correction runs for the ticket, its locked tests stay as they are, and the ticket goes on to its fix rounds with its other findings; a changed locked file is still restored. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. After two `correct-again` stops on a ticket, its next question offers only `accept` (recommended) and `redesign`, so a test-writer and a reviewer that never agree cannot loop. |
199
201
  | `final-finding` | `final-finding-<n>` | A finding is open after the second round of the final review. | 2 | `fix` (recommended): the finding stays open and nothing is pushed. `accept`: close the finding. |
200
202
 
201
203
  `n` counts the questions of that ticket and kind in the run, so an id is never used twice.
@@ -57,6 +57,24 @@ KINDS = {
57
57
  "redesign": Option(
58
58
  "Keep the ticket BLOCKED. The design changes before more work on it.",
59
59
  "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
60
+ "locked-test-again": Kind(
61
+ True,
62
+ "Ticket {ticket}: a locked-test finding is open after the test-writer correction: {subject}",
63
+ "The test-writer correction did not close this finding on the locked tests: the review after it found it "
64
+ "again, or the driver rejected the correction (the ledger line says which). Ticket {ticket} is BLOCKED and "
65
+ "each ticket that it blocks waits.",
66
+ "correct-again",
67
+ {"correct-again": Option(
68
+ "The test-writer corrects the locked tests once more, from the next review. Then the fix rounds go on.",
69
+ "Ruling: {ticket} locked-test finding goes back to the test-writer for one more correction "
70
+ "(correct-again): {subject}.", {"phase": "review"}),
71
+ "accept": Option(
72
+ "Close the finding as it is: the locked tests stay as they are, and no more correction runs for the "
73
+ "ticket. The ticket goes on to its fix rounds with its other findings.",
74
+ "Ruling: {ticket} locked-test finding closed as it is (accept): {subject}.", {"phase": "review"}),
75
+ "redesign": Option(
76
+ "Keep the ticket BLOCKED. The design changes before more work on it.",
77
+ "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
60
78
  # A final-review question belongs to no ticket: its `ticket` is "".
61
79
  "final-finding": Kind(
62
80
  True,
@@ -72,6 +90,19 @@ KINDS = {
72
90
  }
73
91
 
74
92
 
93
+ AGAIN = 2 # the extra corrections a ticket may get: a test-writer and a reviewer that never agree cannot loop
94
+
95
+
96
+ def corrections(questions: list[dict], ticket: str) -> tuple[int, bool]:
97
+ """(the extra corrections that the `locked-test-again` stops of `ticket` gave, whether one stop accepted its
98
+ findings). A stop with one `correct-again` answer gives one correction; a stop with only `accept` accepts."""
99
+ stops: dict[int, set] = {}
100
+ for q in questions:
101
+ if (q["ticket"], q["kind"]) == (ticket, "locked-test-again") and q["answer"]:
102
+ stops.setdefault(q["stop"], set()).add(q["answer"])
103
+ return sum("correct-again" in answers for answers in stops.values()), {"accept"} in stops.values()
104
+
105
+
75
106
  def contradicted(role: str, report: dict) -> str:
76
107
  """The locked tests that a BLOCKED report of an implementer or a fixer says contradict the spec; "" when it is not
77
108
  that stop."""
@@ -85,9 +116,12 @@ def question(kind: str, ticket: str, subject: str, evidence: list[str], asked: l
85
116
  """A new open question, id `<NN>-<kind>-<n>` (`<kind>-<n>` with no ticket); n counts in `asked`, the whole run."""
86
117
  made, values = KINDS[kind], {"ticket": ticket, "subject": subject}
87
118
  number = 1 + sum((q["ticket"], q["kind"]) == (ticket, kind) for q in asked)
119
+ options, recommended = made.options, made.recommended
120
+ if kind == "locked-test-again" and corrections(asked, ticket)[0] >= AGAIN:
121
+ options, recommended = {name: options[name] for name in ("accept", "redesign")}, "accept"
88
122
  return {"id": f"{ticket}-{kind}-{number}".lstrip("-"), "title": made.title.format(**values), "why": made.why.format(**values),
89
- "evidence": evidence, "recommended": made.recommended,
90
- "options": [{"id": name, "description": option.description} for name, option in made.options.items()],
123
+ "evidence": evidence, "recommended": recommended,
124
+ "options": [{"id": name, "description": option.description} for name, option in options.items()],
91
125
  "ticket": ticket, "kind": kind, "subject": subject, "stop": stop, "answer": None}
92
126
 
93
127
 
@@ -11,6 +11,7 @@ from concurrent.futures import ThreadPoolExecutor
11
11
  from dataclasses import dataclass, field
12
12
 
13
13
  import driver_agents
14
+ import driver_decisions
14
15
  import driver_gate
15
16
  import driver_merge
16
17
  import driver_review
@@ -108,9 +109,10 @@ def _correct(job: Job, findings: list[dict]) -> list[dict]:
108
109
  """One test-writer correction for the findings on the locked tests. It is outside the fix rounds. Returns the
109
110
  findings that it did not correct, as findings of kind code for the fixer (issue #111)."""
110
111
  run, number = job.run, job.ticket.number
112
+ titles, evidence = [finding["title"] for finding in findings], str(OUT / number / f"findings-{job.round}.json")
111
113
  if job.corrected:
112
- titles = "; ".join(finding["title"] for finding in findings)
113
- raise Blocked(f"the review: a locked-test finding is open after the test-writer correction: {titles}")
114
+ run.ask(number, "locked-test-again", titles, evidence)
115
+ raise Blocked(f"the review: a locked-test finding is open after the test-writer correction: {'; '.join(titles)}")
114
116
  restored = run.restore_locked_files(number, job.slot)
115
117
  job.tip = driver_slots.head(job.slot) # the restore is a commit of the driver
116
118
  # The gate was green on the tip before the restore, so a red gate here is a restored file that fails with the
@@ -126,9 +128,13 @@ def _correct(job: Job, findings: list[dict]) -> list[dict]:
126
128
  "record": record and os.path.relpath(record, job.slot)}
127
129
  notes = ["correction"] + ["restored"] * bool(restored) + ["restored-red"] * bool(record)
128
130
  with during("the test-writer correction"):
129
- report = run.agent("test-writer", number, job.slot, values, notes=notes, fix_round=job.round + 1,
130
- check={"correction": True, "restored": restored, "restore_red": bool(record),
131
- "findings": [finding["title"] for finding in findings]})
131
+ try:
132
+ report = run.agent("test-writer", number, job.slot, values, notes=notes, fix_round=job.round + 1,
133
+ check={"correction": True, "restored": restored, "restore_red": bool(record),
134
+ "findings": titles})
135
+ except Blocked:
136
+ run.ask(number, "locked-test-again", titles, evidence) # a rejected correction is one that did not close
137
+ raise
132
138
  job.tip, job.previous, job.corrected = driver_slots.head(job.slot), "", True
133
139
  entry = run.state.read()["tickets"][number]
134
140
  run.state.ticket(number, tip=job.tip, **driver_review.written(job.slot, entry, report["locked"], job.tip))
@@ -181,10 +187,24 @@ def _fix(job: Job) -> None:
181
187
  job.corrected, job.proofs, job.again = False, set(followed), due
182
188
 
183
189
 
190
+ def _unaccepted(job: Job, state: dict, to_correct: list[dict]) -> list[dict]:
191
+ """The findings for a correction once an `accept` ruling closed the ticket's locked-test findings: only the
192
+ driver's, since a changed locked file is still restored. With no such ruling, `to_correct`."""
193
+ number = job.ticket.number
194
+ if not driver_decisions.corrections(state["run"]["questions"], number)[1]:
195
+ return to_correct
196
+ for finding in to_correct:
197
+ if finding["source"] != "driver":
198
+ ledger(f"Ticket {number}: {finding['kind']} finding in {finding['file']} closed as it is by the ruling "
199
+ f"(accept), with no correction: {finding['title']}.")
200
+ return [finding for finding in to_correct if finding["source"] == "driver"]
201
+
202
+
184
203
  def _act_on(job: Job, found: list[dict]) -> bool:
185
204
  """Do what the findings of a review ask for: a correction, a fix round, or a stop. True: none is open."""
186
- locked = job.run.state.read()["tickets"][job.ticket.number]["locked"]
187
- to_correct, to_fix = driver_review.route(found, locked)
205
+ state = job.run.state.read()
206
+ to_correct, to_fix = driver_review.route(found, state["tickets"][job.ticket.number]["locked"])
207
+ to_correct = _unaccepted(job, state, to_correct)
188
208
  if job.round == ROUNDS:
189
209
  # No correction after round 4: no fix round could make its new locked tests green, so `accept` could not merge.
190
210
  to_correct, to_fix = [], [finding for finding in found if finding in to_correct + to_fix]
@@ -1,11 +1,15 @@
1
1
  """The gate: the repo's one check command, run by the driver on the commit it is about to trust.
2
2
 
3
3
  A gate record is `<folder>/gate-<first 7 hex of the commit>.log`. It is green only for exit 0 on a tree that is
4
- clean before the command and after it, with HEAD still on the commit.
4
+ clean before the command and after it, with HEAD still on the commit. A command that a signal ended, on a clean tree
5
+ with HEAD unmoved, did not judge the commit: it runs once more, and that run overwrites the record. A signal ended the
6
+ command when its exit is negative, or when it is 128+N for N in SIGHUP, SIGINT, SIGKILL or SIGTERM: a shell that does
7
+ not exec its last command, as dash does not, outlives the killed child and exits with 128+N.
5
8
  """
6
9
  from __future__ import annotations
7
10
 
8
11
  import os
12
+ import signal
9
13
  import subprocess
10
14
  from datetime import datetime, timezone
11
15
  from pathlib import Path
@@ -25,18 +29,25 @@ def _after(slot: str, commit: str) -> str:
25
29
  return "not clean\n" + "".join(f" {line}\n" for line in status.splitlines()).rstrip("\n") if status else "clean"
26
30
 
27
31
 
32
+ _KILLS = {signal.SIGHUP, signal.SIGINT, signal.SIGKILL, signal.SIGTERM}
33
+
34
+
35
+ def _signal(code: int | str) -> int | None:
36
+ """The signal that ended the command: from a negative exit, or from 128+N as a shell reports its killed child."""
37
+ if not isinstance(code, int):
38
+ return None
39
+ if code < 0:
40
+ return -code
41
+ return code - 128 if code - 128 in _KILLS else None
42
+
43
+
28
44
  def record_path(folder: Path, commit: str) -> Path:
29
45
  return folder / f"gate-{commit[:7]}.log"
30
46
 
31
47
 
32
- def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Path]:
33
- """Gate the HEAD of `slot`. Returns (green, the record)."""
34
- commit = head(slot)
48
+ def _attempt(command: str, slot: str, commit: str, record: Path, env: dict) -> tuple[int | str, str]:
49
+ """Run the command once into `record`. Returns (the exit code or "not run", the state after it)."""
35
50
  status = git(slot, "status", "--short").stdout
36
- folder.mkdir(parents=True, exist_ok=True)
37
- record = record_path(folder, commit)
38
- # The cache of compiled Python stays out of the slot, so the gate leaves the tree clean.
39
- env = dict(os.environ, IMPLEMENT_SPEC_BASE=pr_branch, PYTHONPYCACHEPREFIX=str(folder.parent.resolve() / "pycache"))
40
51
  with record.open("w") as out:
41
52
  out.write(f"start: {_now()}\ncommit: {commit}\nstatus: {'not clean' if status else 'clean'}\n")
42
53
  out.writelines(f" {line}\n" for line in status.splitlines())
@@ -48,4 +59,21 @@ def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Pa
48
59
  ).returncode
49
60
  after = "not run" if status else _after(slot, commit)
50
61
  out.write(f"\nexit: {code}\nafter: {after}\nend: {_now()}\n")
51
- return code == 0 and after == "clean", record
62
+ return code, after
63
+
64
+
65
+ def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Path, list[str]]:
66
+ """Gate the HEAD of `slot`. Returns (green, the record, a ledger sentence per gate that a signal ended)."""
67
+ commit = head(slot)
68
+ folder.mkdir(parents=True, exist_ok=True)
69
+ record = record_path(folder, commit)
70
+ # The cache of compiled Python stays out of the slot, so the gate leaves the tree clean.
71
+ env = dict(os.environ, IMPLEMENT_SPEC_BASE=pr_branch, PYTHONPYCACHEPREFIX=str(folder.parent.resolve() / "pycache"))
72
+ code, after = _attempt(command, slot, commit, record, env)
73
+ killed = []
74
+ # A process outside the gate can kill it, as a `pkill -f` of another slot does: that run judged nothing.
75
+ number = _signal(code)
76
+ if number and after == "clean":
77
+ killed.append(f"the gate of {commit[:7]} was killed by signal {number} and runs again")
78
+ code, after = _attempt(command, slot, commit, record, env)
79
+ return code == 0 and after == "clean", record, killed
@@ -150,7 +150,9 @@ class Run:
150
150
  at = driver_slots.head(slot)
151
151
  if at != commit:
152
152
  raise Blocked(f"the slot is at {at[:7]}, not at {commit[:7]}: the gate did not run")
153
- green, record = driver_gate.run(self.args.gate, slot, OUT / number, self.pr)
153
+ green, record, killed = driver_gate.run(self.args.gate, slot, OUT / number, self.pr)
154
+ for sentence in killed:
155
+ ledger(f"{_owner(number)}: {sentence}.")
154
156
 
155
157
  def count(state: dict) -> None:
156
158
  state["run"]["gates"] += 1
@@ -29,4 +29,5 @@ Write one JSON report at {report} that matches this schema:
29
29
  }
30
30
  ```
31
31
 
32
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
32
33
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -34,4 +34,5 @@ Write one JSON report at {report} that matches this schema:
34
34
  }
35
35
  ```
36
36
 
37
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
37
38
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -35,4 +35,5 @@ Write one JSON report at {report} that matches this schema:
35
35
 
36
36
  Run git as plain `git` in this worktree, and leave the git config as it is: all worktrees read one shared config, and one key written there, such as a `core.worktree`, breaks git in each of them. So never set GIT_DIR or GIT_WORK_TREE, and never write with `git config`.
37
37
  To run a check off this worktree, read the gate record of the driver, {gate}, or make a copy with `git worktree add --detach <temp dir> {start_sha}`, run the check there, and remove the copy with `git worktree remove --force <temp dir>` before you report.
38
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
38
39
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -35,4 +35,5 @@ Write one JSON report at {report} that matches this schema:
35
35
  }
36
36
  ```
37
37
 
38
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
38
39
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -31,4 +31,5 @@ Write one JSON report at {report} that matches this schema:
31
31
  }
32
32
  ```
33
33
 
34
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
34
35
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -30,4 +30,5 @@ Write one JSON report at {report} that matches this schema:
30
30
  }
31
31
  ```
32
32
 
33
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
33
34
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -33,4 +33,5 @@ Write one JSON report at {report}. When your sandbox is read-only, give the JSON
33
33
 
34
34
  Run git as plain `git` in this worktree, and leave the git config as it is: all worktrees read one shared config, and one key written there, such as a `core.worktree`, breaks git in each of them. So never set GIT_DIR or GIT_WORK_TREE, and never write with `git config`.
35
35
  To run a check off this worktree, read the gate record of the driver, {gate_record}, or make a copy with `git worktree add --detach <temp dir> {start_sha}`, run the check there, and remove the copy with `git worktree remove --force <temp dir>` before you report.
36
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
36
37
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -33,4 +33,5 @@ Write one JSON report at {report} that matches this schema:
33
33
  }
34
34
  ```
35
35
 
36
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
36
37
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -290,6 +290,16 @@ def test_every_prompt_ends_with_report_path_schema_and_the_never_rule(env, role,
290
290
  assert report in prompt
291
291
 
292
292
 
293
+ @pytest.mark.parametrize("role", ["test-writer", "implementer", "fixer", "conflict", "reviewer", "final-reviewer",
294
+ "final-fixer", "rebase-conflict"])
295
+ def test_each_role_that_runs_commands_stops_only_its_own_processes(role):
296
+ """Issue 101: a `pkill -f` of one slot killed the gate of another."""
297
+ text = (SKILL / f"prompts/{role}.md").read_text()
298
+ assert "Stop only processes you started and their child processes, by PID" in text
299
+ assert "Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name" in text
300
+ assert "If a process you did not start blocks you, report it in your concerns and do not kill it." in text
301
+
302
+
293
303
  def test_no_report_is_a_violation_with_one_rerun_then_blocked(env):
294
304
  w = World(env, refactor=True)
295
305
  blocked(w.run({"implementer": [{}, {}, impl()]}))
@@ -4,6 +4,7 @@ import json
4
4
  import os
5
5
  import shutil
6
6
  import subprocess
7
+ import sys
7
8
 
8
9
  import jsonschema
9
10
  import pytest
@@ -23,10 +24,13 @@ from test_walk import impl, plan, tw
23
24
  class Inside(test_review.Review):
24
25
  """The rig of test_review with the driver called in this process."""
25
26
 
27
+ command = "{gate}" # the gate command; `{gate}` is the rig's gate script
28
+
26
29
  def run(self, steps, *extra, parallel="2", watch=False):
27
30
  (self.rig / "plan.json").write_text(json.dumps(steps))
28
- args = ["--tickets", ".agent/tickets", "--gate", str(self.rig / "gate"), "--spec", "specs/csv/spec.md",
29
- "--models", str(self.models), "--runner", str(self.rig / "run-agent"), "--parallel", parallel, *extra]
31
+ args = ["--tickets", ".agent/tickets", "--gate", self.command.format(gate=self.rig / "gate"), "--spec",
32
+ "specs/csv/spec.md", "--models", str(self.models), "--runner", str(self.rig / "run-agent"), "--parallel",
33
+ parallel, *extra]
30
34
  here = os.getcwd()
31
35
  os.chdir(self.repo)
32
36
  try:
@@ -137,12 +141,67 @@ def test_a_locked_file_check_that_git_cannot_make_is_a_finding(tmp_path):
137
141
  assert found["severity"] == "critical" and found["title"].startswith("locked file check failed: ")
138
142
 
139
143
 
140
- def test_a_fixture_finding_that_comes_back_after_its_correction_blocks_the_ticket(tmp_path):
141
- stale = finding("STALE", kind="fixture", file="tests/test_01.py")
142
- correction = {**tw("01"), "files": {"tests/test_01.py": "# corrected\n"}, "commit": "test: 01 fixture fix"}
143
- rig = Inside(tmp_path).run(plan(**{"01/test-writer": [tw("01"), correction], "01/reviewer": [review("01", [stale])] * 2}))
144
- assert blocked(rig).endswith("BLOCKED at the review: a locked-test finding is open after the test-writer correction: STALE.")
145
- assert len(rig.calls("01", "test-writer")) == 2 and rig.state()["tickets"]["01"]["round"] == 0
144
+ STALE = finding("STALE", kind="fixture", file="tests/test_01.py")
145
+ AGAIN_1 = "01-locked-test-again-1"
146
+
147
+
148
+ def corrections(n):
149
+ """`n` test-writer corrections of tests/test_01.py, each with its own content."""
150
+ return [{**tw("01"), "files": {"tests/test_01.py": f"# corrected {i}\n"}, "commit": f"test: 01 correction {i}"}
151
+ for i in range(1, n + 1)]
152
+
153
+
154
+ def asked(rig):
155
+ """The open questions of the run: id -> option ids."""
156
+ return {q["id"]: [o["id"] for o in q["options"]] for q in rig.state()["run"]["questions"] if q["answer"] is None}
157
+
158
+
159
+ def test_a_locked_test_finding_that_comes_back_after_its_correction_asks_the_operator(tmp_path):
160
+ # Issue #107: the ticket was BLOCKED with no question, so only an edit of state.json could resume it.
161
+ steps = plan(**{"01/test-writer": [tw("01"), *corrections(2)],
162
+ "01/reviewer": [review("01", [STALE])] * 3 + [review("01")]})
163
+ rig = Inside(tmp_path).run(steps)
164
+ assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
165
+ assert rig.led("BLOCKED at the review: a locked-test finding is open after the test-writer correction: STALE.")
166
+ assert asked(rig) == {AGAIN_1: ["correct-again", "accept", "redesign"]}
167
+ (question,) = rig.state()["run"]["questions"]
168
+ assert question["recommended"] == "correct-again" and question["evidence"][0] == ".agent/implement/01/findings-0.json"
169
+ rig.run(steps, "--answer", f"{AGAIN_1}=correct-again")
170
+ assert rig.code == 0, rig.ledger()
171
+ order = [call["role"] for call in rig.calls("01")]
172
+ assert order == ["test-writer", "implementer", "reviewer", "test-writer", "reviewer", "reviewer", "test-writer",
173
+ "reviewer"]
174
+ assert rig.led("Ruling: 01 locked-test finding goes back to the test-writer for one more correction")
175
+ assert rig.state()["tickets"]["01"]["phase"] == "merged"
176
+
177
+
178
+ def test_an_accepted_locked_test_finding_lets_the_ticket_go_on_to_its_fix_rounds(tmp_path):
179
+ steps = plan(**{"01/test-writer": [tw("01"), *corrections(1)], "01/fixer": [fix("01", 1)],
180
+ "01/reviewer": [review("01", [STALE]), review("01", [STALE]), review("01", [STALE, STUCK]),
181
+ review("01", [STALE])]})
182
+ rig = Inside(tmp_path).run(steps)
183
+ assert rig.code == 2 and list(asked(rig)) == [AGAIN_1], rig.ledger()
184
+ rig.run(steps, "--answer", f"{AGAIN_1}=accept")
185
+ assert rig.code == 0, rig.ledger()
186
+ order = [call["role"] for call in rig.calls("01")]
187
+ assert order == ["test-writer", "implementer", "reviewer", "test-writer", "reviewer", "reviewer", "fixer",
188
+ "reviewer"]
189
+ assert rig.state()["tickets"]["01"]["round"] == 1
190
+ assert rig.led("STALE", "closed as it is by the ruling")
191
+
192
+
193
+ def test_the_extra_corrections_are_bounded_and_redesign_keeps_the_ticket_blocked(tmp_path):
194
+ steps = plan(**{"01/test-writer": [tw("01"), *corrections(3)], "01/reviewer": [review("01", [STALE])] * 6})
195
+ rig = Inside(tmp_path).run(steps)
196
+ for n in (1, 2):
197
+ assert asked(rig) == {f"01-locked-test-again-{n}": ["correct-again", "accept", "redesign"]}, rig.ledger()
198
+ rig.run(steps, "--answer", f"01-locked-test-again-{n}=correct-again")
199
+ # Two extra corrections did not close it: a third one is not offered.
200
+ assert asked(rig) == {"01-locked-test-again-3": ["accept", "redesign"]}, rig.ledger()
201
+ assert len(rig.calls("01", "test-writer")) == 4
202
+ rig.run(steps, "--answer", "01-locked-test-again-3=redesign")
203
+ assert rig.code == 1 and rig.state()["tickets"]["01"]["phase"] == "blocked" and asked(rig) == {}
204
+ assert rig.led("Ruling: 01 stays BLOCKED, the design changes first (redesign): STALE.")
146
205
 
147
206
 
148
207
  def test_an_open_finding_survives_the_fixture_correction_of_its_review_and_starts_the_fix_round(tmp_path):
@@ -278,10 +337,15 @@ def test_the_fix_rounds_count_from_0_after_an_overruled_test(tmp_path):
278
337
  assert rig.state()["tickets"]["01"]["round"] == 1 and not rig.led("after round 4")
279
338
 
280
339
 
281
- def test_a_fixture_correction_that_is_rejected_blocks_the_ticket(tmp_path):
282
- stale = finding("STALE", kind="fixture", file="tests/test_01.py")
283
- rig = Inside(tmp_path).run(plan(**{"01/test-writer": [tw("01"), {}, {}], "01/reviewer": [review("01", [stale])]}))
284
- assert "BLOCKED at the test-writer correction: report .agent/implement/01/test-writer-1.json is not" in blocked(rig)
340
+ def test_a_fixture_correction_that_is_rejected_asks_the_operator(tmp_path):
341
+ # Issue #107: a correction the driver rejects (for one, a change to a file it does not list) was a dead end too.
342
+ steps = plan(**{"01/test-writer": [tw("01"), {}, {}, *corrections(1)],
343
+ "01/reviewer": [review("01", [STALE])] * 2 + [review("01")]})
344
+ rig = Inside(tmp_path).run(steps)
345
+ assert rig.code == 2 and list(asked(rig)) == [AGAIN_1], rig.ledger()
346
+ assert rig.led("BLOCKED at the test-writer correction: report .agent/implement/01/test-writer-1.json is not")
347
+ rig.run(steps, "--answer", f"{AGAIN_1}=correct-again")
348
+ assert rig.code == 0 and len(rig.calls("01", "test-writer")) == 4, rig.ledger()
285
349
 
286
350
 
287
351
  # ---------------------------------------------------------------- the locked files of the merged tickets
@@ -530,6 +594,76 @@ def test_a_red_gate_on_the_implementer_commit_starts_fix_round_1_with_the_record
530
594
  assert gate["title"] == f"the gate is red on {tip[:7]}" and record in gate["evidence"]
531
595
  assert "findings-0.json" in rig.prompt("fixer-1") and rig.state()["tickets"]["01"]["phase"] == "merged"
532
596
  assert "The fix is" not in rig.prompt("reviewer-1") # no review saw the implementer commit: a full review
597
+ assert [gate["commit"] for gate in rig.gates()].count(tip) == 1 and not rig.led("killed by signal")
598
+
599
+
600
+ def killed(rig, subject, times, end="os.kill(os.getpid(), signal.SIGTERM)"):
601
+ """The rig's gate, ended by `end` (SIGTERM by default) on its first `times` runs on the commit with `subject`, as a
602
+ `pkill -f` of another slot ends it (issue 101). A killed run logs nothing into `<rig>/gates/`."""
603
+ gate, real = rig.rig / "gate", rig.rig / "real-gate"
604
+ gate.rename(real)
605
+ gate.write_text(f"""#!{sys.executable}
606
+ import os, signal, subprocess, sys
607
+ from pathlib import Path
608
+ kills = Path(__file__).with_name("kills")
609
+ subject = subprocess.run(["git", "log", "-1", "--format=%s"], capture_output=True, text=True).stdout.strip()
610
+ if subject == {subject!r} and len(kills.read_text() if kills.exists() else "") < {times}:
611
+ with kills.open("a") as file:
612
+ file.write("x")
613
+ {end}
614
+ os.execv({str(real)!r}, [{str(real)!r}])
615
+ """)
616
+ gate.chmod(0o755)
617
+ return rig
618
+
619
+
620
+ # How the gate's shell reports a SIGTERM of the command: `exec` replaces the shell, so the exit is -15; a shell that
621
+ # outlives its child, as Ubuntu's dash does even for one simple command, exits 128+15.
622
+ SHAPES = {"exec": ("exec {gate}", -15), "compound": ("{gate}; exit $?", 143)}
623
+
624
+
625
+ def shaped(tmp_path, command):
626
+ rig = Inside(tmp_path)
627
+ rig.command = command
628
+ return rig
629
+
630
+
631
+ @pytest.mark.parametrize("command, code", SHAPES.values(), ids=SHAPES)
632
+ def test_a_gate_killed_by_a_signal_runs_once_more_and_its_green_second_run_counts(tmp_path, command, code):
633
+ rig = killed(shaped(tmp_path, command), "feat: 01 rows", 1).run(plan(**{"01/reviewer": [review("01")]}))
634
+ assert rig.code == 0, rig.ledger()
635
+ tip = rig.sha("01", "implementer")
636
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "reviewer"]
637
+ assert rig.led("killed by signal") == [f"Ticket 01: the gate of {tip[:7]} was killed by signal 15 and runs again."]
638
+ assert rig.led(f"Ticket 01: the gate is green on {tip[:7]}") and not rig.led("finding of kind")
639
+ assert json.loads((rig.folder() / "findings-0.json").read_text()) == [] # the review's, with no gate finding
640
+ record = (rig.folder() / f"gate-{tip[:7]}.log").read_text()
641
+ assert record.count("exit: ") == 1 and "\nexit: 0\nafter: clean\n" in record # the second run overwrote it
642
+
643
+
644
+ @pytest.mark.parametrize("command, code", SHAPES.values(), ids=SHAPES)
645
+ def test_a_gate_killed_by_a_signal_twice_is_red(tmp_path, command, code):
646
+ rig = killed(shaped(tmp_path, command), "feat: 01 rows", 2)
647
+ rig.run(plan(**{"01/reviewer": [review("01")], "01/fixer": [fix("01", 1)]}))
648
+ assert rig.code == 0, rig.ledger()
649
+ tip = rig.sha("01", "implementer")
650
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "fixer", "reviewer"]
651
+ assert len(rig.led("killed by signal")) == 1 and tip not in [gate["commit"] for gate in rig.gates()]
652
+ (gate,) = json.loads((rig.folder() / "findings-0.json").read_text())
653
+ assert gate["title"] == f"the gate is red on {tip[:7]}"
654
+ assert f"\nexit: {code}\nafter: clean\n" in (rig.folder() / f"gate-{tip[:7]}.log").read_text()
655
+
656
+
657
+ @pytest.mark.parametrize("exit", [1, 142]) # 142 is 128+SIGALRM: a signal, but not one that kills a gate from outside
658
+ def test_a_gate_that_exits_with_any_other_code_is_red_without_running_again(tmp_path, exit):
659
+ rig = killed(shaped(tmp_path, "{gate}; exit $?"), "feat: 01 rows", 1, end=f"sys.exit({exit})")
660
+ rig.run(plan(**{"01/reviewer": [review("01")], "01/fixer": [fix("01", 1)]}))
661
+ assert rig.code == 0, rig.ledger()
662
+ tip = rig.sha("01", "implementer")
663
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "fixer", "reviewer"]
664
+ assert not rig.led("killed by signal") and tip not in [gate["commit"] for gate in rig.gates()]
665
+ record = (rig.folder() / f"gate-{tip[:7]}.log").read_text()
666
+ assert record.count("exit: ") == 1 and f"\nexit: {exit}\nafter: clean\n" in record
533
667
 
534
668
 
535
669
  def test_a_red_gate_on_the_fixer_commit_of_round_4_blocks_the_ticket(tmp_path):
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-10-19T11:13:23.574Z",
3
+ "generatedAt": "2026-10-20T08:20:29.273Z",
4
4
  "skills": [
5
5
  {
6
6
  "name": "backlog",
@@ -46,8 +46,8 @@
46
46
  },
47
47
  {
48
48
  "name": "implement-spec",
49
- "version": "0.1.27",
50
- "hash": "sha256-5cd78074157850b0abb3de812a51a911486bd5da29fe5f553a4838b25e61d30b",
49
+ "version": "0.1.29",
50
+ "hash": "sha256-777240d5b64b5fdff5e6fa9633e2ed21d9f5147c3781404c88dc11c0248bfaee",
51
51
  "description": "Implement a specification in code."
52
52
  },
53
53
  {