Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: changelog entry for Moltworld presence panel fix (#2022)

Adam Eivy815980d1d851
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index a03a5c33d1..31b0dca3e8 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -106,6 +106,7 @@
## Fixed
+- **[issue-2022] Moltworld presence panel no longer shows phantom agents after everyone leaves** — `useMoltworldWs`'s `handlePresence`/`handleNearby` gated the state write on `agents.length > 0`, so an empty "nobody nearby" snapshot (forwarded verbatim from the external Moltworld WS) was silently dropped and the WorldTab "Nearby Agents" panel stuck on a stale agent list forever. Both handlers now validate `Array.isArray(agents)` and call `setPresence` unconditionally for a well-formed array, so a confirmed-empty event clears the panel. `presence` initializes to `null` (not-yet-known) rather than `[]`, and `WorldTab` distinguishes the two: `null` falls back to the last REST join/explore list, while an empty array is a live "nobody here" snapshot that wins over the stale fallback. A malformed non-array payload preserves prior state. Covered by new hook tests. (`client/src/hooks/useMoltworldWs.js`, `client/src/components/agents/tabs/WorldTab.jsx`, Closes #2022)
- **PortOS self-restart / reconcile no longer hangs at "stopping apps" and leaves the server down** — restarting the PortOS app (Apps → restart, or a reconcile) sends `portos-server` a SIGINT, but the graceful-shutdown handler hung forever, so PM2's default 1600ms `kill_timeout` SIGKILLed the process — and the tree-kill took the in-flight restart orchestration down with it, so the server never came back and had to be restarted by hand. **Root cause:** the handler called `httpServer.close()` *after* `io.close()`, but socket.io's `io.close()` already closes its current `this.httpServer` — and since every `io.attach()` reassigns that reference (`socket.io` index.js:303), with HTTPS enabled it's the loopback mirror, not `:5555`. Calling `close()` a second time on an already-closed server makes Node register the callback as a one-time `'close'` listener for an event that already fired — so it never runs and the `await` blocks until the 10s force-exit timer (which PM2 pre-empted with SIGKILL). The rewritten `shutdown()`: force-drops long-lived SSE/keep-alive sockets with `closeAllConnections()` up front; closes socket.io + **both** HTTP servers idempotently (`ERR_SERVER_NOT_RUNNING` = already-closed = success), each behind a short bounded backstop so a WebSocket-upgraded socket that neither `closeAllConnections()` nor the server's connection tracker can reach can't stall the exit; bounds the DB-pool `close()` the same way (a leaked/`LISTEN` client can't hang it); and `unref()`s the force-exit timer so it can't itself hold the loop open. Graceful shutdown now completes in well under a second with the DB pool closed cleanly, every time (down from a 10s hang that ended in SIGKILL). As a backstop, `portos-server` also gains an explicit PM2 `kill_timeout: 12000` (just above the app's own 10s force-exit) so even a future stall defers to the app's clean exit instead of an abrupt SIGKILL. (`server/index.js`, `ecosystem.config.cjs`)
- **[issue-1922] Music-video federation's bundled track tombstone is now ack-tracked, closing a narrow track-GC strand window** — #1858 bundles a music-video project's linked track record (`linkedTrack`) so a Music-Videos-only peer (no `track` subscription) can resolve it, and a track delete fans the tombstone out the same way. But `computeAckedDeletesFromPayload` (`peerSyncReceive.js`) only looked at `record`/`issues`, never `linkedTrack`, so such a peer could never ack a bundled track delete through any cursor — and the sender's `track`-tombstone GC cohort (`tombstoneGc.js`) only ever waited on peers with a direct `track` subscription, so it was entirely blind to a musicVideoProjects-only peer regardless of the ack fix. Implemented option (a) from the deferred #1858 review: `computeAckedDeletesFromPayload` now folds in a bundled `linkedTrack` tombstone's `deletedAt`, and the `track` GC cutoff additionally folds `musicVideoProject` subscribers into its cohort, reading their confirmed-delivery floor off a new bundle-specific `lastConfirmedTrackBundleAtMs` (stamped only when the bundled track merge actually succeeded — not the generic `lastConfirmedPushedAt`, which advances even when the bundle failed or was stripped for a legacy peer). Local subscription-state addition only; no wire-payload shape change, so no schema-version bump. (#1922)
- **[issue-1858] Music-video federation now ships the linked track to a Music-Videos-only subscriber** — a music-video project created the normal way stores a `trackId` with `uploadedAudioFilename: null`, so a peer subscribed to the **Music Videos** category only (not Music/Tracks) received the project and scene clips but no master audio, and its render failed with `Linked track not found` / `AUDIO_MISSING`. Because the receiver's `resolveMasterAudioPath()` looks the track up by id *before* touching any file, shipping the bytes alone wasn't enough — the push now bundles the linked **track record** itself (`linkedTrack`, merged via `mergeTracksFromSync` and gated by the same tombstone/opt-out rules as `linkedCollection`) *and* its `audioFilename` bytes in the music-video asset manifest. Additive optional payload key, so no schema-version bump and older peers ignore it; dedup-by-`music:<filename>` keeps a separately-federated track from double-shipping. A linked-track edit now also fans a push out to every music-video project that links it (so the bundled audio stays fresh on a Music-Videos-only peer), the receiver requires the bundle's id to match the project's `trackId` (no smuggling an unrelated track), and the bundle rides the push hash + schema gate + delivery-pending ack exactly like the existing `linkedCollection`/`manuscriptReview` bundles. (#1858)