fix(evolution): prevent Evolution instances from getting stuck in 'cl…#2420
Open
ElioBonfim wants to merge 1 commit intoEvolutionAPI:mainfrom
Open
fix(evolution): prevent Evolution instances from getting stuck in 'cl…#2420ElioBonfim wants to merge 1 commit intoEvolutionAPI:mainfrom
ElioBonfim wants to merge 1 commit intoEvolutionAPI:mainfrom
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
Contributor
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
|
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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: