-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(evolution): prevent Evolution instances from getting stuck in 'cl… #2420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(evolution): prevent Evolution instances from getting stuck in 'cl… #2420
Conversation
…ose' state Evolution is a webhook-based integration that should always be considered 'open' since it passively receives events. Three changes fix the issue: 1. monitor.service.ts: Always call connectToWhatsapp() for Evolution instances on server restart, regardless of stored connection status. 2. instance.controller.ts: Call connectToWhatsapp() for Evolution instances during creation to initialize Chatwoot settings. 3. evolution.channel.service.ts: Restore stateConnection to 'open' and persist it to DB when connectToWhatsapp() is called in init mode. Closes EvolutionAPI#2419 https://claude.ai/code/session_013wxk4cj5U2H5fr2cxCgWdH
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures Evolution WhatsApp integration instances are always treated as 'open' webhook-based connections by auto-connecting them on startup/creation and resetting their connection state to 'open' when initialized, including persisting that state to the database. Sequence diagram for Evolution instance auto-connect on server restartsequenceDiagram
participant Server
participant WAMonitoringService
participant PrismaRepository
participant EvolutionStartupService
Server->>WAMonitoringService: onStartup()
WAMonitoringService->>PrismaRepository: findManyInstances()
PrismaRepository-->>WAMonitoringService: instanceList
loop forEach instanceData
WAMonitoringService->>WAMonitoringService: shouldAutoConnect(instanceData)
alt instanceData.connectionStatus is open or connecting or integration is EVOLUTION
WAMonitoringService->>EvolutionStartupService: connectToWhatsapp(instanceData)
alt data is not provided (init mode)
EvolutionStartupService->>EvolutionStartupService: stateConnection = { state: open }
alt instanceId is defined
EvolutionStartupService->>PrismaRepository: updateInstance(id, connectionStatus = open)
PrismaRepository-->>EvolutionStartupService: updatedInstance
end
EvolutionStartupService->>EvolutionStartupService: loadChatwoot()
else data is provided
EvolutionStartupService->>EvolutionStartupService: normal connection flow
end
else no auto connect
WAMonitoringService->>WAMonitoringService: skipConnect(instanceData)
end
end
Sequence diagram for Evolution instance creation and initializationsequenceDiagram
actor Client
participant InstanceController
participant PrismaRepository
participant EvolutionStartupService
Client->>InstanceController: createInstance(requestBody)
InstanceController->>PrismaRepository: createInstanceInDatabase(requestBody)
PrismaRepository-->>InstanceController: instanceData
InstanceController->>EvolutionStartupService: createInstance(instanceData)
EvolutionStartupService-->>InstanceController: instance
InstanceController->>InstanceController: prepareResponseData(instance, instanceData)
alt instanceData.integration is EVOLUTION
InstanceController->>EvolutionStartupService: connectToWhatsapp()
EvolutionStartupService->>EvolutionStartupService: stateConnection = { state: open }
alt instanceId is defined
EvolutionStartupService->>PrismaRepository: updateInstance(id, connectionStatus = open)
PrismaRepository-->>EvolutionStartupService: updatedInstance
end
EvolutionStartupService->>EvolutionStartupService: loadChatwoot()
end
InstanceController-->>Client: createdInstanceResponse
Updated class diagram for Evolution startup, monitoring, and instance controllerclassDiagram
class WAMonitoringService {
- logger
- prismaRepository
+ onStartup() void
+ monitorInstances() void
+ connectInstance(instanceData) void
}
class InstanceController {
- prismaRepository
- logger
+ createInstance(requestBody) Promise
+ getInstance(instanceId) Promise
}
class EvolutionStartupService {
- prismaRepository
- instanceId
- stateConnection
+ connectToWhatsapp(data) Promise
+ loadChatwoot() void
}
class PrismaRepository {
+ findManyInstances() Promise
+ updateInstance(id, connectionStatus) Promise
+ createInstanceInDatabase(requestBody) Promise
}
class Integration {
<<enumeration>>
EVOLUTION
OTHER
}
WAMonitoringService --> PrismaRepository : uses
WAMonitoringService --> EvolutionStartupService : creates_and_connects
InstanceController --> PrismaRepository : uses
InstanceController --> EvolutionStartupService : initializes_and_connects
EvolutionStartupService --> PrismaRepository : updates_instance_state
InstanceController --> Integration : checks_integration_type
WAMonitoringService --> Integration : checks_integration_type
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- In
InstanceController, consider whetherawait instance.connectToWhatsapp()on Evolution creation should block the whole request (and potentially fail instance creation on connection/init errors) or if it would be safer to kick this off asynchronously and surface errors via monitoring instead. - The auto-connect log message in
WAMonitoringServicestill reportsconnectionStatuseven when auto-connecting solely becauseintegration === Integration.EVOLUTION; consider clarifying the log text or including the integration type so the reason for auto-connection is unambiguous in logs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `InstanceController`, consider whether `await instance.connectToWhatsapp()` on Evolution creation should block the whole request (and potentially fail instance creation on connection/init errors) or if it would be safer to kick this off asynchronously and surface errors via monitoring instead.
- The auto-connect log message in `WAMonitoringService` still reports `connectionStatus` even when auto-connecting solely because `integration === Integration.EVOLUTION`; consider clarifying the log text or including the integration type so the reason for auto-connection is unambiguous in logs.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ose' state
Evolution is a webhook-based integration that should always be considered 'open' since it passively receives events. Three changes fix the issue:
Closes #2419
https://claude.ai/code/session_013wxk4cj5U2H5fr2cxCgWdH
📋 Description
🔗 Related Issue
Closes #(issue_number)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
Summary by Sourcery
Ensure Evolution WhatsApp integrations are always initialized and marked as open so they do not remain stuck in a closed state.
Bug Fixes: