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

address review (codex): keep a retry when the parity-sweep job read fails transiently (#4519)

[._.]/ Adam Eivya8d77589b669
diff --git a/client/src/components/instances/BrainParitySchedule.jsx b/client/src/components/instances/BrainParitySchedule.jsx
index f90ceae980..a0178e87d1 100644
--- a/client/src/components/instances/BrainParitySchedule.jsx
+++ b/client/src/components/instances/BrainParitySchedule.jsx
@@ -17,7 +17,7 @@
* a user is looking when they wonder whether their brains actually agree.
*/
-import { useEffect, useState } from 'react';
+import { useCallback, useEffect, useState } from 'react';
import { CalendarClock, ToggleLeft, ToggleRight } from 'lucide-react';
import toast from '../ui/Toast';
import { getCosJob, toggleCosJob, updateCosJob } from '../../services/api';
@@ -27,23 +27,61 @@ import { timeAgo } from '../../utils/formatters';
export const PARITY_SWEEP_JOB_ID = 'job-brain-parity-sweep';
export default function BrainParitySchedule() {
- // `undefined` = not loaded yet, `null` = this install has no such job (a
- // server too old to ship it). Distinct states so a pending fetch never
- // renders as "unsupported" — and an unsupported install renders nothing
- // rather than a control whose writes would 404.
+ // `undefined` = not loaded yet, `null` = this install genuinely has no such
+ // job (a 404 from a server too old to ship it). Distinct states so a pending
+ // fetch never renders as "unsupported", and an unsupported install renders
+ // nothing rather than a control whose writes would 404.
const [job, setJob] = useState(undefined);
+ // A transient read failure is NOT the same as "unsupported". Folding both
+ // into `null` would make the control vanish on a dropped connection with no
+ // way back short of a page reload, so a non-404 failure keeps a retry.
+ const [loadFailed, setLoadFailed] = useState(false);
const [saving, setSaving] = useState(false);
- useEffect(() => {
- let active = true;
+ const load = useCallback(() => {
// `silent` — an install without the job is an expected outcome here, not an
// error worth toasting on every Instances page load.
- getCosJob(PARITY_SWEEP_JOB_ID, { silent: true })
- .then((data) => { if (active) setJob(data ?? null); })
- .catch(() => { if (active) setJob(null); });
- return () => { active = false; };
+ return getCosJob(PARITY_SWEEP_JOB_ID, { silent: true }).then(
+ (data) => ({ job: data ?? null, failed: false }),
+ (err) => ({ job: null, failed: err?.status !== 404 })
+ );
}, []);
+ useEffect(() => {
+ let active = true;
+ load().then(({ job: next, failed }) => {
+ if (!active) return;
+ setJob(next);
+ setLoadFailed(failed);
+ });
+ return () => { active = false; };
+ }, [load]);
+
+ const retry = async () => {
+ setSaving(true);
+ const { job: next, failed } = await load();
+ setJob(next);
+ setLoadFailed(failed);
+ setSaving(false);
+ };
+
+ if (loadFailed) {
+ return (
+ <div className="mb-3 flex flex-wrap items-center gap-2 rounded-lg border border-port-border bg-port-card/40 px-3 py-2">
+ <CalendarClock size={14} className="text-gray-500 shrink-0" />
+ <p className="text-xs text-gray-500 flex-1">Could not read the scheduled parity sweep setting.</p>
+ <button
+ type="button"
+ onClick={retry}
+ disabled={saving}
+ className="text-[11px] text-port-accent hover:underline disabled:opacity-50"
+ >
+ Retry
+ </button>
+ </div>
+ );
+ }
+
if (job === undefined || job === null) return null;
const handleToggle = async () => {
diff --git a/client/src/components/instances/BrainParitySchedule.test.jsx b/client/src/components/instances/BrainParitySchedule.test.jsx
index 4422d53f02..1dee9c39af 100644
--- a/client/src/components/instances/BrainParitySchedule.test.jsx
+++ b/client/src/components/instances/BrainParitySchedule.test.jsx
@@ -44,12 +44,27 @@ describe('BrainParitySchedule', () => {
});
it('renders nothing on a server too old to ship the job', async () => {
- getCosJob.mockRejectedValue(new Error('Job not found'));
+ const err = new Error('Job not found');
+ err.status = 404;
+ getCosJob.mockRejectedValue(err);
const { container } = render(<BrainParitySchedule />);
await waitFor(() => expect(getCosJob).toHaveBeenCalled());
expect(container).toBeEmptyDOMElement();
});
+ it('offers a retry on a transient read failure rather than vanishing like an unsupported server', async () => {
+ // A dropped connection must not read as "this install has no such job" —
+ // that would hide the control with no way back short of a page reload.
+ const err = new Error('Server unreachable');
+ getCosJob.mockRejectedValueOnce(err).mockResolvedValueOnce(job());
+ render(<BrainParitySchedule />);
+
+ await userEvent.click(await screen.findByRole('button', { name: 'Retry' }));
+
+ expect(await screen.findByText('Off')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
+ });
+
it('enables the sweep through the job toggle and reflects the server result', async () => {
getCosJob.mockResolvedValue(job());
toggleCosJob.mockResolvedValue({ success: true, job: job({ enabled: true }) });