Skip to content

Commit 3a4e21e

Browse files
committed
workflow: skip the store write when the same Bot already holds the card
A second assign({ botId }) for a card the same Bot holds rewrote the store with identical bytes, so the file's mtime moved (CI caught it on #2487). Return the ingest legs' already:true shape before rememberClaim/write(); the card's line and the store stay untouched.
1 parent 2fdab99 commit 3a4e21e

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎plugins/workflow/src/service.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,11 @@ export function createWorkflowService({
942942
const taskId = cleanLine(body.taskId ?? body.id, 80)
943943
const title = cleanLine(body.title, 300)
944944
if (!taskId || !title) return { ok: false, error: 'A task needs an id and a title' }
945+
// #2485: the same Bot already holds the card. Same shape as the ingest legs'
946+
// `prev?.key === key` early return: a repeat writes no line and no store.
947+
if (state.routes[taskId]?.key === `bot:${bot.id}`) {
948+
return { ok: true, matched: true, already: true, decision: { kind: 'bot', id: bot.id } }
949+
}
945950
// #2485: a card a lane holds can be handed straight to a Bot here, without
946951
// passing through `ingest`. The lane that lost it gets the same one line,
947952
// in the write that moves the claim.

‎plugins/workflow/test/claim-reroute-log.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ test('#2485: a card the same Bot already holds is not written again', async () =
331331

332332
const again = svc.assign({ taskId: 't-1', title: 'Ship it', botId: 'main' })
333333
assert.equal(again.ok, true, again.error)
334+
assert.equal(again.already, true, 'the same route is a no-op, as it is on the ingest legs')
334335
assert.deepEqual(messagesOf(svc, 'Alpha'), before, 'a repeated assignment adds no line')
335336
assert.deepEqual(readFileSync(join(dir, 'workflows.json')), bytes, 'the store is byte-identical')
336337
assert.equal(statSync(join(dir, 'workflows.json')).mtimeMs, mtimeMs, 'the store was not rewritten')

0 commit comments

Comments
 (0)