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: retain peer quality rows when snapshot publication races
Adam Eivy900ec720415b
diff --git a/server/services/appQualitySnapshotFile.js b/server/services/appQualitySnapshotFile.jsindex 3ace1cb035..da7e0fe3a3 100644--- a/server/services/appQualitySnapshotFile.js+++ b/server/services/appQualitySnapshotFile.js@@ -229,7 +229,7 @@ async function publishNow(app, deps) {lastPublishedBody.set(app.repoPath, next);return skipped(app, 'no-changes');}- return landOrReuse(app, git, base.defaultBranch, deps, next, snapshot.measurements.length);+ return landOrReuse(app, git, base.defaultBranch, deps, next, snapshot.measurements.length, { snapshot });}async function migrateNow(app, deps) {@@ -264,6 +264,21 @@ async function migrateNow(app, deps) {});}+// Remote rows can be newer than our initial default-branch read: another+// install may have queued a PR, or landed it while our push lost its lease.+// Keep those contributions while retaining full timestamps for local evidence+// (the compact file has already reduced timestamps to UTC days).+function mergeRemoteRows(next, stored, deps, options) {+ const candidate = classifyQualitySnapshot(next);+ if (options.snapshot) {+ return mergeWithPublished(options.snapshot, {+ records: [...candidate.records, ...(stored.records || [])],+ }, deps.now ?? Date.now());+ }+ // Explicit format migration does not expire historical rows.+ return serializeQualitySnapshot(candidate.repository, [...candidate.records, ...(stored.records || [])]);+}+async function landOrReuse(app, git, defaultBranch, deps, next, count, options = {}) {const onBranch = await readGitSnapshot(git, app.repoPath, `origin/${QUALITY_SNAPSHOT_BRANCH}:${APP_QUALITY_SNAPSHOT_FILENAME}`,@@ -276,6 +291,8 @@ async function landOrReuse(app, git, defaultBranch, deps, next, count, options =if (REWRITE_BLOCKED.has(onBranch.status) || REWRITE_BLOCKED.has(legacyOnBranch.status)) {return untouched(app, REWRITE_BLOCKED.has(onBranch.status) ? onBranch.status : legacyOnBranch.status);}+ next = mergeRemoteRows(next, onBranch, deps, options);+ if (!next) return skipped(app, 'invalid-evidence');if (sameSnapshot(onBranch, next) && legacyOnBranch.status === 'absent') {const reused = await reuseOpenSnapshotPr(app, git, defaultBranch, deps);if (reused.published) lastPublishedBody.set(app.repoPath, next);@@ -298,6 +315,8 @@ async function landOrReuse(app, git, defaultBranch, deps, next, count, options =git, app.repoPath, `origin/${freshDefaultBranch}:${APP_QUALITY_SNAPSHOT_FILENAME}`,);if (REWRITE_BLOCKED.has(onDefault.status)) return untouched(app, onDefault.status);+ next = mergeRemoteRows(next, onDefault, deps, options);+ if (!next) return skipped(app, 'invalid-evidence');if (sameSnapshot(onDefault, next)) {lastPublishedBody.set(app.repoPath, next);return skipped(app, 'no-changes');diff --git a/server/services/appQualitySnapshotFile.test.js b/server/services/appQualitySnapshotFile.test.jsindex 47f2780b74..8049ae036e 100644--- a/server/services/appQualitySnapshotFile.test.js+++ b/server/services/appQualitySnapshotFile.test.js@@ -626,3 +626,65 @@ it('keeps rows already on the default branch when fresh evidence covers less', aexpect(written.categories).toEqual(['privacy', 'security']);expect(written.measurements).toHaveLength(2);});++it.each(['open-branch', 'lease-branch', 'lease-default'])('preserves another install’s rows during %s publication', async location => {+ const peer = snapshot();+ peer.measurements[0].report.category = 'privacy';+ const peerBody = qualityFileFromWireSnapshot(peer);+ let pushes = 0;+ let fetches = 0;+ const git = gitDouble({+ fetchOrigin: vi.fn(async () => { fetches++; }),+ execGit: vi.fn(async args => {+ if (args[0] === 'show') {+ const branch = String(args[1]).includes(`${QUALITY_SNAPSHOT_BRANCH}:`);+ const hasPeer = location === 'open-branch' ? branch+ : fetches > 1 && (location === 'lease-branch' ? branch : !branch);+ return hasPeer ? { exitCode: 0, stdout: peerBody, stderr: '' } : missingShow;+ }+ if (args[0] === 'rev-parse') return { exitCode: 0, stdout: (fetches > 1 ? 'bb' : 'aa').repeat(20), stderr: '' };+ if (args[0] === 'push' && ++pushes === 1 && location !== 'open-branch') throw new Error('! [rejected] (stale info)');+ return { exitCode: 0, stdout: '', stderr: '' };+ }),+ });+ const deps = testDeps({ git, now: Date.parse('2026-09-20T00:00:00Z') });+ expect(await publishAppQualitySnapshot(app, deps)).toMatchObject({ published: true });+ const written = JSON.parse(deps.writeFile.mock.calls.at(-1)[1]);+ expect(written.categories).toEqual(['privacy', 'security']);+ expect(written.measurements).toHaveLength(2);+});++it('keeps the publication window and fresh same-day evidence when coalescing an open branch', async () => {+ const peer = snapshot(3);+ peer.measurements[0].report.score = 99;+ peer.measurements[1].report.category = 'privacy';+ peer.measurements[2].report.category = 'documentation';+ peer.measurements[2].assessedAt = '2026-08-01T10:00:00Z';+ const git = gitDouble({ execGit: vi.fn(async args => {+ if (args[0] === 'show' && String(args[1]).includes(`${QUALITY_SNAPSHOT_BRANCH}:`)) {+ return { exitCode: 0, stdout: qualityFileFromWireSnapshot(peer), stderr: '' };+ }+ return args[0] === 'show' || args[0] === 'rev-parse' ? missingShow : { exitCode: 0, stdout: '', stderr: '' };+ }) });+ const deps = testDeps({ git, now: Date.parse('2026-09-20T00:00:00Z') });+ await publishAppQualitySnapshot(app, deps);+ const written = JSON.parse(deps.writeFile.mock.calls[0][1]);+ expect(written.categories).toEqual(['privacy', 'security']);+ expect(written.measurements.find(row => row[1] === 1)[2]).toBe(82);+});++it('preserves open-branch history during explicit format migration without applying the publication window', async () => {+ const peer = snapshot();+ peer.measurements[0].report.category = 'privacy';+ peer.measurements[0].assessedAt = '2025-01-01T10:00:00Z';+ const git = gitDouble({ execGit: vi.fn(async args => {+ if (args[0] === 'show') return { exitCode: 0, stderr: '', stdout: String(args[1]).includes(`${QUALITY_SNAPSHOT_BRANCH}:`)+ ? qualityFileFromWireSnapshot(peer) : serialized(snapshot()) };+ return args[0] === 'rev-parse' ? missingShow : { exitCode: 0, stdout: '', stderr: '' };+ }) });+ const deps = testDeps({ git });+ await migrateAppQualitySnapshot(app, deps);+ const written = JSON.parse(deps.writeFile.mock.calls[0][1]);+ expect(written.categories).toEqual(['privacy', 'security']);+ expect(written.measurements).toHaveLength(2);+});