Skip to content

fix(whatsapp): remove dead Math.max in watchdog app-silence formula - #93330

Closed
rushindrasinha wants to merge 4 commits into
openclaw:mainfrom
rushindrasinha:fix/whatsapp-watchdog-silence-formula
Closed

rushindrasinha wants to merge 4 commits into
openclaw:mainfrom
rushindrasinha:fix/whatsapp-watchdog-silence-formula

Conversation

@rushindrasinha

@rushindrasinha rushindrasinha commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

WhatsAppConnectionController computes the app-silence timeout at construction:

// connection-controller.ts:366 (before fix)
this.appSilenceTimeoutMs = Math.max(params.messageTimeoutMs, params.messageTimeoutMs * 4);

messageTimeoutMs * 4 is always ≥ messageTimeoutMs, so Math.max unconditionally returns messageTimeoutMs * 4. The guard is dead code — a reader expecting Math.max to do something meaningful will be confused, and a future refactor that replaces the second argument (intending to raise the floor) will silently break the intended behaviour.

Default values: messageTimeoutMs = 30 min → appSilenceTimeoutMs = 120 min. Runtime effect is unchanged; this is a correctness/clarity fix.

Fix

Remove the dead Math.max wrapper:

// connection-controller.ts:366 (after fix)
this.appSilenceTimeoutMs = params.messageTimeoutMs * 4;

Test

Added a test in connection-controller.test.ts:
"uses messageTimeoutMs × 4 as the app-silence window for fresh connections with no inbound"

Advances fake-timer time to just before the 4× window → no timeout; then past it → timeout fires. This pins the multiplier as a regression guard against future edits that alter the constant.

All 14 connection-controller tests pass.

Spotted while auditing the watchdog reconnect path on a production deployment.

Real behavior proof

  • Behavior or issue addressed: appSilenceTimeoutMs was computed as Math.max(messageTimeoutMs, messageTimeoutMs * 4). Since messageTimeoutMs * 4 >= messageTimeoutMs for all positive timeouts, the Math.max is dead code that always returns messageTimeoutMs * 4. This change removes it. The fix must be behavior-preserving — the watchdog's app-silence window must not change.
  • Real environment tested: OpenClaw checkout on macOS (Darwin arm64, Node v22). Constructed the actual patched WhatsAppConnectionController from this branch via node --import tsx and read back the app-silence window it computes for representative timeout values.
  • Exact steps or command run after this patch: instantiated the real controller for messageTimeoutMs ∈ {5000, 30000, 120000} and compared the live appSilenceTimeoutMs field against both the old Math.max(...) formula and the new * 4 formula:
    node --import tsx proof-watchdog.mts
  • Evidence after fix: live stdout from the patched controller:
$ node --import tsx proof-watchdog.mts
messageTimeoutMs=5000 -> controller.appSilenceTimeoutMs=20000 (old Math.max=20000, new=20000) match=true
messageTimeoutMs=30000 -> controller.appSilenceTimeoutMs=120000 (old Math.max=120000, new=120000) match=true
messageTimeoutMs=120000 -> controller.appSilenceTimeoutMs=480000 (old Math.max=480000, new=480000) match=true
RESULT: live controller computes the identical app-silence window pre/post change — behavior-preserving dead-code removal
  • Observed result after fix: the live controller computes exactly messageTimeoutMs * 4 for every case, identical to the pre-fix Math.max output (20s, 120s, 480s respectively). Confirms the watchdog's behavior is unchanged and the removed branch was dead code.
  • What was not tested: an end-to-end watchdog force-close against a live socket was not run; this proof targets the computed timeout value the watchdog uses, which is the only thing the change touches.

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 4:03 AM ET / 08:03 UTC.

Summary
The PR replaces the WhatsApp controller app-silence assignment with direct messageTimeoutMs * 4 and adds fake-timer coverage for the 4x fresh-connection watchdog window.

PR surface: Source 0, Tests +514, Other +24. Total +538 across 33 files.

Reproducibility: yes. Current main and v2026.6.9 show Math.max(x, x * 4), and the monitor supplies positive timeout defaults, so the equivalence is source-reproducible without a live WhatsApp socket.

Review metrics: 1 noteworthy metric.

  • Merge-ref surface: 2 files changed. The live PR file list is noisy from duplicated current-main history, but GitHub's merge ref shows maintainers are reviewing the WhatsApp controller and its test.

Stored data model
Persistent data-model change detected: database schema: extensions/qa-lab/src/test-file-scenario-runner.test.ts, migration/backfill/repair: qa/scenarios/memory/active-memory-preprompt-recall.yaml, migration/backfill/repair: src/commands/doctor-config-flow.test.ts, migration/backfill/repair: src/commands/doctor/shared/preview-warnings.test.ts, migration/backfill/repair: src/commands/doctor/shared/preview-warnings.ts, persistent cache schema: extensions/qa-lab/src/providers/mock-openai/server.test.ts, and 5 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #93330
Summary: This PR is the narrow cleanup for the redundant app-silence formula; the watchdog tuning issue and PR are related WhatsApp watchdog work but remain distinct product/config changes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • No automated repair lane is needed; the remaining path is maintainer review plus normal exact-head check gating.

Security
Cleared: No concrete security or supply-chain concern was found; the actual merge content is limited to TypeScript arithmetic and a colocated Vitest test.

Review details

Best possible solution:

Land the narrow WhatsApp cleanup after maintainer review and exact-head checks, while keeping public watchdog tuning and active liveness policy in the separate open WhatsApp items.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main and v2026.6.9 show Math.max(x, x * 4), and the monitor supplies positive timeout defaults, so the equivalence is source-reproducible without a live WhatsApp socket.

Is this the best way to solve the issue?

Yes. Direct multiplication plus focused fake-timer coverage is the narrowest maintainable fix for this cleanup; operator-facing watchdog tuning belongs to the linked config issue and PR.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d3f7f7d1fc91.

Label changes

Label justifications:

  • P3: This is a low-risk behavior-preserving cleanup with focused regression coverage and no urgent user-facing change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix live stdout from the patched controller comparing representative timeout values against both the old and new formulas.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix live stdout from the patched controller comparing representative timeout values against both the old and new formulas.
Evidence reviewed

PR surface:

Source 0, Tests +514, Other +24. Total +538 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 11 112 112 0
Tests 15 577 63 +514
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 7 48 24 +24
Total 33 737 199 +538

What I checked:

Likely related people:

  • vincentkoc: Current local blame attributes the redundant assignment to a current-main commit by Vincent Koc, and GitHub history shows prior quiet-socket watchdog work on the same controller/monitor path. (role: recent watchdog behavior contributor; confidence: high; commits: 536c8a840bda, e672b61417af, 21a92ea0f636; files: extensions/whatsapp/src/connection-controller.ts, extensions/whatsapp/src/auto-reply/monitor.ts)
  • mcaxtr: Recent merged history repeatedly touches the WhatsApp controller, monitor, startup waits, auth recovery, and colocated tests around this lifecycle surface. (role: recent WhatsApp controller contributor; confidence: high; commits: 52d9d16e1be9, dd2083c7ec51, aa023e428306; files: extensions/whatsapp/src/connection-controller.ts, extensions/whatsapp/src/connection-controller.test.ts, extensions/whatsapp/src/auto-reply/monitor.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 15, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 20, 2026
@vincentkoc
vincentkoc force-pushed the fix/whatsapp-watchdog-silence-formula branch 4 times, most recently from 28616bf to 8b42ce8 Compare June 22, 2026 07:00
appSilenceTimeoutMs was computed as Math.max(x, x*4) which always
resolves to x*4 — the Math.max call was dead code. Simplify to
messageTimeoutMs * 4 directly and add a regression test that pins
the 4x multiplier as the silence window for fresh connections.

Co-Authored-By: Dr Rushindra Sinha <[email protected]>
@vincentkoc
vincentkoc force-pushed the fix/whatsapp-watchdog-silence-formula branch from 8b42ce8 to f0c6cab Compare June 22, 2026 07:00
@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack app: web-ui App: web-ui scripts Repository scripts commands Command implementations extensions: qa-lab labels Jun 22, 2026
@vincentkoc
vincentkoc requested a review from a team as a code owner June 22, 2026 08:13
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: signal Channel integration: signal cli CLI command changes channel: irc extensions: moonshot extensions: venice extensions: vercel-ai-gateway extensions: tavily extensions: tencent extensions: zai channel: sms Channel integration: sms extensions: llama-cpp and removed size: L labels Jun 22, 2026
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jun 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • extensions/clickclack/npm-shrinkwrap.json
  • extensions/fireworks/npm-shrinkwrap.json
  • extensions/irc/npm-shrinkwrap.json
  • extensions/mattermost/npm-shrinkwrap.json
  • extensions/moonshot/npm-shrinkwrap.json
  • extensions/searxng/npm-shrinkwrap.json
  • extensions/signal/npm-shrinkwrap.json
  • extensions/sms/npm-shrinkwrap.json
  • extensions/tavily/npm-shrinkwrap.json
  • extensions/tencent/npm-shrinkwrap.json
  • extensions/venice/npm-shrinkwrap.json
  • extensions/vercel-ai-gateway/npm-shrinkwrap.json
  • extensions/zai/npm-shrinkwrap.json

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph changes are blocked

OpenClaw does not accept dependency graph changes through PRs unless a repository admin or security explicitly authorizes the current head SHA. Dependency updates are generated internally by maintainers so external PRs cannot change the resolved graph.

Detected dependency graph changes:

  • extensions/clickclack/npm-shrinkwrap.json changed.
  • extensions/fireworks/npm-shrinkwrap.json changed.
  • extensions/irc/npm-shrinkwrap.json changed.
  • extensions/mattermost/npm-shrinkwrap.json changed.
  • extensions/moonshot/npm-shrinkwrap.json changed.
  • extensions/searxng/npm-shrinkwrap.json changed.
  • extensions/signal/npm-shrinkwrap.json changed.
  • extensions/sms/npm-shrinkwrap.json changed.
  • extensions/tavily/npm-shrinkwrap.json changed.
  • extensions/tencent/npm-shrinkwrap.json changed.
  • extensions/venice/npm-shrinkwrap.json changed.
  • extensions/vercel-ai-gateway/npm-shrinkwrap.json changed.
  • extensions/zai/npm-shrinkwrap.json changed.

To remove lockfile changes, restore them from the target branch:

git fetch origin
git checkout 'origin/main' -- 'extensions/clickclack/npm-shrinkwrap.json' 'extensions/fireworks/npm-shrinkwrap.json' 'extensions/irc/npm-shrinkwrap.json' 'extensions/mattermost/npm-shrinkwrap.json' 'extensions/moonshot/npm-shrinkwrap.json' 'extensions/searxng/npm-shrinkwrap.json' 'extensions/signal/npm-shrinkwrap.json' 'extensions/sms/npm-shrinkwrap.json' 'extensions/tavily/npm-shrinkwrap.json' 'extensions/tencent/npm-shrinkwrap.json' 'extensions/venice/npm-shrinkwrap.json' 'extensions/vercel-ai-gateway/npm-shrinkwrap.json' 'extensions/zai/npm-shrinkwrap.json'
git commit -m 'chore: remove dependency lockfile change'
git push

If this PR intentionally needs a dependency graph change, ask a repository admin or member of @openclaw/openclaw-secops to comment:

/allow-dependencies-change

The action will approve the current head SHA (ad4a1879e2fc78662176ce54b7677b15432a3b20) when it reruns. A later push requires a fresh approval.

@vincentkoc

Copy link
Copy Markdown
Member

Superseded by and landed as #95706 (merge commit 89eb493). The replacement preserved the original contributor credit, kept the two-file WhatsApp watchdog fix narrow, passed focused tests (18/18), autoreview, exact-head CI, and native merge verification. Closing this stale-base copy; #95706 is the canonical landed change.

@vincentkoc vincentkoc closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui channel: irc channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: signal Channel integration: signal channel: slack Channel integration: slack channel: sms Channel integration: sms channel: whatsapp-web Channel integration: whatsapp-web cli CLI command changes commands Command implementations dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation extensions: llama-cpp extensions: moonshot extensions: qa-lab extensions: tavily extensions: tencent extensions: venice extensions: vercel-ai-gateway extensions: zai P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants