diff --git a/packages/runner/src/incidents.ts b/packages/runner/src/incidents.ts index b6554a7e..31426e49 100644 --- a/packages/runner/src/incidents.ts +++ b/packages/runner/src/incidents.ts @@ -133,10 +133,11 @@ async function execute( await sendIncidentMessage(db, row, { kind: "ask", note: limitNote }); return row; } + // The decision goes first: whoever sees the incident with its task sees the decision too. + await updateIncident(db, i.id, base); const ref = await createBugTask(db, i, by, by === "triage" ? reason : null); - let row = await updateIncident(db, i.id, base); const started = action === "start" ? await startBugTask(db, ref, o) : false; - row = await getIncident(db, i.id); + const row = await getIncident(db, i.id); await sendIncidentMessage(db, row, { kind: "task", task: ref, started, reason: by === "triage" ? reason : null }); return row; } diff --git a/packages/testkit/test/incidents.test.ts b/packages/testkit/test/incidents.test.ts index 2a376e48..d1076a7f 100644 --- a/packages/testkit/test/incidents.test.ts +++ b/packages/testkit/test/incidents.test.ts @@ -308,13 +308,15 @@ describe("Политика инцидентов проекта", () => { triage({ rules: [{ match: "PaymentError", action: "start", confidence: 0.92, reason: "падает оплата — по правилам сразу в работу" }] }); const c = await connected({ policy: "triage", triagePrompt: prompt }); await bugsink.capture(c.api, { type: "PaymentError", value: "card declined handler crashed", environment: "prod", release: "a1b2c3", frames: [{ filename: "billing/pay.ts", function: "pay", lineno: 3 }] }); + await waitIncident(c, "PaymentError: card declined handler crashed", (x) => x.status === "task"); + // The message is the last step of the decision: after it the incident and the task are final. + const m = await waitPm("PaymentError: card declined", (x) => /Агент взялся/.test(x.text)); const i = await waitIncident(c, "PaymentError: card declined handler crashed", (x) => x.status === "task"); assert.equal(i.decidedBy, "triage"); assert.equal(i.decision, "start"); const t = (await tasksOf(c)).find((x) => x.id === i.taskId)!; assert.equal(t.status, "in_progress"); assert.match(t.description!, /Решение триажёра: падает оплата — по правилам сразу в работу/); - const m = await waitPm("PaymentError: card declined", (x) => /Агент взялся/.test(x.text)); assert.match(m.text, /🤖 Триажёр: падает оплата/); const call = triageLog().at(-1); assert.equal(call.pmRules, prompt);