Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(plugins): prune registry ghosts of legacy removed built-ins at boot (#809)
Yudhi Armyndharis3327c492a3a0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 19b380b78..76fda35ef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -57,6 +57,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- Boot no longer warns about (and the plugin list no longer shows) ghost entries for the legacy+ bundled extensions removed in v0.7 (`auto-reply`, `translation`): when their code directory has no+ manifest, the stale registry entry is pruned at startup. The guard is scoped to those known ids so+ a temporarily unreadable plugin directory never loses its persisted config.++- Long-lived sessions no longer die permanently after hours of uptime. A dead whatsapp-web.jsChromium (browser process exit, renderer crash, or closed page) is now detected through thepuppeteer lifecycle handles and driven through the standard disconnect → reconnect pipeline, anddiff --git a/src/core/plugins/plugin-loader.service.spec.ts b/src/core/plugins/plugin-loader.service.spec.tsindex 6a6581ceb..f5bcaf9d9 100644--- a/src/core/plugins/plugin-loader.service.spec.ts+++ b/src/core/plugins/plugin-loader.service.spec.ts@@ -410,6 +410,60 @@ describe('PluginLoaderService — skips dot-prefixed directories on load (crash-});});+describe('PluginLoaderService — prunes registry ghosts of removed built-ins', () => {+ let tmpDir: string;+ let pluginsDir: string;+ let loader: PluginLoaderService;+ let storage: PluginStorageService;++ beforeEach(() => {+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'owa-ghosts-'));+ pluginsDir = path.join(tmpDir, 'plugins');+ fs.mkdirSync(pluginsDir, { recursive: true });+ const config = {+ get: (k: string) => (k === 'plugins.dir' ? pluginsDir : k === 'dataDir' ? tmpDir : undefined),+ } as unknown as ConfigService;+ storage = new PluginStorageService(config);+ loader = new PluginLoaderService(config, new HookManager(), storage, {} as unknown as ModuleRef);+ });+ afterEach(() => fs.rmSync(tmpDir, { recursive: true, force: true }));++ const seedGhost = (id: string): void => {+ // A leftover directory with no manifest (code deleted) + a stale registry entry still claiming+ // the plugin is installed — the ghost state upgrades from <=0.6 are in.+ fs.mkdirSync(path.join(pluginsDir, id), { recursive: true });+ storage.setPluginEntry({+ id,+ type: 'extension',+ name: id,+ version: '1.0.0',+ status: 'installed',+ config: {},+ builtIn: true,+ installedAt: new Date(),+ updatedAt: new Date(),+ } as never);+ };++ it('prunes registry entries of legacy removed built-ins (auto-reply, translation) with no manifest', () => {+ seedGhost('auto-reply');+ seedGhost('translation');++ loader.onModuleInit();++ expect(storage.getPluginEntry('auto-reply')).toBeUndefined();+ expect(storage.getPluginEntry('translation')).toBeUndefined();+ });++ it('keeps a manifest-less NON-legacy plugin entry (config survives an unreadable dir)', () => {+ seedGhost('some-other-plugin');++ loader.onModuleInit();++ expect(storage.getPluginEntry('some-other-plugin')).toBeDefined();+ });+});+describe('PluginLoaderService — enable concurrency', () => {let tmpDir: string;let loader: PluginLoaderService;diff --git a/src/core/plugins/plugin-loader.service.ts b/src/core/plugins/plugin-loader.service.tsindex fdb7bc7ee..f8dae7313 100644--- a/src/core/plugins/plugin-loader.service.ts+++ b/src/core/plugins/plugin-loader.service.ts@@ -132,6 +132,13 @@ export function dispatchConversationMedia(}}+// Plugin ids whose bundled-extension code was permanently removed (v0.7 — superseded by the+// marketplace chat-flow / group-translate; also reserved in plugin-installer). A leftover+// directory without a manifest marks them as deleted on disk, so the stale registry entry (which+// still reports them installed/enabled) is pruned on boot. Scoped to these known ids so a+// temporarily-unreadable plugin dir (e.g. an unmounted volume) never loses its persisted config.+const LEGACY_REMOVED_PLUGIN_IDS = new Set(['auto-reply', 'translation']);+@Injectable()export class PluginLoaderService implements OnModuleInit, OnModuleDestroy {private readonly logger = createLogger('PluginLoaderService');@@ -221,6 +228,12 @@ export class PluginLoaderService implements OnModuleInit, OnModuleDestroy {pluginPath,action: 'manifest_missing',});+ if (LEGACY_REMOVED_PLUGIN_IDS.has(entry.name)) {+ this.pluginStorage.deletePluginEntry(entry.name);+ this.logger.log(`Pruned stale registry entry for removed built-in plugin: ${entry.name}`, {+ action: 'registry_ghost_pruned',+ });+ }continue;}