Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stop a built-in container the new config turns off
Yudhi Armyndharis775f4b32d344
diff --git a/dashboard/src/hooks/useRestartFlow.ts b/dashboard/src/hooks/useRestartFlow.tsindex 1ab49eb8b..437dec14a 100644--- a/dashboard/src/hooks/useRestartFlow.ts+++ b/dashboard/src/hooks/useRestartFlow.ts@@ -6,6 +6,8 @@ export type RestartStatus = 'idle' | 'restarting' | 'waiting' | 'success' | 'errexport interface RestartOpenRequest {profiles: string[];+ // The built-in profiles running now; the restart stops each one the new config no longer needs.+ running: string[];dbSwitch: boolean;storageSwitch: boolean;}@@ -15,7 +17,7 @@ export interface RestartFlow {restartCountdown: number;restartStatus: RestartStatus;pendingProfiles: string[];- previousProfiles: string[];+ runningProfiles: string[];dbSwitch: boolean;storageSwitch: boolean;open: (req: RestartOpenRequest) => void;@@ -24,22 +26,22 @@ export interface RestartFlow {}/**- * Owns the post-save restart modal: the show/countdown/status state machine, the pending/previous+ * Owns the post-save restart modal: the show/countdown/status state machine, the pending/running* profile pair that drives `infraApi.restart(...)`, and the db/storage-switch flags the modal's* data-loss warning reads (#488). `open()` is the single entry point a caller (the page's save* `onSaved`) uses to hand over a fresh save result.*- * The profile pair is one state object rotated by a single functional update, not two separate- * setters reading each other's render-scoped value — React StrictMode double-invokes updater- * functions, which would otherwise make the rotation order fragile.+ * The running set is taken from the caller on every open, not carried over from an earlier save: the+ * page reloads after each restart, so an earlier save is usually not there, and when it is, it says+ * what that save wanted rather than what is running.*/export function useRestartFlow(): RestartFlow {const [showRestartModal, setShowRestartModal] = useState(false);const [restartCountdown, setRestartCountdown] = useState(0);const [restartStatus, setRestartStatus] = useState<RestartStatus>('idle');- const [profiles, setProfiles] = useState<{ pending: string[]; previous: string[] }>({+ const [profiles, setProfiles] = useState<{ pending: string[]; running: string[] }>({pending: [],- previous: [],+ running: [],});// Set when the just-saved config changes the DB or storage backend vs what's running, so the restart// modal can warn that the new backend starts empty and offer a data backup before switching (#488).@@ -81,11 +83,12 @@ export function useRestartFlow(): RestartFlow {};const open = ({- profiles: newProfiles,+ profiles: pending,+ running,dbSwitch: nextDbSwitch,storageSwitch: nextStorageSwitch,}: RestartOpenRequest) => {- setProfiles(prev => ({ previous: prev.pending, pending: newProfiles }));+ setProfiles({ pending, running });setDbSwitch(nextDbSwitch);setStorageSwitch(nextStorageSwitch);setShowRestartModal(true);@@ -123,7 +126,7 @@ export function useRestartFlow(): RestartFlow {setRestartStatus('restarting');setRestartCountdown(30);- const profilesToRemove = profiles.previous.filter(p => !profiles.pending.includes(p));+ const profilesToRemove = profiles.running.filter(p => !profiles.pending.includes(p));// Kept outside the try: the poll deadline is derived from it, and the restart call is expected to// fail sometimes (the server may go down before it answers).@@ -156,7 +159,7 @@ export function useRestartFlow(): RestartFlow {restartCountdown,restartStatus,pendingProfiles: profiles.pending,- previousProfiles: profiles.previous,+ runningProfiles: profiles.running,dbSwitch,storageSwitch,open,diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.tsindex d42925941..61c54b9dd 100644--- a/dashboard/src/pages/Infrastructure.test.ts+++ b/dashboard/src/pages/Infrastructure.test.ts@@ -591,6 +591,37 @@ test('an operator engine pick under a pin is deliberate and still saved', async});});+// ── Built-in containers the restart stops ────────────────────────────────────++test('turning a running built-in Redis off asks the restart to stop its container', async () => {+ const { screen, waitFor, fireEvent, within } = rtl;+ resetFetchCalls();+ // Built-in Redis is running and saved as built-in; the operator switches it to an external Redis.+ overrides = {+ status: { ...INFRA_STATUS, redis: { enabled: true, connected: true, host: 'redis', port: 6379, builtIn: true } },+ saved: {+ ...SAVED_CONFIG,+ redis: { enabled: true, builtIn: true, host: 'redis', port: '6379', passwordSet: false },+ },+ };+ const { container } = renderInfrastructure();++ await screen.findByText('Database Configuration');+ await awaitConfigHydrated(container);+ const builtInRedis = toggleInput(container, 'Use Built-in Redis Container');+ await waitFor(() => assert.equal(builtInRedis.checked, true));+ fireEvent.click(builtInRedis);+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));++ const dialog = await screen.findByRole('dialog');+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));++ await waitFor(() => assert.ok(findFetchCall('POST', '/api/infra/restart'), 'expected the restart POST'));+ // The page reloads after every restart, so the first save of a page visit is the normal case: the+ // container to stop must come from what is running, not from an earlier save on this page.+ assert.deepEqual(findFetchCall('POST', '/api/infra/restart')!.body, { profiles: [], profilesToRemove: ['redis'] });+});+// ── Restart-flow timer cleanup on unmount ────────────────────────────────────test('unmounting mid-restart cancels the health poll and countdown timers', { timeout: 10_000 }, async () => {diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex cbdfe162c..e246f94e1 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -81,7 +81,14 @@ export function Infrastructure() {!!infraStatus &&(configForm.storageConfig.type !== infraStatus.storage.type ||(configForm.storageConfig.type === 's3' && configForm.storageConfig.builtIn !== infraStatus.storage.builtIn));- restartFlow.open({ profiles, dbSwitch, storageSwitch });+ // The built-in containers running now, so the restart stops each one the new config dropped. With no+ // status read there is nothing to go on, and nothing is stopped.+ const running = [+ infraStatus?.database.type === 'postgres' && infraStatus.database.builtIn && 'postgres',+ infraStatus?.redis.builtIn && 'redis',+ infraStatus?.storage.type === 's3' && infraStatus.storage.builtIn && 'minio',+ ].filter((p): p is string => typeof p === 'string');+ restartFlow.open({ profiles, running, dbSwitch, storageSwitch });},});diff --git a/src/modules/infra/infra-config.controller.ts b/src/modules/infra/infra-config.controller.tsindex aeb31d6e0..1a8f88079 100644--- a/src/modules/infra/infra-config.controller.ts+++ b/src/modules/infra/infra-config.controller.ts@@ -418,9 +418,9 @@ export class InfraConfigController {// Remove only the profiles the Save flow explicitly asked to remove, and never one we're about to// (re)start. We deliberately do NOT infer teardown from the saved *_BUILTIN flag: the default// data/.env.generated carries POSTGRES_BUILTIN=false, so a bare compose-profile restart would- // otherwise tear down the very backend the app is running on. (Known minor limitation: switching- // away from a built-in backend and then reloading the page before restarting can leave the old- // container running until the next explicit change.)+ // otherwise tear down the very backend the app is running on. The dashboard fills this list from the+ // live /infra/status builtIn flags at save time (running minus the new profiles), so a container is+ // left running only when that status read had failed and the dashboard had nothing to go on.// Only ever tear down OpenWA-managed services. An arbitrary profile name (or the empty string)// would otherwise reach stopManagedService and, via container-name matching, could stop an unrelated// container — so constrain teardown to the managed allowlist and drop anything else.