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: don't report brain parity as verified when the peer served no checksum (#4519)

[._.]/ Adam Eivy25ee8dcec8b9
diff --git a/client/src/components/instances/BrainParityPanel.jsx b/client/src/components/instances/BrainParityPanel.jsx
index c8b2bd5d40..c11642c4b9 100644
--- a/client/src/components/instances/BrainParityPanel.jsx
+++ b/client/src/components/instances/BrainParityPanel.jsx
@@ -12,7 +12,7 @@
* immediately on load; the button re-runs it.
*/
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { ChevronDown, ChevronRight, ScanSearch, RefreshCw } from 'lucide-react';
import Pill from '../ui/Pill';
import { runBrainParityCheck } from '../../services/api';
@@ -46,9 +46,14 @@ const outOfParityCount = (summary) =>
/**
* One-line verdict for the collapsed header.
*
- * A checksum mismatch with zero out-of-parity records is its own finding, not a
- * clean result: the two sides hold the same record ids with the same clocks but
- * different contents, which only the whole-brain checksum can see.
+ * Three distinct clean-ish outcomes, never collapsed into one green pill:
+ * - `content mismatch` — the manifest agrees on every id AND clock, but the
+ * whole-brain checksums differ, so at least one record BODY differs. Only
+ * the checksum can see this.
+ * - `unverified` — ids and clocks agree but the peer returned no checksum
+ * (too old, or the fetch failed), so bodies were never compared. Reporting
+ * "in parity" here would claim a verification that did not happen.
+ * - `in parity` — ids, clocks, AND the checksum all agree.
*/
function verdict(report) {
if (!report) return { label: 'not checked', tone: 'note' };
@@ -56,6 +61,7 @@ function verdict(report) {
const outOfParity = outOfParityCount(report.summary);
if (outOfParity > 0) return { label: `${outOfParity} out of parity`, tone: 'warning' };
if (report.checksums?.match === false) return { label: 'content mismatch', tone: 'warning' };
+ if (report.checksums?.match !== true) return { label: 'unverified', tone: 'note' };
return { label: 'in parity', tone: 'success' };
}
@@ -68,6 +74,16 @@ export default function BrainParityPanel({ peer, report: storedReport }) {
const [freshReport, setFreshReport] = useState(null);
const [error, setError] = useState(null);
+ // A card is keyed by the LOCAL peer id, which survives the remote install
+ // behind that address being replaced (`handleAnnounce` swaps `instanceId` in
+ // place). Without this, the previous install's fresh report would keep
+ // out-ranking the new peer's stored one until the page remounted — a parity
+ // verdict attributed to the wrong machine.
+ useEffect(() => {
+ setFreshReport(null);
+ setError(null);
+ }, [peer.instanceId]);
+
const report = freshReport ?? storedReport ?? null;
const { label, tone } = verdict(report);
@@ -144,14 +160,25 @@ export default function BrainParityPanel({ peer, report: storedReport }) {
)
))}
{outOfParityCount(report.summary) === 0 && (
- <Pill tone="success" size="xs" bordered={false}>every record matches</Pill>
+ report.checksums?.match === true
+ ? <Pill tone="success" size="xs" bordered={false}>every record matches</Pill>
+ : <Pill tone="muted" size="xs" bordered={false}>every record id and clock matches</Pill>
)}
</div>
{report.checksums?.match === false && outOfParityCount(report.summary) === 0 && (
<p className="text-port-warning">
Every record id and timestamp matches, but the whole-brain checksums differ — at least one record
- body differs between the two installs. The next sync cycle will pull the peer&apos;s copy.
+ body differs between the two installs. Anti-entropy reconcile will <strong>not</strong> resolve this
+ on its own: with equal timestamps, last-writer-wins skips the peer&apos;s copy in both directions.
+ Edit the record on the side you want to win so its clock advances, then re-check.
+ </p>
+ )}
+
+ {report.checksums?.match !== true && report.checksums?.match !== false && (
+ <p className="text-gray-500">
+ Record ids and timestamps were compared, but this peer returned no brain checksum, so record
+ <em> contents</em> were not verified. Two records can share an id and a timestamp and still differ.
</p>
)}
diff --git a/client/src/components/instances/BrainParityPanel.test.jsx b/client/src/components/instances/BrainParityPanel.test.jsx
index a024bb9a07..9b4df5e6e1 100644
--- a/client/src/components/instances/BrainParityPanel.test.jsx
+++ b/client/src/components/instances/BrainParityPanel.test.jsx
@@ -95,6 +95,61 @@ describe('BrainParityPanel', () => {
expect(screen.getByText(/rec-only-here, rec-only-there/)).toBeInTheDocument();
});
+ it('does not claim parity when the peer returned no checksum', async () => {
+ // Ids and clocks matched, but bodies were never compared — reporting green
+ // here would claim a verification that did not happen.
+ const user = userEvent.setup();
+ render(
+ <BrainParityPanel
+ peer={PEER}
+ report={report({
+ summary: summary({ total: 5, 'in-parity': 5 }),
+ checksums: { local: 'a', peer: null, match: null },
+ })}
+ />,
+ );
+
+ expect(screen.getByText('unverified')).toBeInTheDocument();
+ expect(screen.queryByText('in parity')).not.toBeInTheDocument();
+ await user.click(screen.getByRole('button', { name: /Brain parity/ }));
+ expect(screen.getByText(/no brain checksum/)).toBeInTheDocument();
+ expect(screen.queryByText('every record matches')).not.toBeInTheDocument();
+ });
+
+ it('says a content mismatch will NOT self-heal — equal clocks defeat last-writer-wins', async () => {
+ const user = userEvent.setup();
+ render(
+ <BrainParityPanel
+ peer={PEER}
+ report={report({
+ summary: summary({ total: 5, 'in-parity': 5 }),
+ checksums: { local: 'a', peer: 'b', match: false },
+ })}
+ />,
+ );
+
+ await user.click(screen.getByRole('button', { name: /Brain parity/ }));
+ expect(screen.getByText(/last-writer-wins skips the peer/)).toBeInTheDocument();
+ expect(screen.getByText(/Edit the record on the side you want to win/)).toBeInTheDocument();
+ });
+
+ it('drops a fresh report when the peer identity behind the card changes', async () => {
+ const user = userEvent.setup();
+ runBrainParityCheck.mockResolvedValue({
+ reports: [report({ summary: summary({ total: 4, 'in-parity': 3, 'peer-only': 1 }) })],
+ });
+
+ const { rerender } = render(<BrainParityPanel peer={PEER} report={null} />);
+ await user.click(screen.getByRole('button', { name: /Check/ }));
+ await waitFor(() => expect(screen.getByText('1 out of parity')).toBeInTheDocument());
+
+ // The install behind this address was replaced: same local peer id, new
+ // instanceId. The old install's verdict must not carry over.
+ rerender(<BrainParityPanel peer={{ ...PEER, instanceId: 'inst-peer-2' }} report={null} />);
+
+ await waitFor(() => expect(screen.getByText('not checked')).toBeInTheDocument());
+ });
+
it('explains an unreachable peer instead of reporting divergence', async () => {
const user = userEvent.setup();
render(<BrainParityPanel peer={PEER} report={{ available: false, reason: 'peer-unreachable' }} />);