Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): restore the pending-restart notice and stop a stale engine overwriting a saved one

Yudhi Armyndharisae2e19fddb52
diff --git a/.env.example b/.env.example
index 2fae65b89..2d1b8c054 100644
--- a/.env.example
+++ b/.env.example
@@ -199,8 +199,10 @@ BAILEYS_MARK_ONLINE_ON_CONNECT=true
# than you asked for. Counts come from the messages table, so they survive a restart — but that also
# means the cap only sees sends that WRITE a row there. Status posts, message edits and Baileys
# product sends are real outbound traffic that persists no new row, so they pass through the check
-# without being counted: a session doing any of them can exceed its stated daily allowance. Chat
-# sends, bulk included, are counted exactly.
+# without being counted — and so does a bulk item the engine refuses, because bulk writes its row
+# only after the send succeeds. A session doing any of them can exceed its stated daily allowance.
+# A bulk item that SUCCEEDS is counted, as is a failed single send, whose PENDING row is kept as
+# FAILED.
# SEND_PACING_ENABLED=true
# SEND_PACING_WARMUP_SCHEDULE=20,40,80,160,320,640,1000
#
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b0c956b0..e74230c2c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+
+- **The Infrastructure page's "saved, but not applied yet" notice no longer disappears for the rest of the session** — it was suppressed by a latch that is set when a save succeeds and cleared only by a restart's page reload, so from the first successful save none of the four cards could report a setting that was still waiting on a restart, which is the one state the notice exists for.
+- **A dashboard save no longer overwrites the saved engine with a stale running one** — the engine radio seeded from the running engine, which the gateway resolves once at boot, so after an engine change that had not been restarted yet a save of any unrelated field wrote the old engine back over the operator's choice; the radio now seeds from the saved configuration, which the previous release only did when an environment variable pinned the setting.
+- **The send-pacing documentation now matches the code on bulk sends** — `.env.example` and the API specification said bulk sends were counted exactly against the warm-up cap, but a bulk item the engine refuses is checked against the cap without ever being counted into it, because bulk writes its row only after the send succeeds.
+
## [0.14.3] - 2026-08-07
### Added
diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.ts
index 38921fa48..4d4e5152e 100644
--- a/dashboard/src/hooks/useInfraConfigForm.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.ts
@@ -62,10 +62,9 @@ export interface InfraConfigForm {
/**
* Owns the editable infrastructure form: dbConfig/redisConfig/storageConfig/engineConfig, the
* redis-enabled/queue-enabled toggles, and the hydration that seeds them from the two server
- * sources (live /status + saved /config). Takes those two query results (plus the resolved current
- * engine) as arguments rather than calling the query hooks itself — the page already holds them for
- * its own loading/error early returns, and passing them in keeps this hook testable without a
- * QueryClientProvider.
+ * sources (live /status + saved /config). Takes those two query results as arguments rather than
+ * calling the query hooks itself — the page already holds them for its own loading/error early
+ * returns, and passing them in keeps this hook testable without a QueryClientProvider.
*
* `redisConfig.connected` and the page's `queueStats` are LIVE indicators, not editable form state —
* they are seeded by a separate effect that lives in the page (every refetch, not just once), and
@@ -74,7 +73,6 @@ export interface InfraConfigForm {
export function useInfraConfigForm(
infraStatus: InfraStatus | undefined,
savedConfig: SavedConfig | undefined,
- currentEngine: string,
): InfraConfigForm {
const [dbConfig, setDbConfig] = useState<DatabaseConfig>({
type: 'sqlite',
@@ -124,14 +122,14 @@ export function useInfraConfigForm(
// operator's in-progress, unsaved edits. A successful save restarts → full page reload, re-arming it.
const formHydrated = useRef(false);
- // The engine radio seeds ONCE — from the running engine, or from the saved file when ENGINE_TYPE is
- // pinned (see the effect below) — then is never re-stamped by a background refetch. `engineTouched`
- // additionally wins over a late first resolution: if the operator clicked a different engine before
- // the seed resolved, the delayed seed must not revert their selection (#735).
+ // The engine radio seeds ONCE from the saved file (see the effect below), then is never re-stamped by
+ // a background refetch. `engineTouched` additionally wins over a late first resolution: if the
+ // operator clicked a different engine before the seed resolved, the delayed seed must not revert
+ // their selection (#735).
const engineHydrated = useRef(false);
const engineTouched = useRef(false);
- /** Whether engineConfig.type reflects a real value (seeded from the running engine or user-picked)
+ /** Whether engineConfig.type reflects a real value (seeded from the saved config or user-picked)
* rather than the useState default — the save payload omits `type` when it doesn't. */
const engineTypeKnown = (): boolean => engineHydrated.current || engineTouched.current;
@@ -209,23 +207,23 @@ export function useInfraConfigForm(
if (infraStatus && savedConfig) formHydrated.current = true;
}, [infraStatus, savedConfig]);
- // The active engine reflects what's actually running, so seed the selected radio from it rather than
- // the saved .env.generated value — but only ONCE, and never after the operator has touched it. Without
- // that guard a background refetch (or a late first resolution racing an early click) re-stamps the
- // running engine over an in-progress selection (#735).
+ // Seed the radio from the SAVED engine, once, and never after the operator has touched it (#735).
//
- // When ENGINE_TYPE is PINNED by the environment the running engine is that pin, not a choice anyone
- // made here. Seeding from it would present the pin as the operator's own selection and then persist it
- // over their saved engine on the next save of any field on this page — so unsetting the variable could
- // no longer restore what they picked. A pinned deployment seeds from the saved file instead; the card
- // badge still reports what is actually running (#1082).
+ // Not from the running engine, which this used to do: the gateway resolves ENGINE_TYPE once at boot,
+ // so the running value is stale from the moment a change is saved until the server restarts, and it
+ // is the pinned value outright when an environment variable supplies one. Either way it is a value
+ // nobody chose here, and because `buildSavePayload` always sends `type` once the radio has seeded,
+ // the next save of ANY field on this page wrote it back over the operator's saved engine — losing a
+ // choice that unsetting the variable, or restarting, was supposed to reveal (#1082).
+ //
+ // The saved file is the intent; what is actually running is reported by the card badge and, when the
+ // two differ, named by the card's own notice.
useEffect(() => {
- if (!infraStatus || engineHydrated.current || engineTouched.current) return;
- const seed = infraStatus.envPinned?.includes('ENGINE_TYPE') ? savedConfig?.engine.type : currentEngine;
- if (!seed) return;
+ const seed = savedConfig?.engine.type;
+ if (!seed || engineHydrated.current || engineTouched.current) return;
engineHydrated.current = true;
setEngineConfig(prev => (prev.type === seed ? prev : { ...prev, type: seed }));
- }, [currentEngine, infraStatus, savedConfig]);
+ }, [savedConfig]);
const updateDbConfig = (key: keyof DatabaseConfig, value: string | number | boolean) =>
setDbConfig(prev => ({ ...prev, [key]: value }));
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 489340160..0bb2ed91f 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -90,6 +90,11 @@ const PINNED_STATUS: InfraStatus = { ...INFRA_STATUS, envPinned: ['ENGINE_TYPE']
// the whole subject of these tests, and the stock fixtures agree on whatsapp-web.js.
const SAVED_BAILEYS: SavedConfig = { ...SAVED_CONFIG, engine: { ...SAVED_CONFIG.engine, type: 'baileys' } };
+// Saved storage differs from the running one — the "saved, awaiting restart" state, with no pin.
+const SAVED_STORAGE_DRIFT: SavedConfig = { ...SAVED_CONFIG, storage: { ...SAVED_CONFIG.storage, type: 's3' } };
+
+const PENDING_RESTART_NOTE = 'Saved, but not applied yet — restart the server for this change to take effect.';
+
function jsonResponse(data: unknown, status = 200): Response {
return new Response(JSON.stringify(data), {
status,
@@ -321,25 +326,83 @@ async function awaitConfigHydrated(container: HTMLElement): Promise<void> {
await rtl.waitFor(() => assert.equal(fieldInput(container, 'Username').value, 'openwa_admin'));
}
-test('the engine radio seeds from the running engine when ENGINE_TYPE is not pinned', async () => {
- const { screen } = rtl;
+test('the engine radio seeds from the saved engine even when nothing pins ENGINE_TYPE', async () => {
+ const { screen, waitFor } = rtl;
resetFetchCalls();
- // Running and saved disagree, but nothing pins ENGINE_TYPE — the running engine still wins, because
- // a save IS able to change it and the radio should show what is actually in effect. Pins the
- // pre-existing behaviour, so an implementation that always seeded from the saved file would fail here.
+ // Running and saved disagree with no pin at all — the ordinary "saved but not restarted yet" state.
+ // The running engine is stale here (the gateway resolves ENGINE_TYPE once at boot), so seeding from
+ // it would show an engine nobody currently wants and write it back on the next save.
overrides = { saved: SAVED_BAILEYS };
const { container } = renderInfrastructure();
await screen.findByText('Database Configuration');
await awaitConfigHydrated(container);
- assert.equal(
- engineRadios(container)[0].checked,
- true,
- 'expected the running engine (whatsapp-web.js) to be selected',
+ await waitFor(() =>
+ assert.equal(engineRadios(container)[1].checked, true, 'expected the saved engine (baileys) to be selected'),
);
});
+test('saving after an unrestarted engine change does not write the running engine back', async () => {
+ const { screen, waitFor, fireEvent } = rtl;
+ resetFetchCalls();
+ // No pin anywhere. The operator changed the engine earlier and has not restarted, so /engines/current
+ // still reports the old one. Saving an unrelated field must not resurrect it over the saved choice.
+ overrides = { saved: SAVED_BAILEYS };
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await awaitConfigHydrated(container);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+
+ await waitFor(() => {
+ const call = findFetchCall('PUT', '/api/infra/config');
+ assert.ok(call, 'expected a PUT to /infra/config');
+ const body = call!.body as { engine?: { type?: string } };
+ assert.equal(body.engine?.type, 'baileys');
+ });
+});
+
+test('an operator selection wins over the seed and is what gets saved', async () => {
+ const { screen, waitFor, fireEvent } = rtl;
+ resetFetchCalls();
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await awaitConfigHydrated(container);
+
+ // Guards the #735 invariant through the seeding rewrite: whatever the seed chose, a click owns the
+ // field afterwards and the payload must carry the click.
+ fireEvent.click(engineRadios(container)[1]);
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+
+ await waitFor(() => {
+ const call = findFetchCall('PUT', '/api/infra/config');
+ assert.ok(call, 'expected a PUT to /infra/config');
+ const body = call!.body as { engine?: { type?: string } };
+ assert.equal(body.engine?.type, 'baileys');
+ });
+});
+
+test('the pending-restart note survives a successful save', async () => {
+ const { screen, waitFor, fireEvent } = rtl;
+ resetFetchCalls();
+ // Storage differs between running and saved: the exact "saved, awaiting restart" state the note
+ // describes. It must still be readable AFTER a save — that is the operator who chose Restart Later.
+ overrides = { saved: SAVED_STORAGE_DRIFT };
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await awaitConfigHydrated(container);
+ await screen.findByText(PENDING_RESTART_NOTE);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+ await waitFor(() => assert.ok(findFetchCall('PUT', '/api/infra/config'), 'expected a PUT to /infra/config'));
+
+ assert.ok(screen.queryByText(PENDING_RESTART_NOTE), 'the pending-restart note must not vanish once a save succeeds');
+});
+
test('the engine radio seeds from the saved engine when ENGINE_TYPE is pinned', async () => {
const { screen, waitFor } = rtl;
resetFetchCalls();
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index 1d713b194..337b6fe40 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -47,7 +47,7 @@ export function Infrastructure() {
const { data: currentEngineData } = useCurrentEngineQuery();
const currentEngine = currentEngineData?.engineType ?? '';
- const configForm = useInfraConfigForm(infraStatus, savedConfig, currentEngine);
+ const configForm = useInfraConfigForm(infraStatus, savedConfig);
const restartFlow = useRestartFlow();
const dataBackup = useDataBackup();
@@ -138,9 +138,11 @@ export function Infrastructure() {
</p>
);
}
- // savePending suppresses the note only while the request is in flight; afterwards the saved value
- // genuinely differs from the running one until a restart, and saying so is the whole point.
- const pendingRestart = !configSave.savePending && !!infraStatus && !!savedConfig && running !== saved;
+ // Suppressed only while the request is actually in flight. `saving` is that flag; `savePending` is
+ // a latch set once a save SUCCEEDS and cleared only by a restart's page reload, so gating on it
+ // hid this note for the whole life of the page from the first successful save — which is exactly
+ // the state it exists to report, and exactly what the operator who chose "Restart Later" is in.
+ const pendingRestart = !configSave.saving && !!infraStatus && !!savedConfig && running !== saved;
return pendingRestart ? (
<p className="env-pin-note">
<AlertTriangle size={14} /> {t('infrastructure.pendingRestartNote')}
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index b918f48da..43490a037 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -1244,11 +1244,11 @@ extra work is done.
When enabled, three rules can refuse a send:
-| Rule | What it means |
-| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| Warm-up daily cap | The session has used its allowance for the current **UTC** day. The allowance grows with the session's age (`SEND_PACING_WARMUP_SCHEDULE`), because a brand-new WhatsApp account that immediately sends at volume is the pattern that gets numbers banned. The count comes from the messages table, so it survives restarts — and so it only sees sends that write a row there. Status posts, message edits and Baileys product sends are checked against the cap but never counted into it — none of them writes a row, and an edit only updates one — so a session using them can exceed its stated allowance; chat sends, bulk included, are counted exactly. |
-| Cold-reachout cap | The session has used its allowance of **new conversations** for the UTC day (`SEND_PACING_COLD_DAILY_CAP`). A send is a cold reachout when the account has no history with that chat in **either** direction — replying to someone who wrote to you first is never counted, and never refused by this rule. Status posts address no chat and are exempt. |
-| Failure breaker | Consecutive send failures reached `SEND_PACING_BREAKER_THRESHOLD`, which usually means WhatsApp has already started refusing this account. The streak has no time decay — only a successful send resets it, so failures spread across a long quiet period still accumulate toward the threshold. Sends resume after `SEND_PACING_BREAKER_COOLDOWN_MS`, or immediately after any send succeeds. |
+| Rule | What it means |
+| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Warm-up daily cap | The session has used its allowance for the current **UTC** day. The allowance grows with the session's age (`SEND_PACING_WARMUP_SCHEDULE`), because a brand-new WhatsApp account that immediately sends at volume is the pattern that gets numbers banned. The count comes from the messages table, so it survives restarts — and so it only sees sends that write a row there. Status posts, message edits and Baileys product sends are checked against the cap but never counted into it — none of them writes a row, and an edit only updates one — and neither is a bulk item the engine refuses, because bulk persists its row only after the send succeeds. A session using any of them can exceed its stated allowance. A bulk item that succeeds is counted, as is a failed single send, whose PENDING row is kept as FAILED. |
+| Cold-reachout cap | The session has used its allowance of **new conversations** for the UTC day (`SEND_PACING_COLD_DAILY_CAP`). A send is a cold reachout when the account has no history with that chat in **either** direction — replying to someone who wrote to you first is never counted, and never refused by this rule. Status posts address no chat and are exempt. |
+| Failure breaker | Consecutive send failures reached `SEND_PACING_BREAKER_THRESHOLD`, which usually means WhatsApp has already started refusing this account. The streak has no time decay — only a successful send resets it, so failures spread across a long quiet period still accumulate toward the threshold. Sends resume after `SEND_PACING_BREAKER_COOLDOWN_MS`, or immediately after any send succeeds. |
A refusal is `429` with a body carrying **`code: "SEND_PACING_LIMITED"`** and `retryAfterSeconds`: