diff --git a/src/commands/mcp.ts b/src/commands/mcp.ts index f17075d..6d63f73 100644 --- a/src/commands/mcp.ts +++ b/src/commands/mcp.ts @@ -505,7 +505,7 @@ export function createServer(ctx: ResolvedContext, rememberOpts: { cwd: string; { description: archived ? unavailable - : 'Take a ticket for a run before starting work on it, so two agents or two runs never work the same ticket. A ticket has one holder: if someone else holds it — or you hold it under a different ref, meaning a run already exists — the claim is refused and tells you who has it; do not start work then. Calling it again with the same holder and ref confirms the claim and updates the stage, so call it on every handoff (build → review → qa). Only pass force when a person tells you to take the ticket over.', + : 'For unattended runs: take a ticket before a run starts work on it, so two agents or two runs never work the same ticket. Do not claim in an ordinary conversation with a person — move the ticket to in_progress and set its assignee instead. A ticket has one holder: if someone else holds it — or you hold it under a different ref, meaning a run already exists — the claim is refused and tells you who has it; do not start work then. Calling it again with the same holder and ref confirms the claim and updates the stage, so call it on every handoff (build → review → qa). Only pass force when a person tells you to take the ticket over.', inputSchema: { key: z.string().min(1).describe('e.g. CAR-3'), holder: z.string().optional().describe('who holds it, e.g. "enso:athena"; defaults to you'), diff --git a/src/commands/work.ts b/src/commands/work.ts index 7fb037a..c4db9e8 100644 --- a/src/commands/work.ts +++ b/src/commands/work.ts @@ -342,8 +342,14 @@ export function workMove(cwd: string, key: string, status: string, input: Change return mutate(cwd, opts, (items, _prefix, actor, at) => { const item = requireItem(items, key) const from = item.status - const change = applyChange(item, { status: to }, { at, by: actor, via: opts.via ?? 'cli', reason, sources: cleanList(input.sources) }) - if (Object.keys(change).length === 0) throw new Error(`work move: ${item.key} is already ${to}`) + // Someone who claimed a ticket by hand (no run behind the claim) and then hands it + // on — to review, done or the archive — has stopped working it: let the claim go with + // the move. A run's claim is its runner's to release. + const held = item.claim + const letGo = held && !held.ref && held.holder === actor && (to === 'review' || to === 'done' || to === 'archived') + if (letGo) delete item.claim + const change = applyChange(item, { status: to }, { at, by: actor, via: opts.via ?? 'cli', reason, sources: cleanList(input.sources) }, letGo && to !== from ? { claim: [describeClaim(held), null] } : {}) + if (!('status' in change)) throw new Error(`work move: ${item.key} is already ${to}`) return { item, message: `move ${item.key} ${from} → ${to} (${reason})`, source: input.sources?.[0] } }) } diff --git a/src/work.ts b/src/work.ts index d73c07d..bf31911 100644 --- a/src/work.ts +++ b/src/work.ts @@ -113,9 +113,14 @@ export function claimIsStale(claim: Pick, now = Date.now() return Number.isFinite(renewed) && now - renewed > hours * 3_600_000 } -/** Open tickets whose holder has gone quiet. */ +/** + * Open tickets whose run has gone quiet. Only a claim that names a run + * (`ref`) is expected to keep confirming itself: a runner heartbeats, a + * person or a chat session that claimed a ticket does not, and their silence + * says nothing. + */ export function staleClaims(items: LoreWorkItem[], now = Date.now(), hours = CLAIM_STALE_HOURS): LoreWorkItem[] { - return items.filter((i) => i.claim && i.state === 'open' && claimIsStale(i.claim, now, hours)) + return items.filter((i) => i.claim?.ref && i.state === 'open' && claimIsStale(i.claim, now, hours)) } export interface LoreWorkItem { diff --git a/test/work-claim.test.ts b/test/work-claim.test.ts index 101dbee..6967892 100644 --- a/test/work-claim.test.ts +++ b/test/work-claim.test.ts @@ -164,3 +164,23 @@ test('work claim: of two machines racing for a ticket through the same origin, t else process.env.LORE_HOME = prevHome } }) + +test('claims: one made by hand is let go when its holder hands the ticket on, and is never reported as quiet', async () => { + const { root } = await fixture() + const as = (by: string, at: string) => ({ context: root, at, by }) + await captureConsole(async () => { + workClaim(root, 'ACM-1', { stage: 'build', status: 'in_progress' }, as('jeff', '2026-09-21T09:00:00.000Z')) + workClaim(root, 'ACM-2', { holder: 'enso:athena', ref: 'WEB-2', stage: 'build' }, as('runner', '2026-09-21T09:00:00.000Z')) + assert.equal(item(root, 'ACM-1').claim!.holder, 'jeff') + + const sent: MailMessage[] = [] + const config = { ...ACME, client: { ...ACME.client!, owner: 'lead@agency.test' } } + assert.deepEqual(await alertStaleClaims(root, config, { send: async (m) => void sent.push(m), now: Date.parse('2026-09-22T09:00:00.000Z') }), ['ACM-2'], 'only the run is expected to check in') + + await workMove(root, 'ACM-2', 'review', { reason: 'a person moved it' }, as('jeff', '2026-09-22T10:00:00.000Z')) + assert.equal(item(root, 'ACM-2').claim!.ref, 'WEB-2', "a run's claim is its runner's to release") + await workMove(root, 'ACM-1', 'review', { reason: 'PR is up' }, as('jeff', '2026-09-22T10:01:00.000Z')) + assert.equal(item(root, 'ACM-1').claim, undefined) + assert.deepEqual(item(root, 'ACM-1').history.at(-1)!.change, { claim: ['jeff @build', null], status: ['in_progress', 'review'] }) + }) +}) diff --git a/web/src/bits.tsx b/web/src/bits.tsx index c7bd235..36625fc 100644 --- a/web/src/bits.tsx +++ b/web/src/bits.tsx @@ -60,7 +60,8 @@ const CLAIM_STALE_MS = 6 * 3_600_000 export function ClaimBadge({ item }: { item: Item }) { const c = item.claim if (!c) return null - const stale = item.state === 'open' && Date.now() - Date.parse(c.renewed) > CLAIM_STALE_MS + // Only a run is expected to keep confirming its claim; a person's claim is never "quiet". + const stale = Boolean(c.ref) && item.state === 'open' && Date.now() - Date.parse(c.renewed) > CLAIM_STALE_MS const label = `${c.holder}${c.stage ? ` · ${c.stage}` : ''}` const title = `Held by ${c.holder}${c.ref ? ` (${c.ref})` : ''} , claimed ${ago(c.since)}${stale ? ` — last heard from ${ago(c.renewed)}` : ''}` return (