Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): drop lid absence marks before a reload read
Yudhi Armyndharis68d5bdd5f1f1
diff --git a/src/engine/identity/lid-mapping-store.service.ts b/src/engine/identity/lid-mapping-store.service.tsindex 9bdab8b72..5ccd02df6 100644--- a/src/engine/identity/lid-mapping-store.service.ts+++ b/src/engine/identity/lid-mapping-store.service.ts@@ -128,6 +128,9 @@ export class LidMappingStoreService implements LidMappingStore, OnModuleInit {* fail the import — resolution falls back to engine re-resolution until the table is readable.*/async reload(): Promise<void> {+ // Dropped before the read too: a restore may have replaced the table, so if the read fails, a lid+ // not cached must read through rather than trust a stale absence.+ this.absentFromTable.clear();try {// Deterministic preload: an unordered find() followed by LRU eviction keeps an ARBITRARY// subset once the table exceeds the cap. Order by last-write and take at most the cap, sodiff --git a/src/engine/identity/lid-mapping-store.spec.ts b/src/engine/identity/lid-mapping-store.spec.tsindex 1dd92b09a..eef9c1817 100644--- a/src/engine/identity/lid-mapping-store.spec.ts+++ b/src/engine/identity/lid-mapping-store.spec.ts@@ -561,6 +561,24 @@ describe('LidMappingStoreService — deterministic preload + repository fallbackexpect(store.getCached('lid-imported')).toBe('620003'); // asked the table again rather than blocked});+ it('forgets every recorded absence even when the reload cannot read the table', async () => {+ const repo = makeFakeRepo();+ const store = new LidMappingStoreService(repo as unknown as Repository<LidMapping>);++ expect(store.getCached('lid-restored')).toBeUndefined();+ await new Promise(resolve => setImmediate(resolve));+ expect(repo.findOne).toHaveBeenCalledTimes(1); // 'lid-restored' is now known to have no row++ // A restore brings the row back, then the post-commit reload fails.+ repo.rows.push({ lid: 'lid-restored', phone: '620005', sessionId: null, updatedAt: new Date() });+ repo.find.mockRejectedValueOnce(new Error('SQLITE_BUSY'));+ await expect(store.reload()).resolves.toBeUndefined();++ expect(store.getCached('lid-restored')).toBeUndefined();+ await new Promise(resolve => setImmediate(resolve));+ expect(store.getCached('lid-restored')).toBe('620005');+ });+it('swallows a fallback read error (table unavailable) — the miss stays a miss and never throws', async () => {const repo = makeFakeRepo();repo.findOne.mockRejectedValueOnce(new Error('no such table: lid_mappings'));