Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .claude/skills/orchestrate/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,19 @@ the same defect then taxes every later run until somebody schedules it.

So once every ticket in the run is merged or stopped, and NOTHING is still executing:

1. **The run ticket stays the record; each defect gets its own CHILD ticket to be fixed
from.** The aggregate ticket above is one per RUN and cannot carry N repair PRs: it would
close on the first merge, leaving the rest with no live issue to launch from, attach to or
close, and `launch-worker.mjs` derives the worktree name and branch from the issue, so two
PRs off one issue collide before that even matters. So file one child ticket per ledger
entry (`orca linear create --parent <run ticket>`), each passing `check-ticket.mjs`, each
describing ONE defect. A ledger with exactly one entry needs no child: the run ticket is
already that shape.
1. **The run ticket stays the durable record of every ledger entry; only recurring or blocking
defects get a CHILD ticket to be fixed from.** Create a child
(`orca linear create --parent <run ticket>`) when the defect occurred on at least three
tickets or blocked the run. Record every entry below that threshold in the parent ticket's
body with its evidence. If later evidence raises a recorded entry to three occurrences or
shows that it blocked a run, create its child then from the accumulated evidence.
Each child describes ONE defect, passes `check-ticket.mjs`, and contains this fixed line:
`Ledger occurrence: <count>; blocked: no|<what it blocked>`. Use `no` only for a
non-blocking defect; a blocking value must name the run step, ticket, or operation that
could not proceed. The aggregate ticket above cannot carry N repair PRs: it would close on
the first merge, leaving the rest with no live issue to launch from, attach to or close,
and `launch-worker.mjs` derives the worktree name and branch from the issue, so two PRs off
one issue collide before that even matters.
2. Work the children one PR per ticket, through the same worker machinery as any ticket. The
run is over, so editing `tools/`, this skill or `.claude/orchestrator.json` no longer
changes a contract anything is executing.
Expand Down
80 changes: 80 additions & 0 deletions tools/check-ticket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import { execFileSync } from "node:child_process"
import { existsSync, readFileSync } from "node:fs"
import { request } from "node:https"
import { homedir } from "node:os"
import { join } from "node:path"

const USAGE = `usage: check-ticket.mjs --issue ORB-12 | --file body.md

Expand Down Expand Up @@ -38,6 +41,8 @@ const REQUIRED_SECTIONS = [

/** D4: one ticket = one repo. repo:both is a defect, not a label. */
const REPO_LABELS = ["repo:ui", "repo:api", "repo:landing"]
const LEDGER_OCCURRENCE_THRESHOLD = 3
const LEDGER_OCCURRENCE_FORMAT = "Ledger occurrence: <count>; blocked: no|<what it blocked>"

const problems = []
const require_ = (condition, message) => {
Expand Down Expand Up @@ -82,6 +87,74 @@ const validateLabels = (labels) => {
}
}

const isLedgerChild = (issue, relations) => {
if (issue.parent) return true
return relations.some((relation) => {
Comment thread
thomasluizon marked this conversation as resolved.
Resolved
const relationship = relation.relationship ?? relation.type
return relationship === "parent" || relationship === "childOf"
})
}

const readLinearParent = async (issue) => {
if (!issue.id || Object.hasOwn(issue, "parent")) return issue.parent ?? null
const keyPath = join(process.env.USERPROFILE || homedir(), ".linear-api-key")
if (!existsSync(keyPath)) throw new Error(`missing ${keyPath}`)
const apiKey = readFileSync(keyPath, "utf8").trim()
if (!apiKey) throw new Error(`${keyPath} is empty`)
const requestBody = JSON.stringify({
query: "query($id: String!) { issue(id: $id) { parent { id identifier } } }",
variables: { id: issue.id },
})
const response = await new Promise((resolve, reject) => {
const linearRequest = request("https://api.linear.app/graphql", {
method: "POST",
agent: false,
headers: {
Authorization: apiKey,
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(requestBody),
},
}, (linearResponse) => {
const chunks = []
linearResponse.on("data", (chunk) => chunks.push(chunk))
linearResponse.on("end", () => resolve({
status: linearResponse.statusCode ?? 0,
body: Buffer.concat(chunks).toString("utf8"),
}))
})
linearRequest.on("error", reject)
linearRequest.end(requestBody)
})
const payload = JSON.parse(response.body)
if (response.status < 200 || response.status >= 300 || payload.errors) {
throw new Error(payload.errors?.[0]?.message ?? `HTTP ${response.status}`)
}
return payload.data?.issue?.parent ?? null
}

const validateLedgerOccurrence = (body) => {
const occurrenceLine = body.split(/\r?\n/).find((line) => line.startsWith("Ledger occurrence:"))
if (!occurrenceLine) {
problems.push(`ledger child is missing the fixed line: ${LEDGER_OCCURRENCE_FORMAT}`)
return
}
const parsedLine = occurrenceLine.match(/^Ledger occurrence: (\d+); blocked: ([^\r\n]+)$/)
if (!parsedLine) {
problems.push(`ledger occurrence line is unparseable; expected: ${LEDGER_OCCURRENCE_FORMAT}`)
return
}
const occurrenceCount = Number(parsedLine[1])
if (occurrenceCount >= LEDGER_OCCURRENCE_THRESHOLD) return
const blockingClaim = parsedLine[2].trim()
if (!blockingClaim || /^(yes|true|blocked)[.!]?$/i.test(blockingClaim)) {
Comment thread
thomasluizon marked this conversation as resolved.
Resolved
problems.push(`ledger child carries a bare blocking claim; name what it blocked`)
return
}
if (blockingClaim.toLowerCase() === "no") {
problems.push(`ledger child states ${occurrenceCount} occurrences, below the threshold of ${LEDGER_OCCURRENCE_THRESHOLD}, without a blocking claim naming what it blocked`)
}
}

const mode = process.argv[2]
const target = process.argv[3]

Expand Down Expand Up @@ -110,6 +183,13 @@ if (mode === "--file") {
validateBody(body)
validateLabels(labels)
const relations = parsedResult.relations ?? issue.relations ?? []
try {
issue.parent ??= await readLinearParent(issue)
Comment thread
thomasluizon marked this conversation as resolved.
Resolved
} catch (error) {
console.error(`check-ticket: could not read the Linear parent relation: ${error instanceof Error ? error.message : String(error)}`)
process.exit(2)
}
if (isLedgerChild(issue, relations)) validateLedgerOccurrence(body)
const blockedBy = relations.filter((r) => r.relationship === "blockedBy" || r.type === "blockedBy")
if (/\b(after|once|depends on|blocked by)\b/i.test(body) && blockedBy.length === 0) {
problems.push("body PROSE mentions a dependency but the issue has no blockedBy relation; the DAG is explicit, never inferred from titles (6.2)")
Expand Down
42 changes: 42 additions & 0 deletions tools/test-tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,48 @@ const gateCases = {
"check-ticket.mjs": () => {
check("check-ticket.mjs", "an incomplete body is rejected", ["--file", stage("ticket.md", "# A ticket\n\nno template sections here\n")], { nonZero: true })
check("check-ticket.mjs", "a missing body file is a usage error", ["--file", join(root, "absent.md")], { status: 2 })
const ledgerIssue = (line) => ({
...VALID_ISSUE,
description: `${VALID_TICKET_BODY}\n\n${line}`,
parent: { identifier: "ORB-140" },
})
const checkIssue = (name, issue, expect) =>
check(
"check-ticket.mjs",
name,
["--issue", issue.identifier],
expect,
{ env: orcaEnv([{ match: `linear issue ${issue.identifier}`, stdout: JSON.stringify({ ok: true, result: { issue, relations: [] } }) }]) },
)

checkIssue("a ledger child with 7 occurrences passes", ledgerIssue("Ledger occurrence: 7; blocked: no"), { status: 0, stdout: /ticket ok/ })
checkIssue("a ledger child at the threshold of 3 occurrences passes", ledgerIssue("Ledger occurrence: 3; blocked: no"), { status: 0, stdout: /ticket ok/ })
checkIssue(
"a non-blocking ledger child below the threshold fails with the count and threshold",
ledgerIssue("Ledger occurrence: 2; blocked: no"),
{ status: 1, stderr: /2[\s\S]*threshold of 3/i },
)
checkIssue(
"a below-threshold ledger child passes when it names what blocked the run",
ledgerIssue("Ledger occurrence: 2; blocked: the merge sweep could not merge qualifying PRs"),
{ status: 0, stdout: /ticket ok/ },
)
checkIssue(
"a bare blocking claim does not bypass the threshold",
ledgerIssue("Ledger occurrence: 2; blocked: yes"),
{ status: 1, stderr: /bare blocking claim; name what it blocked/i },
)
checkIssue(
"a ledger child with no occurrence line fails",
{ ...VALID_ISSUE, parent: { identifier: "ORB-140" } },
{ status: 1, stderr: /missing[\s\S]*Ledger occurrence/i },
)
checkIssue("a recorded non-ledger ticket is unaffected", VALID_ISSUE, { status: 0, stdout: /ticket ok/ })
checkIssue(
"an unparseable ledger occurrence line fails",
ledgerIssue("Ledger occurrence: several; blocked: no"),
{ status: 1, stderr: /ledger occurrence line is unparseable/i },
)
},
"check-push-target.mjs": () => {
check("check-push-target.mjs", "a push to main is blocked", [], { status: 1, stderr: /BLOCKED/ }, { input: "refs/heads/main abc refs/heads/main def\n" })
Expand Down