From 402ffd0131e6aabd47790b3f93b7651b8a129284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannik=20A=C3=9Ffalg?= <67785539+repeat98@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:27:09 +0100 Subject: [PATCH] Fix: the board check counts a run claimed ahead of the work as covering the part a branch adds A hook claim on digitakt-ii/tables/4-6 now covers a branch that adds tables 4-5, so #1999 no longer fails as unclaimed. pr:ready renews a covering run whole. Co-Authored-By: Claude Opus 5.5 --- docs/AGENT_BOARD.md | 2 +- scripts/agent-board.mjs | 10 ++++++---- scripts/agent-board.test.mjs | 17 +++++++++++++++++ scripts/pr-ready.mjs | 5 +++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/AGENT_BOARD.md b/docs/AGENT_BOARD.md index a8ea131f32..a5d172bda0 100644 --- a/docs/AGENT_BOARD.md +++ b/docs/AGENT_BOARD.md @@ -9,7 +9,7 @@ A claim has a kind and a key, and each key has one holder at a time: | Kind | Key | Example | | --- | --- | --- | | `module` | machine and module id | `octatrack/tape-echo`, `digitone/swarm` | -| `hook` | machine and hook or table index: its `index` in `sdk/machines/octatrack/events.json`, or its place in the core's `interface.json` on the elemod machines. Consecutive new indices are one claim on a run, which `pr:ready` makes and which takes the place of your own claims inside it | `octatrack/39`, `octatrack/38-51`, `digitakt/events/7`, `digitakt/tables/1` | +| `hook` | machine and hook or table index: its `index` in `sdk/machines/octatrack/events.json`, or its place in the core's `interface.json` on the elemod machines. Consecutive new indices are one claim on a run, which `pr:ready` makes and which takes the place of your own claims inside it. A run claimed ahead of the work also covers a branch that adds only part of it | `octatrack/39`, `octatrack/38-51`, `digitakt/events/7`, `digitakt/tables/1` | | `migration` | D1 migration number | `0085` | | `dsp-region` | machine and DSP memory claim name; no file declares these yet, so they are claimed by hand | `octatrack/fx2-delay-line` | | `machine-id` | machine and the id a manifest takes in `platform.claims` (`machine:`); kits store it, so like a hook index it is never renumbered | `digitakt/10` | diff --git a/scripts/agent-board.mjs b/scripts/agent-board.mjs index 90b438fd27..2e44469c75 100644 --- a/scripts/agent-board.mjs +++ b/scripts/agent-board.mjs @@ -202,6 +202,7 @@ export function neededClaims({ root, base, head = 'HEAD' }) { const hookSpan = key => { const [, list, first, last] = /^(.+)\/(\d+)(?:-(\d+))?$/.exec(key); return { list, first: Number(first), last: Number(last ?? first) } } const overlaps = (a, b) => { const x = hookSpan(a), y = hookSpan(b); return x.list === y.list && x.first <= y.last && y.first <= x.last } +const covers = (a, b) => { const x = hookSpan(a), y = hookSpan(b); return x.list === y.list && x.first <= y.first && y.last <= x.last } /** Consecutive new hook indices of one list become one claim (octatrack/38-51): a base change may add more hooks than * one person may hold claims. */ function hookRuns(items) { @@ -224,13 +225,14 @@ export async function compareClaims(needed, login, { pullRequest, ...options } = const claims = await listClaims({}, options), byKey = new Map(claims.map(item => [item.kind + ' ' + item.key, item])) const result = { mine: [], others: [], free: [], unknown: [] } for (const item of needed) { - // Hook claims overlap by index; the holder's own inside a run give way to it when the run is claimed. + // Hook claims overlap by index; the holder's own inside a run give way to it when the run is claimed. A run claimed + // ahead of the work (tables/4-6 while the branch adds 4-5 so far) covers the part a branch adds. const near = item.kind === 'hook' ? claims.filter(claim => claim.kind === 'hook' && overlaps(claim.key, item.key)) : [byKey.get(item.kind + ' ' + item.key)].filter(Boolean) - const theirs = login && near.find(claim => claim.holder !== login.toLowerCase() && !(pullRequest && claim.pullRequest === pullRequest)), exact = near.find(claim => claim.key === item.key) + const theirs = login && near.find(claim => claim.holder !== login.toLowerCase() && !(pullRequest && claim.pullRequest === pullRequest)), held = near.find(claim => claim.key === item.key) ?? (item.kind === 'hook' ? near.find(claim => covers(claim.key, item.key)) : undefined) if (!near.length) result.free.push(item) else if (!login) result.unknown.push({ ...item, claim: near[0] }) else if (theirs) result.others.push({ ...item, claim: theirs }) - else if (exact) result.mine.push({ ...item, claim: exact }) + else if (held) result.mine.push({ ...item, claim: held }) else result.free.push(item) } return result @@ -375,7 +377,7 @@ export function branchVerdict(compared, { requireClaims = false } = {}) { const lines = [] for (const item of compared.others) lines.push(`✗ ${item.kind} ${item.key} (${item.why}) is claimed by ${describeClaim(item.claim)}. Ask them, or renumber / rename.`) for (const item of compared.unknown) lines.push(`· ${item.kind} ${item.key} is claimed by ${describeClaim(item.claim)}; sign in (npm run board -- login) so the check can tell whether that is you.`) - for (const item of compared.mine) lines.push(`✓ ${item.kind} ${item.key}: yours.`) + for (const item of compared.mine) lines.push(`✓ ${item.kind} ${item.key}: yours${item.claim && item.claim.key !== item.key ? ' (claim ' + item.claim.key + ')' : ''}.`) for (const item of compared.free) lines.push(requireClaims ? `✗ ${item.kind} ${item.key} (${item.why}) is unclaimed. Claim it so nobody else starts the same work: npm run board -- login once, then npm run pr:ready (it claims what the branch adds) or npm run board -- claim ${item.kind} ${item.key}. Then rerun this check.` : `· ${item.kind} ${item.key} (${item.why}) is unclaimed: npm run board -- claim ${item.kind} ${item.key}`) diff --git a/scripts/agent-board.test.mjs b/scripts/agent-board.test.mjs index 9d6d7a1052..1a1309dba4 100644 --- a/scripts/agent-board.test.mjs +++ b/scripts/agent-board.test.mjs @@ -91,6 +91,17 @@ describe('the board client', () => { expect((await compare(claimRow('hook', 'octatrack/38-51', 'ada'))).mine).toHaveLength(1) expect((await compare(claimRow('hook', 'octatrack/events/40', 'bo'), claimRow('hook', 'octatrack/52', 'bo'))).free).toHaveLength(1) }) + it('counts a run claimed ahead of the work as covering the part a branch adds', async () => { + const needed = [{ kind: 'hook', key: 'digitakt-ii/tables/4-5' }] + const compare = (claims, pullRequest) => board.compareClaims(needed, 'Ada', { fetch: answer(200, { claims }), pullRequest }) + expect((await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'ada')])).mine[0].claim.key).toBe('digitakt-ii/tables/4-6') + expect((await compare([{ ...claimRow('hook', 'digitakt-ii/tables/4-6', 'claptom'), pullRequest: 1999 }], 1999)).mine).toHaveLength(1) + expect((await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'bo')])).others).toHaveLength(1) + expect((await compare([claimRow('hook', 'digitakt-ii/tables/4', 'ada')])).free).toHaveLength(1) + expect((await compare([claimRow('hook', 'digitakt-ii/tables/5-6', 'ada')])).free).toHaveLength(1) + expect((await compare([claimRow('hook', 'digitakt-ii/events/4-6', 'ada')])).free).toHaveLength(1) + expect(board.branchVerdict(await compare([claimRow('hook', 'digitakt-ii/tables/4-6', 'ada')]), { requireClaims: true })).toEqual({ ok: true, lines: ['✓ hook digitakt-ii/tables/4-5: yours (claim digitakt-ii/tables/4-6).'] }) + }) it('fails an unclaimed item only in a pull request run, and someone else\'s claim always', () => { const free = { mine: [], others: [], unknown: [], free: [{ kind: 'module', key: 'octatrack/drummap', why: 'new module' }] } expect(board.branchVerdict(free).ok).toBe(true) @@ -227,6 +238,12 @@ describe('pr:ready and the board', () => { expect(await run({ claims: [handWritten] })).toEqual([{ kind: 'module', key: 'octatrack/slicer', branch: 'work', note: 'Slices a loop.' }, { kind: 'module', key: 'octatrack/echo', branch: 'work' }]) expect((await run({ refuseNotes: true })).map(item => item.key + (item.note ? ' + note' : ''))).toEqual(['octatrack/slicer + note', 'octatrack/slicer', 'octatrack/echo + note', 'octatrack/echo']) }) + it('renews a covering run whole instead of claiming only the part the branch adds', async () => { + const { taken, module } = fake({ claims: [claimRow('hook', 'octatrack/36-38', 'ada')] }) + const result = await boardClaims('.', 'main', module) + expect(taken.map(item => item.key)).toEqual(['0084', 'octatrack/36-38']) + expect(result.notes).toContain('Board: claimed hook octatrack/36-38 for @ada.') + }) it('only notes an unreachable board', async () => { const result = await boardClaims('.', 'main', fake({ fail: true }).module) expect(readiness({ board: result })).toMatchObject({ ok: true, notes: expect.arrayContaining([expect.stringContaining('claims not checked')]) }) diff --git a/scripts/pr-ready.mjs b/scripts/pr-ready.mjs index 3acc372d63..9de0f06dbd 100644 --- a/scripts/pr-ready.mjs +++ b/scripts/pr-ready.mjs @@ -130,9 +130,10 @@ export async function boardClaims(root, base, board) { else for (const item of open) { try { // A claim says what the work is; a note its holder wrote by hand stays, and one the server refuses never costs the claim. - const request = { kind: item.kind, key: item.key, branch: board.currentBranch(root) }, note = item.claim?.note ? '' : item.note + // A run you hold that covers this item is renewed whole, so claiming the part never gives up the rest of the run. + const request = { kind: item.kind, key: item.claim?.key ?? item.key, branch: board.currentBranch(root) }, note = item.claim?.note ? '' : item.note const result = note ? await board.claim({ ...request, note }).catch(error => { if (error instanceof board.BoardError && error.status === 400) return board.claim(request); throw error }) : await board.claim(request) - notes.push((result.renewed ? 'Board: renewed your claim on ' : 'Board: claimed ') + item.kind + ' ' + item.key + ' for @' + login + '.') + notes.push((result.renewed ? 'Board: renewed your claim on ' : 'Board: claimed ') + item.kind + ' ' + request.key + ' for @' + login + '.') } catch (error) { if (error instanceof board.BoardUnavailable) { notes.push('Board: could not claim ' + item.kind + ' ' + item.key + '. ' + error.message); continue } problems.push('Board: ' + item.kind + ' ' + item.key + ': ' + error.message)