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([sharing-v2-per-sender-subscription-filenames]): archive to DONE.md

[._.]/ Adam Eivy42c0cff30cf1
diff --git a/DONE.md b/DONE.md
index 3fde88f3bd..c7e777addf 100644
--- a/DONE.md
+++ b/DONE.md
@@ -10,6 +10,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./
### 2026-05-17
+- **[sharing-v2-per-sender-subscription-filenames] Per-sender subscription filenames.** `subscriptionFilename()` now keys on the `senderInstanceId` segment (`sub-<kind>-<recordId>-<senderInstanceId>.json`) so two peers subscribed to the same record write to distinct bucket files instead of clobbering each other. Touched `server/services/sharing/manifest.js` (signature + new `legacySubscriptionFilename` export + `manifestFilename` plumbs `manifest.senderInstanceId` through to the helper + extracted `SUBSCRIPTION_FILE_PREFIX` constant shared with the prune filter), `subscriptions.js` (`unsubscribe` now reads `getInstanceId()` for the new name AND best-effort cleans up the pre-v2 legacy file only when its `senderInstanceId` matches this instance — so a still-subscribed peer's pre-upgrade file isn't stomped), `importer.js` (inbox dedup now keys on `(recordKind, recordId, senderInstanceId)` so peerB's update no longer wipes peerA's inbox row), and the `exporter.js` doc comment. Coverage: 3 new tests in `subscriptions.test.js` (filename-with-sender, legacy cleanup gated on own instance, legacy preserved for other peer's instance), 2 new in `manifest.test.js` (per-sender determinism + two-peer-distinct + `legacySubscriptionFilename` shape), and integration test updated to assert the new naming. All 5,315 server tests pass. Follow-up captured in PLAN.md as `[sharing-inbox-orphans-on-peer-instance-id-rotation]` — per-sender dedup means a peer that rotates its instanceId leaves their old inbox row as an orphan (pre-v2 dedup wiped it implicitly).
- **[extract-upsertbyidprepend-helper-universe-builder] Extract `upsertByIdPrepend(list, item)` helper.** New `client/src/lib/upsertByIdPrepend.js` collapses the "filter-by-id then prepend" worlds-list upsert into one helper. The PLAN line called out 3 sites; the actual count was 7 — all collapsed to `setWorlds((prev) => upsertByIdPrepend(prev, entity))`: 1 in `client/src/hooks/useUniverseAction.js` (LLM-action result merge) + 6 in `client/src/pages/UniverseBuilder.jsx` (`handleCreate`, `handleSave`, expand auto-save, refine auto-save, `handleMoveCategoryToTrunk`, `handleGenerateInCategory`). 4 new vitest cases in `upsertByIdPrepend.test.js` (new-id prepend, id replacement, empty-list, no input mutation).
- **[universe-builder-redesign-trunks-sub-buckets] Universe Builder redesign — trunks + sub-buckets layout (Phases A–D + Phase C follow-ups).** Multi-phase rewrite landing across 2026-05-15 → 2026-05-17. Phase A added a `kind: 'characters'|'settings'|'objects'|'other'` field to every category bucket + a migration to backfill the built-in defaults; Phase B taught `buildExpansionPrompt()` + `isExpansionShape()` to emit and accept rich canon arrays alongside categories, with client-side `handleExpand` merging canon entries into `universe.{characters,settings,objects}` (dedupe by name, respect locks); Phase C rewrote the page as a tabbed-trunk layout (Bible / Cast / Places / Objects / Other / Composites / Render) with URL state, a unified `EntryCard` rendering both canon entries and category variations, and per-trunk / per-bucket / all-canon batch-render targeting; Phase D shipped `POST /:id/promote-variation` to LLM-expand a variation into a full canon entry (atomic canon append + variation removal in one `updateUniverse` patch, duplicate-name 409 before the LLM call, trunk picker for `kind: 'other'` buckets). Phase C follow-ups closed today: (1) `updateUniverse(id, mutator)` now accepts an async `mutator(latest) => patch` callback that runs INSIDE `queueUniverseWrite` — `autoSortOtherBuckets` and `promoteVariationToCanon` route their read-modify-write through this so a slow LLM call can't admit a concurrent edit between read and persist; promote's variation removal also re-locates by label inside the queue rather than relying on the stale pre-LLM index, and the duplicate-name 409 is re-checked against the latest canon (returns `UNIVERSE_PROMOTE_CATEGORY_GONE` / `UNIVERSE_PROMOTE_VARIATION_GONE` when the bucket/variation disappears mid-flight); (2) `handleAutoSort` / `handlePromoteVariation` / `handleGenerateInCategory` now flush a dirty draft via `handleSave()` before kicking off — `UniverseBuilder.jsx` tracks a `savedDraftSnapshotRef` baseline (compared via `draftSnapshotForDirty`) that updates on universe-load, manual save, expand auto-save, refine auto-save, generate auto-save, and after each LLM mutator's `onFreshResult` merge. `useUniverseAction` gained a `preflight` option that runs AFTER the ref/savedId guard so double-clicks short-circuit before flushing. 5 new server tests (`updateUniverse` mutator overload — happy path, null-skip, throw-propagation, non-object validation, queue-ordering against a parallel literal-patch write) + 4 new client tests (`useUniverseAction` preflight — returns-false abort, throw-as-false, returns-true continue, post-ref-guard ordering).
- **[canoncard-from-series-name-full-provenance-label] CanonCard "from series: <name>" full provenance label.** The provenance chip now reads `seriesNameMap?.[entry.sourceSeriesId]` to render `from <Series Name>` with `Introduced by series "<name>" (<id>)` in the tooltip; missing-name fallback preserves the existing `from series` label + id-only tooltip. Chip rendering extracted into a `SourceSeriesChip` helper alongside `ChipPicker` / `ReadonlyChip` in `client/src/components/pipeline/CanonCard.jsx`. Map plumbed from both parents: `UniverseCanonSection.jsx` passes `usage?.seriesNameMap` (no new fetch — reuses the canon-usage call it already makes), and `NounsStage.jsx` fetches `getUniverseCanonUsage(series.universeId)` once on universe load. Server-side `getUniverseCanonUsage` (`server/services/canonUsage.js`) gains a top-level `seriesNameMap: { [seriesId]: name }` field built from every `linkedSeries` (not just ones with prose-match rows) so an entry whose `sourceSeriesId` points at a series with no matching prose still resolves to a name. Coverage: 4 new vitest cases in `CanonCard.test.jsx` (chip omitted with no `sourceSeriesId`; generic fallback when map missing; resolved name + dual-tooltip when present; fallback when id not in map) and 2 new `canonUsage.test.js` cases (linked-with-no-prose-match included; empty map when no series link). NounsStage's per-render fetch is acknowledged as quadratic-cost relative to need; deferred to `[nounsstage-cheaper-seriesnamemap-fetch]` for a thin-endpoint follow-up.
diff --git a/PLAN.md b/PLAN.md
index ac7e0bbcf5..fce386b088 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -16,8 +16,8 @@ _Nothing currently parked — pick the next item from the Backlog._
- [ ] [extend-syncorchestrator-to-cover-pipeline-universe] **Extend `syncOrchestrator` to cover pipeline/universe over Tailscale.** Same-network peers should sync these categories without going through a bucket.
- [ ] [multi-hop-provenance-chains-re-share-authors-a] **Multi-hop provenance chains.** Re-share authors a fresh `origin` block; `chain[]` would preserve full attribution. Defer until users ask.
- [ ] [same-collection-export-pattern-for-pipeline-series] **Same collection-export pattern for pipeline series with auto-collections.** Series renders that get auto-filed into a per-series collection should also flow through `manifest.collection`.
-- [ ] [sharing-v2-per-sender-subscription-filenames] **Per-sender subscription filenames.** Today `subscriptionFilename()` returns `sub-<kind>-<recordId>.json` (`server/services/sharing/manifest.js:194`); extend to `sub-<kind>-<recordId>-<senderInstanceId>.json` so two peers sharing the same record don't collide. Tombstone-based item removals already shipped for annotations (`server/services/sharing/annotationsSync.js:56`).
- [ ] [sharing-inbox-live-subscription-badge] **"🔄 live" badge on inbox subscription rows.** No badge UI today; mark rows whose subscription file has updated within the last sync window.
+- [ ] [sharing-inbox-orphans-on-peer-instance-id-rotation] **Cull orphan inbox rows on peer instance-id rotation.** Post-`sharing-v2-per-sender-subscription-filenames` (2026-05-17), inbox dedup in `server/services/sharing/importer.js:applyInbox` keys on `(recordKind, recordId, senderInstanceId)`. A peer that rotates its `instanceId` (factory reset, new device onboarding) re-shares with a new id; the old id's row no longer matches and persists forever as an "active" subscription row. Detect on import: when an incoming subscription manifest's `(recordKind, recordId, source)` matches an existing row but `senderInstanceId` differs, prompt the user (or auto-cull rows older than N days with the same source name) so stale identity rows don't pile up. Pre-v2 behavior wiped these implicitly because dedup was per-record, not per-sender.
### Importer (deferred research)