Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(infra): report the inline media an export had to drop

Yudhi Armyndharisa4ce62d88e61
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 414127979..3a43a2907 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- **A data export now reports the media it had to leave behind** — an over-budget attachment is replaced with the same omitted marker that media skipped on the way in gets, so a truncated backup was indistinguishable from a complete one both on inspection and on restore; the response now carries `omittedInlineMedia` alongside `skippedTables`, and the dashboard warns after a download that dropped anything.
- **A node that has observed the loss of its session lease no longer writes `FAILED` for that session** — engine callbacks were fenced only by a local liveness check, so between a heartbeat detecting the loss and the teardown it schedules, a dying generation could park a row a peer already owned in `FAILED`, which is excluded from both the boot reset and the takeover sweep by design and so left the session outside every automatic recovery path on every node until an operator restarted it by hand. The fence engages from the heartbeat tick that detects the loss, not from the moment the lease lapses, so a window remains.
- **Thirteen settings that did nothing under Docker now take effect** — Compose forwards environment explicitly and has no `env_file`, so `BAILEYS_MARK_ONLINE_ON_CONNECT`, `BAILEYS_SYNC_FULL_HISTORY`, `WEBHOOK_CONTACT_DETAILS`, `ALLOW_UNSIGNED_INGRESS`, `STORE_EPHEMERAL_MESSAGES`, `RESOLVE_LID_TO_PHONE`, `SIMULATE_TYPING`, `MCP_ENABLED`, `SEARCH_ENABLED`, `SERVE_DASHBOARD`, `CACHE_ENABLED`, `DATABASE_LOGGING` and `MAIN_DATABASE_SYNCHRONIZE` never reached the container however the operator's `.env` was written — the MCP server could not be enabled at all, `SEARCH_ENABLED=false` did not disable the search route it documents, and `BAILEYS_MARK_ONLINE_ON_CONNECT` left the paired phone's notifications suppressed for as long as the gateway stayed connected.
diff --git a/dashboard/src/hooks/useDataBackup.ts b/dashboard/src/hooks/useDataBackup.ts
index 1156c15c0..b925769cb 100644
--- a/dashboard/src/hooks/useDataBackup.ts
+++ b/dashboard/src/hooks/useDataBackup.ts
@@ -33,6 +33,18 @@ export function useDataBackup(): DataBackup {
a.download = `openwa-backup-${dump.exportedAt?.slice(0, 10) || 'data'}.json`;
a.click();
URL.revokeObjectURL(url);
+
+ // The download itself is silent on success, which is fine when the backup is complete. It is
+ // not fine when the budget dropped media: the archive restores without error and nothing else
+ // would ever tell the operator that some history came back without its attachments.
+ const omitted = dump.omittedInlineMedia;
+ const dropped = (omitted?.messages ?? 0) + (omitted?.messageBatches ?? 0);
+ if (dropped > 0) {
+ toast.warning(
+ t('infrastructure.migration.exportPartialTitle'),
+ t('infrastructure.migration.exportPartial', { count: dropped }),
+ );
+ }
} catch (err) {
toast.error(
t('infrastructure.migration.exportFailed'),
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index 0ecebbbe0..2edd6bde0 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -794,6 +794,8 @@
"export": "تصدير البيانات",
"import": "استيراد البيانات",
"exportFailed": "تعذّر تصدير البيانات",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "تعذّر استيراد البيانات",
"importOk": "تمّ استيراد البيانات",
"importConfirm": "سيؤدّي الاستيراد إلى استبدال جميع البيانات الحالية بالنسخة الاحتياطية ({{rows}} صفًّا). لا يمكن التراجع عن هذا الإجراء. هل تريد المتابعة؟",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 474dd6fbc..9b96dbb9e 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -760,6 +760,8 @@
"export": "Daten exportieren",
"import": "Daten importieren",
"exportFailed": "Daten konnten nicht exportiert werden",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "Daten konnten nicht importiert werden",
"importOk": "Daten wurden importiert",
"importConfirm": "Beim Import werden alle aktuellen Daten durch die Sicherung ERSETZT ({{rows}} Zeilen). Dies kann nicht rückgängig gemacht werden. Fortfahren?",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 6be949090..40b004789 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -760,6 +760,8 @@
"export": "Export data",
"import": "Import data",
"exportFailed": "Couldn't export data",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "Couldn't import data",
"importOk": "Data imported",
"importConfirm": "Importing will REPLACE all current data with the backup ({{rows}} rows). This cannot be undone. Continue?",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index ea56f0b61..fd0b3d1f4 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -779,6 +779,8 @@
"export": "Exportar datos",
"import": "Importar datos",
"exportFailed": "No se pudieron exportar los datos",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "No se pudieron importar los datos",
"importOk": "Datos importados",
"importConfirm": "La importación REEMPLAZARÁ todos los datos actuales con la copia de seguridad ({{rows}} filas). Esto no se puede deshacer. ¿Continuar?",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index f018021d0..390f8d92e 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -779,6 +779,8 @@
"export": "Exporter les données",
"import": "Importer les données",
"exportFailed": "Impossible d'exporter les données",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "Impossible d'importer les données",
"importOk": "Données importées",
"importConfirm": "L'importation REMPLACERA toutes les données actuelles par la sauvegarde ({{rows}} lignes). Cette action est irréversible. Continuer ?",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 05a66cba8..23cf7b89a 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -788,6 +788,8 @@
"export": "ייצוא נתונים",
"import": "ייבוא נתונים",
"exportFailed": "לא ניתן לייצא את הנתונים",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "לא ניתן לייבא את הנתונים",
"importOk": "הנתונים יובאו",
"importConfirm": "הייבוא יחליף את כל הנתונים הנוכחיים בגיבוי ({{rows}} שורות). לא ניתן לבטל פעולה זו. להמשיך?",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 0632e4fe8..2fc12f8f4 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -779,6 +779,8 @@
"export": "Esporta dati",
"import": "Importa dati",
"exportFailed": "Impossibile esportare i dati",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "Impossibile importare i dati",
"importOk": "Dati importati",
"importConfirm": "L'importazione SOSTITUIRÀ tutti i dati attuali con il backup ({{rows}} righe). Questa operazione non può essere annullata. Continuare?",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 50d2709de..da723feba 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -760,6 +760,8 @@
"export": "데이터 내보내기",
"import": "데이터 가져오기",
"exportFailed": "데이터를 내보내지 못했습니다",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "데이터를 가져오지 못했습니다",
"importOk": "데이터를 가져왔습니다",
"importConfirm": "가져오기를 실행하면 현재 데이터가 백업본({{rows}}행)으로 완전히 대체됩니다. 되돌릴 수 없습니다. 계속할까요?",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 74bd60c85..06d71d253 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -779,6 +779,8 @@
"export": "Exportar dados",
"import": "Importar dados",
"exportFailed": "Não foi possível exportar os dados",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "Não foi possível importar os dados",
"importOk": "Dados importados",
"importConfirm": "A importação IRÁ SUBSTITUIR todos os dados atuais pelo backup ({{rows}} linhas). Isso não pode ser desfeito. Continuar?",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 90e523423..bb354da92 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -779,6 +779,8 @@
"export": "డేటాను ఎక్స్‌పోర్ట్ చేయండి",
"import": "డేటాను ఇంపోర్ట్ చేయండి",
"exportFailed": "డేటాను ఎక్స్‌పోర్ట్ చేయలేకపోయాం",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "డేటాను ఇంపోర్ట్ చేయలేకపోయాం",
"importOk": "డేటా ఇంపోర్ట్ చేయబడింది",
"importConfirm": "ఇంపోర్ట్ చేయడం వల్ల ప్రస్తుత డేటా మొత్తం బ్యాకప్‌తో ({{rows}} వరుసలు) భర్తీ చేయబడుతుంది. దీన్ని వెనక్కి తీసుకోలేరు. కొనసాగించాలా?",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index c43ae5d2d..bc620bcbb 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -779,6 +779,8 @@
"export": "导出数据",
"import": "导入数据",
"exportFailed": "无法导出数据",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "无法导入数据",
"importOk": "数据已导入",
"importConfirm": "导入操作将用备份数据替换(REPLACE)当前所有数据({{rows}} 行)。此操作无法撤销。是否继续?",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index dccaa589c..051149e5d 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -779,6 +779,8 @@
"export": "匯出資料",
"import": "匯入資料",
"exportFailed": "無法匯出資料",
+ "exportPartialTitle": "Backup is missing some media",
+ "exportPartial": "{{count}} attachment payload(s) exceeded the export media budget and were saved as placeholders. The messages restore; their media does not.",
"importFailed": "無法匯入資料",
"importOk": "資料已匯入",
"importConfirm": "匯入將以備份({{rows}} 列)取代所有目前資料。此操作無法復原。是否繼續?",
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 0c55f920c..9990f88d3 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -1074,6 +1074,10 @@ export const infraApi = {
// Optional tables absent from an older schema. Always present in the response; a non-empty
// list means the backup is partial, not that those tables were empty.
skippedTables: string[];
+ // Inline media payloads the export budget refused. Always present; non-zero means the rows are
+ // all there but some of their media is not — a state a restored archive cannot express, since
+ // the omitted marker is the same one media skipped on the way in gets.
+ omittedInlineMedia: { messages: number; messageBatches: number };
}>('/infra/export-data'),
// 200 contract includes the orphan-engine reconciliation result (restartRequired / notices /
// stopped+failed ids). 409 has several causes and the error's `code` distinguishes them:
diff --git a/src/modules/infra/infra-data.controller.spec.ts b/src/modules/infra/infra-data.controller.spec.ts
index 5076452fe..295abe71f 100644
--- a/src/modules/infra/infra-data.controller.spec.ts
+++ b/src/modules/infra/infra-data.controller.spec.ts
@@ -727,6 +727,10 @@ describe('InfraDataController.importData round-trips export-data (no silent mess
expect(exported?.type).toBe('image');
expect(exported?.waMessageId).toBe('WA-MEDIA');
+ // The count is what tells a truncated backup from a complete one: the marker alone is
+ // indistinguishable from media that was never downloaded in the first place.
+ expect(dump.omittedInlineMedia).toEqual({ messages: 1, messageBatches: 0 });
+
// And the backup still restores.
const res = await controller.importData({ tables: dump.tables });
expect(res.imported).toBe(true);
@@ -783,6 +787,9 @@ describe('InfraDataController.importData round-trips export-data (no silent mess
expect(msgs[0].content.image).not.toHaveProperty('base64');
expect(msgs[0].content.image).toMatchObject({ mimetype: 'image/png', caption: 'hi' });
expect(msgs[1].content.image).toEqual({ url: 'https://cdn.example.com/x.png', mimetype: 'image/png' });
+ // Attributed to the batches arm, not lumped in with messages — an operator restoring this needs
+ // to know WHICH history came back without its media.
+ expect(dump.omittedInlineMedia).toEqual({ messages: 0, messageBatches: 1 });
});
});
diff --git a/src/modules/infra/infra-data.controller.ts b/src/modules/infra/infra-data.controller.ts
index e087e14bc..ddf4ccebb 100644
--- a/src/modules/infra/infra-data.controller.ts
+++ b/src/modules/infra/infra-data.controller.ts
@@ -183,14 +183,28 @@ function newestFirst<T>(rows: readonly T[], at: (row: T) => number): T[] {
return [...rows].sort((a, b) => key(b) - key(a));
}
-/** Spends the shared budget. Returns true when this payload does not fit and must be dropped. */
-function createInlineMediaBudget(): (encodedBytes: number) => boolean {
+/**
+ * Spends the shared budget, and remembers what it refused.
+ *
+ * `exceeds` returns true when this payload does not fit and must be dropped. The tally matters as
+ * much as the bound: an over-budget payload is replaced with the engine's own omitted marker, which
+ * is deliberately the same shape a payload skipped on the way in gets — so without a count, a
+ * truncated backup is indistinguishable from a complete one, both on inspection and on restore.
+ */
+function createInlineMediaBudget(): { exceeds: (encodedBytes: number) => boolean; droppedPayloads: () => number } {
const budget = exportInlineMediaBudgetBytes();
let spent = 0;
- return (encodedBytes: number): boolean => {
- if (spent + encodedBytes > budget) return true;
- spent += encodedBytes;
- return false;
+ let dropped = 0;
+ return {
+ exceeds: (encodedBytes: number): boolean => {
+ if (spent + encodedBytes > budget) {
+ dropped += 1;
+ return true;
+ }
+ spent += encodedBytes;
+ return false;
+ },
+ droppedPayloads: () => dropped,
};
}
@@ -336,6 +350,12 @@ export class InfraDataController {
};
/** Optional tables that were skipped because they genuinely do not exist in this DB (older schema). */
skippedTables: string[];
+ /**
+ * Inline media payloads the export budget refused, so a truncated backup can be told apart from
+ * a complete one. Zeroes mean everything fitted. Restoring an archive with a non-zero count is
+ * still valid — the rows come back, their media does not.
+ */
+ omittedInlineMedia: { messages: number; messageBatches: number };
}> {
// Get all entities from Data DB
const sessions = await this.dataDataSource.query<SessionRow[]>('SELECT * FROM sessions');
@@ -362,7 +382,8 @@ export class InfraDataController {
// One budget shared by the two tables that carry a full inline payload — `messages` and
// `message_batches` — so the total is what is bounded rather than each table separately.
- const exceedsBudget = createInlineMediaBudget();
+ const inlineMediaBudget = createInlineMediaBudget();
+ const exceedsBudget = inlineMediaBudget.exceeds;
const messages = await queryOptionalTable<MessageRow>('messages');
// Postgres carries a STORED generated tsvector column `body_ts` (FTS) that `SELECT *` picks up.
@@ -374,6 +395,9 @@ export class InfraDataController {
for (const row of newestFirst(messages, row => Number(row.timestamp))) {
stripInlineMediaPayload(row, exceedsBudget);
}
+ // Snapshot between the two loops so the report can say WHICH table lost payloads — messages are
+ // served first, batches spend what is left.
+ const omittedMessageMedia = inlineMediaBudget.droppedPayloads();
const messageBatches = await queryOptionalTable<MessageBatchRow>('message_batches');
// Batches spend what the messages left, and by the same newest-first rule: a run left PROCESSING
// keeps its payloads indefinitely, so a stale one must not outbid a current one.
@@ -438,6 +462,10 @@ export class InfraDataController {
},
counts,
skippedTables,
+ omittedInlineMedia: {
+ messages: omittedMessageMedia,
+ messageBatches: inlineMediaBudget.droppedPayloads() - omittedMessageMedia,
+ },
};
}