Skip to content

fix(whatsapp): reset watchdog timeout after reconnect#60007

Merged
mcaxtr merged 2 commits intoopenclaw:mainfrom
MonkeyLeeT:codex/59830-whatsapp-watchdog
Apr 3, 2026
Merged

fix(whatsapp): reset watchdog timeout after reconnect#60007
mcaxtr merged 2 commits intoopenclaw:mainfrom
MonkeyLeeT:codex/59830-whatsapp-watchdog

Conversation

@MonkeyLeeT
Copy link
Copy Markdown
Contributor

Summary

  • reset WhatsApp reconnect runs to start with a fresh watchdog window
  • use the new connection start time as the watchdog baseline until the next inbound message arrives
  • update the reconnect watchdog test to prove the new listener survives before the fresh timeout expires

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

  • pnpm test -- extensions/whatsapp/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts
  • pnpm build

Fixes #59830

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Apr 3, 2026
@MonkeyLeeT MonkeyLeeT changed the title [codex] WhatsApp: reset watchdog timeout after reconnect fix(whatsapp): reset watchdog timeout after reconnect Apr 3, 2026
@MonkeyLeeT MonkeyLeeT marked this pull request as ready for review April 3, 2026 03:43
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 3, 2026

Greptile Summary

This PR fixes a watchdog false-positive on WhatsApp reconnect: previously, createActiveConnectionRun inherited the stale lastInboundAt from the previous connection, so a quiet channel could trip the watchdog immediately after reconnecting. The fix resets lastInboundAt to null on every new run and falls back to active.startedAt as the watchdog baseline, giving each reconnect (and initial connection) a clean timeout window.

  • createActiveConnectionRun() no longer accepts or carries over lastInboundAt from the prior run — every connection starts fresh.
  • Watchdog timer: watchdogBaselineAt = active.lastInboundAt ?? active.startedAt replaces the early-return guard, so the countdown begins from connection time rather than from an arbitrarily old message timestamp.
  • Log field lastInboundAt now emits null correctly when no message has been received (previously this path was unreachable; now it can occur when startedAt expires before the first inbound).
  • The renamed test "gives a reconnected listener a fresh watchdog window" properly validates the new contract: after reconnect, the second listener survives the first 20 ms check-point and only trips after the 40 ms total (MESSAGE_TIMEOUT_MS = 30 ms in the test harness).

Confidence Score: 4/5

Safe 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 startedAt rather than being permanently exempt until the first message — is a clear improvement (dead first connections will now self-heal) but is not called out in the PR description. This is a minor omission, not a defect, hence a 4 rather than 5.

No files require special attention.

Reviews (1): Last reviewed commit: "WhatsApp: reset watchdog timeout after r..." | Re-trigger Greptile

@mcaxtr mcaxtr self-assigned this Apr 3, 2026
@mcaxtr mcaxtr force-pushed the codex/59830-whatsapp-watchdog branch 2 times, most recently from 3fc5f36 to 3b30df3 Compare April 3, 2026 23:02
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +310 to +311
const watchdogBaselineAt = active.lastInboundAt ?? active.startedAt;
const timeSinceLastMessage = Date.now() - watchdogBaselineAt;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@mcaxtr mcaxtr force-pushed the codex/59830-whatsapp-watchdog branch from 3b30df3 to d7abee7 Compare April 3, 2026 23:09
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@mcaxtr mcaxtr force-pushed the codex/59830-whatsapp-watchdog branch from d7abee7 to 64223e5 Compare April 3, 2026 23:23
@mcaxtr mcaxtr merged commit ff62705 into openclaw:main Apr 3, 2026
13 of 25 checks passed
@mcaxtr
Copy link
Copy Markdown
Member

mcaxtr commented Apr 3, 2026

Merged via squash.

Thanks @MonkeyLeeT!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

KimGLee pushed a commit to KimGLee/openclaw that referenced this pull request Apr 4, 2026
Merged via squash.

Prepared head SHA: 64223e5
Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Merged via squash.

Prepared head SHA: 64223e5
Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
Merged via squash.

Prepared head SHA: 64223e5
Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Merged via squash.

Prepared head SHA: 64223e5
Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WhatsApp watchdog reconnect loop: lastInboundAt persists across reconnects

2 participants