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-3705]): address claude review round 2 — guard onFailure hook, cover the decline branch

Adam Eivy5f4f5b3611c2
diff --git a/server/lib/icloudFile.js b/server/lib/icloudFile.js
index 2f95573bc8..d083241eb1 100644
--- a/server/lib/icloudFile.js
+++ b/server/lib/icloudFile.js
@@ -268,7 +268,14 @@ export function requestMaterialization(path, options = {}) {
const notifyFailure = () => {
if (failureNotified) return;
failureNotified = true;
- onFailure?.();
+ // try/catch at a child-process/timer boundary (permitted by the repo's
+ // no-try/catch rule): this runs from the unref'd deadline timer and the
+ // 'error'/'exit' handlers — all *outside* the request lifecycle — and
+ // `onFailure` is a caller-supplied hook on a public API. An uncaught throw
+ // here would crash the process with no `next(err)` to bubble to.
+ try { onFailure?.(); } catch (err) {
+ console.error(`❌ brctl onFailure hook threw for ${label}: ${err.message}`);
+ }
};
// Kill the child if it outlives its deadline, so a wedged `brctl` frees its slot
// instead of holding it forever. `unref` so the timer itself never keeps the
diff --git a/server/services/mortalLoomStore.test.js b/server/services/mortalLoomStore.test.js
index a231c8ef87..b607b6a131 100644
--- a/server/services/mortalLoomStore.test.js
+++ b/server/services/mortalLoomStore.test.js
@@ -953,6 +953,40 @@ describe('initMortalLoomStore — brctl pinning', () => {
settingsEvents.emit('settings:updated', { mortalloom: { enabled: true, path: null } });
}).not.toThrow();
});
+
+ it('does not spawn brctl for a non-iCloud (non-healable) configured path', async () => {
+ // The shared helper only spawns `brctl download` for genuinely healable iCloud
+ // paths. A configured path outside `/Library/Mobile Documents/` (here the
+ // suite's ordinary `/icloud/...` fixture, which isHealablePath declines) must
+ // not be handed a doomed download.
+ Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
+
+ spawnMock.mockReturnValue(makeFakeChild());
+ settings = { mortalloom: { enabled: true, path: '/icloud/MortalLoom.json' } };
+ await store.initMortalLoomStore();
+ expect(spawnMock).not.toHaveBeenCalled();
+ });
+
+ it('clears the sticky path when the helper declines to spawn, so the same path can retry', async () => {
+ // Regression for the `if (!spawned && lastPinnedPath === path) lastPinnedPath = null`
+ // guard: when requestMaterialization declines (here a synchronous spawn failure —
+ // EMFILE — but equally a path that is non-healable at boot and healable once its
+ // ubiquity container syncs in), the pin must NOT leave its sticky path set, or the
+ // SAME path would be deduped as "already pinned" forever and never retry.
+ Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
+
+ // First spawn throws → the helper catches it and returns false (declined).
+ spawnMock.mockImplementationOnce(() => { throw Object.assign(new Error('EMFILE'), { code: 'EMFILE' }); });
+ settings = { mortalloom: { enabled: true, path: ubiq('MortalLoom.json') } };
+ await store.initMortalLoomStore();
+ expect(spawnMock).toHaveBeenCalledTimes(1); // attempted, threw — nothing in flight
+
+ // A later settings:updated for the SAME path must re-attempt (not be deduped).
+ spawnMock.mockReturnValue(makeFakeChild());
+ settingsEvents.emit('settings:updated', { mortalloom: { enabled: true, path: ubiq('MortalLoom.json') } });
+ expect(spawnMock).toHaveBeenCalledTimes(2);
+ expect(spawnMock).toHaveBeenLastCalledWith('brctl', ['download', ubiq('MortalLoom.json')], expect.any(Object));
+ });
});
// =============================================================================