@oakgreencc/cambium 0.0.36 → 0.0.37
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 +12 -5
- package/package.json +1 -1
- package/src/dispatch-engine.mjs +73 -5
- package/src/github.mjs +10 -1
- package/src/graphs/dispatch.mjs +107 -20
- package/src/labels.mjs +10 -1
- package/src/marker.mjs +7 -2
- package/src/phases/dispatch.mjs +26 -6
package/README.md
CHANGED
|
@@ -395,7 +395,8 @@ flowchart TD
|
|
|
395
395
|
n4["to-human"]
|
|
396
396
|
n5["close-duplicate"]
|
|
397
397
|
n6["deferred"]
|
|
398
|
-
n7["
|
|
398
|
+
n7["blocked"]
|
|
399
|
+
n8["close-obsolete"]
|
|
399
400
|
end_(("end"))
|
|
400
401
|
start_ --> n0
|
|
401
402
|
n0 -->|"started"| n1
|
|
@@ -406,7 +407,8 @@ flowchart TD
|
|
|
406
407
|
n1 -->|"actionable"| n3
|
|
407
408
|
n1 -->|"duplicate"| n5
|
|
408
409
|
n1 -->|"defer"| n6
|
|
409
|
-
n1 -->|"
|
|
410
|
+
n1 -->|"blocked"| n7
|
|
411
|
+
n1 -->|"obsolete"| n8
|
|
410
412
|
n1 -->|"needsHuman"| n4
|
|
411
413
|
n1 --> n4
|
|
412
414
|
n2 -->|"attemptsLeft"| n0
|
|
@@ -416,7 +418,9 @@ flowchart TD
|
|
|
416
418
|
n5 --> end_
|
|
417
419
|
n6 -->|"budgetSpent"| n4
|
|
418
420
|
n6 --> end_
|
|
421
|
+
n7 -->|"noneOpen"| n6
|
|
419
422
|
n7 --> end_
|
|
423
|
+
n8 --> end_
|
|
420
424
|
```
|
|
421
425
|
|
|
422
426
|
| Node | Kind | Queue label | Holds `running` |
|
|
@@ -428,13 +432,16 @@ flowchart TD
|
|
|
428
432
|
| `to-human` | step | `q:human` | no |
|
|
429
433
|
| `close-duplicate` | step | none | no |
|
|
430
434
|
| `deferred` | step | `q:intake` | no |
|
|
435
|
+
| `blocked` | step | `q:intake` | no |
|
|
431
436
|
| `close-obsolete` | step | none | no |
|
|
432
437
|
|
|
433
|
-
- **The verdict.** The worker's final message must end with a JSON block, validated by zod (`TriageResult`): `{ verdict: 'actionable' | 'needs-human' | 'duplicate' | 'obsolete' | 'defer', duplicateOf?, recheckHours?, reason, title?, acceptance? }` (`duplicateOf` is required on a duplicate and cannot be the issue itself). cambium reads it from the worker's stdout log: the last `result` event's `result` text, its last fenced block (else the bare JSON).
|
|
434
|
-
- **Outcomes.** `actionable` → a comment with the reason, the task title and acceptance checks (when given), then `q:task` with a task-graph marker at `start-worker`, attempt 1, history kept; the checks also ride in the marker (`triage`) into the task worker's prompt. The issue body is never rewritten: cambium's write path has no issue edit, and the author's text stays as written. `needs-human` → `q:human` + `why:triage`, the reason as the state comment's last failure. `duplicate` → closed with reason `duplicate` and `Duplicate of #n (<link>). <reason>`. `obsolete` (the work no longer applies, verified: the code path is gone, already fixed, its check already passed) → closed as `not_planned` with `Obsolete: <reason>`. `defer` → stays in `q:intake` at `deferred` (see below). A missing or invalid verdict (no `result` event, no JSON, a schema error) or a worker killed at `wallClockMinutes` (the unlabelled `triaging → to-human` edge) → `q:human` + `why:triage` with the error.
|
|
438
|
+
- **The verdict.** The worker's final message must end with a JSON block, validated by zod (`TriageResult`): `{ verdict: 'actionable' | 'needs-human' | 'duplicate' | 'obsolete' | 'defer' | 'blocked', duplicateOf?, blockedBy?, recheckHours?, reason, title?, acceptance? }` (`duplicateOf` is required on a duplicate and cannot be the issue itself; `blockedBy`, issue numbers, likewise on blocked). cambium reads it from the worker's stdout log: the last `result` event's `result` text, its last fenced block (else the bare JSON).
|
|
439
|
+
- **Outcomes.** `actionable` → a comment with the reason, the task title and acceptance checks (when given), then `q:task` with a task-graph marker at `start-worker`, attempt 1, history kept; the checks also ride in the marker (`triage`) into the task worker's prompt. The issue body is never rewritten: cambium's write path has no issue edit, and the author's text stays as written. `needs-human` → `q:human` + `why:triage`, the reason as the state comment's last failure. `duplicate` → closed with reason `duplicate` and `Duplicate of #n (<link>). <reason>`. `obsolete` (the work no longer applies, verified: the code path is gone, already fixed, its check already passed) → closed as `not_planned` with `Obsolete: <reason>`. `defer` → stays in `q:intake` at `deferred`, `blocked` → stays in `q:intake` at `blocked` (see below). A missing or invalid verdict (no `result` event, no JSON, a schema error) or a worker killed at `wallClockMinutes` (the unlabelled `triaging → to-human` edge) → `q:human` + `why:triage` with the error.
|
|
435
440
|
- **Read-only checkout.** Triage reads code to judge feasibility and duplicates, so it gets a checkout, but a disposable one: a detached worktree at `<root>/triage-<n>` on `origin/<base>` (the repo's worktree root), no install, hydrate or `prepare`, tools `Read,Glob,Grep,Bash` with Edit/Write and every graft/git write verb denied. It is removed outright after the verdict (no `graft status`: nothing in it is worth keeping).
|
|
436
441
|
- **Retries.** A worker that cannot start, or a lost `running` lease on a `q:intake` issue (Sweep), goes back to `q:intake` with attempt + 1, then to `q:human` once `phases.dispatch.maxAttempts` are spent. A marker from another graph or a finished triage starts over at attempt 1.
|
|
437
|
-
- **Defer, not a human.** A verdict that hangs on something a machine can check later (a CD run that has not happened, a release, a merge, a deploy) is `defer`, never `needs-human`: asking a human to verify what a machine can is what the factory exists to avoid. The issue rests at `deferred` with `deferUntil` (now + `recheckHours`, else `phases.dispatch.deferHours`, default 6) and `deferReason` in its marker; Schedule skips it until then, and the next triage gets the reason in its prompt ("check it now"). A defer is not a failed attempt. A deferred issue whose GitHub "blocked by" issues are all closed, at least one after it was deferred, is triaged again at the next tick instead of waiting for `deferUntil`. After `phases.dispatch.maxDefers` (default 8) it goes to `q:human` + `why:triage` with the last reason.
|
|
442
|
+
- **Defer, not a human.** A verdict that hangs on something a machine can check later (a CD run that has not happened, a release, a merge, a deploy) is `defer`, never `needs-human`: asking a human to verify what a machine can is what the factory exists to avoid. The issue rests at `deferred` with `deferUntil` (now + `recheckHours`, else `phases.dispatch.deferHours`, default 6) and `deferReason` in its marker; Schedule skips it until then, and the next triage gets the reason in its prompt ("check it now"). A defer is not a failed attempt. A deferred issue whose GitHub "blocked by" issues are all closed, at least one after it was deferred, is triaged again at the next tick instead of waiting for `deferUntil`. After `phases.dispatch.maxDefers` (default 8) it goes to `q:human` + `why:triage` with the last reason. While it waits it carries `wait:deferred`.
|
|
443
|
+
- **Blocked by issues, not a timer.** A verdict that waits on other issues is `blocked` with `blockedBy: [n, …]`. cambium adds each as a GitHub "blocked by" link on the issue when it is missing, then parks it at `blocked` with `wait:blocked`, the open blockers in the marker's `blockedBy` and no `deferUntil`. Schedule never triages an intake issue with an open `blockedBy` issue, whoever linked it: one not yet at `blocked` (new, or deferred) is parked there first. The tick after the last blocker closes, the label comes off and the issue is triaged again, its earlier reason in the prompt. A blocked wait is not a defer and does not count toward `maxDefers`; a `blocked` verdict none of whose issues is open (closed, or the link failed) is a defer.
|
|
444
|
+
- **`wait:*` labels.** Intake holds two kinds of issue: awaiting triage, and parked by it. `wait:deferred` and `wait:blocked` mark the parked ones (canopy shows them apart from Intake); Schedule adds or removes them each tick to match the marker and the blockers, and any queue move drops them.
|
|
438
445
|
- **Leaving intake.** If the issue is closed or relabelled while triage runs, the verdict is dropped and the checkout removed.
|
|
439
446
|
- **Tracing.** Wired as in the task graph (see [Tracing](#tracing)): the driver's node and wait spans under a `cambium.issue` root that continues mycelium's intake span from the issue body, the triage worker's `TRACEPARENT` (its `start-triage` span), and its stream-json spans when `triaging` ends.
|
|
440
447
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oakgreencc/cambium",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "The scheduler daemon: reads the q:* queues from GitHub every tick, runs headless claude workers in their own worktrees up to a cap, and makes every queue transition itself.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
package/src/dispatch-engine.mjs
CHANGED
|
@@ -5,15 +5,19 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - Reconcile: every tracked triage worker's issue at `triaging`.
|
|
7
7
|
* - Sweep: a stale `running` lease on a `q:intake` issue runs `retry-triage`.
|
|
8
|
-
* - Schedule: `q:intake`
|
|
9
|
-
*
|
|
8
|
+
* - Schedule: first parks: a `q:intake` issue without a lease that has an open GitHub `blockedBy` issue goes to the
|
|
9
|
+
* `blocked` node (`wait:blocked`) if it is not there yet, and every other one gets the `wait:*` label its marker
|
|
10
|
+
* calls for (`wait:deferred` while its `deferUntil` is ahead, none once due or unblocked). Then `q:intake` issues
|
|
11
|
+
* without a lease, by priority then age, up to `phases.dispatch.cap` counted from live triage workers, skipping
|
|
12
|
+
* one deferred until later or blocked; each starts at `start-triage`.
|
|
10
13
|
*
|
|
11
14
|
* A turn advances one transition at a time and stops on entering a wait, at the entry node again (only Schedule
|
|
12
15
|
* admits entries), at a wait that is not ready, or at the end.
|
|
13
16
|
*/
|
|
14
17
|
import { advance } from './graph/index.mjs'
|
|
15
|
-
import { dispatch, lostLeaseOf, nodeOf } from './graphs/dispatch.mjs'
|
|
16
|
-
import {
|
|
18
|
+
import { dispatch, lostLeaseOf, nodeOf, openBlockers } from './graphs/dispatch.mjs'
|
|
19
|
+
import { setLabels } from './issue-state.mjs'
|
|
20
|
+
import { byPriorityThenAge, Q, RUNNING, WAIT } from './labels.mjs'
|
|
17
21
|
import { each, staleLeases } from './tick.mjs'
|
|
18
22
|
import { markerTrace, turnTracer } from './tracing.mjs'
|
|
19
23
|
|
|
@@ -120,7 +124,8 @@ export function intakeCandidates(deps, ctx) {
|
|
|
120
124
|
issue.labels.includes(Q.intake) &&
|
|
121
125
|
!issue.labels.includes(RUNNING) &&
|
|
122
126
|
!store.worker(slug, issue.number) &&
|
|
123
|
-
!deferredPast(issue, ctx.now)
|
|
127
|
+
!deferredPast(issue, ctx.now) &&
|
|
128
|
+
!openBlockers(issue).length
|
|
124
129
|
)
|
|
125
130
|
candidates.push({ slug, issue, snap })
|
|
126
131
|
const order = byPriorityThenAge(config.priorityLabels)
|
|
@@ -141,6 +146,67 @@ const deferredPast = (issue, now) => {
|
|
|
141
146
|
return !unblockedSince(issue.blockedBy ?? [], m.enteredAt)
|
|
142
147
|
}
|
|
143
148
|
|
|
149
|
+
/**
|
|
150
|
+
* The `q:intake` issues at rest (no `running`, no tracked worker), whatever the cap: these are parked or unparked.
|
|
151
|
+
* @param {Deps} deps @param {Ctx} ctx
|
|
152
|
+
*/
|
|
153
|
+
function restingIntake(deps, ctx) {
|
|
154
|
+
/** @type {{ slug: string, issue: import('./github.mjs').Issue, snap: import('./github.mjs').Snapshot }[]} */
|
|
155
|
+
const out = []
|
|
156
|
+
for (const [slug, snap] of ctx.snaps)
|
|
157
|
+
for (const issue of snap.issues.values())
|
|
158
|
+
if (
|
|
159
|
+
issue.state === 'OPEN' &&
|
|
160
|
+
issue.labels.includes(Q.intake) &&
|
|
161
|
+
!issue.labels.includes(RUNNING) &&
|
|
162
|
+
!deps.store.worker(slug, issue.number)
|
|
163
|
+
)
|
|
164
|
+
out.push({ slug, issue, snap })
|
|
165
|
+
return out
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The `wait:*` label a resting `q:intake` issue should carry, open blockers aside: `wait:deferred` while its
|
|
170
|
+
* `deferUntil` is ahead, else none (it awaits triage).
|
|
171
|
+
* @param {import('./github.mjs').Issue} issue @param {number} now
|
|
172
|
+
*/
|
|
173
|
+
const waitLabelOf = (issue, now) => (deferredPast(issue, now) ? WAIT.deferred : null)
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Park and unpark: an issue with an open `blockedBy` goes to the `blocked` node unless it rests there already with
|
|
177
|
+
* `wait:blocked`; any other gets the `wait:*` label {@link waitLabelOf} says, and loses the rest.
|
|
178
|
+
* @param {Deps} deps @param {Ctx} ctx
|
|
179
|
+
*/
|
|
180
|
+
async function park(deps, ctx) {
|
|
181
|
+
await each(
|
|
182
|
+
deps,
|
|
183
|
+
restingIntake(deps, ctx),
|
|
184
|
+
async (c) => {
|
|
185
|
+
const { issue } = c
|
|
186
|
+
const open = openBlockers(issue)
|
|
187
|
+
const m = issue.stateComment?.marker
|
|
188
|
+
const atBlocked = m?.graph === dispatch.name && m.node === 'blocked'
|
|
189
|
+
if (open.length) {
|
|
190
|
+
if (atBlocked && issue.labels.includes(WAIT.blocked)) return
|
|
191
|
+
const subject = { slug: c.slug, number: issue.number, snap: c.snap, issue }
|
|
192
|
+
const reason =
|
|
193
|
+
m?.graph === dispatch.name && m.node === 'deferred' && m.deferReason
|
|
194
|
+
? m.deferReason
|
|
195
|
+
: `GitHub shows it blocked by ${open.map((n) => `#${n}`).join(', ')}.`
|
|
196
|
+
await driveDispatch(deps, ctx, subject, { node: 'blocked', input: { blockedBy: open, reason } })
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
const want = waitLabelOf(issue, ctx.now)
|
|
200
|
+
const has = issue.labels.filter((l) => l.startsWith('wait:'))
|
|
201
|
+
await setLabels(deps, c.slug, issue, {
|
|
202
|
+
add: want && !has.includes(want) ? [want] : [],
|
|
203
|
+
remove: has.filter((l) => l !== want),
|
|
204
|
+
})
|
|
205
|
+
},
|
|
206
|
+
(c) => ({ repo: c.slug, issue: c.issue.number }),
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
144
210
|
/**
|
|
145
211
|
* All blockers closed, at least one after `since`.
|
|
146
212
|
* @param {import('./github.mjs').Blocker[]} blockers @param {string | null} since
|
|
@@ -152,6 +218,8 @@ const unblockedSince = (blockers, since) =>
|
|
|
152
218
|
|
|
153
219
|
/** @param {Deps} deps @param {Ctx} ctx */
|
|
154
220
|
async function schedule(deps, ctx) {
|
|
221
|
+
if (deps.config.phases.dispatch.cap <= 0) return
|
|
222
|
+
await park(deps, ctx)
|
|
155
223
|
await each(
|
|
156
224
|
deps,
|
|
157
225
|
intakeCandidates(deps, ctx),
|
package/src/github.mjs
CHANGED
|
@@ -64,10 +64,12 @@ import { BASE_FIELDS, baseHealthOf } from './base-health.mjs'
|
|
|
64
64
|
* behindBase(slug: string, number: number): Promise<{ behind: number, base: string }>,
|
|
65
65
|
* updatePull(slug: string, number: number): Promise<void>,
|
|
66
66
|
* linkIssue(slug: string, pr: number, issue: number): Promise<void>,
|
|
67
|
+
* addBlockedBy(slug: string, number: number, blocker: number): Promise<{ state: 'OPEN' | 'CLOSED' }>,
|
|
67
68
|
* }} GitHub
|
|
68
69
|
* `behindBase`: how many commits of its base the PR's head lacks, read live (not from the tick's snapshot), so a
|
|
69
70
|
* merge earlier in the same tick counts. `updatePull`: merge the base into the PR (`graft pr update`).
|
|
70
71
|
* `linkIssue`: put `Closes #<issue>` at the top of the PR's body, so the PR names the issue it closes.
|
|
72
|
+
* `addBlockedBy`: record GitHub's "blocked by" dependency of issue `number` on `blocker`; resolves the blocker's state.
|
|
71
73
|
*/
|
|
72
74
|
|
|
73
75
|
const PR_FIELDS = `number url headRefName state headRefOid isInMergeQueue body mergeable reviewDecision createdAt updatedAt
|
|
@@ -220,7 +222,7 @@ function toIssue(n, botLogin) {
|
|
|
220
222
|
stateComment: stateCommentOf(n, botLogin),
|
|
221
223
|
blockedBy: (n.blockedBy?.nodes ?? []).filter(Boolean).map((/** @type {any} */ b) => ({
|
|
222
224
|
number: b.number,
|
|
223
|
-
state: b.state,
|
|
225
|
+
state: b.state === 'OPEN' ? 'OPEN' : 'CLOSED',
|
|
224
226
|
closedAt: b.closedAt ?? null,
|
|
225
227
|
})),
|
|
226
228
|
}
|
|
@@ -475,5 +477,12 @@ export function graftGitHub({ config, exec: run = exec }) {
|
|
|
475
477
|
const linked = `Closes #${issue}${body ? `\n\n${body}` : ''}`
|
|
476
478
|
await graft(slug, ['api', 'PATCH', path, '--body', JSON.stringify({ body: linked })])
|
|
477
479
|
},
|
|
480
|
+
async addBlockedBy(slug, number, blocker) {
|
|
481
|
+
// The dependencies API takes the blocker's database id, not its number.
|
|
482
|
+
const b = await json(graft(slug, ['api', 'GET', `/repos/${slug}/issues/${blocker}`]))
|
|
483
|
+
const path = `/repos/${slug}/issues/${number}/dependencies/blocked_by`
|
|
484
|
+
await graft(slug, ['api', 'POST', path, '--body', JSON.stringify({ issue_id: b.id })])
|
|
485
|
+
return { state: b.state === 'open' ? 'OPEN' : 'CLOSED' }
|
|
486
|
+
},
|
|
478
487
|
}
|
|
479
488
|
}
|
package/src/graphs/dispatch.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* The Dispatch phase as a graph: a `q:intake` issue is triaged by a one-shot `claude -p` worker whose final
|
|
4
4
|
* message carries a typed verdict ({@link TriageResult}), then moved to `q:task`, moved to `q:human`, or closed as
|
|
5
|
-
* a duplicate or obsolete,
|
|
5
|
+
* a duplicate or obsolete, deferred to be triaged again later, or parked as blocked until its GitHub `blockedBy` issues close. Same conventions as the task graph (graphs/task.mjs): each node declares its queue label and
|
|
6
6
|
* whether it holds `running`, and a node's write is the marker first, then the labels via `move()`.
|
|
7
7
|
*
|
|
8
8
|
* The triage worker runs in a read-only checkout (workers.mjs `readOnly`): detached at the base branch, no install,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { z } from 'zod'
|
|
12
12
|
import { defineGraph, defineNode, defineWait, END } from '../graph/index.mjs'
|
|
13
13
|
import { iso, key, markerOf, MIN, setLabels, setMarker } from '../issue-state.mjs'
|
|
14
|
-
import { move, Q, WHY } from '../labels.mjs'
|
|
14
|
+
import { move, Q, WAIT, WHY } from '../labels.mjs'
|
|
15
15
|
import { newMarker, withHistory } from '../marker.mjs'
|
|
16
16
|
import { readTriage, TriageResult, triageComment, triagePrompt } from '../phases/dispatch.mjs'
|
|
17
17
|
import { traceWorker } from '../tracing.mjs'
|
|
@@ -29,7 +29,10 @@ import { task } from './task.mjs'
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
/** The nodes an issue in `q:intake` can rest at; a marker elsewhere starts triage over at attempt 1. */
|
|
32
|
-
const INTAKE_NODES = new Set(['start-triage', 'triaging', 'retry-triage', 'deferred'])
|
|
32
|
+
const INTAKE_NODES = new Set(['start-triage', 'triaging', 'retry-triage', 'deferred', 'blocked'])
|
|
33
|
+
|
|
34
|
+
/** The open issues among `issue`'s GitHub `blockedBy` links. @param {Issue} issue */
|
|
35
|
+
export const openBlockers = (issue) => (issue.blockedBy ?? []).filter((b) => b.state === 'OPEN').map((b) => b.number)
|
|
33
36
|
|
|
34
37
|
/** The pseudo-branch that names an issue's triage checkout (`<root>/triage-<n>`); never created. @param {number} n */
|
|
35
38
|
export const triageBranch = (n) => `cambium/triage-${n}`
|
|
@@ -110,6 +113,8 @@ const needsHuman = (/** @type {Triaged} */ o) => verdictOf(o) === 'needs-human'
|
|
|
110
113
|
const duplicate = (/** @type {Triaged} */ o) => verdictOf(o) === 'duplicate'
|
|
111
114
|
const obsolete = (/** @type {Triaged} */ o) => verdictOf(o) === 'obsolete'
|
|
112
115
|
const defer = (/** @type {Triaged} */ o) => verdictOf(o) === 'defer'
|
|
116
|
+
const blocked = (/** @type {Triaged} */ o) => verdictOf(o) === 'blocked'
|
|
117
|
+
const noneOpen = (/** @type {{ to: string }} */ o) => o.to === 'defer'
|
|
113
118
|
|
|
114
119
|
/** @param {DispatchCtx} ctx */
|
|
115
120
|
export const lostLeaseOf = (ctx) => ({
|
|
@@ -183,7 +188,9 @@ const startTriage = declare(
|
|
|
183
188
|
queued,
|
|
184
189
|
agentsMd,
|
|
185
190
|
deferHours: caps.deferHours,
|
|
186
|
-
deferred:
|
|
191
|
+
deferred:
|
|
192
|
+
m0.deferReason && !m0.blockedBy?.length ? { count: m0.defers ?? 0, reason: m0.deferReason } : null,
|
|
193
|
+
blocked: m0.blockedBy?.length ? { by: m0.blockedBy, reason: m0.deferReason ?? '' } : null,
|
|
187
194
|
}),
|
|
188
195
|
})
|
|
189
196
|
} catch (err) {
|
|
@@ -455,21 +462,27 @@ const deferred = declare(
|
|
|
455
462
|
}
|
|
456
463
|
const hours = d.recheckHours ?? deferHours
|
|
457
464
|
const until = iso(ctx.tick.now + hours * 60 * MIN)
|
|
458
|
-
await land(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
465
|
+
await land(
|
|
466
|
+
ctx,
|
|
467
|
+
'deferred',
|
|
468
|
+
{
|
|
469
|
+
...withHistory(m, {
|
|
470
|
+
at: iso(ctx.tick.now),
|
|
471
|
+
attempt: m.attempt,
|
|
472
|
+
outcome: 'defer',
|
|
473
|
+
reason: d.reason,
|
|
474
|
+
log: d.log,
|
|
475
|
+
}),
|
|
476
|
+
defers,
|
|
477
|
+
deferUntil: until,
|
|
478
|
+
deferReason: d.reason,
|
|
479
|
+
blockedBy: null,
|
|
480
|
+
host: null,
|
|
481
|
+
start: null,
|
|
482
|
+
input: null,
|
|
483
|
+
},
|
|
484
|
+
{ extra: [WAIT.deferred] },
|
|
485
|
+
)
|
|
473
486
|
ctx.log('info', `triage deferred until ${until} (${defers}/${maxDefers}): ${d.reason.split('\n')[0]}`, {
|
|
474
487
|
repo: ctx.subject.slug,
|
|
475
488
|
issue: issue.number,
|
|
@@ -480,6 +493,77 @@ const deferred = declare(
|
|
|
480
493
|
{ queue: Q.intake, running: false },
|
|
481
494
|
)
|
|
482
495
|
|
|
496
|
+
const BlockedIn = z.object({
|
|
497
|
+
blockedBy: z.array(z.number().int().positive()).min(1),
|
|
498
|
+
reason: z.string(),
|
|
499
|
+
log: z.string().optional(),
|
|
500
|
+
})
|
|
501
|
+
const blockedNode = declare(
|
|
502
|
+
defineNode({
|
|
503
|
+
name: 'blocked',
|
|
504
|
+
input: BlockedIn,
|
|
505
|
+
output: z.discriminatedUnion('to', [
|
|
506
|
+
z.object({ to: z.literal('wait'), blockedBy: z.array(z.number().int()) }),
|
|
507
|
+
z.object({ to: z.literal('defer'), reason: z.string(), log: z.string() }),
|
|
508
|
+
]),
|
|
509
|
+
/**
|
|
510
|
+
* Blocked: the issue waits on other issues. Each one triage named that GitHub does not link yet is added as a
|
|
511
|
+
* `blockedBy` link; then the issue rests here in `q:intake` with `wait:blocked` and no `deferUntil`. Schedule
|
|
512
|
+
* does not triage it while any `blockedBy` issue is open, and triages it the tick after the last one closes.
|
|
513
|
+
* Not a defer: `maxDefers` does not count it. Schedule also parks an untriaged issue here that GitHub already
|
|
514
|
+
* shows blocked. When none of the named issues is open (closed, or the link failed) it is a plain defer.
|
|
515
|
+
* @param {z.infer<typeof BlockedIn>} b @param {DispatchCtx} ctx
|
|
516
|
+
*/
|
|
517
|
+
run: async (b, ctx) => {
|
|
518
|
+
const { slug } = ctx.subject
|
|
519
|
+
const issue = issueOf(ctx)
|
|
520
|
+
const m = markerOf(issue)
|
|
521
|
+
const links = [...(issue.blockedBy ?? [])]
|
|
522
|
+
for (const n of b.blockedBy) {
|
|
523
|
+
if (n === issue.number || links.some((l) => l.number === n)) continue
|
|
524
|
+
try {
|
|
525
|
+
const { state } = await ctx.github.addBlockedBy(slug, issue.number, n)
|
|
526
|
+
links.push({ number: n, state, closedAt: null })
|
|
527
|
+
ctx.log('info', `linked blockedBy #${n}`, { repo: slug, issue: issue.number })
|
|
528
|
+
} catch (err) {
|
|
529
|
+
ctx.log('warn', `could not link blockedBy #${n}: ${errText(err)}`, { repo: slug, issue: issue.number })
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
issue.blockedBy = links
|
|
533
|
+
const open = openBlockers(issue)
|
|
534
|
+
const list = b.blockedBy.map((n) => `#${n}`).join(', ')
|
|
535
|
+
if (!open.length)
|
|
536
|
+
return { to: 'defer', reason: `blocked by ${list}, but none is open. ${b.reason}`, log: b.log ?? '' }
|
|
537
|
+
await land(
|
|
538
|
+
ctx,
|
|
539
|
+
'blocked',
|
|
540
|
+
{
|
|
541
|
+
...withHistory(m, {
|
|
542
|
+
at: iso(ctx.tick.now),
|
|
543
|
+
attempt: m.attempt,
|
|
544
|
+
outcome: 'blocked',
|
|
545
|
+
reason: `${open.map((n) => `#${n}`).join(', ')}: ${b.reason}`,
|
|
546
|
+
...(b.log ? { log: b.log } : {}),
|
|
547
|
+
}),
|
|
548
|
+
deferUntil: null,
|
|
549
|
+
deferReason: b.reason,
|
|
550
|
+
blockedBy: open,
|
|
551
|
+
host: null,
|
|
552
|
+
start: null,
|
|
553
|
+
input: null,
|
|
554
|
+
},
|
|
555
|
+
{ extra: [WAIT.blocked] },
|
|
556
|
+
)
|
|
557
|
+
ctx.log('info', `blocked by ${open.map((n) => `#${n}`).join(', ')}: ${b.reason.split('\n')[0]}`, {
|
|
558
|
+
repo: slug,
|
|
559
|
+
issue: issue.number,
|
|
560
|
+
})
|
|
561
|
+
return { to: 'wait', blockedBy: open }
|
|
562
|
+
},
|
|
563
|
+
}),
|
|
564
|
+
{ queue: Q.intake, running: false },
|
|
565
|
+
)
|
|
566
|
+
|
|
483
567
|
const ObsIn = z.object({ reason: z.string(), log: z.string() })
|
|
484
568
|
const closeObsolete = declare(
|
|
485
569
|
defineNode({
|
|
@@ -527,7 +611,7 @@ export const dispatch = defineGraph({
|
|
|
527
611
|
name: 'dispatch',
|
|
528
612
|
version: 1,
|
|
529
613
|
entry: { queue: Q.intake, node: 'start-triage', input: () => ({}) },
|
|
530
|
-
nodes: [startTriage, triaging, retryTriage, toTask, toHuman, closeDuplicate, deferred, closeObsolete],
|
|
614
|
+
nodes: [startTriage, triaging, retryTriage, toTask, toHuman, closeDuplicate, deferred, blockedNode, closeObsolete],
|
|
531
615
|
edges: [
|
|
532
616
|
['start-triage', 'triaging', started, (o) => ({ attempt: o.attempt })],
|
|
533
617
|
['start-triage', 'to-human', budgetSpent],
|
|
@@ -537,6 +621,7 @@ export const dispatch = defineGraph({
|
|
|
537
621
|
['triaging', 'to-task', actionable, (o) => ({ ...pick(o.result, ['reason', 'title', 'acceptance']), log: o.log })],
|
|
538
622
|
['triaging', 'close-duplicate', duplicate, (o) => ({ ...pick(o.result, ['duplicateOf', 'reason']), log: o.log })],
|
|
539
623
|
['triaging', 'deferred', defer, (o) => ({ ...pick(o.result, ['reason', 'recheckHours']), log: o.log })],
|
|
624
|
+
['triaging', 'blocked', blocked, (o) => ({ blockedBy: o.result.blockedBy, reason: o.result.reason, log: o.log })],
|
|
540
625
|
['triaging', 'close-obsolete', obsolete, (o) => ({ reason: o.result.reason, log: o.log })],
|
|
541
626
|
['triaging', 'to-human', needsHuman, (o) => ({ reason: o.result.reason, outcome: 'needs-human', log: o.log })],
|
|
542
627
|
['triaging', 'to-human'],
|
|
@@ -547,6 +632,8 @@ export const dispatch = defineGraph({
|
|
|
547
632
|
['close-duplicate', END],
|
|
548
633
|
['deferred', 'to-human', budgetSpent],
|
|
549
634
|
['deferred', END],
|
|
635
|
+
['blocked', 'deferred', noneOpen, (o) => ({ reason: o.reason, log: o.log })],
|
|
636
|
+
['blocked', END],
|
|
550
637
|
['close-obsolete', END],
|
|
551
638
|
],
|
|
552
639
|
})
|
package/src/labels.mjs
CHANGED
|
@@ -7,6 +7,12 @@ export const Q = /** @type {const} */ ({
|
|
|
7
7
|
})
|
|
8
8
|
export const QUEUE_LABELS = Object.values(Q)
|
|
9
9
|
export const RUNNING = 'running'
|
|
10
|
+
/**
|
|
11
|
+
* A parked `q:intake` issue triage already looked at, so canopy can tell it from one awaiting triage:
|
|
12
|
+
* `wait:deferred` rests at the dispatch graph's `deferred` node until `deferUntil`; `wait:blocked` has open GitHub
|
|
13
|
+
* `blockedBy` issues. Any queue move drops them unless it names one again.
|
|
14
|
+
*/
|
|
15
|
+
export const WAIT = /** @type {const} */ ({ deferred: 'wait:deferred', blocked: 'wait:blocked' })
|
|
10
16
|
export const WHY = /** @type {const} */ ({
|
|
11
17
|
budget: 'why:budget',
|
|
12
18
|
reject: 'why:reject',
|
|
@@ -25,7 +31,10 @@ export function move(labels, target, { running = false, extra = [] } = {}) {
|
|
|
25
31
|
const want = new Set([...(target ? [target] : []), ...extra, ...(running ? [RUNNING] : [])])
|
|
26
32
|
const leaving = (/** @type {string} */ l) =>
|
|
27
33
|
!want.has(l) &&
|
|
28
|
-
((l.startsWith('q:') && l !== target) ||
|
|
34
|
+
((l.startsWith('q:') && l !== target) ||
|
|
35
|
+
l === RUNNING ||
|
|
36
|
+
(l.startsWith('why:') && target !== Q.human) ||
|
|
37
|
+
l.startsWith('wait:'))
|
|
29
38
|
return {
|
|
30
39
|
add: [...want].filter((l) => !labels.includes(l)),
|
|
31
40
|
remove: labels.filter(leaving),
|
package/src/marker.mjs
CHANGED
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
* defers?: number,
|
|
48
48
|
* deferUntil?: string | null,
|
|
49
49
|
* deferReason?: string | null,
|
|
50
|
+
* blockedBy?: number[] | null,
|
|
50
51
|
* }} Marker
|
|
51
52
|
* `mergeRefusal`: the last `graft pr merge` cambium was refused (PR graph `merge`), and on which head.
|
|
52
53
|
* `reworks`: how many times the PR graph sent this issue's PR back to a worker.
|
|
53
54
|
* `defers`, `deferUntil`, `deferReason`: the dispatch graph's `deferred` node: how many times triage deferred, until
|
|
54
|
-
* when, and what the next triage should check.
|
|
55
|
+
* when, and what the next triage should check. At the `blocked` node `deferReason` is why and `blockedBy` the open
|
|
56
|
+
* GitHub `blockedBy` issues it waits on (no `deferUntil`).
|
|
55
57
|
* `triage`: what the dispatch graph's triage added when it handed the issue to `q:task`; the task prompt shows it.
|
|
56
58
|
* @typedef {{ graph: string, entryNode: string, nodes?: Iterable<string> }} QueueOwner
|
|
57
59
|
*/
|
|
@@ -180,7 +182,10 @@ export function renderMarker(input, { maxAttempts } = {}) {
|
|
|
180
182
|
(marker.pr ? ` · PR #${marker.pr}` : '') +
|
|
181
183
|
(marker.host ? ` · host \`${marker.host}\`` : '') +
|
|
182
184
|
(marker.start ? ` · started ${marker.start}` : '') +
|
|
183
|
-
(marker.node === 'deferred' && marker.deferUntil ? ` · re-triage after ${marker.deferUntil}` : '')
|
|
185
|
+
(marker.node === 'deferred' && marker.deferUntil ? ` · re-triage after ${marker.deferUntil}` : '') +
|
|
186
|
+
(marker.node === 'blocked' && marker.blockedBy?.length
|
|
187
|
+
? ` · re-triage once ${marker.blockedBy.map((n) => `#${n}`).join(', ')} close`
|
|
188
|
+
: ''),
|
|
184
189
|
]
|
|
185
190
|
if (marker.lastFailure)
|
|
186
191
|
lines.push(
|
package/src/phases/dispatch.mjs
CHANGED
|
@@ -21,8 +21,9 @@ export const DISPATCH_NOT_BUILT = 'dispatch phase is not built yet; q:intake iss
|
|
|
21
21
|
/** The verdict a triage worker ends with, as the last JSON block of its final message. */
|
|
22
22
|
export const TriageResult = z
|
|
23
23
|
.object({
|
|
24
|
-
verdict: z.enum(['actionable', 'needs-human', 'duplicate', 'defer', 'obsolete']),
|
|
24
|
+
verdict: z.enum(['actionable', 'needs-human', 'duplicate', 'defer', 'blocked', 'obsolete']),
|
|
25
25
|
duplicateOf: z.number().int().positive().optional(),
|
|
26
|
+
blockedBy: z.array(z.number().int().positive()).min(1).optional(),
|
|
26
27
|
recheckHours: z.number().positive().max(168).optional(),
|
|
27
28
|
reason: z.string().trim().min(1),
|
|
28
29
|
title: z.string().trim().min(1).optional(),
|
|
@@ -32,6 +33,10 @@ export const TriageResult = z
|
|
|
32
33
|
message: 'a duplicate verdict needs duplicateOf',
|
|
33
34
|
path: ['duplicateOf'],
|
|
34
35
|
})
|
|
36
|
+
.refine((r) => r.verdict !== 'blocked' || r.blockedBy !== undefined, {
|
|
37
|
+
message: 'a blocked verdict needs blockedBy',
|
|
38
|
+
path: ['blockedBy'],
|
|
39
|
+
})
|
|
35
40
|
|
|
36
41
|
/** @typedef {z.infer<typeof TriageResult>} Triage */
|
|
37
42
|
|
|
@@ -100,6 +105,8 @@ export function readTriage(log, issue) {
|
|
|
100
105
|
return { ok: false, error: `invalid triage result: ${parsed.error.issues.map(formatIssue).join('; ')}` }
|
|
101
106
|
if (parsed.data.verdict === 'duplicate' && parsed.data.duplicateOf === issue)
|
|
102
107
|
return { ok: false, error: `invalid triage result: duplicateOf: #${issue} cannot duplicate itself` }
|
|
108
|
+
if (parsed.data.verdict === 'blocked' && parsed.data.blockedBy?.includes(issue))
|
|
109
|
+
return { ok: false, error: `invalid triage result: blockedBy: #${issue} cannot block itself` }
|
|
103
110
|
return { ok: true, result: parsed.data }
|
|
104
111
|
}
|
|
105
112
|
|
|
@@ -111,9 +118,20 @@ export function readTriage(log, issue) {
|
|
|
111
118
|
* repo: string, baseBranch: string, issue: import('../github.mjs').Issue,
|
|
112
119
|
* queued: { number: number, title: string, labels: string[] }[], agentsMd: string | null,
|
|
113
120
|
* deferred?: { count: number, reason: string } | null, deferHours?: number,
|
|
121
|
+
* blocked?: { by: number[], reason: string } | null,
|
|
114
122
|
* }} input
|
|
123
|
+
* `blocked`: an earlier triage parked it on these issues, all closed now.
|
|
115
124
|
*/
|
|
116
|
-
export function triagePrompt({
|
|
125
|
+
export function triagePrompt({
|
|
126
|
+
repo,
|
|
127
|
+
baseBranch,
|
|
128
|
+
issue,
|
|
129
|
+
queued,
|
|
130
|
+
agentsMd,
|
|
131
|
+
deferred = null,
|
|
132
|
+
deferHours = 6,
|
|
133
|
+
blocked = null,
|
|
134
|
+
}) {
|
|
117
135
|
const others = queued
|
|
118
136
|
.filter((q) => q.number !== issue.number)
|
|
119
137
|
.map((q) => `- #${q.number} ${q.title} (${q.labels.filter((l) => l.startsWith('q:')).join(', ') || 'no queue'})`)
|
|
@@ -128,20 +146,22 @@ Verdicts:
|
|
|
128
146
|
- needs-human: too foggy to ticket; a decision only a human can make (direction, priority, money, access, policy); information no one but a human has; or work that is not a code change in this repository. \`reason\` says exactly what the human must decide or supply. Never for something a machine can check, now or later.
|
|
129
147
|
- duplicate: the same work as another issue, open or closed. \`duplicateOf\` is that issue's number (never #${issue.number}); \`reason\` says why they are the same.
|
|
130
148
|
- obsolete: the work no longer applies, and you verified it: the code path is gone, the bug is already fixed on ${baseBranch}, or its verification already passed. cambium closes it as not planned. \`reason\` gives the evidence (commit, file, run).
|
|
131
|
-
- defer: the verdict hangs on something a machine can check later but not yet: a CI or CD run that has not happened, a release, a PR still merging, a deploy, an upstream fix. cambium triages it again after \`recheckHours\` (default ${deferHours}). \`reason\` says exactly what to check next time and what each answer means (e.g. "next main cd run green → obsolete; red → actionable").
|
|
149
|
+
- defer: the verdict hangs on something a machine can check later but not yet: a CI or CD run that has not happened, a release, a PR still merging, a deploy, an upstream fix. cambium triages it again after \`recheckHours\` (default ${deferHours}). \`reason\` says exactly what to check next time and what each answer means (e.g. "next main cd run green → obsolete; red → actionable"). Not for waiting on another issue: that is blocked.
|
|
150
|
+
- blocked: it cannot start until other issues in ${repo} are done. \`blockedBy\` lists their numbers (never #${issue.number}); cambium records each as a GitHub "blocked by" link on this issue and triages it again as soon as the last of them closes, not on a timer. \`reason\` says what each blocker must deliver.
|
|
132
151
|
|
|
133
152
|
How to look:
|
|
134
153
|
- Read the code here (Read, Glob, Grep) to judge what the change touches and whether it already exists.
|
|
135
154
|
- First, has it already been done? Its comments (\`graft api GET /repos/${repo}/issues/${issue.number}/comments\`) and its timeline (\`graft api GET '/repos/${repo}/issues/${issue.number}/timeline?per_page=100'\`: cross-referenced PRs, and whether they merged) often say so. A merged PR whose change is on ${baseBranch}, and nothing left of the issue, is obsolete; a PR still open or in CI is defer.
|
|
155
|
+
- Does it already wait on other issues? Its GitHub "blocked by" links: \`graft api GET /repos/${repo}/issues/${issue.number}/dependencies/blocked_by\`. An open one, or prose naming an open issue it needs first, is blocked.
|
|
136
156
|
- Read an issue with \`graft issue read <n>\`; search with \`graft api GET '/search/issues?q=repo:${repo}+is:issue+<words>'\`. Never \`gh\`.
|
|
137
157
|
- Be quick: a verdict, not an investigation. When in doubt whether the work is clear enough to do, choose needs-human; when in doubt whether something is true, check it, or defer until it can be checked.
|
|
138
158
|
|
|
139
159
|
End your final message with exactly one fenced JSON block, and nothing after it:
|
|
140
160
|
\`\`\`json
|
|
141
|
-
{ "verdict": "actionable" | "needs-human" | "duplicate" | "obsolete" | "defer", "duplicateOf": 123, "recheckHours": 6, "reason": "…", "title": "…", "acceptance": ["…"] }
|
|
161
|
+
{ "verdict": "actionable" | "needs-human" | "duplicate" | "obsolete" | "defer" | "blocked", "duplicateOf": 123, "blockedBy": [124], "recheckHours": 6, "reason": "…", "title": "…", "acceptance": ["…"] }
|
|
142
162
|
\`\`\`
|
|
143
|
-
\`duplicateOf\` only for duplicate; \`recheckHours\` only for defer, and optional; \`title\` and \`acceptance\` only for actionable, and optional. A missing or malformed block sends the issue to a human with the error.
|
|
144
|
-
${deferred ? `\nThis is re-triage ${deferred.count + 1}: an earlier triage deferred it to check this:\n${deferred.reason}\nCheck it now. If it still cannot be checked, defer again.\n` : ''}${others ? `\nOther issues in cambium's queues right now:\n${others}\n` : ''}
|
|
163
|
+
\`duplicateOf\` only for duplicate; \`blockedBy\` only for blocked; \`recheckHours\` only for defer, and optional; \`title\` and \`acceptance\` only for actionable, and optional. A missing or malformed block sends the issue to a human with the error.
|
|
164
|
+
${deferred ? `\nThis is re-triage ${deferred.count + 1}: an earlier triage deferred it to check this:\n${deferred.reason}\nCheck it now. If it still cannot be checked, defer again.\n` : ''}${blocked ? `\nAn earlier triage found it blocked by ${blocked.by.map((n) => `#${n}`).join(', ')}, now closed:\n${blocked.reason}\nJudge it again now that they are done.\n` : ''}${others ? `\nOther issues in cambium's queues right now:\n${others}\n` : ''}
|
|
145
165
|
--- Issue #${issue.number}: ${issue.title} (${issue.url})
|
|
146
166
|
${issue.body}
|
|
147
167
|
${agentsMd ? `\n--- AGENTS.md (the contract a task worker will follow)\n${agentsMd}` : ''}`
|