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([issue-1072]): address claude+codex review

Adam Eivy2c14ff41b973
diff --git a/client/src/lib/syncCounts.js b/client/src/lib/syncCounts.js
index 1703a7d8cc..c5643671a3 100644
--- a/client/src/lib/syncCounts.js
+++ b/client/src/lib/syncCounts.js
@@ -33,7 +33,14 @@ export function diffSeq(ahead, behind) {
const b = toBig(behind);
if (a === null || b === null) return null;
const d = a - b;
- return d > 0n ? Number(d) : 0;
+ if (d <= 0n) return 0;
+ // The seqs themselves can exceed Number.MAX_SAFE_INTEGER (that's why we
+ // compare as BigInt), but the DELTA is a pending-item backlog between two
+ // syncs — realistically tiny. Should it ever exceed the safe integer range,
+ // cap at MAX_SAFE_INTEGER so the count degrades to a still-honest "very large
+ // backlog" rather than a precise-looking-but-wrong Number from a lossy cast.
+ const MAX = BigInt(Number.MAX_SAFE_INTEGER);
+ return Number(d > MAX ? MAX : d);
}
// { toPull, toPush } — each a non-negative Number, or null when unknown.
diff --git a/client/src/lib/syncCounts.test.js b/client/src/lib/syncCounts.test.js
index a692554bfd..7ebee2a746 100644
--- a/client/src/lib/syncCounts.test.js
+++ b/client/src/lib/syncCounts.test.js
@@ -24,6 +24,12 @@ describe('diffSeq', () => {
expect(diffSeq(big, lo)).toBe(3);
});
+ it('caps a delta beyond MAX_SAFE_INTEGER instead of returning a lossy value', () => {
+ // ahead is 2^53 + 100 over behind=0 → delta exceeds the safe range.
+ const huge = (BigInt(Number.MAX_SAFE_INTEGER) + 100n).toString();
+ expect(diffSeq(huge, '0')).toBe(Number.MAX_SAFE_INTEGER);
+ });
+
it('returns null when either side is absent', () => {
expect(diffSeq(undefined, 5)).toBeNull();
expect(diffSeq(5, null)).toBeNull();
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsx
index a65f532afe..c17f44296b 100644
--- a/client/src/pages/Instances.jsx
+++ b/client/src/pages/Instances.jsx
@@ -997,8 +997,11 @@ function PeerCard({ peer, onRefresh, syncStatus, tailnetInfo }) {
} else if (payload.phase === 'complete') {
setSyncing(false);
// Pull the freshest cursors/seqs so the card settles to the new
- // directional summary without waiting for the next 60s probe.
- if (payload.totalApplied > 0) onRefresh();
+ // directional summary without waiting for the next 60s probe. Refresh
+ // even on a zero-applied complete: a convergence/no-op sync still
+ // advances `lastSyncAt` and snapshot checksums, so the badge would
+ // otherwise read stale until the next manual probe.
+ onRefresh();
}
// `applied` events are informational (and drive the server-side log) —
// the global `syncing` flag already animates every badge, so the client
@@ -1086,11 +1089,18 @@ function PeerCard({ peer, onRefresh, syncStatus, tailnetInfo }) {
// error UI, so request() must stay silent to avoid a double toast.
setSyncing(true);
const result = await syncPeer(peer.id, { silent: true }).catch(() => null);
+ // The POST awaits the full sync server-side, so its resolution IS the
+ // authoritative completion for a manual sync — clear here rather than
+ // relying solely on the fire-and-forget `complete` socket event, which a
+ // transient socket disconnect could drop and leave the card stuck spinning.
+ setSyncing(false);
if (!result) {
- setSyncing(false);
toast.error(`Couldn't sync with ${peer.name} — is it online?`);
+ } else {
+ // Settle to the new directional summary (the socket `complete` also
+ // refreshes when records moved; this covers the no-op/socket-miss case).
+ onRefresh();
}
- // On success the `complete` progress event clears `syncing` and refreshes.
};
const handleRemove = async () => {
@@ -1141,10 +1151,12 @@ function PeerCard({ peer, onRefresh, syncStatus, tailnetInfo }) {
</div>
<div className="flex items-center gap-1">
<button
+ type="button"
onClick={handleSync}
disabled={syncing || peer.status !== 'online'}
className="p-1.5 text-gray-500 hover:text-port-accent transition-colors disabled:opacity-40 disabled:hover:text-gray-500"
title={peer.status === 'online' ? 'Sync now' : 'Peer offline — cannot sync'}
+ aria-label={peer.status === 'online' ? 'Sync now' : 'Peer offline — cannot sync'}
>
<RefreshCcw size={14} className={syncing ? 'animate-spin text-port-accent' : ''} />
</button>