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: keep tombstone required fields + reference-watch writable

Adam Eivy4b15dbb2c10a
diff --git a/PLAN.md b/PLAN.md
index 290efdb35f..83bfb8bcd6 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -23,6 +23,8 @@ 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-per-record-tombstone-ack-cursor] **Tombstone ack cursor is per-peer but should be per-(peer,record).** Codex iter-6 in v2.7.0 release review (P2). Today `ackDeletesUpTo(peerId, deletedAt)` writes a single high-water-mark per peer. If push for record-A fails and a later push for record-B succeeds, the receiver returns `ackedDeletesUpTo = B.deletedAt > A.deletedAt`; the sender then advances the cursor past A's deletedAt even though A was never confirmed delivered. After grace, `tombstoneGc` treats A as acked, prunes it, and A's stale live copy on the receiver resurrects on the next sync that lands. Fix options: (a) per-`(peer, kind, recordId)` cursor (storage proliferation; needs cleanup on record GC); (b) per-(peer, kind) cursor advanced only when the push response cumulatively confirms every-tombstone-up-to-that-deletedAt was delivered (requires receiver to track-and-respond with "I have all your tombstones up to T"); (c) keep current cursor but also persist a per-record `lastConfirmedPushedAt` on each subscription row, and let GC's `cutoffForKind` use `min(min-of-lastConfirmedPushedAt-across-all-records-of-this-kind)`. Option (c) is the smallest behavioral change. Defer because under the dominant single-writer/single-reader pattern in PortOS, push failures are rare and re-tried on the next event tick.
+- [ ] [peer-sync-medialightbox-use-mediaimage-for-syncing-assets] **`MediaLightbox.jsx` uses a raw `<img src=...>` for the main media element — peer-synced images that haven't been pulled yet show a broken image and don't get the `peerSync:asset-arrived` placeholder/live-swap.** Codex iter-6 in v2.7.0 release review (P2). The `MediaImage` component was added specifically to handle this, but only thumbnail/card paths use it. Replace the lightbox's `<img>` with `MediaImage` so opening an image during the sync window shows the "Syncing" placeholder and atomically swaps to bytes when they land. Cross-check every `<img>` in `MediaPreview.jsx`, `MediaCollectionDetail.jsx`, `UniverseBuilder.jsx` for the same gap. Defer because the lightbox is reached after the user clicks a thumbnail — by then the thumbnail's MediaImage has likely already swapped to live bytes, so the lightbox typically sees the same.
- [ ] [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.
diff --git a/server/lib/syncWire.js b/server/lib/syncWire.js
index bfc99089c2..0982c60f10 100644
--- a/server/lib/syncWire.js
+++ b/server/lib/syncWire.js
@@ -91,18 +91,30 @@ export function sanitizeRecordForWire(kind, 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.
+ // tombstones cross the wire). Minimize to the structural fields
+ // the receiver's sanitizers REQUIRE (otherwise sanitizeTemplate /
+ // sanitizeSeries / sanitizeIssue drops the record on the floor
+ // and the tombstone never lands) plus the tombstone fields.
+ //
+ // Required fields by kind, derived from sanitizeTemplate /
+ // sanitizeSeries / sanitizeIssue:
+ // universe → name (non-empty string)
+ // series → name (non-empty string)
+ // issue → seriesId + title
+ // We send a placeholder when the on-disk value is missing — the
+ // receiver only uses these to pass the sanitizer; the tombstone
+ // fields drive everything downstream.
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 } : {}),
};
+ if (kind === 'universe' || kind === 'series') {
+ minimized.name = isNonEmptyStr(record.name) ? record.name : '_';
+ } else if (kind === 'issue') {
+ if (record.seriesId) minimized.seriesId = record.seriesId;
+ minimized.title = isNonEmptyStr(record.title) ? record.title : '_';
+ }
return { ...minimized, ...sanitizeSoftDeleteFields(record) };
}
return { ...rest, ...sanitizeSoftDeleteFields(record) };
diff --git a/server/services/referenceRepos.js b/server/services/referenceRepos.js
index 35dd8543ca..5bbac29e9b 100644
--- a/server/services/referenceRepos.js
+++ b/server/services/referenceRepos.js
@@ -621,7 +621,12 @@ export async function triggerReferenceAnalysis(app, ref, snapshot) {
repoPath: app.repoPath,
analysisType: 'reference-watch',
autoGenerated: true,
- readOnly: true,
+ // The reference-watch prompt v2 instructs the agent to APPEND
+ // slug-tagged checklist items to PLAN.md (and commit). readOnly:true
+ // would inject the "do not modify or commit files" guard into the
+ // system prompt and the agent would refuse to write the PLAN
+ // entries — defeating the whole flow. Mark writable.
+ readOnly: false,
context: fullPrompt,
},
autoApproved: true,