From 049072d5aad49d311096a7125d891f7de1738017 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Mon, 16 Nov 2026 14:32:29 +0200 Subject: pi forum: an agent stopped by a signal or crash keeps its forums A shutdown sends pi SIGTERM or SIGHUP, which pi handles as a quit, so every agent left its forums, and a dingger restore brought them back in none. Only a quit the user asks for now ends membership. An agent whose pi was stopped any other way stays registered as stopped, and the next pi to start on its session (pi --session, pi -c, a dingger restore) takes it back: same id, same forums, same read position, with a notice of what is unread. pi stops its TUI before session_shutdown on a user's quit, and after it on a signal, so a terminal still in raw mode there means a signal. A crash runs no handler and leaves a dead pid, or a socket nobody answers on, which counts the same. Read positions are saved as they move, for that case. Stopped members are listed as such by the tool, /forums and pi-forum. A direct message to one fails, saying so; a post may mention one, and waits for it as unread. /forum remove and /forum delete clear them. --- bin/pi-forum | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'bin/pi-forum') diff --git a/bin/pi-forum b/bin/pi-forum index 9d87440..37ea051 100755 --- a/bin/pi-forum +++ b/bin/pi-forum @@ -80,7 +80,9 @@ function forums() { .sort((a, b) => a.createdAt - b.createdAt); } -// Agents running now, with their registrations. +// Registered agents, each marked stopped when no pi is running for it: one a +// signal or crash stopped while it was in a forum, which the next pi to open +// its session takes back. function agents() { let files; try { @@ -90,7 +92,12 @@ function agents() { } return files .map((f) => readJson(path.join(AGENTS, f))) - .filter((a) => a && typeof a.id === "string" && typeof a.pid === "number" && alive(a.pid)); + .filter((a) => a && typeof a.id === "string" && typeof a.pid === "number") + .map((a) => ({ + ...a, + stopped: a.stoppedAt !== undefined || !alive(a.pid) || !fs.existsSync(path.join(AGENTS, `${a.id}.sock`)), + })) + .filter((a) => !a.stopped || (a.forums || []).length); } function find(arg) { @@ -139,7 +146,8 @@ function format(post, no, forum, opts) { } function memberLine(a) { - return ` ${who(a)}${dim(` ${a.cwd}`)}`; + if (!a.stopped) return ` ${who(a)}${dim(` ${a.cwd}`)}`; + return dim(` ${who(a)} stopped${a.stoppedAt ? ` since ${when(a.stoppedAt)}` : ""}`); } function list() { @@ -154,7 +162,8 @@ function list() { const members = live.filter((a) => (a.forums || []).includes(f.id)); const last = posts.length ? `, last ${when(posts[posts.length - 1].at)}` : ""; console.log(`${bold(f.name)} ${dim(`[${f.id}] ${posts.length} post(s)${last}`)}`); - console.log(members.length ? members.map(memberLine).join("\n") : dim(" no members running")); + members.sort((a, b) => a.stopped - b.stopped); + console.log(members.length ? members.map(memberLine).join("\n") : dim(" no members")); if (f.pin) console.log(` ${yellow("pin")}: ${f.pin.text} ${dim(`(${who(f.pin.by)}, ${when(f.pin.at)})`)}`); console.log(); } -- cgit v1.2.3