fix(whatsapp): reset watchdog timeout after reconnect#60007
fix(whatsapp): reset watchdog timeout after reconnect#60007mcaxtr merged 2 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR fixes a watchdog false-positive on WhatsApp reconnect: previously,
Confidence Score: 4/5Safe to merge — targeted, well-tested fix with no regressions visible in the changed surface. The fix is minimal and precisely addresses the stated root cause. Both the production code change and the test update are logically consistent. The one implicit behavioral side-effect — first-time (non-reconnect) connections are now also subject to the watchdog countdown from No files require special attention. Reviews (1): Last reviewed commit: "WhatsApp: reset watchdog timeout after r..." | Re-trigger Greptile |
3fc5f36 to
3b30df3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b30df3cce
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const watchdogBaselineAt = active.lastInboundAt ?? active.startedAt; | ||
| const timeSinceLastMessage = Date.now() - watchdogBaselineAt; |
There was a problem hiding this comment.
Start watchdog window after connection is established
Using active.startedAt as the fallback watchdog baseline can still cause near-immediate reconnects after a "successful" reconnect when socket setup is slow. In this code path, startedAt is captured before listenerFactory completes, and monitorWebInbox waits for waitForWaConnection(...) before returning, so a long connect/login stall (for example prolonged network recovery) can consume most or all of the timeout window before the listener is even active. That reintroduces reconnect churn right after reconnect; the baseline should be set from a post-connect timestamp instead of pre-connect run start.
Useful? React with 👍 / 👎.
3b30df3 to
d7abee7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7abee7ed3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| const timeSinceLastMessage = Date.now() - active.lastInboundAt; | ||
| // A reconnect should get a fresh watchdog window even before the next inbound arrives. | ||
| const watchdogBaselineAt = active.lastInboundAt ?? active.startedAt; |
There was a problem hiding this comment.
Base watchdog window on established connection time
active.startedAt is set before listenerFactory/monitorWebInbox finishes, so this fallback baseline counts connection setup time as inactivity. In slow reconnect/login scenarios that consume most of MESSAGE_TIMEOUT_MS, the first watchdog check can force another reconnect almost immediately after a successful connect, which recreates reconnect churn under network recovery. Use a timestamp captured after the listener is actually connected (for example right after noteConnected) as the fallback baseline.
Useful? React with 👍 / 👎.
d7abee7 to
64223e5
Compare
|
Merged via squash.
Thanks @MonkeyLeeT! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64223e5dd4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| const timeSinceLastMessage = Date.now() - active.lastInboundAt; | ||
| // A reconnect should get a fresh watchdog window even before the next inbound arrives. | ||
| const watchdogBaselineAt = active.lastInboundAt ?? active.startedAt; |
There was a problem hiding this comment.
Start watchdog window after connection completes
Using active.startedAt as the fallback timeout baseline starts the watchdog clock before the awaited socket setup finishes, so a slow reconnect/login can consume most of MESSAGE_TIMEOUT_MS before the listener is actually connected and then trigger another forced reconnect almost immediately. Fresh evidence in this commit is that createActiveConnectionRun() now initializes startedAt before listenerFactory resolves, and the watchdog now falls back to that timestamp when lastInboundAt is null.
Useful? React with 👍 / 👎.
Summary
Root cause
The reconnect path reused the previous run's
lastInboundAt, so a quiet channel could reconnect and immediately trip the watchdog again with stale message age.Validation
Fixes #59830