PEP-57: PM question on red CI is not closed by the agent's prompts

After three red runs Peppa asked the PM with the session attached, then pasted
"wait for the PM" into that session — its prompt hook closed the question as
answered in the terminal. The question is now task-only; answers to task
questions without a session go to the task's active session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Асель 2026-11-13 16:54:30 +05:00
parent ae37ba90d5
commit 07e2caa393
3 changed files with 14 additions and 3 deletions

View File

@ -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) {

View File

@ -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") {

View File

@ -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");