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-annotationssync-cache-bucket-asset-keys]): archive to DONE.md

[._.]/ Adam Eivyd1d0d57a4c33
diff --git a/DONE.md b/DONE.md
index e90bc2f598..34db5536b7 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-19
+- **[sharing-annotationssync-cache-bucket-asset-keys] Cache `listBucketAssetKeys` per (bucket, manifests-dir mtime).** `server/services/sharing/annotationsSync.js#listBucketAssetKeys` previously re-scanned every manifest in every auto-merge bucket on every 2s-debounced annotation flush. Manifests are the only source of truth post-v2 (content-addressed `assets/blobs/<hash>` paths don't carry filenames), so per-flush fan-out scaled O(buckets × manifests). The function now stats `<bucket>/manifests/` on each call and reuses the previously-parsed `Set<assetKey>` whenever the directory mtime matches — every manifest write/archive goes through `atomicWrite` (temp + rename) or `rename`, both of which bump the dir mtime, so the mtime is a complete invalidation signal. The legacy v1 `assets/{images,videos}/` dir scan stays uncached (small + rare fall-through). The annotation manifest emitted by `exportAnnotationsToBucket` rolls the cached mtime forward so the post-write bump doesn't immediately invalidate the same bucket's cache on the next flush. New `__resetBucketAssetKeysCache` test hook + 7 new vitest cases in `annotationsSync.test.js` covering hit, mtime-advance miss, per-bucket isolation, legacy-dir-scan-still-runs, ENOENT-on-manifests-dir as a stable cache key, non-ENOENT stat error bypasses caching, and post-write mtime-roll-forward keeps the next flush hot.
- **[export-isplainobject-helper-from-server-lib-objects] Export `isPlainObject` from `server/lib/objects.js`.** Promoted the previously-private `isPlainObject(v) = !!v && typeof v === 'object' && !Array.isArray(v)` helper to a named export of `server/lib/objects.js` (surfaces automatically through the `server/lib/index.js` barrel) and migrated 18 inline call sites onto it — every site that exactly matched the 3-part check pattern. Sites: the previously-private declarations in `server/lib/objects.js` + `server/lib/mediaModels.js` (which now imports from objects.js), the 12 sites enumerated in PLAN (`services/calendarAccounts.js`, `messageAccounts.js`, `messagePlaywrightSync.js`, `loras.js`, `mortalLoomStore.js`, `updateChecker.js`, `meatspacePost.js`, `dataSync.js`, `featureAgents.js`, `taskSchedule.js` — also dropped its single-use local `const isPlainObject`, `pipeline/issues.js`, `sharing/exporter.js`), and 4 additional matching sites that landed between when the PLAN entry was authored and now (`routes/loras.js#DELETE /auth/civitai`, `services/universeBuilderExpand.js#sanitizeCategory`, `server/scripts/moltbook-probe.mjs`, and `scripts/check-themes.js` ×2 — the last two caught by codex review after the initial grep missed `.mjs` files and the top-level `scripts/` dir). Sites with a partial-shape second predicate (`mortalLoomStore.js`'s `current[k] && typeof current[k] === 'object'` and the symmetric block in `featureAgents.js`) kept their second predicate intact — only the full 3-part check was migrated, keeping the PR a pure refactor. Helper retains the loose "non-null, non-array `object`" semantics that match every call site's behavior (Date / Map / class instances still return true — documented in the JSDoc and locked in by 3 new vitest cases). `server/lib/README.md` row updated to name both `deepMerge` and `isPlainObject`. No behavioral changes. All 5832 server tests + 154 client tests pass.
- **[unify-videogen-resolutions-with-shared-image-gen] Unify VideoGen `RESOLUTIONS` with shared image-gen list.** New `client/src/lib/videoGenResolutions.js` holding `VIDEO_RESOLUTIONS` as the companion to `imageGenResolutions.js`, registered in the lib barrel + README so future image+video work finds it via the catalog. New `resolveResolutionLabel(list, w, h) → { matched, label }` helper in `imageGenResolutions.js` collapses the duplicate "find matching preset OR fall back to `${w}×${h}` for the custom-fallback dropdown option" pattern that lived inline in both `client/src/pages/VideoGen.jsx` and `client/src/components/imageGen/ImageGenControls.jsx`. Both consumers now import the helper; image side's prior `(width && height ? ... : '')` empty-string-when-unset guard is preserved in the helper (returns `label: ''` when either dimension is falsy). Picked a distinct constant name (`VIDEO_RESOLUTIONS` vs the image side's `RESOLUTIONS`) to avoid a flat-barrel name collision in the lib `index.js` `export *` chain. All 154 client tests pass (barrel-shape test confirms the new module is wired correctly into both `index.js` and `README.md`).
- **[med-sharing-server-services-sharing] [med-sharing-server-services-mediaannotations-js-38] [low-sharing-server-services-mediaannotations-js] [low-sharing-server-services-mediaannotations-js-2] [low-sharing-server-services-sharing] Sharing/annotation-merge hardening bundle.** Five v2.1.0 pre-release residue items shipped together because they all touch the same annotation-sync + LWW-merge surface. (1) `annotationsSync.flushAll` no longer resolves one `sourceName` for all buckets — `exportAnnotationsToBucket` now resolves its own per-bucket name, so per-bucket `displayNameOverride` is honored in outgoing annotation manifest envelopes the same way it already was for series/universe/media manifests. The bucket-effective resolver lives in `sharing/annotationIdentity.js` as a new `resolveBucketSourceName(bucket)` export consumed by both the exporter and the annotation flush (the exporter's local copy in `sharing/exporter.js` was deleted in favor of the shared helper). (2) `mediaAnnotations.mergePeerAnnotations` now pre-rejects peer payloads with missing/invalid `updatedAt` before they reach `sanitizeAuthorEntry`'s `now`-fallback — previously a malformed peer record would always win LWW. The pre-check disambiguates "empty tombstone" (still applies as a delete) from "malformed payload" (now ignored entirely, instead of silently deleting the prior peer entry through the tombstone branch). (3) `sanitizeAuthorEntry` gained an opt-in `clampUpdatedAtTo` option used by the merge path so a peer whose clock is years ahead can't ratchet every subsequent LWW round on the same key — its `updatedAt` is clamped to local-now on import without disturbing reasonable timestamps. (4) `mergePeerAnnotations` rejects `peerInstanceId === 'unknown'` (and empty/non-string) on import — the outgoing path already guarded but a hand-crafted manifest or inconsistent peer could otherwise alias every record into the same "unknown" bucket and clobber each other on every merge. (5) `exportAnnotationsToBucket` now has a cheap early-out before `listBucketAssetKeys`: if local has zero annotations AND no prior record exists on disk for this `(bucket, instance)`, skip the manifest+asset-dir scan entirely (the common fresh-install fan-out case). A late-stage skip (both filtered AND prior empty) still covers the case where the bucket has assets but none overlap local. Coverage: 11 new vitest cases across `mediaAnnotations.test.js` (refuses `'unknown'` / empty peer id, drops missing+invalid updatedAt without nuking prior, clamps future-skewed peer ts) and new sibling `sharing/annotationsSync.test.js` (per-bucket displayNameOverride honored in record, cheap early-out skips `listManifestFilenames`, late skip when no local matches + no prior, asset-less bucket short-circuit, inbox-mode short-circuit, tombstone synthesis preserved for prior keys still in bucket). `/simplify` follow-up deferred to `[promote-unknown-instance-id-constant]` — promote the existing `UNKNOWN_INSTANCE_ID` constant from `importer.js` to a shared module + replace the bare `'unknown'` literal at the four remaining sites. All 5775 server tests pass.
diff --git a/PLAN.md b/PLAN.md
index 961c37bd1f..a560451a22 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -20,10 +20,6 @@ _Nothing currently parked — pick the next item from the Backlog._
- [ ] [flux2-multi-reference-python-runner] **FLUX.2 multi-reference Python runner.** The UI + server contract for multi-reference editing shipped 2026-05-17 (slug `multi-reference-image-editing-for-flux-2-ui`); the Python runner (`scripts/flux2_macos.py`) currently ignores the `--reference-images`/`--reference-strengths` args that `local.js` now passes. Wire diffusers' multi-reference API in the runner and swap `server/lib/mediaModels.js#flux2-klein-9b` `tokenizerRepo` to `FLUX.2-klein-9B-kv` (gated repo — requires the user to accept the license on HF). Validate end-to-end with 2–4 uploaded refs.
-### Sharing — performance follow-ups (deferred from content-addressed asset dedup, 2026-05-18)
-
-- [ ] [sharing-annotationssync-cache-bucket-asset-keys] **Cache `listBucketAssetKeys` per (bucket, manifests-dir mtime).** Today `annotationsSync.js#listBucketAssetKeys` re-scans every manifest in every auto-merge bucket on every 2s-debounced annotation flush (post-v2 because content-addressed blob paths don't carry filenames, so manifests are the only source of truth). Memoize `Map<bucketPath, { mtime, keys }>` keyed on the manifests dir mtime; invalidate when mtime advances. The legacy `assets/{images,videos}/` dir scan is still needed as a fall-through for pre-v2 buckets and can run un-cached.
-
### Code quality / dedup (from `/simplify` passes)
- [ ] [extract-mergeexpandintodraft-draft-result-from] **Extract `mergeExpandIntoDraft(draft, result)` from `UniverseBuilder.jsx#handleExpand`.** The function is ~150 lines mixing pure-merge logic (categories, sheets, canon, locks) with I/O shell (API call, setDraft, auto-save, toast). Pull the merge into a top-level pure helper so the I/O surface shrinks and the merge is unit-testable. Deferred from Phase B `/simplify` to keep that PR tightly scoped.