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 (codex): backfill authors + mediaCollections on category toggle

[._.]/ Adam Eivy502d8181ed43
diff --git a/PLAN.md b/PLAN.md
index 776b9140c0..0a9d582e2f 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -32,6 +32,8 @@ independently.
- [ ] [authors-headshot-upload-asset-sync] **Make uploaded (non-gallery) author headshots transfer their bytes to peers.** The authors federation (above) syncs the headshot IMAGE BYTES only when `headshotImageUrl` points at `/data/images/<f>` (gallery-picked) — `headshotImageFilename()` in `authors/logic.js` maps that to an `image` asset the peer-sync pull worker fetches. But the Authors page's *upload* button (`client/src/pages/Authors.jsx` → `POST /api/uploads`) stores the file in `data/uploads/` and sets `headshotImageUrl = /api/uploads/<f>`, which is NOT one of the three pullable asset kinds (`image`→`/data/images`, `image-ref`, `video`), so on a peer the author record syncs but the headshot 404s. Two options: (a) route author-headshot uploads through the gallery (`/data/images/`) so they ride the existing `image` pull path (smaller change, recommended), or (b) add an `upload`/`/data/uploads` pullable asset kind end-to-end — new `ASSET_KIND_TO_URL_PREFIX` entry + `directoryForAssetKind` + `PATHS.uploads` + the `peerAssetManifestEntrySchema` kind enum in `peerSyncValidation.js`. External `http(s)`/`data:` URLs intentionally never transfer (the receiver resolves them itself). Estimated scope: small (a) / medium (b).
+- [ ] [peer-sync-unknown-kind-as-schema-block] **Treat a pre-feature peer's generic 400 rejection of a brand-new record `kind` as a schema-version block (not a bare `http-400` retry).** From codex review of the authors-federation PR (#1263). `pushRecordToPeer`'s schema-block / SchemaGapBadge pause path keys on a **409 `SCHEMA_VERSION_AHEAD`** from `applyIncomingPush`'s version gate. But when a NEW record kind is introduced (authors now; `mediaCollection` had the same gap when it landed), a peer running an older PortOS whose `peerSyncPushSchema` discriminated union doesn't include that `kind` rejects the push at **Zod validation with a generic 400** — *before* `applyIncomingPush` (and its gate) ever runs. So the sub retries as a plain `http-400` and the UI never surfaces "peer needs to update PortOS." This is benign under the trust model (the push lands once the peer upgrades; no corruption), which is why it's deferred — but the proper fix is cross-cutting version-negotiation work that applies to EVERY kind, not just authors: in `pushRecordToPeer`, detect a 400 whose body indicates an unrecognized `kind` discriminator (mirror the existing `portosMeta`/`catalogBundle` 400-retry detection block) and route it into `persistSchemaVersionBlock` with an empty-gap/`peer-pre-feature` marker so the SchemaGapBadge shows and the edit-push cooldown engages, OR preflight the peer's advertised `schemaVersions`/capabilities before creating the sub. Needs its own tests for the unknown-kind-400 classification. Estimated scope: medium (cross-cutting peer-sync negotiation + tests).
+
### Trigger-gated (waiting for a precondition)
- [ ] [ref-watch-phosphene-spaced-lora-id-decode-validate] **Harden trained-character/LoRA id handling for spaced filenames + percent-encoded path segments.** From `reference-watch` review of Phosphene (commit `ce031395`, 2026-06-12). Upstream's character-id validation regex was a hard gate that ran *before* the sidecar was read, so a LoRA whose trigger/filename contained a space (e.g. `Annie Phosphene_v2.safetensors`) was misclassified as style-only and vanished from the Characters tab; the fix widened the id class to allow spaces and made the route `unquote()`-then-validate (staying traversal-safe because an encoded `../` or `/` decodes to chars the class still rejects). PortOS's equivalent is `server/services/loras.js#assertSafeLoraFilename()` plus the trained-LoRA `character` classification it surfaces. Fix (if applicable): audit whether any PortOS LoRA/character id route 404s or misclassifies spaced filenames and whether percent-encoded id segments are decoded before validation; if so, widen the allowed id class to permit spaces and decode-then-validate in the route. **Decision needed:** confirm PortOS actually exposes id-addressed character/LoRA routes (not just filename-addressed ones) and reproduces the spaced-name misclassification before investing — it may already be covered by `assertSafeLoraFilename`'s filename-only model. Estimated scope: small.
diff --git a/server/services/instances.js b/server/services/instances.js
index 62198ca041..bcf620e81a 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -232,6 +232,23 @@ const DEFAULT_SYNC_CATEGORIES = {
export { DEFAULT_SYNC_CATEGORIES };
+// Sync categories whose records ride the PER-RECORD push pipeline (not the 60s
+// snapshot loop), paired with the record kind autoSubscribePeerToAllRecords
+// backfills. A false→true toggle on any of these triggers an inline backfill of
+// existing local records so the user doesn't have to wait for the next
+// `peer:online` / manual sync-now. Mirror of peerSync's KIND_TO_CATEGORY
+// (inverted). `pipeline → series` bundles child issues at push time; authors +
+// mediaCollections are standalone per-record kinds with NO snapshot category, so
+// the toggle-time backfill is the ONLY place existing records get subscribed
+// short of a reconnect — omitting them here strands a user's existing authors /
+// collections until the peer next comes online.
+const PER_RECORD_CATEGORY_KINDS = Object.freeze([
+ ['universe', 'universe'],
+ ['pipeline', 'series'],
+ ['mediaCollections', 'mediaCollection'],
+ ['authors', 'author'],
+]);
+
export async function addPeer({ address, port = DEFAULT_PEER_PORT, name, host, auth }) {
const peer = await withData(async (data) => {
const normalizedHost = validHost(host);
@@ -311,10 +328,9 @@ export async function updatePeer(id, updates) {
const prev = peer.syncCategories || DEFAULT_SYNC_CATEGORIES;
const incoming = updates.syncCategories;
// Detect false→true flips for kinds the per-record push pipeline owns
- // (universe → 'universe' kind; pipeline → 'series' kind, which bundles
- // child issues at push time). enabled + outbound-allowed gating is
+ // (PER_RECORD_CATEGORY_KINDS). enabled + outbound-allowed gating is
// enforced inside peerSync.autoSubscribePeerToAllRecords.
- for (const [cat, kind] of [['universe', 'universe'], ['pipeline', 'series']]) {
+ for (const [cat, kind] of PER_RECORD_CATEGORY_KINDS) {
if (prev[cat] !== true && incoming[cat] === true) turnedOnKinds.push(kind);
}
peer.syncCategories = { ...prev, ...incoming };
@@ -791,7 +807,7 @@ export async function applyReciprocalSync(instanceId, categories) {
const next = { ...prev, ...sanitized };
// No-op when nothing actually flips — the echo guard.
if (Object.keys(next).every(k => next[k] === prev[k])) return entry;
- for (const [cat, kind] of [['universe', 'universe'], ['pipeline', 'series']]) {
+ for (const [cat, kind] of PER_RECORD_CATEGORY_KINDS) {
if (prev[cat] !== true && next[cat] === true) turnedOnKinds.push(kind);
}
entry.syncCategories = next;