Skip to content

fix(whatsapp): make shutdown drain coverage deterministic - #159115

Merged
steipete merged 1 commit into
mainfrom
codex/whatsapp-close-drain
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/whatsapp-close-drain

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #151608

What Problem This Solves

Fixes a scheduler-dependent WhatsApp shutdown test failure that blocked the database campaign's CI in run 36263315182. This is a focused maintainer-requested unblocker.

User Impact

No runtime behavior changes. Shutdown coverage now verifies every received message and read receipt completes before the socket closes, whether asynchronous admission places two messages in one debounce window or separate windows.

Why This Change Was Made

The old test expected two messages from one upsert to coalesce within a real 20 ms window. Their durable admissions are asynchronous and sequential, so that is not guaranteed. It asserted the second callback's body before waiting for shutdown or the third message, and a failed assertion left the first handler held.

Use a controlled clock and existing queue/admission hooks to exercise both exact schedules. Keep close pending on the first handler, check the expected ordered message bodies, and verify all three read receipts, empty pending/claimed queues, and read-before-socket-close ordering. Always release the held work in cleanup.

Evidence

  • Reproduced the original assertion deterministically: holding the third durable append across the 20 ms window gives second at callback two, while the same-window case gives second\nthird. The original expectation fails only for the split-window schedule.
  • Original CI's 14-file selection passed before editing: 146 tests, 168.30 seconds including cold transforms.
  • Post-fix original CI selection: 14 files and 147 tests passed in 83.35 seconds. The two controlled shutdown cases took 210 ms and 219 ms.
  • Final standalone owner file: 18 tests passed in 51.39 seconds including transforms (9.238 seconds of reported test time).
  • Fresh independent Codex review: no actionable findings through P2.
  • node scripts/check-changed.mjs -- extensions/whatsapp/src/monitor-inbox.delivery-and-dedupe.test.ts passed, including strict extension-test types, formatting, policy guards, dead-export scans, and lint; git diff --check passed.

Control both same-window and split-window admission schedules instead of
assuming every upsert batch coalesces within 20 ms. Keep exact delivery,
read-receipt, durable-claim, and socket-close assertions and release held
work even when an assertion fails.

The original expectation fails deterministically when the third append
crosses the debounce window. Production behavior is unchanged.

Related: #151608
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 26, 2026 19:13
@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 3:20 PM ET / 19:20 UTC.

ClawSweeper review

What this changes

The branch replaces one WhatsApp shutdown test with two controlled timing cases that check delivery, read receipts, queue drain, and socket-close ordering.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open. Current main still has the scheduler-dependent assertion, and this focused test repair addresses it. The code review found no actionable defect, but the repository’s repeated-run flake qualification is not yet recorded.

Priority: P2
Reviewed head: 33b14f46e4334f2bb86d8ddfdabb7b3cf0da5c2d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent test repair has causal failure evidence and passing reported checks; repeated flake qualification is the remaining confidence gap.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The Repository State identifies a member-authored, test-only patch, so the external-contributor runtime-proof gate does not apply. The PR body reports a causal pre-fix failure and passing post-fix test runs; the repository’s separate repeated-run flake qualification remains unrecorded. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The Repository State identifies a member-authored, test-only patch, so the external-contributor runtime-proof gate does not apply. The PR body reports a causal pre-fix failure and passing post-fix test runs; the repository’s separate repeated-run flake qualification remains unrecorded. No stored-data contract changes.
Evidence reviewed 7 items Introduced test change: The pinned merge-base-to-head patch replaces the fixed coalescing expectation with controlled same-window and separate-window cases; the verified test merge carries only this test-file change.
Current-main gap: The fetched main revision still contains the original single shutdown test and its unconditional combined-body assertion; the PR’s controlled cases remain a unique change.
Production ordering: One upsert admits messages sequentially, and shutdown alternates debounce flushing with waiting for pending handlers and durable ingress before stopping the monitor.
Findings None None.
Security None None.

How this fits together

The WhatsApp plugin admits incoming socket messages to a durable queue, groups eligible messages in a debounce window, and delivers them to a handler. Listener shutdown drains that work before closing the socket.

flowchart LR
 A[WhatsApp socket] --> B[Durable admission]
 B --> C[Debounce window]
 C --> D[Message handler]
 D --> E[Read receipts]
 E --> F[Socket close]
Loading

Before merge

  • Resolve merge risk (P1) - The PR reports one clean post-fix original-shard run and one standalone run; it has not recorded the testing guide’s repeated-run qualification for a flake repair.
  • Complete next step (P2) - Record the testing guide’s 20 clean standalone runs, three clean original-shard runs, and sibling coverage at this head before merge.
Agent review details

Security

None.

PR surface

Tests +74. Total +74 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 112 38 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 112 38 +74

Review metrics

Metric Value Why it matters
Code growth production +0, tests +74 net lines The additional code is confined to the shutdown test and its controlled timing cases.
Reported owner-suite cost 9.238 s test time; 51.39 s wall including transforms The stated test time is below the guide’s 30-second explanation threshold, though the flake qualification still needs repeated runs.

Merge-risk options

Maintainer options:

  1. Complete flake qualification (recommended)
    Record the prescribed clean standalone and original-shard repetitions at this head, together with sibling coverage, before relying on the changed CI test.

Technical review

Best possible solution:

Keep an owner-boundary shutdown test that accepts both legal admission schedules while requiring every admitted message and receipt to finish before socket close.

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

Yes. Delaying the third durable append beyond the debounce window makes the current-main test’s fixed combined-body expectation invalid; the PR reports that pre-fix failure, and the sequential admission path supports it. I did not execute the test.

Is this the best way to solve the issue?

Yes. Controlled time and admission gates exercise both schedules through the existing monitor and shutdown boundary without changing production behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a focused CI-blocking test defect with no reported production behavior change.
  • add merge-risk: 🚨 automation: The patch changes a timing-sensitive CI test whose residual flakiness could continue to block unrelated PRs.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The Repository State identifies a member-authored, test-only patch, so the external-contributor runtime-proof gate does not apply. The PR body reports a causal pre-fix failure and passing post-fix test runs; the repository’s separate repeated-run flake qualification remains unrecorded. No stored-data contract changes.

Label justifications:

  • P2: This is a focused CI-blocking test defect with no reported production behavior change.
  • merge-risk: 🚨 automation: The patch changes a timing-sensitive CI test whose residual flakiness could continue to block unrelated PRs.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The Repository State identifies a member-authored, test-only patch, so the external-contributor runtime-proof gate does not apply. The PR body reports a causal pre-fix failure and passing post-fix test runs; the repository’s separate repeated-run flake qualification remains unrecorded. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • mcaxtr: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record 20 clean standalone runs and three clean runs of the original shard at this head, as required by the testing guide.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

@steipete

Copy link
Copy Markdown
Contributor Author

Applying the maintainer’s explicit proof scope for this deterministic ordering defect: causal RED/GREEN, final owner and relevant sibling coverage, the original failing order, and required CI replace the blanket 20 standalone / three shard repetitions. Stress repetition remains required if a timing hypothesis is unresolved; none remains for this reproduced batching assumption.

The original combined-body assertion fails deterministically when the third durable append is held across the 20 ms debounce boundary. The repaired test explicitly controls both legal schedules and keeps exact body ordering, all three receipt IDs, empty pending/claimed queues, and receipt-before-socket-close assertions. It does not depend on wall-clock scheduling to select a batching outcome.

The original 14-file selection passed with 147 tests, the final standalone owner file passed with 18 tests, strict changed checks passed, two independent review passes found no actionable defects, and exact-head CI is green. There is no unresolved timing hypothesis from this failure that additional identical repetitions need to distinguish. No production behavior changed.

@steipete
steipete merged commit 32e46c9 into main Sep 26, 2026
161 of 162 checks passed
@steipete
steipete deleted the codex/whatsapp-close-drain branch September 26, 2026 19:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 26, 2026
Merge main with the canonical WhatsApp shutdown fixture fix in #159115. The same-upsert messages can cross separate debounce windows during asynchronous admission; delivery and close ordering remain correct.

Register queued recap work synchronously with the publication owner so a drain cannot finish before deferred row preparation starts.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…59115)

Control both same-window and split-window admission schedules instead of
assuming every upsert batch coalesces within 20 ms. Keep exact delivery,
read-receipt, durable-claim, and socket-close assertions and release held
work even when an assertion fails.

The original expectation fails deterministically when the third append
crosses the debounce window. Production behavior is unchanged.

Related: openclaw#151608
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 merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant