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
Media-library federation (#1566)
Approved: 2026-06-24 · Issue: #1566 (child of #1561 full-sync tracking) · Branch: next/issue-1566
Goal
For a declared full-sync peer pair, mirror the standalone media library — generated images/videos/thumbnails/audio plus user-uploaded music — and their bytes, so each peer's Media tab is a complete replica. Today only assets referenced by a synced creative record get receiver-pulled; the standalone library + its bytes do not federate.
Key finding — most of the machinery already exists
- Byte transport is fully reusable: static mounts for
/data/{images,image-refs,videos, video-thumbnails,audio,music}all exist (server/index.js), andfetchCappedAssetBuffer- the receiver-pull diff are generic.
- Video history metadata already union-merges via the
videoHistorydataSync category (union byid, LWW) for all peers — what's missing is the backing.mp4/thumbnail bytes. media_assetsis a derived index rebuilt from disk byreconcileMediaAssets()(idempotent) — the receiver just re-runs it after bytes land.
So #1566 reduces to: a library-level manifest (vs per-record), a fullSync-gated receiver sweep, two small kind-map extensions (audio + video-thumbnail), and a post-pull reconcile.
Decisions (locked 2026-06-24)
data/history.jsonlis NOT federated. It is the generic app action-audit log (logAction, 500-entry cap), machine-local activity — not media gen history. "Generation history converges" is satisfied byvideo-history.json(already union-merges) + image sidecars (ride with image bytes).- All five media kinds mirror, including user-uploaded
data/music.image-refsis excluded (ephemeral FLUX multi-ref scratch). - Byte replication is gated to
peer.fullSync === true. Non-fullSync peers are unchanged (today's record-referenced-only behavior).
Implementation
Sender — advertise the whole library
buildMediaLibraryManifest()walksPATHS.{images,videos,videoThumbnails,audio,music}, hashes each file (reusehashSimpleAsset/getOrComputeImageSha256/sidecarGenParamsHash), honors backupDEFAULT_EXCLUDES. Returns{ schemaVersion, manifestHash, assets: [{ kind, filename, sha256, sidecarSha256? }] }. Logged cap on entry count (pagination = follow-up if ever hit).GET /api/peer-sync/library-manifestinserver/routes/peerSync.js.
Receiver — fullSync-gated sweep
- New
server/services/sharing/mediaLibrarySync.js: per onlinefullSyncpeer, fetch manifest (short-circuit on unchangedmanifestHash), diff vs local disk, pull missing bytes viafetchCappedAssetBuffer(image sidecars ride alongside). Per-peer re-entrancy lock + cooldown. DebouncedreconcileMediaAssets()+ emit existingpeerSync:asset-arrived. - Hook into the existing 30s
probeAllPeers()success path (server/services/instances.js).
Shared extensions
assetDirForKind(peerSync.js:~979) +diffAssetManifestAgainstLocal+ per-kind byte caps: addaudio→PATHS.audio,video-thumbnail→PATHS.videoThumbnails.PORTOS_SCHEMA_VERSIONS.mediaLibrary = 1; Zod manifest-response schema inpeerSyncValidation.js; addaudio+video-thumbnailto the kind enum. Receiver gently skips (not rejects) a sender whose manifest schema is newer.
Tests
manifest build/excludes · diff across kinds (incl audio/thumbnail) · fullSync gate (non-fullSync
= no-op) · schema-skip · history.jsonl untouched · reconcile-after-pull called · re-entrancy lock.
Acceptance (from #1566)
- Library asset bytes replicate to full-sync peers via manifest+pull with SHA256 integrity.
- Generation history union-merges across peers without duplicates (video-history + sidecars).
-
media_assetsindex rebuilds on the receiver after bytes arrive. - Byte replication gated to full-sync peers and respects backup exclusions.
Test plan
Verify on this instance ↔ the void peer: enable fullSync A↔B, generate media on A not
attached to any synced record, confirm B's Media tab converges (and vice-versa).