Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(brain): warn on a failed refresh instead of showing stale data silently\n\nThe error branch was reachable only while `graph` was null, and the catch in\n`load()` never clears `graph`. So the FIRST load failing showed an alert, but\nevery later failure set `error` behind an already-truthy `graph` and rendered\nnothing: the user kept reading a graph that had silently stopped being current.\n\nThe product choice, since the issue asks for one: keep the stale graph and warn\nabove it, rather than clearing `graph` on error. Clearing would also have made\nthe alert appear, and it is the worse option — the graph is expensive to\nrebuild and remains useful when a refresh blips, so discarding it turns a\ntransient failure into total data loss on screen. The unacceptable option was\nthe third one, which is what shipped: stale data with no indication at all.\n\nThe two states are now distinct components rather than two branches of one\nternary, because they say different things: `warning` means "what you see is\nold", `destructive` means "there is nothing to see". Both are in\n`ASSERTIVE_VARIANTS` (Alert.tsx:62) so both announce.\n\nAdds `brain.refreshError` to en plus all 13 locales with real translations, no\nem dashes.\n\nSCOPE — I checked whether this defect has siblings, and it does not. Five other\ncomponents share the `) : error ? (` shape (GoalsPanel, VaultHealthChecklist,\nAgentEditorToolsPicker, AgentsPanel, ApprovalHistoryPanel). None has the bug:\nevery one of them tests `error` BEFORE its data, so a failed reload surfaces.\nBrain was the only place the error branch sat behind truthy data. The class has\nexactly one member.\n\nTESTS — `Brain.errorRecovery.test.tsx` deliberately characterised this bug and\nits own comment said it "must be rewritten to assert whichever was chosen" once\nfixed. Done: the test that proved the swallow now proves the notification, and\nasserts BOTH halves (warning present AND graph retained), since clearing the\ngraph would satisfy a warning-only assertion. Added the cold-load case so a fix\nrouting every failure through the stale-data warning would fail.\n\nAssertions read `data-variant` rather than `role="alert"`, because warning and\ndestructive both carry that role and an assertion that cannot tell them apart\nwould pass on either branch.\n\nThe fix also makes an existing assertion falsifiable for the first time. The\nrecovery test's comment recorded that it could not prove `setError(null)` ran,\nsince a stale `error` behind a truthy `graph` was invisible. It is visible now,\nso that test gained a real check for it.\n\nNOT VERIFIED BY EXECUTION: local builds and test runs are prohibited under a\ncurrent standing rule, so none of this was run. Verified by reading\nBrain.tsx:244-255 and :108-112, Alert.tsx:62 and :85, and the five sibling call\nsites. CI is the check.\n\n## Related\n\nCloses #5895\n

M3gA-Mindcb9475fbce45
diff --git a/app/src/lib/i18n/ar.ts b/app/src/lib/i18n/ar.ts
index 2daffafc99..679fe89e8d 100644
--- a/app/src/lib/i18n/ar.ts
+++ b/app/src/lib/i18n/ar.ts
@@ -334,6 +334,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'المزامنة',
'brain.empty': 'دماغك فارغ في الوقت الحالي: قم بربط مصدر لبدء بناء الذاكرة.',
'brain.error': 'تعذّر تحميل دماغك. يرجى المحاولة مرة أخرى.',
+ 'brain.refreshError': 'تعذّر تحديث دماغك. يتم عرض آخر البيانات التي تم تحميلها.',
'common.cancel': 'إلغاء',
'common.save': 'حفظ',
'common.confirm': 'تأكيد',
diff --git a/app/src/lib/i18n/bn.ts b/app/src/lib/i18n/bn.ts
index 284f6bda2f..5fda48e92a 100644
--- a/app/src/lib/i18n/bn.ts
+++ b/app/src/lib/i18n/bn.ts
@@ -346,6 +346,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'সিঙ্ক',
'brain.empty': 'আপনার ব্রেইন এখন খালি: মেমরি তৈরি শুরু করতে একটি উৎস সংযুক্ত করুন।',
'brain.error': 'আপনার ব্রেইন লোড করা যায়নি। অনুগ্রহ করে আবার চেষ্টা করুন।',
+ 'brain.refreshError': 'আপনার ব্রেইন রিফ্রেশ করা যায়নি। সর্বশেষ লোড হওয়া তথ্য দেখানো হচ্ছে।',
'common.cancel': 'বাতিল',
'common.save': 'সংরক্ষণ',
'common.confirm': 'নিশ্চিত করুন',
diff --git a/app/src/lib/i18n/de.ts b/app/src/lib/i18n/de.ts
index 2be2a69862..3fab1fa53e 100644
--- a/app/src/lib/i18n/de.ts
+++ b/app/src/lib/i18n/de.ts
@@ -364,6 +364,8 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'Synchronisierung',
'brain.empty': 'Dein Gehirn ist noch leer – verbinde eine Quelle, um Speicher aufzubauen.',
'brain.error': 'Dein Gehirn konnte nicht geladen werden. Bitte versuche es erneut.',
+ 'brain.refreshError':
+ 'Dein Gehirn konnte nicht aktualisiert werden. Angezeigt werden die zuletzt geladenen Daten.',
'common.cancel': 'Abbrechen',
'common.save': 'Speichern',
'common.confirm': 'Bestätigen',
diff --git a/app/src/lib/i18n/en.ts b/app/src/lib/i18n/en.ts
index 07b15dd2e2..de104d5af4 100644
--- a/app/src/lib/i18n/en.ts
+++ b/app/src/lib/i18n/en.ts
@@ -67,6 +67,7 @@ const en: TranslationMap = {
'brain.tabs.sync': 'Sync',
'brain.empty': 'Your brain is empty for now: connect a source to start building memory.',
'brain.error': "Couldn't load your brain. Please try again.",
+ 'brain.refreshError': "Couldn't refresh your brain. Showing the last data that loaded.",
'brain.goals.title': 'Long-term Goals',
'brain.goals.description':
"The agent's durable goals for working with you. Edit them here or let Reflect update them.",
diff --git a/app/src/lib/i18n/es.ts b/app/src/lib/i18n/es.ts
index 50e9fee0fb..d40980797c 100644
--- a/app/src/lib/i18n/es.ts
+++ b/app/src/lib/i18n/es.ts
@@ -355,6 +355,7 @@ const messages: TranslationMap = {
'brain.empty':
'Tu cerebro está vacío por ahora: conecta una fuente para empezar a construir tu memoria.',
'brain.error': 'No se pudo cargar tu cerebro. Inténtalo de nuevo.',
+ 'brain.refreshError': 'No se pudo actualizar tu cerebro. Se muestran los últimos datos cargados.',
'common.cancel': 'Cancelar',
'common.save': 'Guardar',
'common.confirm': 'Confirmar',
diff --git a/app/src/lib/i18n/fr.ts b/app/src/lib/i18n/fr.ts
index 0fd1914bd4..d56dbcc02b 100644
--- a/app/src/lib/i18n/fr.ts
+++ b/app/src/lib/i18n/fr.ts
@@ -362,6 +362,8 @@ const messages: TranslationMap = {
'brain.empty':
'Votre cerveau est vide pour l’instant: connectez une source pour commencer à constituer votre mémoire.',
'brain.error': 'Impossible de charger votre cerveau. Veuillez réessayer.',
+ 'brain.refreshError':
+ 'Impossible de rafraîchir votre cerveau. Les dernières données chargées sont affichées.',
'common.cancel': 'Annuler',
'common.save': 'Enregistrer',
'common.confirm': 'Confirmer',
diff --git a/app/src/lib/i18n/hi.ts b/app/src/lib/i18n/hi.ts
index bd24f07fd8..da8937fcdc 100644
--- a/app/src/lib/i18n/hi.ts
+++ b/app/src/lib/i18n/hi.ts
@@ -348,6 +348,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'सिंक',
'brain.empty': 'आपका ब्रेन अभी खाली है: मेमोरी बनाना शुरू करने के लिए कोई स्रोत कनेक्ट करें।',
'brain.error': 'आपका ब्रेन लोड नहीं हो सका। कृपया फिर से प्रयास करें।',
+ 'brain.refreshError': 'आपका ब्रेन रिफ़्रेश नहीं हो सका। पिछली बार लोड हुआ डेटा दिखाया जा रहा है।',
'common.cancel': 'रद्द करें',
'common.save': 'सेव करें',
'common.confirm': 'कन्फर्म करें',
diff --git a/app/src/lib/i18n/id.ts b/app/src/lib/i18n/id.ts
index 0d874bb4d7..2a6c278051 100644
--- a/app/src/lib/i18n/id.ts
+++ b/app/src/lib/i18n/id.ts
@@ -352,6 +352,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'Sinkronisasi',
'brain.empty': 'Otak Anda masih kosong: hubungkan sumber untuk mulai membangun memori.',
'brain.error': 'Tidak dapat memuat otak Anda. Silakan coba lagi.',
+ 'brain.refreshError': 'Tidak dapat menyegarkan otak Anda. Menampilkan data terakhir yang dimuat.',
'common.cancel': 'Batal',
'common.save': 'Simpan',
'common.confirm': 'Konfirmasi',
diff --git a/app/src/lib/i18n/it.ts b/app/src/lib/i18n/it.ts
index a03d2ade97..f47e1f6b55 100644
--- a/app/src/lib/i18n/it.ts
+++ b/app/src/lib/i18n/it.ts
@@ -357,6 +357,8 @@ const messages: TranslationMap = {
'brain.empty':
'Il tuo cervello è ancora vuoto: collega una fonte per iniziare a costruire la memoria.',
'brain.error': 'Impossibile caricare il tuo cervello. Riprova.',
+ 'brain.refreshError':
+ 'Impossibile aggiornare il tuo cervello. Vengono mostrati gli ultimi dati caricati.',
'common.cancel': 'Annulla',
'common.save': 'Salva',
'common.confirm': 'Conferma',
diff --git a/app/src/lib/i18n/ko.ts b/app/src/lib/i18n/ko.ts
index 269b245a91..4fb15b9b72 100644
--- a/app/src/lib/i18n/ko.ts
+++ b/app/src/lib/i18n/ko.ts
@@ -342,6 +342,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': '동기화',
'brain.empty': '아직 브레인이 비어 있습니다: 소스를 연결하여 메모리를 만들어 보세요.',
'brain.error': '브레인을 불러올 수 없습니다. 다시 시도해 주세요.',
+ 'brain.refreshError': '브레인을 새로고침할 수 없습니다. 마지막으로 불러온 데이터를 표시합니다.',
'common.cancel': '취소',
'common.save': '저장',
'common.confirm': '확인',
diff --git a/app/src/lib/i18n/pl.ts b/app/src/lib/i18n/pl.ts
index 3d6aaa8628..119f0c92a7 100644
--- a/app/src/lib/i18n/pl.ts
+++ b/app/src/lib/i18n/pl.ts
@@ -356,6 +356,8 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'Synchronizacja',
'brain.empty': 'Twój mózg jest na razie pusty: połącz źródło, aby zacząć budować pamięć.',
'brain.error': 'Nie udało się załadować Twojego mózgu. Spróbuj ponownie.',
+ 'brain.refreshError':
+ 'Nie udało się odświeżyć Twojego mózgu. Wyświetlane są ostatnio załadowane dane.',
'common.cancel': 'Anuluj',
'common.save': 'Zapisz',
'common.confirm': 'Potwierdź',
diff --git a/app/src/lib/i18n/pt.ts b/app/src/lib/i18n/pt.ts
index e2e471c207..7aa62faff2 100644
--- a/app/src/lib/i18n/pt.ts
+++ b/app/src/lib/i18n/pt.ts
@@ -351,6 +351,8 @@ const messages: TranslationMap = {
'brain.empty':
'Seu cérebro está vazio por enquanto: conecte uma fonte para começar a construir a memória.',
'brain.error': 'Não foi possível carregar seu cérebro. Tente novamente.',
+ 'brain.refreshError':
+ 'Não foi possível atualizar seu cérebro. Exibindo os últimos dados carregados.',
'common.cancel': 'Cancelar',
'common.save': 'Salvar',
'common.confirm': 'Confirmar',
diff --git a/app/src/lib/i18n/ru.ts b/app/src/lib/i18n/ru.ts
index 7a36c3fd79..4afd1b8ba7 100644
--- a/app/src/lib/i18n/ru.ts
+++ b/app/src/lib/i18n/ru.ts
@@ -351,6 +351,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': 'Синхронизация',
'brain.empty': 'Ваш мозг пока пуст: подключите источник, чтобы начать формировать память.',
'brain.error': 'Не удалось загрузить ваш мозг. Пожалуйста, попробуйте ещё раз.',
+ 'brain.refreshError': 'Не удалось обновить ваш мозг. Показаны последние загруженные данные.',
'common.cancel': 'Отмена',
'common.save': 'Сохранить',
'common.confirm': 'Подтвердить',
diff --git a/app/src/lib/i18n/zh-CN.ts b/app/src/lib/i18n/zh-CN.ts
index fe4cda552d..81cc2341ed 100644
--- a/app/src/lib/i18n/zh-CN.ts
+++ b/app/src/lib/i18n/zh-CN.ts
@@ -319,6 +319,7 @@ const messages: TranslationMap = {
'brain.tabs.sync': '同步',
'brain.empty': '你的大脑暂时是空的:连接一个来源即可开始构建记忆。',
'brain.error': '无法加载你的大脑,请重试。',
+ 'brain.refreshError': '无法刷新你的大脑,显示的是上次加载的数据。',
'common.cancel': '取消',
'common.save': '保存',
'common.confirm': '确认',
diff --git a/app/src/pages/Brain.tsx b/app/src/pages/Brain.tsx
index ceeccb2ffe..5c2c1d8737 100644
--- a/app/src/pages/Brain.tsx
+++ b/app/src/pages/Brain.tsx
@@ -241,6 +241,29 @@ export default function Brain() {
contentRootAbs={graph?.content_root_abs}
/>
+ {/*
+ A failed refresh AFTER a good load keeps the graph on
+ screen and warns, rather than replacing it with an
+ error. The graph is expensive to rebuild and stays
+ useful when a refresh blips, so destroying it would
+ turn a transient failure into total data loss on
+ screen. What is not acceptable is the third option —
+ showing stale data with no indication at all, which is
+ what this did before: the error branch below is
+ reachable only while `graph` is null, and the catch in
+ `load()` never clears `graph`, so a later failure was
+ invisible.
+
+ The two states are deliberately different components:
+ this one means "what you see is old", the one below
+ means "there is nothing to see".
+ */}
+ {error && graph ? (
+ <Alert variant="warning">
+ <AlertDescription>{t('brain.refreshError')}</AlertDescription>
+ </Alert>
+ ) : null}
+
{graph ? (
<MemoryGraph
nodes={graph.nodes}
diff --git a/app/src/pages/__tests__/Brain.errorRecovery.test.tsx b/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
index 908971b01c..cc7c348c8b 100644
--- a/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
+++ b/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
@@ -1,8 +1,8 @@
/**
- * Brain graph — transient-failure recovery, and the failure that is swallowed.
+ * Brain graph — transient-failure recovery, and what a failed refresh shows.
*
* `Brain.test.tsx` already covers "an alert appears when the fetch fails".
- * Neither of the two behaviours here is covered anywhere:
+ * None of the behaviours here is covered anywhere:
*
* 1. A transient failure must CLEAR on the next successful load. This is the
* accurate half of the "Couldn't load your brain" report — the panel is
@@ -11,11 +11,15 @@
* stays reachable), but nothing pinned that, so deleting that one line
* would have turned a recoverable error into a permanent one silently.
*
- * 2. A refresh that fails AFTER a successful load shows the user nothing.
- * `Brain.tsx:244-255` only reaches the alert when `graph` is null, and the
- * catch at `:108-112` never clears `graph`, so a failed refresh leaves the
- * stale graph on screen with no indication. That is BUG-W4-3, and the
- * second test characterises it rather than asserting it is correct.
+ * 2. A refresh that fails AFTER a successful load keeps the stale graph and
+ * warns. This was BUG-W4-3 (#5895): the alert branch was reachable only
+ * while `graph` was null, and the catch in `load()` never clears `graph`,
+ * so a failed refresh left stale data on screen with no indication. The
+ * second test used to CHARACTERISE that swallow; it now asserts the
+ * warning, which is the same test inverted by the fix.
+ *
+ * 3. A FIRST load that fails still shows the destructive "couldn't load"
+ * alert and no graph — the branch that must not be swallowed by (2).
*
* Both drive the retry through the `openhuman:memory-tree-completed` window
* event, which is the in-product refetch trigger (`Brain.tsx:113-117`) and
@@ -127,16 +131,18 @@ describe('Brain graph — transient failure recovery', () => {
window.dispatchEvent(new Event('openhuman:memory-tree-completed'));
});
- // What is actually provable here, stated honestly: the panel RECOVERS —
- // the retry runs and its data renders.
+ // The panel RECOVERS: the retry runs and its data renders.
+ //
+ // This comment used to say the test could not prove `error` itself was
+ // cleared — once `graph` was truthy, a still-set `error` was simply not in
+ // the DOM, so deleting `setError(null)` from `Brain.tsx` left both tests in
+ // this file passing. That was true, and it was a consequence of BUG-W4-3.
//
- // What this cannot prove is that `error` state itself was cleared. The
- // render is `graph ? <graph> : error ? <alert> : null`, so once `graph` is
- // truthy a still-set `error` is simply not in the DOM. I verified that by
- // deleting `setError(null)` from `Brain.tsx:97` and re-running: both tests
- // in this file still passed. The alert assertion below therefore documents
- // the recovered UI, not the state reset — and the reason the state reset is
- // unobservable is itself BUG-W4-3, which the next test characterises.
+ // Fixing #5895 makes the state reset OBSERVABLE, which is a second benefit
+ // of the fix worth naming: a stale `error` alongside a loaded graph now
+ // renders the warning variant. So the absence of that warning after a
+ // successful reload is real evidence that `setError(null)` ran, and the
+ // assertion below can fail if it is removed.
//
// Revert-checked by disabling the `openhuman:memory-tree-completed`
// listener (`Brain.tsx:113-117`): both tests then fail on the call-count
@@ -145,9 +151,12 @@ describe('Brain graph — transient failure recovery', () => {
expect(screen.getByTestId('memory-graph')).toHaveTextContent('nodes:2');
});
expect(graphExportMock).toHaveBeenCalledTimes(2);
+ // The error state was genuinely cleared, not merely hidden: a surviving
+ // `error` beside a loaded graph would render the stale-data warning.
+ expect(document.querySelector('[data-variant="warning"]')).toBeNull();
});
- it('CHARACTERISES BUG-W4-3: a refresh that fails after a good load is silently swallowed', async () => {
+ it('warns and keeps the stale graph when a refresh fails after a good load', async () => {
// Succeed first, then fail — the opposite order to the test above.
graphExportMock
.mockResolvedValueOnce(makeGraph(3))
@@ -167,32 +176,47 @@ describe('Brain graph — transient failure recovery', () => {
expect(graphExportMock).toHaveBeenCalledTimes(2);
});
- // What the user sees: the OLD graph, and no warning that the refresh died.
- //
- // This asserts today's behaviour deliberately. When BUG-W4-3 is fixed —
- // by surfacing the error alongside stale data, or by clearing `graph` on
- // error — this test goes red and must be rewritten to assert whichever
- // was chosen. That is the intent: right now the swallow is invisible.
- //
- // The alert assertion below looks like the one deleted from the recovery
- // test above, and the difference is FALSIFIABILITY, not intent.
+ // This test previously asserted the OPPOSITE — `queryByRole('alert')` was
+ // expected to be absent — as a deliberate characterisation of BUG-W4-3,
+ // with a note saying it must be rewritten "to assert whichever was chosen"
+ // once the bug was fixed. #5895 chose: warn and keep the stale graph. So
+ // this is that rewrite, and the test that used to prove the swallow now
+ // proves the notification.
//
- // Up there, the alert was absent after a SUCCESSFUL recovery — and it would
- // have been absent whether or not `setError(null)` ran, in both the broken
- // and the fixed product. No change to `Brain.tsx` could have made it fail,
- // which is what made it worthless.
- //
- // Here the alert is absent after a FAILED refresh, and it is absent
- // *because of BUG-W4-3*: `graph ? <graph> : error ? <alert> : null` cannot
- // reach the alert branch while `graph` stays truthy, and the catch at
- // `Brain.tsx:108-112` never clears `graph`. Fix that — surface the error
- // beside the stale data, or clear `graph` on error — and an alert appears
- // and this line fails. It is the notification, which is exactly the job.
- //
- // Thanks to @YellowSnnowmann for forcing the distinction; I had only
- // asserted "the unreachability is the defect", which is not the same
- // argument.
+ // Both halves matter and neither alone is the fix:
+ // - the warning appears, so the failure is no longer silent;
+ // - the graph is still there, so a transient blip does not wipe data the
+ // user can still read. Clearing `graph` on error would also have made
+ // the alert appear, and would have been the worse product choice.
+ // Asserted on `data-variant` (emitted by `Alert` at `Alert.tsx:85`) rather
+ // than on `role="alert"`: BOTH the warning and the destructive variant are
+ // in `ASSERTIVE_VARIANTS` (`Alert.tsx:62`) and so both carry that role, and
+ // an assertion that cannot tell the two apart would pass on either branch.
+ const alert = document.querySelector('[data-slot="alert"]');
+ expect(alert).not.toBeNull();
+ expect(alert).toHaveAttribute('data-variant', 'warning');
expect(screen.getByTestId('memory-graph')).toHaveTextContent('nodes:3');
- expect(screen.queryByRole('alert')).not.toBeInTheDocument();
+ });
+
+ it('shows the load error, and no graph, when the FIRST load fails', async () => {
+ // The other side of the branch: with no previously loaded graph there is
+ // nothing stale to keep, so the destructive "couldn't load" alert is
+ // correct and the warning must not be what renders. This guards against a
+ // fix that routes every failure through the stale-data warning.
+ graphExportMock.mockRejectedValue(new Error('cold load blew up'));
+
+ await act(async () => {
+ renderWithProviders(<Brain />, { initialEntries: ['/?tab=graph'] });
+ });
+
+ await waitFor(() => {
+ expect(document.querySelector('[data-slot="alert"]')).not.toBeNull();
+ });
+ expect(document.querySelector('[data-slot="alert"]')).toHaveAttribute(
+ 'data-variant',
+ 'destructive'
+ );
+ expect(document.querySelector('[data-variant="warning"]')).toBeNull();
+ expect(screen.queryByTestId('memory-graph')).not.toBeInTheDocument();
});
});