Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): persist only the keys a plugin config update sets

Yudhi Armyndharis05ff351e13f0
diff --git a/src/core/plugins/plugin-lifecycle.ts b/src/core/plugins/plugin-lifecycle.ts
index 600596185..974202c40 100644
--- a/src/core/plugins/plugin-lifecycle.ts
+++ b/src/core/plugins/plugin-lifecycle.ts
@@ -206,8 +206,13 @@ export class PluginLifecycle {
plugin.config = { ...plugin.config, ...config };
- // Persist config
- this.pluginStorage.setPluginConfig(pluginId, plugin.config);
+ // Persist only the operator's keys on top of what was persisted before, not the effective merge:
+ // a built-in's effective config carries its env-derived defaults, and storing those would freeze
+ // them over later .env changes (see registerBuiltInPlugin).
+ this.pluginStorage.setPluginConfig(pluginId, {
+ ...(this.pluginStorage.getPluginConfig(pluginId) ?? {}),
+ ...config,
+ });
// Notify the running plugin of the config change (fire and forget). A sandboxed plugin's
// onConfigChange lives in the worker (plugin.instance is null), so route it through the live worker
diff --git a/src/core/plugins/plugin-loader.service.spec.ts b/src/core/plugins/plugin-loader.service.spec.ts
index f590584aa..6d0f6c6da 100644
--- a/src/core/plugins/plugin-loader.service.spec.ts
+++ b/src/core/plugins/plugin-loader.service.spec.ts
@@ -252,6 +252,27 @@ describe('PluginLoaderService — enable/config persistence', () => {
loader2.registerBuiltInPlugin(manifest, {}, { apiKey: 'default' });
expect(loader2.getPlugin('persist-test')?.config).toEqual({ apiKey: 'operator-secret' });
});
+
+ it('persists only the keys a config update set, so other env-derived keys stay live', () => {
+ loader.registerBuiltInPlugin(manifest, {}, { execPath: '/old/chromium', headless: true });
+ loader.updatePluginConfig('persist-test', { apiKey: 'operator-secret' });
+ expect(loader.getPlugin('persist-test')?.config).toEqual({
+ execPath: '/old/chromium',
+ headless: true,
+ apiKey: 'operator-secret',
+ });
+ expect(storage.getPluginConfig('persist-test')).toEqual({ apiKey: 'operator-secret' });
+
+ // Restart with a changed env value: it wins, and the operator's key is still applied.
+ const storage2 = new PluginStorageService(config);
+ const loader2 = new PluginLoaderService(config, new HookManager(), storage2, {} as unknown as ModuleRef);
+ loader2.registerBuiltInPlugin(manifest, {}, { execPath: '/new/chromium', headless: true });
+ expect(loader2.getPlugin('persist-test')?.config).toEqual({
+ execPath: '/new/chromium',
+ headless: true,
+ apiKey: 'operator-secret',
+ });
+ });
});
describe('PluginLoaderService — engine mutual exclusion', () => {