diff --git a/packages/runner/src/ci-feedback.ts b/packages/runner/src/ci-feedback.ts index 030cc42f..09ac608a 100644 --- a/packages/runner/src/ci-feedback.ts +++ b/packages/runner/src/ci-feedback.ts @@ -68,9 +68,10 @@ export async function recordCheck(db: Db, project: Project, r: CheckReport): Pro if (attempts >= MAX_CI_ATTEMPTS) { if (!newRun) return { task: ref.key, action: "none" }; // the PM already has this commit + // Not tied to the session: the "wait for the PM" paste below (and any prompt of the agent) + // would close it as answered in the terminal. The answer still reaches the task's agent. await askPm(db, ref, { kind: "question", - sessionId: sessionId ?? undefined, text: `❌ ${ref.key}: проверки PR красные ${attempts} раза подряд — агент не справился сам. Упала «${r.check}» (коммит ${r.sha.slice(0, 7)}).${link ? `\nЛог: ${link}` : ""}\n\nЧто делать? Ответ уйдёт агенту.`, }); if (sessionId) { diff --git a/packages/runner/src/sessions.ts b/packages/runner/src/sessions.ts index 669a48dd..95ba8b51 100644 --- a/packages/runner/src/sessions.ts +++ b/packages/runner/src/sessions.ts @@ -6,6 +6,7 @@ import { createSession, expireSessionQuestions, getSession, + listSessions, loadSharedRules, PeppaError, resolveTask, @@ -184,8 +185,11 @@ export async function answerAndDeliver( // "Deploy to prod" on a "staging updated" message (PEP-57). if (await onReleaseAnswer(db, q, answer, `PM (${via})`)) return { delivered: true, question: q }; - if (!q.sessionId) return { delivered: false, question: q }; - const s = await getSession(db, q.sessionId); + // A task question asked outside a session (red CI, a manual session) goes to the agent + // working on the task now, if any. + const sessionId = q.sessionId ?? (q.taskId ? (await listSessions(db, { active: true, taskId: q.taskId }))[0]?.id : undefined); + if (!sessionId) return { delivered: false, question: q }; + const s = await getSession(db, sessionId); if (!(await tmux.hasSession(s.tmuxName))) return { delivered: false, question: q }; if (q.kind === "permission") { diff --git a/packages/testkit/test/ci-feedback.test.ts b/packages/testkit/test/ci-feedback.test.ts index bdea79c1..398e189f 100644 --- a/packages/testkit/test/ci-feedback.test.ts +++ b/packages/testkit/test/ci-feedback.test.ts @@ -133,6 +133,12 @@ describe("Красные проверки возвращаются агенту" assert.equal(q.taskId, (await t.ref()).task.id); assert.match(q.text, new RegExp(`красные 3 раза подряд[\\s\\S]*Лог: ${gitea.url}/`)); await t.p.waitLog("runner told to wait", (e) => e.ev === "prompt" && String(e.prompt).includes("жди ответа PM")); + // The agent's prompts (the "wait" paste included) don't close the PM's question… + await new Promise((r) => setTimeout(r, 1500)); + assert.ok((await core.pendingQuestions(db, t.proj.id)).some((x) => x.id === q.id), "question still open after the agent's prompt"); + // …and the answer reaches the agent of the task. + assert.equal((await runner.answerAndDeliver(db, q.id, "откати последний коммит", "web")).delivered, true); + await t.p.waitLog("answer delivered", (e) => e.ev === "prompt" && String(e.prompt).includes("откати последний коммит")); // Green again → the counter starts over. const sha = t.push(); for (const c of Object.keys(CHECKS)) await t.report(sha, c, "success");