Yes, I have searched for similar issues on GitHub and found none that match exactly, though the stack trace pattern resembles older closed reports (#2423, #2218) which appear to be a different underlying trigger (those were tied to existing/legacy data, not fresh installs).
What did i do?
Created a brand new WhatsApp instance (Baileys integration) on a completely fresh install — new Postgres database, new Redis cache, new Docker volumes, no prior data of any kind. This was reproduced independently in two separate environments:
- Production VM (Ubuntu, Docker Compose with Traefik + Postgres 15 + Redis 7), after fully dropping and recreating the
evolution database, flushing Redis, and deleting/recreating the evolution_instances volume.
- Local machine (Docker Desktop, isolated
docker compose stack with its own fresh Postgres 15 + Redis 7, no shared state with the VM at all), using the homolog tag.
In both cases, instance creation was attempted immediately after a clean, verified startup (Prisma migrations completed successfully, license activated where applicable, no prior errors in logs).
Instance creation was attempted two ways, both failing identically:
- Via the Manager UI "New instance" form (Name:
TestWA, Channel: Baileys, auto-generated Token)
- Via direct API call:
curl -s -X POST https://<host>/instance/create \
-H "Content-Type: application/json" \
-H "apikey: <valid_global_api_key>" \
-d '{"instanceName": "TestInstance", "qrcode": true, "integration": "WHATSAPP-BAILEYS"}'
What did you expect to happen?
The instance should be created successfully and return instance details + QR code, as documented.
What actually happened?
The request fails with a 400 Bad Request, and the instance is immediately auto-removed:
{"status":400,"error":"Bad Request","response":{"message":["\nInvalid `a.integrationSession.update()` invocation in\n/evolution/dist/main.js:202:11516\n... Foreign key constraint violated on the constraint: `Setting_instanceId_fkey`"]}}
Corresponding container logs:
[Evolution API] ERROR [InstanceController]
Invalid `a.integrationSession.update()` invocation in
/evolution/dist/main.js:202:11516
Foreign key constraint violated on the constraint: `Setting_instanceId_fkey`
[Evolution API] WARN [WAMonitoringService] Instance "undefined" - REMOVED
Note the instance name resolves to "undefined" in the removal log line, suggesting the instance record is not fully persisted/committed before downstream code (processMessages → integrationSession.update) attempts to write a related Setting row referencing its instanceId — resulting in a race condition / ordering bug where the FK target doesn't exist yet.
This is 100% reproducible — every single instance-creation attempt on a fresh DB fails with this exact error, across all three versions tested.
Environment
- Versions tested (all reproduce identically):
evoapicloud/evolution-api:2.4.0 (stable-tagged, production VM)
evoapicloud/evolution-api:2.4.0-rc2 (implied same code path)
evoapicloud/evolution-api:homolog (pulled ~July 2026, local test)
- Database: PostgreSQL 15 (official
postgres:15 image), freshly created database each time, 59 migrations applied successfully with no errors (db:deploy reports "Migration succeeded")
- Cache: Redis 7 (official
redis:7 image), FLUSHALL run before each test, DBSIZE confirmed 0 before instance creation attempt
- Deployment: Docker Compose, both behind Traefik (production) and standalone with direct port exposure (local test) — same error in both, ruling out reverse proxy/networking as a factor
- Integration type:
WHATSAPP-BAILEYS
- No chatbot/integration env vars enabled (
WEBHOOK_EVENTS_TYPEBOT_START=false, no Chatwoot/OpenAI/Typebot configuration present)
- License: Activated successfully prior to testing on 2.4.0 (
[Licensing] License activated successfully in logs) — not a licensing-related failure
Steps to reproduce (minimal)
- Fresh Postgres 15 + Redis 7 containers, no prior data.
- Start
evoapicloud/evolution-api:homolog (or 2.4.0) pointed at the fresh DB/Redis.
- Confirm clean boot: migrations succeed, no errors, server listening.
- Attempt to create any new instance via
/instance/create or the Manager UI "New instance" form.
- Observe immediate 400 error with the FK violation above; instance is auto-removed.
Additional context
This was discovered while separately investigating an unrelated, also-unresolved issue: intermittent message delivery failures (status: 'ERROR' on messages.update, preceded by Closing session: SessionEntry in logs) for contacts using WhatsApp's @lid addressing — which appears to match the tracked meta-issue #1872. That investigation led to testing 2.4.0/homolog specifically for the @lid fix in #2544, which is how this separate instance-creation bug was found. Rolling back to v2.3.7 avoids this specific FK bug but does not have the @lid fix, so there's currently no available tag that has neither issue.
Yes, I have searched for similar issues on GitHub and found none that match exactly, though the stack trace pattern resembles older closed reports (#2423, #2218) which appear to be a different underlying trigger (those were tied to existing/legacy data, not fresh installs).
What did i do?
Created a brand new WhatsApp instance (Baileys integration) on a completely fresh install — new Postgres database, new Redis cache, new Docker volumes, no prior data of any kind. This was reproduced independently in two separate environments:
evolutiondatabase, flushing Redis, and deleting/recreating theevolution_instancesvolume.docker composestack with its own fresh Postgres 15 + Redis 7, no shared state with the VM at all), using thehomologtag.In both cases, instance creation was attempted immediately after a clean, verified startup (Prisma migrations completed successfully, license activated where applicable, no prior errors in logs).
Instance creation was attempted two ways, both failing identically:
TestWA, Channel:Baileys, auto-generated Token)What did you expect to happen?
The instance should be created successfully and return instance details + QR code, as documented.
What actually happened?
The request fails with a 400 Bad Request, and the instance is immediately auto-removed:
Corresponding container logs:
Note the instance name resolves to
"undefined"in the removal log line, suggesting the instance record is not fully persisted/committed before downstream code (processMessages→integrationSession.update) attempts to write a relatedSettingrow referencing itsinstanceId— resulting in a race condition / ordering bug where the FK target doesn't exist yet.This is 100% reproducible — every single instance-creation attempt on a fresh DB fails with this exact error, across all three versions tested.
Environment
evoapicloud/evolution-api:2.4.0(stable-tagged, production VM)evoapicloud/evolution-api:2.4.0-rc2(implied same code path)evoapicloud/evolution-api:homolog(pulled ~July 2026, local test)postgres:15image), freshly created database each time, 59 migrations applied successfully with no errors (db:deployreports "Migration succeeded")redis:7image),FLUSHALLrun before each test,DBSIZEconfirmed 0 before instance creation attemptWHATSAPP-BAILEYSWEBHOOK_EVENTS_TYPEBOT_START=false, no Chatwoot/OpenAI/Typebot configuration present)[Licensing] License activated successfullyin logs) — not a licensing-related failureSteps to reproduce (minimal)
evoapicloud/evolution-api:homolog(or2.4.0) pointed at the fresh DB/Redis./instance/createor the Manager UI "New instance" form.Additional context
This was discovered while separately investigating an unrelated, also-unresolved issue: intermittent message delivery failures (
status: 'ERROR'onmessages.update, preceded byClosing session: SessionEntryin logs) for contacts using WhatsApp's@lidaddressing — which appears to match the tracked meta-issue #1872. That investigation led to testing 2.4.0/homolog specifically for the@lidfix in #2544, which is how this separate instance-creation bug was found. Rolling back tov2.3.7avoids this specific FK bug but does not have the@lidfix, so there's currently no available tag that has neither issue.