@mrciphersmith/roomyx 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -13,6 +13,48 @@ patch and never a minor. The rule, the reason, and an audit of the four of seven
13
13
  releases that followed it are in
14
14
  [`docs/roomyx/versioning.md`](docs/roomyx/versioning.md) and decision D-13.
15
15
 
16
+ ## [0.8.1] — 2026-09-10
17
+
18
+ A patch. Found by triaging the action list against the code: this defect had
19
+ been sitting in the backlog, unscheduled, with a victim it names itself.
20
+
21
+ ### Fixed
22
+
23
+ - **A room that does not answer within the liveness probe's 500 ms is no longer
24
+ deleted from the registry.** The check returned `state | undefined`, and
25
+ `undefined` had to mean both "I could not reach it" and "the process is gone" —
26
+ so the caller resolved the ambiguity destructively: `undefined → false → prune`,
27
+ plus a history record claiming the room had ended. A room that was merely slow,
28
+ or `SIGSTOP`ped, or on a loaded machine, was silently removed while it was
29
+ still serving. The pid check does not catch it: `process.kill(pid, 0)` succeeds
30
+ for a stopped process.
31
+
32
+ Liveness now answers `live`, `gone` or `unknown`, and only `gone` deletes
33
+ anything. `gone` requires evidence about *this entry* — a registered pid that
34
+ is not running, or a server that answered and named a different log than the
35
+ entry claims.
36
+
37
+ ### Added
38
+
39
+ - **`roomyx rooms list` shows a room that did not answer instead of omitting it**,
40
+ marked `did not answer — still registered`. It used to print `No live rooms.`
41
+ about a registry that had one, which is how a serving room came to look like no
42
+ room at all. An empty registry still prints exactly that sentence.
43
+ - **`listRoomsWithLiveness()`** returns `{ live, unconfirmed }`. Everything that
44
+ decides *what to attach to* keeps reading the confirmed list, so a client never
45
+ auto-attaches to a room that did not answer.
46
+
47
+ ### Notes
48
+
49
+ - The known limit is stated in the code rather than left to be discovered: a pid
50
+ reused by an unrelated process keeps its entry in `unconfirmed` until something
51
+ answers on that port. That is why the pid is a pre-filter and not the assertion
52
+ — and it is strictly better than deleting a live room, which is the trade this
53
+ release makes deliberately.
54
+ - `prune: false` (the MCP surface) still prunes nothing. The load-sensitive half
55
+ of that argument is now structural: a probe that times out returns `unknown`,
56
+ and `unknown` is never pruned even when pruning is asked for.
57
+
16
58
  ## [0.8.0] — 2026-09-10
17
59
 
18
60
  A minor, because it is breaking: `roomyx room append --force` is gone. In `0.x`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "MCP server + terminal UI for startup-room: live room status, chat, per-agent modal, an installable room registry, and skill-sync.",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/cli.ts CHANGED
@@ -4,7 +4,13 @@ import { join, resolve } from "node:path";
4
4
  import { serve } from "./server/serve";
5
5
  import { createServerShutdown } from "./server/shutdown";
6
6
  import { init } from "./installer/init";
7
- import { probeRoomState, registerRoom, deregisterRoom, listLiveRooms } from "./installer/registry";
7
+ import {
8
+ findRoomServing,
9
+ probeRoomState,
10
+ registerRoom,
11
+ deregisterRoom,
12
+ listRoomsWithLiveness,
13
+ } from "./installer/registry";
8
14
  import { archiveRoom, defaultHistoryPath, readHistory } from "./installer/history";
9
15
  import { syncSkill } from "./installer/skill-sync";
10
16
  import { appendMessages, createRoomLog, LEGAL_KINDS, parseRoster } from "./log/write";
@@ -335,7 +341,11 @@ const COMMANDS: Record<string, Command> = {
335
341
  const absoluteRegistry = resolve(typeof flags.registry === "string" ? flags.registry : defaultRegistryPath());
336
342
  const leasePath = writerLeasePathFor(absoluteRegistry, absolute);
337
343
 
338
- const serving = (await listLiveRooms(absoluteRegistry)).find((room) => room.logPath === absolute);
344
+ // Across BOTH lists: an entry whose first probe timed out is `unconfirmed`,
345
+ // and it may still have a dispatcher attached — which is the evidence this
346
+ // guard needs. Searching only the confirmed list is how "the machine was
347
+ // busy" turns into "nothing is writing into this log".
348
+ const serving = findRoomServing(absolute, await listRoomsWithLiveness(absoluteRegistry));
339
349
 
340
350
  // Read the lease BEFORE the probe, and independently of its outcome. A
341
351
  // liveness probe that times out says "could not reach it", which is not
@@ -477,14 +487,25 @@ const COMMANDS: Record<string, Command> = {
477
487
  // `rooms list --registry /nonexistent.json` printed "No live rooms"
478
488
  // about a different file.
479
489
  const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
480
- const rooms = await listLiveRooms(registryPath);
481
- if (rooms.length === 0) {
490
+ const { live, unconfirmed } = await listRoomsWithLiveness(registryPath);
491
+ if (live.length === 0 && unconfirmed.length === 0) {
492
+ // An empty registry and a registry whose rooms did not answer are
493
+ // different facts, and the second used to print this same sentence —
494
+ // which is how a serving room came to look like no room at all.
482
495
  console.log("No live rooms.");
483
496
  return;
484
497
  }
485
- for (const room of rooms) {
498
+ for (const room of live) {
486
499
  console.log(`${room.id} port=${room.port} log=${room.logPath} started=${room.startedAt}`);
487
500
  }
501
+ for (const room of unconfirmed) {
502
+ // Kept in the registry, not claimed live: the probe did not answer, and
503
+ // "did not answer" is not permission to delete a room that may be
504
+ // serving. Named so the reader knows what to re-check.
505
+ console.log(
506
+ `${room.id} port=${room.port} log=${room.logPath} started=${room.startedAt} did not answer — still registered`,
507
+ );
508
+ }
488
509
  },
489
510
  },
490
511
 
@@ -114,61 +114,144 @@ export function listRooms(registryPath: string): RoomRegistryEntry[] {
114
114
  * answers). Dead entries are pruned from the persisted file, not just
115
115
  * omitted from the returned list.
116
116
  */
117
- export async function listLiveRooms(
117
+ /**
118
+ * What a liveness probe established, which is not a yes/no.
119
+ *
120
+ * The defect this type replaces: `probeRoomState` returned `state | undefined`,
121
+ * and `undefined` had to carry both "I could not reach it" and "the process is
122
+ * gone". The caller resolved that ambiguity in the destructive direction —
123
+ * `undefined → false → prune` — so a room that was merely slow had its registry
124
+ * entry deleted and a history record written claiming it had ended. The 500 ms
125
+ * probe is load-sensitive, `process.kill(pid, 0)` succeeds for a `SIGSTOP`ped
126
+ * process, and the failure is silent: the room is serving, and the registry says
127
+ * it never existed.
128
+ *
129
+ * R7's rule, in its own words: **identity mismatch is the one case where
130
+ * deleting is correct — a timeout never is.** Three values is what makes that
131
+ * expressible.
132
+ */
133
+ export type Liveness = "live" | "gone" | "unknown";
134
+
135
+ /**
136
+ * Asks what this entry is, with the destructive answer reserved for evidence.
137
+ *
138
+ * - `gone` — the registered pid is not running, or a server answered and named a
139
+ * different log than this entry claims. Both are facts about *this entry*.
140
+ * - `unknown` — the probe did not reach it: a refused connection, a connect
141
+ * timeout, or a `tools/call` that did not answer in time. Nothing is known, so
142
+ * nothing may be deleted on the strength of it.
143
+ * - `live` — a server answered and named this entry's log, or answered without a
144
+ * `log_path` at all. The second case is an older server: it cannot be shown to
145
+ * be a different room, and failing toward keeping is the safe direction, since
146
+ * the cost of wrongly pruning is higher than that of keeping a stale entry.
147
+ *
148
+ * **Known limit.** A pid that has been reused by an unrelated process keeps its
149
+ * entry in `unknown` where it will stay until something answers on that port.
150
+ * That is why the pid is a pre-filter and not the assertion — and it is strictly
151
+ * better than deleting a live room, which is what the alternative buys.
152
+ */
153
+ export async function checkRoomLiveness(room: RoomRegistryEntry, timeoutMs = 500): Promise<Liveness> {
154
+ if (!isPidAlive(room.pid)) return "gone";
155
+ const state = await probeRoomState(room, timeoutMs);
156
+ if (state === undefined) return "unknown";
157
+ if (state.log_path === undefined) return "live";
158
+ return state.log_path === room.logPath ? "live" : "gone";
159
+ }
160
+
161
+ export interface LiveAndUnconfirmed {
162
+ live: RoomRegistryEntry[];
163
+ /**
164
+ * Registered, probed, and not answered. Returned apart from `live` rather than
165
+ * mixed in, because every consumer of the confirmed list decides *what to
166
+ * attach to* — and a room that did not answer is not a candidate for that.
167
+ */
168
+ unconfirmed: RoomRegistryEntry[];
169
+ }
170
+
171
+ /**
172
+ * The confirmed-live rooms, and the ones nothing is known about, as two lists.
173
+ *
174
+ * Only `gone` prunes and archives. A room pruned here died without
175
+ * deregistering — crashed, or was killed with a signal no handler runs for — and
176
+ * this is the only moment anything observes that it ended, so it is the only
177
+ * place its history entry can be written. An `unknown` room gets neither: the
178
+ * history line would be a claim it ended, and the prune would be a claim about
179
+ * the room made on evidence that is a claim about the network.
180
+ */
181
+ export async function listRoomsWithLiveness(
118
182
  registryPath: string,
119
- options: { prune?: boolean; historyPath?: string } = {},
120
- ): Promise<RoomRegistryEntry[]> {
183
+ options: { prune?: boolean; historyPath?: string; timeoutMs?: number } = {},
184
+ ): Promise<LiveAndUnconfirmed> {
121
185
  const prune = options.prune ?? true;
122
186
  const historyPath = options.historyPath ?? defaultHistoryPath(registryPath);
123
- if (hasNoRegistry(registryPath)) return [];
187
+ if (hasNoRegistry(registryPath)) return { live: [], unconfirmed: [] };
124
188
  const rooms = withLock(registryPath, () => readRegistryUnlocked(registryPath).rooms);
125
189
  const checks = await Promise.all(
126
- rooms.map(async (room) => {
127
- const alive = await isRoomLive(room);
128
- return { room, alive };
129
- }),
190
+ rooms.map(async (room) => ({ room, liveness: await checkRoomLiveness(room, options.timeoutMs ?? 500) })),
130
191
  );
131
- const live = checks.filter((c) => c.alive).map((c) => c.room);
192
+ const pick = (want: Liveness) => checks.filter((c) => c.liveness === want).map((c) => c.room);
193
+ const live = pick("live");
194
+ const unconfirmed = pick("unknown");
195
+ const gone = pick("gone");
196
+
132
197
  // The MCP surface passes `prune: false`. It is the one place a network caller
133
198
  // could cause a filesystem write, and the content is not caller-controlled —
134
199
  // but "the MCP surface only reads" is worth being exactly true rather than
135
200
  // nearly, and the 500ms probe is load-sensitive enough that a busy machine
136
201
  // could prune a live-but-slow room on someone else's call.
137
- if (prune && live.length !== rooms.length) {
202
+ //
203
+ // That reasoning is now structural rather than a convention: a load-sensitive
204
+ // probe returns `unknown`, and `unknown` is not pruned even when pruning is
205
+ // asked for. `prune: false` still matters — it stops the deletion of entries
206
+ // confirmed gone — but the load-sensitive half of the argument no longer
207
+ // depends on every caller remembering to pass it.
208
+ if (prune && gone.length > 0) {
138
209
  // Re-take the lock for the write: another process may have registered or
139
210
  // deregistered a room while the (network) liveness checks above were in
140
211
  // flight. Re-read under the lock and only remove entries this pass
141
- // actually confirmed dead, instead of blindly overwriting with the
142
- // stale `live` list computed before the re-read.
143
- const dead = checks.filter((c) => !c.alive).map((c) => c.room);
212
+ // actually confirmed gone, instead of blindly overwriting with the stale
213
+ // list computed before the re-read.
144
214
  withLock(registryPath, () => {
145
215
  const current = readRegistryUnlocked(registryPath).rooms;
146
- const deadIds = new Set(dead.map((r) => r.id));
216
+ const goneIds = new Set(gone.map((r) => r.id));
147
217
  writeRegistryUnlocked(
148
218
  registryPath,
149
- current.filter((r) => !deadIds.has(r.id)),
219
+ current.filter((r) => !goneIds.has(r.id)),
150
220
  );
151
221
  });
152
- // A room pruned here died without deregistering — crashed, or was killed
153
- // with a signal no handler runs for. This is the only moment anything
154
- // observes that it ended, so it is the only place its history entry can be
155
- // written. Without it the rooms that are most worth being able to reread
156
- // are exactly the ones that leave no trace.
157
- //
158
222
  // `closedAt` is now, not the moment it actually died, which is unknowable
159
223
  // — the entry records when it was found gone.
160
- for (const room of dead) archiveRoom(historyPath, room);
224
+ for (const room of gone) archiveRoom(historyPath, room);
161
225
  }
162
- return live;
226
+ return { live, unconfirmed };
163
227
  }
164
228
 
165
229
  /**
166
- * Is the process that registered this room still running?
230
+ * The registered entry serving a log, whether or not it was confirmed live.
167
231
  *
168
- * Signal 0 performs the permission and existence checks without delivering
169
- * anything. ESRCH means no such process; EPERM means it exists and belongs to
170
- * someone else, which is still "alive" for our purposes.
232
+ * For anything that must know *which room is this*, rather than *may I attach to
233
+ * it*. The distinction matters here because a first probe can time out while the
234
+ * room is alive: searching only the confirmed list made a slow machine's answer
235
+ * to "is anyone writing into this log?" come back "nothing is" — which is the
236
+ * same collapsed question this module's `Liveness` type was introduced to stop
237
+ * asking. An unconfirmed entry is still an entry, and its second probe may
238
+ * answer.
171
239
  */
240
+ export function findRoomServing(
241
+ logPath: string,
242
+ lists: { live: RoomRegistryEntry[]; unconfirmed: RoomRegistryEntry[] },
243
+ ): RoomRegistryEntry | undefined {
244
+ return [...lists.live, ...lists.unconfirmed].find((room) => room.logPath === logPath);
245
+ }
246
+
247
+ /** Confirmed live only — what anything that decides what to attach to must read. */
248
+ export async function listLiveRooms(
249
+ registryPath: string,
250
+ options: { prune?: boolean; historyPath?: string; timeoutMs?: number } = {},
251
+ ): Promise<RoomRegistryEntry[]> {
252
+ return (await listRoomsWithLiveness(registryPath, options)).live;
253
+ }
254
+
172
255
  function isPidAlive(pid: number): boolean {
173
256
  if (!Number.isInteger(pid) || pid <= 0) return true; // no pid recorded — fall back to the probe
174
257
  try {
@@ -223,21 +306,3 @@ export async function probeRoomState(
223
306
  }
224
307
  }
225
308
 
226
- async function isRoomLive(room: RoomRegistryEntry, timeoutMs = 500): Promise<boolean> {
227
- // The probe below proves that *something* MCP-speaking answers on that port,
228
- // never that it is this room. Every `roomyx serve` defaults to 4319, so a
229
- // room that died without deregistering was resurrected as live by the next
230
- // room to bind the port — and then `roomyx-client --room <dead-id>` silently
231
- // rendered a different room's transcript under the dead room's id, while
232
- // `room append` refused a log nothing was serving.
233
- //
234
- // The pid has been in the registry all along and was never read. Checking it
235
- // first also skips a 500 ms network probe per dead entry.
236
- const state = await probeRoomState(room, timeoutMs);
237
- if (state === undefined) return false;
238
- // An older server that predates `log_path` answers without it. Treat that
239
- // as "cannot be shown to be a different room" rather than as dead: failing
240
- // toward the previous behaviour is the safe direction here, because the
241
- // cost of wrongly pruning a live room is higher than of keeping a stale one.
242
- return state.log_path === undefined || state.log_path === room.logPath;
243
- }