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

fix: persist brain parity reports per peer and read the un-probed peer's key (#4519)

[._.]/ Adam Eivye50cf934ec07
diff --git a/client/src/components/instances/BrainParityPanel.jsx b/client/src/components/instances/BrainParityPanel.jsx
index e66ee64e76..c8b2bd5d40 100644
--- a/client/src/components/instances/BrainParityPanel.jsx
+++ b/client/src/components/instances/BrainParityPanel.jsx
@@ -135,9 +135,9 @@ export default function BrainParityPanel({ peer, report: storedReport }) {
{report?.available && (
<>
<div className="flex flex-wrap items-center gap-1.5">
- <Pill tone="muted" size="xs" bordered={false}>{report.summary.total} records compared</Pill>
+ <Pill tone="muted" size="xs" bordered={false}>{report.summary?.total ?? 0} records compared</Pill>
{STATUS_META.map(({ key, label: statusLabel, tone: statusTone }) => (
- report.summary[key] > 0 && (
+ report.summary?.[key] > 0 && (
<Pill key={key} tone={statusTone} size="xs" bordered={false}>
{report.summary[key]} {statusLabel}
</Pill>
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsx
index 30c91f76b2..99140d1793 100644
--- a/client/src/pages/Instances.jsx
+++ b/client/src/pages/Instances.jsx
@@ -1460,13 +1460,17 @@ export default function Instances() {
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
{peers.map(peer => (
+ // Reports key on instanceId (the stable federation identity), but
+ // a peer audited before it was ever probed files under its local
+ // registry id — mirror that fallback here or its report reads as
+ // "not checked".
<PeerCard
key={peer.id}
peer={peer}
onRefresh={fetchData}
syncStatus={syncStatus}
tailnetInfo={tailnetInfo}
- parityReport={parityReports[peer.instanceId] ?? null}
+ parityReport={parityReports[peer.instanceId] ?? parityReports[peer.id] ?? null}
/>
))}
</div>
diff --git a/server/services/brainParity.js b/server/services/brainParity.js
index ac3c898239..6ec5d2ac00 100644
--- a/server/services/brainParity.js
+++ b/server/services/brainParity.js
@@ -324,7 +324,6 @@ export async function runBrainParityCheck({ peerId } = {}) {
return { reports: [{ peerId, available: false, reason: 'peer-not-found', checkedAt: new Date().toISOString() }] };
}
- const stored = await loadReports();
const reports = [];
// Sequential, not Promise.all: each peer costs a manifest fetch plus a full
@@ -333,14 +332,22 @@ export async function runBrainParityCheck({ peerId } = {}) {
for (const peer of targets) {
const report = await checkPeerBrainParity(peer);
reports.push(report);
+ // Read-modify-write per peer rather than once around the whole sweep. A
+ // sweep can span minutes (each peer gets its own 30s fetch budget), and
+ // holding one in-memory copy across all of it would drop a report the user
+ // triggered from a peer card mid-sweep — and would lose every result if the
+ // sweep were interrupted before the final write.
const key = report.peerInstanceId || report.peerId;
- if (key) stored[key] = forStorage(report);
+ if (key) {
+ const stored = await loadReports();
+ stored[key] = forStorage(report);
+ await saveReports(stored);
+ }
const detail = report.available
? `${report.summary[INTEGRITY_STATUS.LOCAL_ONLY]} local-only, ${report.summary[INTEGRITY_STATUS.PEER_ONLY]} peer-only, ${report.summary[INTEGRITY_STATUS.DIVERGED]} diverged`
: report.reason;
console.log(`🧠🔍 Brain parity vs ${peer.name || peer.id}: ${detail}`);
}
- if (reports.length > 0) await saveReports(stored);
return { reports };
}
diff --git a/server/services/brainParity.test.js b/server/services/brainParity.test.js
index b8c44f5a54..5acb892fb0 100644
--- a/server/services/brainParity.test.js
+++ b/server/services/brainParity.test.js
@@ -67,7 +67,9 @@ function peerRoutes(routes) {
beforeEach(() => {
vi.clearAllMocks();
brainReconcile.getBrainChecksum.mockResolvedValue('local-checksum');
- readJSONFile.mockResolvedValue({});
+ // Fresh object per read: the service does a read-modify-write per peer, so a
+ // shared literal would let one write alias another and hide the per-peer save.
+ readJSONFile.mockImplementation(async () => ({}));
stores();
});
@@ -360,6 +362,29 @@ describe('runBrainParityCheck', () => {
expect(reports.map((r) => r.peerId)).toEqual(['peer-local-1', 'peer-local-2']);
});
+ it('files an un-probed peer under its local registry id', async () => {
+ getPeers.mockResolvedValue([{ ...PEER, instanceId: null }]);
+ peerFetch.mockResolvedValue(null);
+
+ await runBrainParityCheck({ peerId: 'peer-local-1' });
+
+ expect(Object.keys(atomicWrite.mock.calls[0][1])).toEqual(['peer-local-1']);
+ });
+
+ it('persists each peer as it finishes rather than once at the end', async () => {
+ getPeers.mockResolvedValue([
+ PEER,
+ { id: 'peer-local-2', instanceId: 'inst-peer-2', name: 'Second Peer', host: 'peer2.example.com', syncEnabled: true },
+ ]);
+ peerFetch.mockResolvedValue(null);
+
+ await runBrainParityCheck();
+
+ // One write per peer — an interrupted sweep keeps the peers it got through.
+ expect(atomicWrite).toHaveBeenCalledTimes(2);
+ expect(Object.keys(atomicWrite.mock.calls[0][1])).toEqual(['inst-peer-1']);
+ });
+
it('preserves reports for peers this run did not check', async () => {
readJSONFile.mockResolvedValue({ 'inst-other': { peerId: 'peer-other', summary: { total: 3 } } });
getPeers.mockResolvedValue([PEER]);