Commit Graph

1695 Commits

Author SHA1 Message Date
Claude 11e7c71fd1 feat(event-buffer): enhance with enterprise-grade features
- Add environment variable configuration (BAILEYS_BUFFER_*)
- Implement destroy() method for proper resource cleanup
- Add force flush capability with flush(force) parameter
- Implement buffer overflow detection and prevention
- Add adaptive timeout algorithm based on event rate
- Replace historyCache.clear() with LRU cache cleanup
- Integrate Prometheus metrics for buffer monitoring
- Add isDestroyed state protection
- Fix createBufferedFunction to prevent orphaned timers
- Add comprehensive statistics tracking (getStatistics())
- Add configuration accessor (getConfig())

Enterprise features:
- Configurable buffer size limits (maxBufferSize)
- Configurable timeout ranges (min/max)
- LRU cleanup ratio configuration
- Buffer overflow warning threshold
- Adaptive timeout based on event rate
2026-01-20 03:45:52 +00:00
Claude 8a705e5a1e fix(metrics): update env vars to match BAILEYS_PROMETHEUS_* convention
- Support BAILEYS_PROMETHEUS_ENABLED, BAILEYS_PROMETHEUS_PORT, etc.
- Add support for BAILEYS_PROMETHEUS_LABELS JSON configuration
- Maintain backward compatibility with METRICS_* prefix
- Update default port to 9092 (matching user's .env)
- Enable by opt-in (enabled=false by default)
- Improved startup log with labels info
2026-01-20 03:19:32 +00:00
Claude 0c173212fd feat(metrics): enhance Prometheus metrics with enterprise-grade features
- Add HTTP server for /metrics endpoint with configurable port
- Add environment variable configuration (METRICS_ENABLED, METRICS_PORT, etc.)
- Add SystemMetricsCollector for process/system metrics (CPU, memory, load avg)
- Add Event Buffer metrics (size, capacity, utilization, flushes, overflows)
- Add Adaptive Flush metrics (interval, adjustments, throughput, backpressure)
- Add Circuit Breaker metrics (state, trips, recoveries, rejections)
- Add Query metrics (latency, count, timeouts)
- Add Presence and Group metrics
- Add History Sync metrics
- Add helper functions (trackDuration, trackDurationAsync, trackOperation)
- Add Express middleware support
- Add global metrics manager with initialize/shutdown lifecycle
- Total metrics increased from 18 to 50+
2026-01-20 03:14:44 +00:00
Claude 5714e8e940 merge: resolve conflicts with master 2026-01-20 02:38:37 +00:00
Claude 61f5f76ef0 feat(socket): integrate circuit breaker with Socket operations
- Add circuit breaker configuration options to SocketConfig type
- Initialize circuit breakers for query, connection, and pre-key operations
- Wrap query() with circuit breaker protection for all WhatsApp queries
- Wrap sendRawMessage() with connection circuit breaker
- Integrate pre-key circuit breaker with uploadPreKeys()
- Add circuit breaker utilities to socket return object (stats, reset)
- Clean up circuit breakers on connection close
- Fix TypeScript errors in utility files (prometheus-metrics, logger-adapter, etc.)

Circuit breakers provide:
- Sliding window failure tracking
- Automatic state transitions (closed -> open -> half-open)
- Configurable thresholds and timeouts
- Prometheus metrics integration
- Event callbacks for monitoring
2026-01-20 02:31:23 +00:00
Claude dd59a7fe65 fix(utils): resolve TypeScript compilation errors
- baileys-event-stream.ts: Add null check for buffer item in priority insertion
- baileys-logger.ts: Handle 'silent' log level and fix JID sanitization
- cache-utils.ts: Fix type incompatibility in global cache with any type
- logger-adapter.ts: Add nullish coalescing for level mapping and fix console type cast
- prometheus-metrics.ts: Rename private 'metrics' property to 'metricsMap' to avoid conflict with method
- trace-context.ts: Store baggage header in variable before accessing to fix undefined check
2026-01-20 02:05:14 +00:00
Claude 64c7712da7 refactor(utils): translate all comments to English and enhance circuit breaker
- Translate all Portuguese comments to English in utility modules
- Enhance circuit-breaker.ts with sliding window failure tracking
- Add factory functions for WhatsApp-specific circuit breakers
  (createPreKeyCircuitBreaker, createConnectionCircuitBreaker, createMessageCircuitBreaker)
- Improve volume threshold support for circuit breaker decisions
- Standardize documentation across all utility files

Files updated:
- structured-logger.ts: English comments
- baileys-logger.ts: English comments
- trace-context.ts: English comments
- prometheus-metrics.ts: English comments
- cache-utils.ts: English comments
- circuit-breaker.ts: Enhanced with sliding window + English comments
- retry-utils.ts: English comments
- baileys-event-stream.ts: English comments
- index.ts: English comments
2026-01-20 01:48:23 +00:00
Claude 882a1f57cf feat(utils): add observability and resilience utilities
Implement comprehensive utility modules for InfiniteAPI:

Logging:
- structured-logger: JSON logging with levels, sanitization, metrics
- logger-adapter: Pino/Console/Structured adapter pattern
- baileys-logger: WhatsApp-specific logger with categories

Observability:
- trace-context: Distributed tracing with spans, correlation IDs
- prometheus-metrics: Counter, Gauge, Histogram, Summary metrics

Resilience:
- cache-utils: LRU cache with TTL, multi-level support
- circuit-breaker: 3-state circuit breaker with fallbacks
- retry-utils: Exponential backoff with jitter, predicates

Event Streaming:
- baileys-event-stream: Priority queues, backpressure, DLQ

Includes unit tests for all new modules.
2026-01-20 01:26:06 +00:00
Rajeh Taher b62cb40a70 chore: lint 2026-01-18 17:16:28 +02:00
Rajeh Taher 282f065f53 connection-deadlock, socket: improve socket end conditions 2026-01-18 17:16:28 +02:00
Vrypt db86cdc545 fix(proto-extract): regenerate corrupted yarn.lock to restore install process (#1981)
* fix(proto-extract): regenerate corrupted yarn.lock to restore install process

* chore(proto-extract): update acorn parser to latest version for compatibility with new WhatsApp JS syntax

* Update baileys version to 2.3000.1029027441

* Update version number in Defaults index

* Revert WAProto.proto to resolve merge conflict and restore expected structure

---------

Co-authored-by: Vrypt <vryptt@gmail.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2026-01-18 01:45:23 +02:00
YonkoSam a2677c89dd Fix critical memory leak in event buffer (#2160) 2026-01-18 01:44:28 +02:00
Rajeh Taher 56ee829757 process-message: remove timeout before event emit 2026-01-18 01:35:50 +02:00
Rajeh Taher e740fc5b4a messages-send: revamp message type function 2026-01-18 01:35:50 +02:00
Rajeh Taher 83e0f22af8 messages-recv: decrease PDO response timeout 2026-01-18 01:34:39 +02:00
Rajeh Taher b1c76ebe2d chore: lint+bugfix 2026-01-18 01:31:56 +02:00
João Lucas de Oliveira Lopes e53fa7b8e5 Feat improve testing coverage e2e (#1799)
* fix: ensure proper socket closure and await connection termination in tests

* feat(tests): enhance E2E tests for image and video message handling, including downloads and group interactions
2026-01-18 01:16:24 +02:00
vini 0b3b2a88cd fix(messages): enhance nullish value checks in message content generation (#2180) 2026-01-18 01:11:33 +02:00
YonkoSam 1408499d7c moved retryCount before validating the session (#2167) 2026-01-18 01:11:10 +02:00
Matheus Filype 349e7bd771 feat: send tctoken to profile update and presence subscribe (#2257)
* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* feat(tc-token): implement buildTcTokenFromJid utility and integrate into chats socket

* fix(tc-token): ensure consistent return value when tcTokenBuffer is absent

* fix(chats): update import path for buildTcTokenFromJid utility
2026-01-18 01:07:53 +02:00
João Lucas de Oliveira Lopes d4ef73aca5 feat: implement automated WhatsApp version update workflow and related scripts (#2130)
* feat: implement automated WhatsApp version update workflow and related scripts

* change cron to weekly

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2026-01-18 01:07:05 +02:00
João Lucas de Oliveira Lopes 9611a1a982 fix(WAProto): Handle string values in long fields during JSON serialization (#1991)
* feat: add patch-tojson functionality for improved proto serialization

* Remove patch-tojson functionality and its import from the main index file to streamline the codebase.

* refactor: simplify longToString and longToNumber functions for better readability and performance
2026-01-14 08:33:45 +02:00
vini 432c26a07c fix(messages): handle encryption failures per recipient and fail when all fail (#2226) 2026-01-08 22:07:11 +02:00
vini c392d4ce6c feat: add support for FB and Interop JID encoding/decoding and empty strings (#2189) 2026-01-08 21:56:50 +02:00
Ibrahim Pelumi Lasisi 720cc688d6 fix: avoid variable shadowing and preserve empty business profile fields (#2183)
* Update business.ts

* chore: fix lint issues
2026-01-08 21:56:13 +02:00
Gustavo Quadri 81d9c12e86 fix: getmessagetype to ensure consistency with whatsapp behavior (#2245) 2026-01-08 21:51:34 +02:00
João Lucas de Oliveira Lopes c9c3481817 implement message reporting tokens (#1906)
* feat: implement message reporting tokens and privacy token handling

* feat: add support for privacy tokens in profile picture requests and history sync

* chore: pr feedback purpshell

* fix: improve privacy token handling and error messaging in socket configuration

* feat: enhance privacy token handling with improved sender mapping

* chore: removing tc token in favor of #2080

* chore: revert some unecessary changes

* feat(reporting): enhance reporting token extraction and compilation logic

* feat(reporting): add unit tests for reporting token utilities

* fix(reporting): streamline reporting token attachment logic in message sending

* fix: adjust reporting token inclusion logic to prevent retries

* chore: add return type to shouldIncludeReportingToken and improve getToken function type safety
2026-01-08 21:50:49 +02:00
Skid 4e681d3219 feat: Verify leaf signature (#2208)
* Update WA_CERT_DETAILS with issuer and public key

* certificate validation

* fix:lint

* padding

* lint: fix tab

---------

Co-authored-by: skidy89 <tutorialesyg310@gmail.com>
2026-01-08 21:49:37 +02:00
Matheus Filype 250477497d Add Feature LabelMember (Based on #2164) (#2198)
* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* feat: add group member label update functionality and event emission

* feat: refactor updateMemberLabel function for improved readability

* feat: use optional chaining for label association message in processMessage

* feat: add updateMemberLabel to makeMessagesSocket for enhanced functionality

* fix: correct log message for group member tag update event

Co-authored-by: FgsiDev
2025-12-19 22:00:48 +02:00
vini 925ed6a7b3 feat(appstate): emit setting events (#2057) 2025-12-15 01:21:44 +02:00
Rajeh Taher 4609a3764e event-buffer: prevent loss of type due to buffering (#2179) 2025-12-14 14:16:28 +02:00
Matheus Filype b7960dbb9a feat: Optimize Offline Node Processing with Batching and Event Loop Yielding (#2138)
* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* fix(messages-recv): improve offline node processing and error handling

* feat: improve offline node processing by yielding to event loop
2025-12-12 06:50:18 +02:00
Rajeh Taher a7a53ad815 auth-utils: release transaction mutex after references are 0 (#2153) 2025-12-12 04:36:47 +02:00
YonkoSam 1e6f65cf5e fix Memory leak in makeMutex - Promise never gets garbage collected (#2151)
* Memory leak in makeMutex - Promise never gets garbage collected

Hey, I've been debugging a memory leak in my application and traced it back to the makeMutex implementation.

The current implementation chains promises indefinitely without ever breaking the chain:

Every call to mutex() creates a new Promise that awaits the previous task, then becomes the new task. The problem is the old promises never get released because each one holds a reference to the previous through the closure.

What I found
Took a heap snapshot after running for a while and found hundreds of Promises from make-mutex.js holding ~15MB and growing. The retainer graph shows a long chain of Promises all pointing back to each other.

Since processingMutex handles every incoming message/notification, this chain grows constantly and never shrinks.

This keeps the same mutex behavior but lets the GC clean up old promises every 50 tasks instead of holding them forever.

* Refactor makeMutex to use AsyncMutex directly

* lint

* revert
2025-12-12 04:35:24 +02:00
Matheus Filype 829fa8d601 feat: Mutex redesign - isolate event processing for better ordering and throughput (#2137)
* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* fix: introduce separate mutexes for message, receipt, app state patch, and notification processing

* fix: remove unused processing mutex for notifications
2025-12-12 04:34:59 +02:00
João Lucas de Oliveira Lopes 43d1787532 fix: improve media upload handling and reduce memory pressure (#2128)
* fix: improve media upload handling and reduce memory pressure

* fix: enhance media upload functionality and add comprehensive tests
2025-12-06 03:06:24 +02:00
João Lucas de Oliveira Lopes 674f116b00 fix(messages-recv): cancel pending phone requests for message retries (#2147) 2025-12-05 23:41:14 +02:00
YonkoSam 96e4e04239 Await cache checks for message resend logic (#2136) 2025-12-05 23:40:38 +02:00
Rajeh Taher f46e8b118c messages-recv: handle newsletter and unavailable message acks 2025-11-21 17:35:46 +02:00
Rajeh Taher 23f1268918 messages-recv: remove outdated case for privacy_token 2025-11-21 17:09:06 +02:00
Rajeh Taher 129df47fbb revert #2010 2025-11-19 16:57:22 +02:00
Rajeh Taher e3cc1acec0 messages-recv: ignore only view once messages 2025-11-19 16:54:57 +02:00
Rajeh Taher 247c717881 messages, auth: rename 'contacts-tc-token' to tctoken 2025-11-19 16:35:18 +02:00
Rajeh Taher 50d410d117 chore: lint 2025-11-19 16:25:56 +02:00
João Lucas de Oliveira Lopes 7254917c53 test: add unit tests for LIDMappingStore and message processing utilities (#1949)
* test: add unit tests for LIDMappingStore and message processing utilities

* Update src/__tests__/Signal/lid-mapping.test.ts

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* Update src/__tests__/Utils/process-message.test.ts

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* Update src/__tests__/Utils/process-message.test.ts

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-19 15:26:34 +02:00
Clayton Lopes ae5260fc96 Fix memory leak caused by missing TTL in cache (#2044) 2025-11-19 15:23:34 +02:00
vini a70e4da1c4 feat(signal): better parity with whatsapp web (#1967) 2025-11-19 15:20:49 +02:00
Marc Knaup 3be21f8b99 Added missing attribute to community participant removal (#2004) 2025-11-19 15:20:07 +02:00
Anychat LLC 2779c9df08 Update messages-media.ts (#1988)
Fix of issue https://github.com/WhiskeySockets/Baileys/issues/1986
2025-11-19 15:19:56 +02:00
Cassio Santos 5c456e514e fix: cannot send message on new Whatsapp Business limited accounts (#2080)
* fix: cannot send message on new Whatsapp Business limited accounts

* chore: add woraround to resend the message on 475 errors

* fix: lint

* fix: add handler

* fix: lint

* Update src/Socket/messages-send.ts

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2025-11-19 15:18:19 +02:00