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

address review: minimize ephemeral tombstones + gate UI subscribe on peer category

Adam Eivy7b9c3c27dbf5
diff --git a/PLAN.md b/PLAN.md
index 686373691f..290efdb35f 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -23,6 +23,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [.changel
- [ ] [ref-watch-phosphene-mlx-post-decode-os-exit] **Bypass MLX post-decode deallocator hang via `os._exit(0)`.** From `reference-watch` review of phosphene (commits `adc1cd25` + `94bd6965`, 2026-05-22). At PortOS's current `LTX2_PIN=f8f20c83` the bug isn't reachable, but the moment a user updates `ltx-2-mlx` or PortOS bumps the pin past the May 9 refactor, every Distilled / Extend / two-stage render stalls 5–15 min after the upstream "Decoding done in X.Xs" log while Metal command-buffer completion handlers hold the GIL through frame teardown. Fix: in `scripts/generate_ltx2.py` `main()`, after `print(json.dumps(...))`, call `os._exit(0)` instead of returning normally — mp4 is on disk, stdout was flushed, skipping deallocator teardown saves up to 15 min. Document why in the file's docstring. Subsumes any in-helper watchdog approach.
- [ ] [ref-watch-phosphene-broaden-negative-prompt-override] **Broaden `DEFAULT_NEGATIVE_PROMPT` override to every module that defines it.** From `reference-watch` review of phosphene (commit `4e6129b7`, 2026-05-22). `scripts/generate_ltx2.py:55-70` `configure_negative_prompt()` only patches `ti2vid_one_stage.DEFAULT_NEGATIVE_PROMPT`. At PortOS's current pin this happens to cover every pipeline (the constant resolves against `ti2vid_one_stage` for the base class), but post-May-9 the constant moves to `ltx_pipelines_mlx._base` and `utils.constants` — and the PortOS override silently no-ops on Q8 / two-stage / HQ paths with no error for the user to chase. Fix: rewrite `configure_negative_prompt()` to probe `ti2vid_one_stage`, `_base`, and `utils.constants`, monkey-patch every module that has the constant. Keep PortOS's *replace* semantics (don't switch to phosphene's append-with-comma). No contextmanager needed — the helper is short-lived.
- [ ] [tombstone-gc-manual-trigger-ui] **Wire a manual "GC tombstones now" button on the Instances page.** Today `sharing/tombstoneGc.js#sweepTombstones` only fires from the 60s `syncOrchestrator` interval and uses a hard-coded `GRACE_MS = 24 * 60 * 60 * 1000`, so a user who just mass-deleted records has to wait 24h for them to disappear from `data/universe-builder.json` / `data/pipeline-series.json` / `data/pipeline-issues.json` (even when every subscribed peer has already acked them). Wiring goals: (1) parameterize `sweepTombstones({ now, graceMs })` so callers can override the 24h buffer — keep the 24h default so the orchestrator path is unchanged. (2) Expose `POST /api/sync/tombstones/sweep` with optional `{ graceMs }` body (Zod-validated; clamp to `[0, 24*60*60*1000]` so the button can only shrink the grace, never bypass the ack horizon). The route still calls `cutoffForKind` for each kind so the existing safety checks (peer-ack horizon, refuse-when-snapshot-peer-uncovered) keep firing. (3) Add a "GC tombstones now" button under the Instances page's Sync Status section that POSTs with `graceMs: 0`. Disabled when any enabled peer has snapshot-mode coverage for a kind it isn't subscribed to (mirror the route's null-cutoff refusal). Surfaces the per-kind prune count in a toast (`pruned N universes / M series / K issues` — quiet when zero). (4) One-shot CLI script in `scripts/gc-tombstones-now.js` for headless cleanups (the inline-Node prune we ran 2026-05-23 for the post-Echoes-cleanup batch is the seed). Use `scripts/cleanup-test-data.js`'s pm2-stop-required wording in the header — the prune helpers serialize through per-file write tails that don't cross processes. Surfaced 2026-05-23 during the media-collections sync PR: peer null had acked 82 universe + 192 series tombstones from a same-day mass-delete and the user wanted them off-disk early.
+- [ ] [peer-sync-snapshot-skip-too-coarse-for-partial-subscriptions] **`syncOrchestrator.categoriesCoveredByPeerSync` skips the entire `universe`/`pipeline` snapshot for any peer with ANY per-record subscription in that category — but partial subscriptions leave the un-subscribed records with no active transport.** Codex iter-4 in v2.7.0 release review (P2). Today: if peer-A has 3 subs for universes A/B/C but the user has 10 universes total, the snapshot for peer-A is fully suppressed. Universes D-J never get edits to peer-A. Two fix options: (a) only suppress the snapshot when the per-record subscription set COVERS every record of that kind for that peer (refresh on subscribe/unsubscribe); (b) send the snapshot but filter out the records that ARE subscribed, so snapshot covers the gap and push covers explicit subs. Option (b) is cleaner — snapshot fills the gap. Scope: `syncOrchestrator.js` skip-decision + `dataSync.getUniverseSnapshot` + `getPipelineSnapshot` accept an exclude-set keyed by record id. Defer because the snapshot-skip works correctly for the common case (peer subscribes to ALL universes or NONE); the partial case requires a thoughtful refactor.
- [ ] [vitest-global-instances-mock-blocks-peer-sync-leakage] **Add a global vitest setup file that mocks `services/instances.js#getPeers` to return `[]` by default, with an opt-out for tests that need the real peer registry.** Surfaced 2026-05-23 during v2.7.0 release: every npm test run was creating "Commit U" + "Commit S" series/universe records on the user's null sync machine. Root cause: `services/instances.js` uses `dataPath('instances.json')` whose closure captures the REAL `PATHS.data`, so a test's `vi.mock('../lib/fileUtils.js', { PATHS: redirected })` doesn't redirect instances reads. `createUniverse`/`createSeries`/`createIssue` then call `autoSubscribeRecordToAllPeers` → `getPeers()` (real instances.json) → `subscribePeer` → initial `pushRecordToPeer` (real HTTP POST to live peer). Three test files were patched as point fixes (`importer.test.js`, `universeBuilderCollectionHook.test.js`, `writersRoom/promoteToPipeline.test.js`) but the pattern will recur as new tests are added. Two paths: (a) add `setupFiles: ['./vitest.setup.js']` to `vitest.config.js`, where setup does `vi.mock('./services/instances.js', { getPeers: () => Promise.resolve([]) })` plus an opt-out registry; (b) refactor `fileUtils.js#dataPath` to use a `getDataRoot()` getter so PATHS mocks propagate through. Option (a) is smaller and more targeted; option (b) fixes a class of leakage beyond peer-sync. Pick (a) for v2.7.x, revisit (b) if more leakage surfaces.
- [ ] [peer-sync-video-collection-metadata-sync] **Sync video-history.json rows alongside .mp4 bytes pushed via peer-sync.** Codex review of the v2.7.0 release PR (2026-05-23) flagged that `buildAssetManifestForCollection` ships the `.mp4` bytes for `kind: 'video'` collection items but never pushes the corresponding `video-history.json` row. After the receiver pulls the asset, `MediaCollectionDetail.jsx#hydrate` looks up the item ref in the `videosById` map (`listVideoHistory()`) and silently filters it out as "missing." The collection appears half-empty on the receiver. Fix options: (a) add `videoHistory` to the snapshot-sync category set so the rows ride the 60s loop; (b) bundle the matching `video-history.json` row alongside the collection item in `linkedCollection` and merge on the receiver; (c) on first pull, synthesize a stub history row from the asset metadata. (a) is the simplest and matches the existing `mediaCollections` snapshot category pattern. Also generate thumbnails on the receiver (or push them as a sibling asset kind). Scope: `server/services/dataSync.js` add `videoHistory` getter + merge; `routes/dataSync.js` add to enum; `routes/instances.js` `syncCategoriesSchema` add the key; `client/src/services/apiInstances.js` `SYNC_CATEGORY_META` add the row. Surfaced in v2.7.0 release codex review.
- [ ] [peer-sync-reverse-subscription-ui-broadcast] **Emit a socket event when applyIncomingPush auto-creates a reverse subscription so the Instances page updates without a refetch.** Today `peerSync:subscription:created` (or similar) doesn't exist; the `PeerCard` in `Instances.jsx` loads `peerSubs` once on mount keyed on `peer.instanceId` only, so a reverse-sub created via `maybeCreateReverseSubscription` is invisible until page reload. Add a socket event (or include a `peerSubsRevision` token on `instances:peers:updated`) and let `PeerCard` re-fetch on bump. Reviewer-3 in v2.7.0 release review.
diff --git a/client/src/components/sharing/SyncToPeerButton.jsx b/client/src/components/sharing/SyncToPeerButton.jsx
index f4a170d8e2..249ca66d69 100644
--- a/client/src/components/sharing/SyncToPeerButton.jsx
+++ b/client/src/components/sharing/SyncToPeerButton.jsx
@@ -63,6 +63,17 @@ export default function SyncToPeerButton({
setLoading(false);
};
+ // Per-record subscribability — mirrors server-side peerHasCategory in
+ // peerSync.js. universe → 'universe' category, series → 'pipeline'.
+ // Without this gate the UI would let the user subscribe to a peer
+ // whose category bit is off, then silently fail every push with
+ // category-disabled (server-side guard in pushRecordToPeer).
+ const requiredCategory = recordKind === 'universe' ? 'universe' : 'pipeline';
+ const peerHasMatchingCategory = (peer) => {
+ const cats = peer?.syncCategories;
+ return !!cats && typeof cats === 'object' && cats[requiredCategory] === true;
+ };
+
useEffect(() => {
if (open) refresh();
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -80,6 +91,7 @@ export default function SyncToPeerButton({
const subscriptionForPeer = (peerInstanceId) =>
subscriptions.find((s) => s.peerId === peerInstanceId) || null;
+
const handleToggle = async (peer) => {
setBusyPeerId(peer.instanceId);
const existing = subscriptionForPeer(peer.instanceId);
@@ -145,13 +157,22 @@ export default function SyncToPeerButton({
{peers.map((p) => {
const subscribed = !!subscriptionForPeer(p.instanceId);
const busy = busyPeerId === p.instanceId;
+ // Disable when the peer's syncCategories doesn't cover this
+ // record kind. server-side pushRecordToPeer would otherwise
+ // accept the subscription but refuse every push with
+ // `category-disabled`, leaving the UI with a misleading
+ // "Syncing" toast for a peer that won't actually receive
+ // any pushes.
+ const categoryEnabled = peerHasMatchingCategory(p);
+ const categoryLabel = requiredCategory === 'universe' ? 'Universe' : 'Pipeline';
return (
<li key={p.instanceId}>
<button
type="button"
onClick={() => handleToggle(p)}
- disabled={busy}
- className="w-full text-left px-3 py-2 hover:bg-port-bg disabled:opacity-50 flex items-start gap-2"
+ disabled={busy || !categoryEnabled}
+ title={!categoryEnabled ? `Enable ${categoryLabel} sync for this peer on the Instances page first.` : undefined}
+ className="w-full text-left px-3 py-2 hover:bg-port-bg disabled:opacity-50 disabled:cursor-not-allowed flex items-start gap-2"
>
<span className="mt-0.5 shrink-0">
{busy
@@ -165,6 +186,7 @@ export default function SyncToPeerButton({
<div className="text-[10px] text-gray-500 truncate">
{p.status === 'online' ? 'online' : p.status || 'offline'}
{p.host ? ` · ${p.host}` : p.address ? ` · ${p.address}` : ''}
+ {!categoryEnabled && ` · ${categoryLabel} sync off`}
</div>
</div>
</button>
diff --git a/client/src/components/sharing/SyncToPeerButton.test.jsx b/client/src/components/sharing/SyncToPeerButton.test.jsx
index 269c67c01c..69ec4db4b7 100644
--- a/client/src/components/sharing/SyncToPeerButton.test.jsx
+++ b/client/src/components/sharing/SyncToPeerButton.test.jsx
@@ -19,8 +19,11 @@ beforeEach(() => {
vi.clearAllMocks();
api.getInstances.mockResolvedValue({
peers: [
- { instanceId: 'peer-a', name: 'Peer A', enabled: true, status: 'online', host: 'host-a.tail.net' },
- { instanceId: 'peer-b', name: 'Peer B', enabled: true, status: 'offline', address: '10.0.0.3' },
+ // syncCategories needs to include the record-kind-matching category
+ // (universe for these tests) so the dropdown's peerHasMatchingCategory
+ // guard doesn't disable the row.
+ { instanceId: 'peer-a', name: 'Peer A', enabled: true, status: 'online', host: 'host-a.tail.net', syncCategories: { universe: true, pipeline: true } },
+ { instanceId: 'peer-b', name: 'Peer B', enabled: true, status: 'offline', address: '10.0.0.3', syncCategories: { universe: true, pipeline: true } },
{ instanceId: 'peer-c', name: 'Peer C disabled', enabled: false, status: 'offline' },
{ instanceId: '', name: 'No-id peer', enabled: true },
],
diff --git a/server/lib/syncWire.js b/server/lib/syncWire.js
index 7c346a3180..bfc99089c2 100644
--- a/server/lib/syncWire.js
+++ b/server/lib/syncWire.js
@@ -88,6 +88,23 @@ export function sanitizeRecordForWire(kind, record) {
// that carried `ephemeral: true` on disk MUST hash identically against
// a pre-flag peer's tombstone for the same record.
const { deleted: _deleted, deletedAt: _deletedAt, ephemeral: _ephemeral, ...rest } = record;
+ // EPHEMERAL TOMBSTONES — minimize the payload. If a record was
+ // created ephemeral and never shared, deleting it would otherwise
+ // ship the full content to peers that never had it (just because
+ // tombstones cross the wire). Minimize to `{ id, updatedAt }` plus
+ // the tombstone fields — enough for an ack on a peer that DID
+ // have the live copy (no-op for one that didn't), no content
+ // leakage either way.
+ if (record.ephemeral === true) {
+ const minimized = {
+ id: record.id,
+ ...(record.updatedAt ? { updatedAt: record.updatedAt } : {}),
+ // Issues need their parent linkage so mergeIssuesFromSync can
+ // route the tombstone to the right series cascade.
+ ...(kind === 'issue' && record.seriesId ? { seriesId: record.seriesId } : {}),
+ };
+ return { ...minimized, ...sanitizeSoftDeleteFields(record) };
+ }
return { ...rest, ...sanitizeSoftDeleteFields(record) };
}
case 'mediaCollection': {