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: keep audit measurements with overstated coverage and stop snapshot publishes dropping existing rows
Adam Eivy66a32bafc457
diff --git a/server/lib/auditQuality.js b/server/lib/auditQuality.jsindex 65fed850f6..9d44c6b2fd 100644--- a/server/lib/auditQuality.js+++ b/server/lib/auditQuality.js@@ -85,7 +85,15 @@ export function parseAuditQualityReport(summary, category) {if (typeof summary !== 'string') return null;const lines = summary.split(/\r?\n/).filter(line => line.startsWith(REPORT_PREFIX));if (lines.length !== 1) return null;- const parsed = auditQualityReportSchema.safeParse(safeJSONParse(lines[0].slice(REPORT_PREFIX.length), null));+ const raw = safeJSONParse(lines[0].slice(REPORT_PREFIX.length), null);+ // An agent that scanned only part of the inventory but labelled it "broad"+ // (the common slip) still measured something real. Record it as the partial+ // assessment it honestly is rather than dropping the whole run's measurement.+ const claim = raw && typeof raw === 'object' && raw.coverage === 'broad' && raw.score !== null+ && Number.isFinite(raw.scannedFiles) && Number.isFinite(raw.totalFiles)+ && raw.scannedFiles > 0 && raw.scannedFiles < raw.totalFiles+ ? { ...raw, coverage: 'partial' } : raw;+ const parsed = auditQualityReportSchema.safeParse(claim);return parsed.success && parsed.data.category === normalizeAuditTaskType(category) ? parsed.data : null;}diff --git a/server/services/appQuality.test.js b/server/services/appQuality.test.jsindex 56ce7418d6..88592caa0a 100644--- a/server/services/appQuality.test.js+++ b/server/services/appQuality.test.js@@ -50,7 +50,7 @@ describe('scheduled audit measurement workflow', () => {const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});const query = vi.fn();const run = { task, taskType: 'better-complexity', agentId: 'agent-1', workspacePath: '/repo', success: true, assessedAt };- for (const contents of ['', sentinel(report({ score: 101 })), sentinel(report({ score: '35' })), sentinel(report({ category: 'security' })), sentinel(report({ scannedFiles: 3 })), sentinel(report({ coverage: 'unavailable' })), sentinel(report()) + sentinel(report())]) {+ for (const contents of ['', sentinel(report({ score: 101 })), sentinel(report({ score: '35' })), sentinel(report({ category: 'security' })), sentinel(report({ scannedFiles: 3, coverage: 'partial', totalFiles: 2 })), sentinel(report({ coverage: 'unavailable' })), sentinel(report()) + sentinel(report())]) {expect(await recordAuditQuality(run, { readFile: async () => contents, query })).toBe(false);}expect(await recordAuditQuality({ ...run, success: false }, { readFile: async () => sentinel(report()), query })).toBe(false);@@ -62,6 +62,12 @@ describe('scheduled audit measurement workflow', () => {expect(parseAuditQualityReport(sentinel(report({ score: 0 })), 'better-complexity')?.score).toBe(0);});+ // Unique regression: a "broad" claim over a partial scan (5907/8923 files) used to drop the whole run's measurement.+ it('records a broad claim over a partial scan as partial coverage instead of discarding it', () => {+ const parsed = parseAuditQualityReport(sentinel(report({ scannedFiles: 59, totalFiles: 89 })), 'better-complexity');+ expect(parsed).toMatchObject({ coverage: 'partial', score: 35, scannedFiles: 59, totalFiles: 89 });+ });+it('excludes stale, partial, low-confidence and inapplicable assessments while retaining their breakdown', () => {const now = Date.now();const records = [diff --git a/server/services/appQualitySnapshotFile.js b/server/services/appQualitySnapshotFile.jsindex 16910575c0..3ace1cb035 100644--- a/server/services/appQualitySnapshotFile.js+++ b/server/services/appQualitySnapshotFile.js@@ -27,7 +27,7 @@ import {APP_QUALITY_LEGACY_SNAPSHOT_FILENAME,APP_QUALITY_SNAPSHOT_FILENAME,classifyQualitySnapshot,- qualityFileFromWireSnapshot,+ serializeQualitySnapshot,} from './appQualitySnapshotFormat.js';export { APP_QUALITY_SNAPSHOT_FILENAME };@@ -189,6 +189,22 @@ function hasOrigin(remote) {return Boolean(remote?.origin && (remote.origin.fetch || remote.origin.push || remote.origin['']));}+const SNAPSHOT_WINDOW_DAYS = 30;++/**+ * Canonical text for the fresh evidence UNIONED with the rows already on the+ * default branch (same 30-day window). The fresh build only sees this install's+ * database plus whichever peers answer right now; a rewrite from that alone+ * silently deleted every row a peer (or an expired local row) had contributed+ * whenever the peer was offline. Fresh rows still win a same-day collision.+ */+function mergeWithPublished(snapshot, onDefault, now) {+ const cutoff = new Date(now - SNAPSHOT_WINDOW_DAYS * 86400000).toISOString().slice(0, 10);+ const kept = (onDefault.records || []).filter(record => record.assessedAt.slice(0, 10) >= cutoff);+ const fresh = snapshot.measurements.map(({ measurementId, assessedAt, report }) => ({ ...report, assessedAt, measurementId }));+ return serializeQualitySnapshot(snapshot.repository, [...kept, ...fresh]);+}+async function publishNow(app, deps) {const git = deps.git || await import('./git.js');// Evidence is resolved before any remote check so a repo that is not a@@ -198,16 +214,15 @@ async function publishNow(app, deps) {const snapshot = await build(app, 30, deps);if (!snapshot?.measurements?.length) return skipped(app, 'no-evidence');- const next = qualityFileFromWireSnapshot(snapshot);- if (!next) return skipped(app, 'invalid-evidence');- if (lastPublishedBody.get(app.repoPath) === next) return skipped(app, 'no-changes');-const base = await repoBase(app, git);if (base.skip) return base.skip;const onDefault = await readGitSnapshot(git, app.repoPath, `origin/${base.defaultBranch}:${APP_QUALITY_SNAPSHOT_FILENAME}`,);if (REWRITE_BLOCKED.has(onDefault.status)) return untouched(app, onDefault.status);+ const next = mergeWithPublished(snapshot, onDefault, deps.now ?? Date.now());+ if (!next) return skipped(app, 'invalid-evidence');+ if (lastPublishedBody.get(app.repoPath) === next) return skipped(app, 'no-changes');// v1 bytes are a real migration even when the scores match. Only v2 that// already canonicalizes to `next` is "no changes".if (sameSnapshot(onDefault, next)) {diff --git a/server/services/appQualitySnapshotFile.test.js b/server/services/appQualitySnapshotFile.test.jsindex aed4a6218c..47f2780b74 100644--- a/server/services/appQualitySnapshotFile.test.js+++ b/server/services/appQualitySnapshotFile.test.js@@ -606,3 +606,23 @@ it('serializes worktree cleanup, retries a failed Git removal, and reports staleexpect(warn).toHaveBeenCalledWith(expect.stringContaining('registration verification unavailable'));warn.mockRestore();});++// Unique regression: a rebuild from only the evidence reachable right now (peers+// offline) used to overwrite the published file and delete every other row.+it('keeps rows already on the default branch when fresh evidence covers less', async () => {+ const existing = snapshot();+ existing.measurements[0].report.category = 'privacy';+ existing.measurements[0].assessedAt = '2026-09-20T10:00:00Z';+ const body = qualityFileFromWireSnapshot(existing);+ const git = gitDouble({+ execGit: vi.fn(async (args) => (args[0] === 'show' && String(args[1]).startsWith('origin/main:')+ ? { exitCode: 0, stdout: body, stderr: '' }+ : args[0] === 'show' || args[0] === 'rev-parse' ? missingShow : { exitCode: 0, stdout: '', stderr: '' })),+ });+ const writeFile = vi.fn(async () => true);+ const result = await publishAppQualitySnapshot(app, testDeps({ git, writeFile, now: Date.parse('2026-10-02T00:00:00Z') }));+ expect(result.published).toBe(true);+ const written = JSON.parse(writeFile.mock.calls[0][1]);+ expect(written.categories).toEqual(['privacy', 'security']);+ expect(written.measurements).toHaveLength(2);+});