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
address review (copilot): videoHistory snapshot includes hidden rows' content but strips the hidden flag, so divergent hide-state across peers still converges
Adam Eivy3ad750e71801
diff --git a/server/services/dataSync.js b/server/services/dataSync.jsindex 82c3b107b2..c8f883ffdf 100644--- a/server/services/dataSync.js+++ b/server/services/dataSync.js@@ -602,23 +602,28 @@ const hasVideoRowId = (r) => typeof r?.id === 'string' && r.id;async function getVideoHistorySnapshot() {const raw = await readJSONFile(VIDEO_HISTORY_FILE, []);- // Exclude rows the user hid from their own gallery (`hidden: true`) — hiding- // is a local-only visibility decision (e.g. inner chunks of a stitched clip,- // or a clip the user tucked away) and must NOT propagate to peers. The whole- // point of this category is to render a SHARED collection's video items, and- // a hidden row is by definition not part of that shared surface.- //- // Also exclude rows without a string `id`: applyVideoHistoryRemote can only- // merge id-keyed rows, so an id-less row in the wire snapshot/checksum would- // be un-appliable on the receiver — its recomputed checksum would never match- // the sender's and the two peers would re-download this category forever.- // Treat id-less rows as strictly local-only on BOTH sides.- const rows = (Array.isArray(raw) ? raw : []).filter((r) => r && !r.hidden && hasVideoRowId(r));+ // Exclude rows without a string `id`: applyVideoHistoryRemote can only merge+ // id-keyed rows, so an id-less row in the wire snapshot/checksum would be+ // un-appliable on the receiver — its recomputed checksum would never match the+ // sender's and the two peers would re-download this category forever. Treat+ // id-less rows as strictly local-only on BOTH sides.+ const rows = (Array.isArray(raw) ? raw : []).filter((r) => r && hasVideoRowId(r));+ // `hidden` is a LOCAL-ONLY visibility flag (e.g. inner chunks of a stitched+ // clip, or a clip the user tucked away). It must NOT influence the wire+ // payload: if the snapshot's content depended on it, two peers that disagree+ // on a row's hidden state would compute different checksums and re-download+ // forever (and a union-merge would never let them converge). So we include+ // the row CONTENT — a shared collection's video still renders on every peer —+ // but strip `hidden` itself so the checksum is hide-state-independent and the+ // flag doesn't propagate (the receiver keeps its own local `hidden` because+ // the immutable-`createdAt` LWW merge keeps the existing row on a tie).// Canonicalize ordering for the wire so two peers holding identical sets// produce identical checksums regardless of insertion (newest-first) order.// Mirrors getMediaCollectionsSnapshot's sort-by-id rationale.const data = {- videos: [...rows].sort((a, b) => a.id.localeCompare(b.id)),+ videos: rows+ .map(({ hidden, ...rest }) => rest) // eslint-disable-line no-unused-vars+ .sort((a, b) => a.id.localeCompare(b.id)),};return { data, checksum: computeChecksum(data) };}diff --git a/server/services/dataSync.pipelineUniverse.test.js b/server/services/dataSync.pipelineUniverse.test.jsindex fd1ecbe7de..0a2558772d 100644--- a/server/services/dataSync.pipelineUniverse.test.js+++ b/server/services/dataSync.pipelineUniverse.test.js@@ -699,10 +699,33 @@ describe('dataSync — videoHistory category', () => {expect(snap.checksum).toBeTruthy();});- it('snapshot excludes hidden rows (local-only visibility must not propagate to peers)', async () => {+ it('snapshot includes hidden rows but strips the hidden flag (hide stays local, checksums converge)', async () => {+ // `hidden` is local-only visibility. The row CONTENT must still ride the wire+ // (so the checksum is hide-state-independent and peers converge), but the+ // `hidden` flag itself must be stripped so it doesn't propagate.writeJSON(VIDEO_HISTORY_PATH, [row('v1'), row('v-hidden', { hidden: true }), row('v2')]);const snap = await dataSync.getSnapshot('videoHistory');- expect(snap.data.videos.map((v) => v.id).sort()).toEqual(['v1', 'v2']);+ expect(snap.data.videos.map((v) => v.id).sort()).toEqual(['v1', 'v-hidden', 'v2'].sort());+ expect(snap.data.videos.every((v) => !('hidden' in v))).toBe(true);+ });++ it('snapshot checksum is identical whether or not a row is hidden (convergence across divergent hide-state)', async () => {+ writeJSON(VIDEO_HISTORY_PATH, [row('v1'), row('v2')]);+ const visible = await dataSync.getSnapshot('videoHistory');+ await new Promise((r) => setTimeout(r, 5)); // ensure mtime changes+ writeJSON(VIDEO_HISTORY_PATH, [row('v1'), row('v2', { hidden: true })]);+ const oneHidden = await dataSync.getSnapshot('videoHistory');+ // Two peers that disagree only on v2's hidden flag compute the SAME checksum.+ expect(oneHidden.checksum).toBe(visible.checksum);+ });++ it('applying a remote (hidden-stripped) row does not unhide a locally-hidden row', async () => {+ // The immutable-createdAt LWW merge keeps the existing local row on a tie, so+ // a peer's visible copy of a row the user hid locally must not undo the hide.+ writeJSON(VIDEO_HISTORY_PATH, [row('v1', { hidden: true })]);+ await dataSync.applyRemote('videoHistory', { videos: [row('v1')] }); // remote has no hidden flag+ const persisted = readJSON(VIDEO_HISTORY_PATH);+ expect(persisted.find((v) => v.id === 'v1')?.hidden).toBe(true);});it('snapshot excludes id-less rows so checksums converge (apply side drops them too)', async () => {