From 8c702b1d4e13fb11a1951f8371f17c378ebe93e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=81=D0=B5=D0=BB=D1=8C?= Date: Sat, 14 Nov 2026 23:42:15 +0500 Subject: [PATCH] PEP-87: the watchdog does not remind or escalate the analyst's self-closing questions Co-Authored-By: Claude Fable 5.2 --- packages/cli/src/index.ts | 2 ++ packages/runner/src/recovery.ts | 3 +++ packages/runner/src/tmux.ts | 30 ++++++++++++++++++++++++++++ packages/testkit/test/intake.test.ts | 5 +++++ 4 files changed, 40 insertions(+) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 19693b9d..24fbec79 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -643,6 +643,8 @@ async function main(): Promise { const ob = await outboxStats(db); console.log(`outbox: ${ob.pending} ожидают, ${ob.failed} не доставлены`); console.log(`раннеры: ${(await listSessions(db, { active: true })).length} активных · вопросы: ${(await pendingQuestions(db)).length} открытых`); + const foreign = await tmux.foreignServerEnv().catch(() => []); + if (foreign.length) console.log(`⚠ в окружении tmux-сервера чужие переменные: ${foreign.join(", ")} — агенты их унаследуют; очистятся при следующем запуске раннера или: ${foreign.map((n) => `tmux set-environment -g -u ${n}`).join("; ")}`); const paired = new Set((await adminRecipients(db)).map((u) => u.login)); const admins = (await platformAdmins(db)).map((l) => `${l}${paired.has(l) ? " (Telegram)" : " (без Telegram)"}`); console.log(`админы: ${admins.join(", ") || "нет"}`); diff --git a/packages/runner/src/recovery.ts b/packages/runner/src/recovery.ts index 4d156bdb..86769fa2 100644 --- a/packages/runner/src/recovery.ts +++ b/packages/runner/src/recovery.ts @@ -19,6 +19,7 @@ import { setSetting, updateSession, type SessionView, + getIntakeState, } from "@peppa/core"; import { projects, questions, sessions, tasks, type Db, type WatchState } from "@peppa/db"; import { formatTaskKey } from "@peppa/shared"; @@ -227,6 +228,8 @@ export async function remindTick(db: Db, o: { now: Date; cfg: WatchdogSettings; .where(and(isNull(questions.answeredAt), inArray(questions.kind, [...REMIND_KINDS]), gestDay(now))); let sent = 0; for (const { q, projectKey, taskNumber } of rows) { + // PEP-87: the analyst's questions close themselves at their deadline (PEP-84) — no nagging. + if (q.taskId && (await getIntakeState(db, q.taskId))?.questionId === q.id) continue; const age = now - q.createdAt.getTime(); const ageMin = Math.round(age / 60_000); const n = q.reminders; diff --git a/packages/runner/src/tmux.ts b/packages/runner/src/tmux.ts index 71ad3c8c..a63468e7 100644 --- a/packages/runner/src/tmux.ts +++ b/packages/runner/src/tmux.ts @@ -41,6 +41,35 @@ export interface NewTmuxSession { width?: number; } +/** + * PEP-69: names that must never come from a tmux server's global environment. Every session + * inherits it, and a server started by some test run or tool shell carries that process's + * GITEA_*, PEPPA_*, DATABASE_URL, MOCK_* — agents and their MCP then talk to the wrong place. + * What an agent needs is passed per session (`new-session -e`) or read from `.env`. + */ +const FOREIGN_ENV = /^(GITEA_|PEPPA_|MOCK_|DATABASE_URL$)/; + +/** Foreign variables in the global environment of the tmux server (default server only). */ +export async function foreignServerEnv(p: Pane = { name: "" }): Promise { + // A dedicated socket (-L, tests) is its owner's own server: nothing foreign in it. + if (process.env.PEPPA_TMUX_SOCKET) return []; + let out: string; + try { + out = await tmuxOn(p, ["show-environment", "-g"]); + } catch (e) { + if (e instanceof HostUnreachable) throw e; + return []; // no server running + } + return out.split("\n").map((l) => l.split("=")[0]!.trim()).filter((k) => FOREIGN_ENV.test(k)); +} + +/** Removes them from the server's global environment; returns the names removed. */ +export async function scrubServerEnv(p: Pane = { name: "" }): Promise { + const names = await foreignServerEnv(p); + for (const n of names) await tmuxOn(p, ["set-environment", "-g", "-u", n]); + return names; +} + export async function newSession(s: NewTmuxSession): Promise { if (isRunnerClient()) return viaService("newSession", [s]); const envArgs = Object.entries(s.env).flatMap(([k, v]) => ["-e", `${k}=${v}`]); @@ -48,6 +77,7 @@ export async function newSession(s: NewTmuxSession): Promise { // Keep the server up when its last session ends: otherwise a session created while the // previous last one is being killed can land on a server that is shutting down. await tmuxOn(p, ["start-server", ";", "set-option", "-s", "exit-empty", "off"]); + await scrubServerEnv(p).catch(() => {}); // PEP-69 await tmuxOn(p, ["new-session", "-d", "-s", s.name, "-c", s.cwd, "-x", String(s.width ?? 220), "-y", "50", ...envArgs, s.command]); // Keep the pane after claude exits so the watchdog can read the exit status. await tmuxOn(p, ["set-option", "-t", s.name, "remain-on-exit", "on"]); diff --git a/packages/testkit/test/intake.test.ts b/packages/testkit/test/intake.test.ts index 2e235a7b..b0829fb5 100644 --- a/packages/testkit/test/intake.test.ts +++ b/packages/testkit/test/intake.test.ts @@ -68,6 +68,11 @@ describe("Продакт и аналитик", () => { assert.equal(q!.id, state.questionId); assert.match(q!.text, /Нужна ли мобильная версия\?\n\s+По умолчанию: Да, страница открывается с телефона/); + // PEP-87: the question closes itself at the deadline, so the watchdog does not nag about it. + const cfg = await runner.getWatchdogSettings(db); + assert.equal(await runner.remindTick(db, { now: new Date(Date.now() + 3 * 3600_000), cfg, log: () => {} }), 0); + assert.equal((await core.getQuestion(db, q!.id)).reminders, 0); + // The PM answers: the analyst finishes with the answer and asks nothing more. await runner.answerAndDeliver(db, q!.id, "Мобильная не нужна, только ноутбук", "web"); assert.equal((await core.getIntakeState(db, ref.task.id))!.stage, "finalize");