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([tolerant-fetch-json-additional-clients]): keep malformed sync bodies from masquerading as empty success

[._.]/ Adam Eivy4394ab394b59
diff --git a/server/services/calendarApiSync.js b/server/services/calendarApiSync.js
index 8a5d01bf07..6a77f2c186 100644
--- a/server/services/calendarApiSync.js
+++ b/server/services/calendarApiSync.js
@@ -94,8 +94,17 @@ export async function syncOutlookCalendarApi(account, _cache, io, options = {})
return { events: [], status: 'api-error' };
}
- const data = await readResponseJson(response);
- const items = data.value || [];
+ // Sentinel fallback: a non-JSON/blank 200 body must NOT masquerade as a
+ // successful empty page. `success` here drives a destructive reconcile in
+ // calendarSync.js (it prunes every cached event absent from this fetch), so
+ // a malformed body has to surface as an api-error instead of silently
+ // wiping the cache (or, mid-pagination, dropping later pages' events).
+ const data = await readResponseJson(response, { fallback: null, emptyValue: null });
+ if (!data || !Array.isArray(data.value)) {
+ console.log(`📅 Calendar API sync: non-JSON or malformed body on page ${page} — treating as api-error`);
+ return { events: [], status: 'api-error' };
+ }
+ const items = data.value;
for (const item of items) {
const extId = makeExternalId(item.Id);
diff --git a/server/services/messageApiSync.js b/server/services/messageApiSync.js
index c27cdf5a1e..cf87cc629b 100644
--- a/server/services/messageApiSync.js
+++ b/server/services/messageApiSync.js
@@ -72,8 +72,17 @@ export async function syncOutlookApi(account, cache, io, options = {}) {
return { messages: [], status: 'api-error' };
}
- const data = await readResponseJson(response);
- const items = data.value || [];
+ // Sentinel fallback: a non-JSON/blank 200 body must NOT masquerade as a
+ // successful empty sync. A truthy `{ messages, status: 'success' }` result
+ // suppresses the Playwright fallback in messageSync.js (and mid-pagination
+ // a partial result would prune still-valid cached messages), so a malformed
+ // body returns null to preserve the pre-helper throw→fallback behavior.
+ const data = await readResponseJson(response, { fallback: null, emptyValue: null });
+ if (!data || !Array.isArray(data.value)) {
+ console.log(`📧 API sync: non-JSON or malformed body on page ${page} — falling back to Playwright`);
+ return null;
+ }
+ const items = data.value;
for (const m of items) {
const extId = makeExternalId('ol', m.Id);