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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([sharing-annotationssync-cache-bucket-asset-keys]): roll cached mtime forward after annotation write
[._.]/ Adam Eivy69ad2f953409
diff --git a/server/services/sharing/annotationsSync.js b/server/services/sharing/annotationsSync.jsindex 80d8ca3a9e..794964da56 100644--- a/server/services/sharing/annotationsSync.js+++ b/server/services/sharing/annotationsSync.js@@ -188,6 +188,15 @@ export async function exportAnnotationsToBucket(bucket, localAnnotations, senderproducedByVersion,});const filename = await writeManifest(bucket.path, manifest);+ // The annotation manifest we just wrote bumps the manifests-dir mtime, but+ // its `assetRefs: []` means the bucket's asset-key set is unchanged. Roll+ // the cached mtime forward so the next flush still hits this bucket's+ // cache instead of re-parsing every other manifest in the dir.+ const cached = manifestKeysCache.get(bucket.path);+ if (cached) {+ const dirStat = await stat(join(bucket.path, 'manifests')).catch(() => null);+ if (dirStat) cached.manifestsMtimeMs = dirStat.mtimeMs;+ }return { skipped: false, filename, entryCount: Object.keys(filtered).length };}diff --git a/server/services/sharing/annotationsSync.test.js b/server/services/sharing/annotationsSync.test.jsindex 31ae5956d8..a32b303f3b 100644--- a/server/services/sharing/annotationsSync.test.js+++ b/server/services/sharing/annotationsSync.test.js@@ -225,6 +225,37 @@ describe('sharing/annotationsSync.listBucketAssetKeys cache', () => {expect(readManifest).toHaveBeenCalledTimes(1);});+ it('rolls the cached mtime forward after a successful annotation write so the next flush still hits', async () => {+ // exportAnnotationsToBucket calls writeManifest, which atomicWrite's+ // temp+rename bumps the manifests-dir mtime. Without the post-write+ // refresh, the very next flush against the same bucket misses the cache+ // and re-parses every other manifest — defeating the optimization in+ // the common "buckets I've actually written to" case.+ const { listManifestFilenames, readManifest } = await import('./manifest.js');+ listManifestFilenames.mockClear();+ readManifest.mockClear();+ listManifestFilenames.mockResolvedValue(['a.manifest.json']);+ readManifest.mockResolvedValue({ assetRefs: [{ kind: 'image', ref: 'a.png' }], collection: null });++ const ann = { 'image:a.png': { starred: true, note: 'hi', updatedAt: '2026-01-01T00:00:00.000Z' } };+ // First call: cache miss, populates entry, then writes manifest. Simulate+ // the post-write stat returning a NEW mtime (rename bumped it).+ statMock.mockResolvedValueOnce({ mtimeMs: 100 }); // pre-scan stat+ statMock.mockResolvedValueOnce({ mtimeMs: 200 }); // post-write stat+ const r1 = await svc.exportAnnotationsToBucket(bucket(), ann, 'local-instance');+ expect(r1.skipped).toBe(false);++ // Second call: cache lookup sees mtime 200 (rolled forward post-write)+ // and the live stat also returns 200 — cache hit, no re-parse.+ statMock.mockResolvedValueOnce({ mtimeMs: 200 });+ statMock.mockResolvedValueOnce({ mtimeMs: 300 }); // post-write of 2nd flush+ await svc.exportAnnotationsToBucket(bucket(), ann, 'local-instance');++ // Manifest parse only ran on the first flush — the post-write refresh+ // prevented a spurious invalidation between flushes.+ expect(listManifestFilenames).toHaveBeenCalledTimes(1);+ });+it('invalidates when manifests-dir mtime advances (new/removed manifest)', async () => {const { listManifestFilenames, readManifest } = await import('./manifest.js');listManifestFilenames.mockClear();