Skip to content

fix(discord,mattermost): release the ingress lane on defer so the debouncer can merge same-lane bursts - #145133

Closed
abacha wants to merge 7 commits into
openclaw:mainfrom
abacha:fix/119382-ingress-lane-release
Closed

abacha wants to merge 7 commits into
openclaw:mainfrom
abacha:fix/119382-ingress-lane-release

Conversation

@abacha

@abacha abacha commented Sep 11, 2026 •

Copy link
Copy Markdown

What Problem This Solves

runIngressDrain holds the ingress lane while a dispatch returns "deferred" unless the monitor
opts out with deferredLaneOccupancy: "release" (src/channels/message/ingress-drain.ts:127,
default "hold").

WhatsApp, Discord and Mattermost all dispatch into a debouncer that defers while the merge window
is open, and none of them passes the option. Their lanes are per-conversation
(remoteJid, channel:<id>), so holding the lane across the debounce wait blocks every same-lane
follow-up from being admitted: the start loop hands it back to the queue instead of dispatching it,
and the lane only frees at onAdopted — after the flush has already created a turn.

The consequence is that no two messages in one conversation can ever land in the same debounce
flush. Each message pays the full debounce window and becomes its own turn, which is exactly what
the debouncer exists to prevent.

Telegram had the identical defect and was fixed in #101335
(extensions/telegram/src/telegram-ingress-drain.ts:459); Slack carries the same
deferredLaneOccupancy: "release" today (extensions/slack/src/monitor/ingress.ts:412). This PR
applies that same one-line opt-out to the three remaining durable ingress monitors.

Fixes #119382

Evidence

Current main (4229c99), the only non-test call sites of the option:

extensions/slack/src/monitor/ingress.ts:412:      deferredLaneOccupancy: "release",
extensions/telegram/src/telegram-ingress-drain.ts:459:      deferredLaneOccupancy: "release",

WhatsApp, Discord and Mattermost do not appear — they run on the "hold" default.

Each channel gets a regression test that fails without the flag and passes with it: a second
same-lane message arriving while the first is still deferred must be dispatched immediately instead
of waiting for adoption. With the flag removed, the Discord/Mattermost cases fail with
expected [ '2001' ] to deeply equal [ '2001', '2002' ].

Local run on this branch (Node 24.21.0, pnpm 12.3.4):

extensions/whatsapp/src/inbound/message-debounce.test.ts        12 passed
extensions/whatsapp/src/inbound/durable-receive.test.ts          (same shard)
extensions/discord/src/monitor/ingress.test.ts                   passed
extensions/mattermost/src/mattermost/monitor-ingress.test.ts     passed
extensions/whatsapp/src/monitor-inbox.delivery-and-dedupe.test.ts 18 passed

Scope

Releasing the lane does not disarm the claim→adoption stall watchdog, which stays armed through the
deferred phase by design (armStallWatchdog + onDeferred in
src/channels/message/ingress-drain.ts). An agent turn longer than adoptionStallTimeoutMs still
dead-letters its own deferred claim. That is #116547 and this change does not address it.

After-fix real behaviour proof (production WhatsApp)

The one-line change has been running in production on a self-hosted gateway since
2026-09-07 12:12 UTC, applied to the installed @openclaw/whatsapp 2026.8.1 bundle (same
value, same object literal as this PR passes in durable-receive.ts). Everything below is real
inbound WhatsApp traffic from that gateway — no synthetic queue, no mocked inbox. Message bodies,
phone numbers, group JIDs and sender names are redacted; only timings, event ids (truncated) and
the shape of the resulting turn are shown.

Two data sources, cross-checked:

  • channel_ingress_events (the durable ingress queue): one row per inbound message, with
    received_at and the completed_at written when the claim settles at adoption.
  • the agent transcript: the user turns that were actually created.

Before the fix — two messages, two turns

Same conversation lane, unpatched gateway, 2026-09-06:

ingress (lane G, group)
  event f4906028…  received 19:40:09.581   completed 19:40:19.663
  event 2a3faf68…  received 19:40:12.234   completed 19:40:29.739   (Δ received = 2.65 s)

transcript
  user turn 19:40:09  "<msg-1>"     (22 chars)
  user turn 19:40:12  "<msg-2>"     (28 chars)

Two turns, settled ~10 s apart: the second message could not join the first one's debounce window,
which is the defect this PR fixes.

After the fix — same shape of burst, one combined turn

Same gateway, same channel, patched, 2026-09-09:

ingress (lane H, group)
  event c173c615…  received 21:22:35.660   completed 21:22:48.618
  event 307b3972…  received 21:22:38.473   completed 21:22:48.619   (Δ received = 2.81 s)

transcript
  user turn 21:22:38  "<msg-1>\n<msg-2>"    (39 chars, single turn)

Both claims settle at the same adoption (1 ms apart) and the transcript holds one turn whose
body is the two messages joined by \n — exactly the combinedBody the WhatsApp debouncer builds
in extensions/whatsapp/src/inbound/message-debounce.ts:105-135.

A second occurrence the same day, wider gap, same outcome:

ingress (lane H, group)
  event b1a4703c…  received 15:35:51.575   completed 15:36:06.850
  event fcac12c6…  received 15:35:56.375   completed 15:36:06.851   (Δ received = 4.80 s)

transcript
  user turn 15:35:56  "<msg-1>\n<msg-2>"    (47 chars, single turn)

Population, stated honestly

Scanning every same-lane consecutive inbound pair in that gateway's ingress table whose second
message reached an agent turn: before the patch, no pair produced a single combined turn (the
closest, Δ 2.65 s above, produced two); after the patch, pairs at Δ 2.81 s and Δ 4.80 s produced
one combined turn each, with both claims settled at the same adoption. Bursts whose second message
was ignored by the channel (self-echo, filtered) complete in a few ms and are excluded — they never
become turns either way.

The gateway carries no other local modification to the ingress or debounce path.

Update 2026-09-19 — rebased on a8046858b9e, scope narrowed to Discord + Mattermost

WhatsApp is fixed on main: #112001 (fix(whatsapp): admit debounce candidates independently)
added deferredLaneOccupancy: "release" at extensions/whatsapp/src/inbound/durable-receive.ts:140
and rewrote the two durable-receive/monitor-inbox tests this PR touched. The three WhatsApp commits
were therefore dropped in the rebase instead of being carried as a duplicate option key.

What remains is the same one-line change on the two channels still running the "hold" default:

  • extensions/discord/src/monitor/ingress.ts
  • extensions/mattermost/src/mattermost/monitor-ingress.ts

Scoped suites on the rebased branch, Node 24.21.0:

extensions/discord/src/monitor/ingress.test.ts
extensions/discord/src/monitor/message-handler.ingress-recovery.test.ts
extensions/mattermost/src/mattermost/monitor-ingress.test.ts
3 files passed, 26 tests passed

The production WhatsApp proof above stands as the behavioural evidence for the mechanism; the
channel it was measured on is now fixed upstream, and Discord and Mattermost share the code path.

Update 2026-09-21 — cross-sender ordering fix (P1)

The 2026-09-20 review's P1 finding is correct: Discord partitions its debounce below the
per-channel ingress lane (author + reply target), Mattermost partitions by thread + sender, and
releasing the lane on defer lets those independent keys admit and flush on their own timers with
no ordering guarantee across keys.

Ported the same cross-sender flush guard WhatsApp already carries
(extensions/whatsapp/src/inbound/message-debounce.ts:167-176, from #112001) into both remaining
batching owners:

  • extensions/discord/src/monitor/message-dispatcher.ts
  • extensions/mattermost/src/mattermost/monitor.ts

Each tracks, per channel lane, which debounce key currently holds the pending batch, and
force-flushes it (debouncer.flushKey) before admitting a message under a different key in the
same lane — so handoff to the next stage stays in strict per-channel arrival order even with the
lane released.

Added regression coverage through the real batching owners, not a helper test: an interleaved
A1/B1/A2 sequence from two senders in one channel must dispatch in that exact order.

extensions/discord/src/monitor/message-handler.debounce-reply-target.test.ts
extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts

Full scoped local run, Node 24.21.0:

extensions/discord/src/monitor/                                   105 files, 1358 tests passed
extensions/mattermost/src/mattermost/                               42 files,  774 tests passed
pnpm tsgo:extensions                                                                      clean
oxlint (4 changed files)                                              0 warnings, 0 errors

Update 2026-09-26 — ClawSweeper re-review, hold the lane until admission (not onFlush start)

The 2026-09-23 review found the 2026-09-21 fix released the lane too early:

Finding 1 (P1, ordering). releaseLane ran at the very start of onFlush, before the
flush's own preparation (preflight/handlePost) reached admission. Starting onFlush only means
the debounce timer elapsed — a timer-fired batch A clears its lane marker and then sits in
preparation. A different-key arrival B in the same channel lane found no marker to wait on,
skipped the guard, and could reach reply processing while A was still preparing.

The obvious fix — just delay the releaseLane call — is not enough: once a batch has actually
started flushing, its buffer has already left the debouncer's own pending-buffer map, so a later
call to debouncer.flushKey(pendingLane.batchKey) is a no-op and does not wait for anything.

Fixed by storing the flush's own admission promise on the lane record once onFlush starts it
(markLaneFlushing), and having a different-key arrival await that admission promise directly
when it is set, falling back to debouncer.flushKey (forcing an immediate flush) only while the
earlier batch is still purely buffered and hasn't started yet:

if (pendingLane && pendingLane.batchKey !== debounceKey) {
  await (pendingLane.admission ?? debouncer.flushKey(pendingLane.batchKey));
}

The lane is released only once that admission settles (flush.admission.finally(...)), scoped to
entries that actually hold a lane record — an untracked flush (debounceMs === 0) still releases
its no-op lane synchronously as before, so it never pays an extra microtask tick. That mattered in
practice: an earlier version of this fix unconditionally deferred the release via .finally() on
every flush, and that alone shifted timing enough to break an unrelated fake-timer retry/backoff
test in monitor.inbound-system-event.test.ts (a message got dispatched twice). Scoping the
deferred path to lane-tracked entries only removed the perturbation while keeping the fix.

Finding 2 (P2, cancellation). In extensions/discord/src/monitor/message-dispatcher.ts, after
await debouncer.flushKey(pendingLane.batchKey) the code tracked the lane and enqueued the entry
without rechecking entry.abortSignal. If Discord deactivated while that await was pending, the
new key had no buffer yet for cancelKey to remove, so the entry could still enqueue after
shutdown. Rechecked the signal right after the await, before trackLane/enqueue, and bailed out
the same way the top-of-function check already does (cancel the turn-adoption lifecycle, or return
failed-retryable).

Applied both to extensions/discord/src/monitor/message-dispatcher.ts and
extensions/mattermost/src/mattermost/monitor.ts (Finding 1 applies to both batching owners;
Finding 2 is Discord-specific, matching the review's own line reference). WhatsApp files
untouched.

New regression coverage:

  • extensions/discord/src/monitor/message-handler.debounce-reply-target.test.ts — a
    different-author arrival now waits on an already-flushing batch's admission (delayed
    preparation, not just onFlush start), and a lane-waiting message is dropped rather than
    enqueued when the handler deactivates during that wait.
  • extensions/mattermost/src/mattermost/monitor.inbound-ordering.test-support.ts — a
    different-sender arrival waits on an already-flushing batch's admission the same way.

Full scoped local run, Node 24.21.0 (ASDF_NODEJS_VERSION=24.21.0, required for pnpm install
under this repo's engines field):

pnpm tsgo:extensions                                                clean
pnpm lint:extensions (oxlint)                                        0 warnings, 0 errors
extensions/discord/src/monitor/          109 files, 1382 tests       passed
extensions/mattermost/src/mattermost/monitor  14 files, 334 tests    passed

Update 2026-09-30

  • Mattermost: abortSignal recheck after the cross-sender lane wait, plus a deactivate-during-cross-key-wait regression test (3b235d70041, mattermost test file 52/52). No Mattermost instance available, so its proof is test-only.
  • Discord real-path proof, branch build at 3b235d70041 on an isolated non-production gateway with a test bot, one allowlisted channel, debounce 4000ms (ids, tokens, endpoints redacted):
    • Interleave A1/B1/A2 by two senders inside the window: dispatches in order A (A1), B (A1,B1), A (A1,B1,A2). Admission order kept, B1 admitted while A's lane was open.
    • Same-lane burst M1/M2/M3 from one sender, ~1s apart: merged into a single dispatch.
  • CI: pr-fail-fast fails with MODULE_NOT_FOUND for scripts/ci-pr-fail-fast.mjs in its base-ref sparse checkout (infra, not this diff); all other selected jobs pass.

Clarification 2026-09-30 (rebased head fc008d5)

In the interleave proof above, the parenthesised lists are the prompt history window, not the batch. Each dispatch's current request carries only its own sender's lines: B's dispatch had current request B1 alone, with A1 present only inside the quoted <conversation_context> history block. No cross-sender merge happened. The proof ran on 3b235d70041; the branch was then rebased on current main with no change to the ingress code (scoped discord+mattermost monitor tests: 119 files passed).

@clawsweeper

clawsweeper Bot commented Sep 11, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T18:24:14.403942Z b8a6a03 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost channel: whatsapp-web Channel integration: whatsapp-web size: M labels Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 30, 2026, 10:38 AM ET / 14:38 UTC (Revision 14).

ClawSweeper review

What this changes

The branch releases deferred Discord and Mattermost channel ingress lanes, coordinates batching across senders to preserve arrival order, and adds ingress, ordering, and cancellation tests.

Merge readiness

⛔ Blocked before merge - 4 items remain

Current main still holds deferred Discord and Mattermost ingress lanes, so this PR has distinct remaining value. The cancellation recheck is present, but its Mattermost regression does not establish that cancellation occurred during the lane wait, and real Mattermost behavior remains unproven.

Priority: P1
Reviewed head: fc008d55b81118d217caf94985f1cff882e49c60

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch addresses a real remaining channel defect and has useful Discord evidence, but Mattermost proof and its cancellation regression leave merge confidence limited.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body reports an isolated Gateway Discord bot run on a prior branch head that observed a merged burst and ordered interleaved messages, plus earlier production WhatsApp traces for a channel no longer in the diff. For the changed Mattermost receive and batching owner, it explicitly reports no real instance and supplies only mocked-socket tests. Add redacted terminal output or logs from the Mattermost path; remove private identifiers, tokens, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. No stored-data contract changes are introduced. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body reports an isolated Gateway Discord bot run on a prior branch head that observed a merged burst and ordered interleaved messages, plus earlier production WhatsApp traces for a channel no longer in the diff. For the changed Mattermost receive and batching owner, it explicitly reports no real instance and supplies only mocked-socket tests. Add redacted terminal output or logs from the Mattermost path; remove private identifiers, tokens, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. No stored-data contract changes are introduced. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Current main retains the reported behavior: At the pinned main revision, neither channel's ingress drain supplies deferredLaneOccupancy, so the shared drain's hold default applies. The latest release tag also lacks both opt-ins.
Shared ingress decision: The shared drain defaults deferred lane occupancy to hold; release must be selected by the channel caller.
Introduced channel behavior: The introduced patch selects release for both ingress monitors and adds per-channel batch admission guards in both dispatch paths.
Findings 1 actionable finding [P2] Synchronize cancellation on the Mattermost lane wait
Security None None.

How this fits together

Discord and Mattermost receive channel posts through durable ingress queues, then pass them to per-sender debouncers and agent reply processing. The change lets another post enter while an earlier post waits to be batched, while coordinating the order in which different senders reach reply processing.

flowchart LR
  A[Discord or Mattermost post] --> B[Durable ingress queue]
  B --> C[Channel lane]
  C --> D[Sender batch]
  D --> E{Same channel, different batch?}
  E -->|Yes| F[Wait for earlier admission]
  E -->|No| G[Reply processing]
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body reports an isolated Gateway Discord bot run on a prior branch head that observed a merged burst and ordered interleaved messages, plus earlier production WhatsApp traces for a channel no longer in the diff. For the changed Mattermost receive and batching owner, it explicitly reports no real instance and supplies only mocked-socket tests. Add redacted terminal output or logs from the Mattermost path; remove private identifiers, tokens, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. No stored-data contract changes are introduced. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Synchronize cancellation on the Mattermost lane wait (P2) - The test starts B1 without observing its progress, then aborts after a 30 ms sleep. It can pass when B1 has not reached the new cross-key wait at all, so it does not protect the cancellation recheck. Signal when B1 enters that wait, abort, release A1, and assert B1 never reaches dispatch or leaves an unsettled claim.
  • Resolve merge risk (P1) - The changed Mattermost batching and cancellation path has only mocked-socket test evidence; a real Mattermost path has not shown burst merging, cross-sender order, and shutdown behavior after this patch.
  • Complete next step (P2) - Make the Mattermost cancellation test prove that B1 reached the cross-key wait before abort, and add redacted real-path Mattermost proof before merge.

Findings

  • [P2] Synchronize cancellation on the Mattermost lane wait — extensions/mattermost/src/mattermost/monitor.inbound-ordering.test-support.ts:275-284
Agent review details

Security

None.

PR surface

Source +256, Tests +471. Total +727 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 4 299 43 +256
Tests 6 539 68 +471
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 838 111 +727

Review metrics

Metric Value Why it matters
Production and test growth production +256 lines; tests and test support +471 lines The production growth implements cross-sender ordering in two channel owners; the test growth needs to prove the cancellation boundary it claims to cover.

Merge-risk options

Maintainer options:

  1. Prove the Mattermost handoff (recommended)
    Synchronize the cancellation regression on the second post entering and leaving the lane wait, then provide redacted real-path Mattermost observations for merging, ordering, and shutdown.
  2. Pause the combined change
    Hold this PR until Mattermost can be exercised, while retaining the branch as the source of the channel-specific ordering work.

Technical review

Best possible solution:

Keep lane release and per-channel admission ordering together, make the cancellation regression wait for an observable cross-key handoff, and capture redacted Mattermost behavior through its real receive path before merge.

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

Yes, from source: current main leaves both monitors on the shared drain's hold default, which prevents a second same-channel deferred event from reaching the debouncer before adoption. I did not execute contributor code in this read-only review.

Is this the best way to solve the issue?

Unclear for merge readiness: channel-local lane release with cross-sender admission ordering fits the existing ingress contract, but the Mattermost cancellation test and real-path proof still need to establish the claimed boundary behavior.

Full review comments:

  • [P2] Synchronize cancellation on the Mattermost lane wait — extensions/mattermost/src/mattermost/monitor.inbound-ordering.test-support.ts:275-284
    The test starts B1 without observing its progress, then aborts after a 30 ms sleep. It can pass when B1 has not reached the new cross-key wait at all, so it does not protect the cancellation recheck. Signal when B1 enters that wait, abort, release A1, and assert B1 never reaches dispatch or leaves an unsettled claim.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.83

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 837a2e3303a2.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Deferred lane ownership can delay later Discord corrections from reaching active reply processing, affecting a live channel workflow.
  • merge-risk: 🚨 message-delivery: Releasing a conversation lane while separate sender batches remain active can change admission order or allow work to continue across shutdown.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports an isolated Gateway Discord bot run on a prior branch head that observed a merged burst and ordered interleaved messages, plus earlier production WhatsApp traces for a channel no longer in the diff. For the changed Mattermost receive and batching owner, it explicitly reports no real instance and supplies only mocked-socket tests. Add redacted terminal output or logs from the Mattermost path; remove private identifiers, tokens, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. No stored-data contract changes are introduced. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Pavan Kumar Gondhi: 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.

  • Synchronize the Mattermost cancellation regression on the second post reaching and leaving the cross-key wait.
  • Add redacted real-path Mattermost observations for burst merging, cross-sender order, and cancellation.

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.

History

Review history (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-21T13:50:03.605Z sha 5fa84aeb532db9749fda3455900892a5b11e40b2 :: needs real behavior proof before merge. :: [P1] [P1] Preserve channel ordering until an active flush is admitted | [P2] [P2] Recheck cancellation after awaiting the previous batch
  • reviewed 2026-09-21T16:49:32.983Z sha 1510ca627cf6586fab9383bc34e0713b9370b484 :: needs real behavior proof before merge. :: [P1] [P1] Preserve channel ordering until an active flush is admitted | [P2] [P2] Recheck cancellation after awaiting the previous batch
  • reviewed 2026-09-22T21:32:32.839Z sha e90b4fe6f7a903ff995e1d4f03bcc4c2a4edde8e :: needs real behavior proof before merge. :: [P1] [P1] Preserve channel ordering until an active flush is admitted | [P2] [P2] Recheck cancellation after awaiting the previous batch
  • reviewed 2026-09-23T21:19:20.596Z sha e90b4fe6f7a903ff995e1d4f03bcc4c2a4edde8e :: needs real behavior proof before merge. :: [P1] Keep the ordering guard until the earlier flush is admitted | [P2] Recheck abort after waiting for a cross-key flush
  • reviewed 2026-09-26T21:54:00.907Z sha b76400067ba58cc12a1b03463e36d2bb98b9843a :: needs real behavior proof before merge. :: [P2] Recheck Mattermost cancellation after the lane wait
  • reviewed 2026-09-26T22:17:49.300Z sha b76400067ba58cc12a1b03463e36d2bb98b9843a :: needs real behavior proof before merge. :: [P2] Recheck Mattermost cancellation after the lane wait
  • reviewed 2026-09-29T22:14:56.516Z sha 3b235d7004174c19ffe658169eb180128a5e3d5d :: needs real behavior proof before merge. :: [P2] Check the Mattermost claim abort after the lane wait
  • reviewed 2026-09-30T14:27:47.807Z sha 3b235d7004174c19ffe658169eb180128a5e3d5d :: needs real behavior proof before merge. :: [P2] Make the cancellation regression reach the lane wait

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 11, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 12, 2026
@abacha
abacha force-pushed the fix/119382-ingress-lane-release branch from 575e084 to a34cd7e Compare September 19, 2026 21:01
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed channel: whatsapp-web Channel integration: whatsapp-web size: M labels Sep 19, 2026
@abacha abacha changed the title fix(whatsapp,discord,mattermost): release the ingress lane on defer so the debouncer can merge same-lane bursts fix(discord,mattermost): release the ingress lane on defer so the debouncer can merge same-lane bursts Sep 19, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Sep 19, 2026
@abacha

abacha commented Sep 20, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

The status: 📣 needs proof ask from the 2026-09-11 review is answered in the body, and the review has not re-armed since (no new review comment after 2026-09-11 18:26 UTC, through two body edits and a rebase):

  • ## After-fix real behaviour proof (production WhatsApp) — before/after on a patched production gateway, cross-referencing channel_ingress_events (received_at / completed_at) against the actual agent turns. Pre-patch, two messages 2.65 s apart produced two separate turns; post-patch, pairs at 2.81 s and 4.80 s each produced a single turn with a combinedBody. Redacted: no phone numbers, no JIDs, no message text.
  • ## Update 2026-09-19 — rebased on a8046858b9e. fix(whatsapp): batch rapid messages without reordering replies #112001 fixed the WhatsApp third upstream, so the three WhatsApp commits were dropped and the PR is now narrowed to the two remaining one-line call sites, Discord and Mattermost, plus their tests.

Current state: MERGEABLE / CLEAN, 52 checks SUCCESS, 0 FAILURE.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 23, 2026
@abacha

abacha commented Sep 26, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

Both findings from the 2026-09-23 21:19 UTC review (patch is incorrect) are fixed and pushed — head is now b76400067ba58cc12a1b03463e36d2bb98b9843a, and the PR body carries them under ## Update 2026-09-26.

Finding 1 (P1, ordering — lane released at the onFlush prologue). Accepted on the merits: starting onFlush is not admission, and Discord/Mattermost partition the batching below the channel lane, so two keys in one lane share no keyChains serialization the way the same-key WhatsApp guard does. The lane record now carries the flush's admission promise (markLaneFlushing), set once onFlush actually starts; an arrival under a different key in the same lane awaits that admission directly instead of a flushKey that is already a no-op once the batch has left the debouncer's buffer map. The deferred-release path is scoped to lane-tracked entries (debounceMs > 0).

Finding 2 (P2, cancellation). entry.abortSignal is rechecked after the flushKey/admission await and before trackLane/enqueue, so a deactivation during the cross-key wait no longer enqueues post-deactivation work.

Regression coverage added: delayed-preparation ordering (earlier batch fires on its timer and is slow inside the flush; the later different-key message must still dispatch after it) for Discord and Mattermost, and deactivate-during-cross-key-wait for Discord.

Validated: tsgo:extensions clean, lint:extensions 0 warnings, Discord monitor 109 files / 1382 tests pass, Mattermost monitor 14 files / 334 tests pass. CI on this head: 47 SUCCESS, 0 FAILURE.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 26, 2026
@abacha

abacha commented Sep 30, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 30, 2026
abacha and others added 7 commits September 30, 2026 11:24
…rn merge can happen

Both Discord's and Mattermost's durable ingress monitors dispatch into
the reply/turn debouncer and can return "deferred", but neither passed
deferredLaneOccupancy, so the drain default ("hold") applied. The lane is
per-conversation (channel:<id>), so holding it across the debounce wait
blocks every same-lane follow-up from being admitted: the start loop
releases it back to the queue instead of dispatching it, and the lane
frees only at onAdopted — after the flush has already created a turn. No
two same-lane messages can land in one flush, and each pays the debounce
window again.

Pass deferredLaneOccupancy: "release" on both drains, mirroring the
Telegram spooled drain's fix for the identical defect (openclaw#101335) and the
WhatsApp durable-receive fix already on this branch.

Adds a regression test per channel proving a second same-lane message
arriving while the first is still deferred is dispatched immediately
instead of waiting for adoption. Both fail with the flag removed
(expected [ '2001' ] to deeply equal [ '2001', '2002' ]) and pass with
it.

Scope note: releasing the lane does not disarm the claim->adoption stall
watchdog, which stays armed through the deferred phase by design
(armStallWatchdog + onDeferred in src/channels/message/ingress-drain.ts).
An agent turn longer than adoptionStallTimeoutMs therefore still
dead-letters its own deferred claim. That is a separate defect (openclaw#116547)
and this change does not address it.

Refs openclaw#119382
The mock annotated event as { id: string }, but DiscordMessageDispatchData.id
is optional. tsgo caught the mismatch (vitest runtime doesn't type-check).
Use the real DiscordMessageEvent type and assert id is present at the two
call sites, matching prior assertion semantics.

Checked the mattermost sibling test (monitor-ingress.test.ts) for the same
pattern -- its dispatch mocks have no explicit param annotations, so
nothing to fix there.
…im expectation

- type the Discord ingress dispatch mock as DiscordMessageEvent (id is optional)
- import MattermostIngressLifecycle instead of referencing an undeclared name
- the recovery case asserted one claim while the lane was held; releasing the
  lane on defer lets the same-lane follower be claimed and buffered by the same
  debounce window, so the buffered handler now holds two claims
…released ingress lanes

Discord and Mattermost partition their inbound debounce below the
per-channel ingress lane (author + reply target for Discord, thread +
sender for Mattermost). Releasing the lane on defer
(deferredLaneOccupancy: "release") lets those independent keys admit
and flush on their own timers with no cross-key ordering guarantee, so
a later sender's message could flush ahead of an earlier sender's
still-buffering one in the same channel.

Port the WhatsApp cross-sender flush guard
(extensions/whatsapp/src/inbound/message-debounce.ts) to both
batching owners: track which debounce key currently holds each
channel lane's pending batch, and force-flush it before admitting a
message under a different key in the same lane. This keeps handoff to
the next stage in strict per-channel arrival order.

Add regression coverage through the real batching owners for both
channels: an interleaved A1/B1/A2 sequence from two senders must
dispatch in that exact order.

Co-authored-by: Ken (Nexus) <[email protected]>
…g module

Moves the collector-admission debounce test and the interleaved
A1/B1/A2 conversation-ordering test out of
monitor.inbound-system-event.test.ts into a new
monitor.inbound-ordering.test-support.ts, following the existing
monitor.block-progress.test-support.ts pattern. Coverage is
preserved (50/50 tests still pass); no eslint-disable or trimmed
assertions. Brings the host file back under the line-cap ratchet's
inherited allowance (2519 counted lines).

Co-authored-by: Ken (Nexus) <[email protected]>
…, not onFlush start

ClawSweeper review of 2026-09-23 found two correctness gaps in the cross-sender
flush guard from the previous commit:

1. (P1, ordering) releaseLane ran at the start of onFlush, before the flush's
   own preparation (preflight/handlePost) had reached admission. A
   different-key arrival in the same channel lane found no pending marker,
   skipped the wait, and could reach reply processing while the earlier batch
   was still preparing -- inverting conversation order. debouncer.flushKey is
   a no-op once a batch has left the debouncer's own pending-buffer map, so
   simply delaying the release is not enough: the lane record now carries the
   flush's admission promise (set once onFlush actually starts it), and a
   different-key arrival awaits that admission directly when present,
   falling back to flushKey only while the batch is still purely buffered.

2. (P2, cancellation) after awaiting the cross-key guard, Discord's
   dispatchMessage did not recheck the entry's abort signal before tracking
   the lane and enqueueing. Deactivation landing during that await left the
   new key with no buffer for cancelKey to remove, so the entry would still
   enqueue after shutdown. Rechecked the signal and bailed out the same way
   the top-of-function check does.

Both fixes are scoped to entries actually holding a lane record
(debounceMs > 0); an untracked flush (debounceMs === 0) releases its
(no-op) lane synchronously as before, so it never pays the extra
admission-promise microtask tick that upstream retry/backoff logic in the
durable ingress queue tests is timing-sensitive to.

Extended the interleaved-sender regression coverage:
- Discord: a different-author arrival now waits on an already-flushing
  batch's admission (not just its onFlush start), and a lane-waiting message
  is dropped, not enqueued, when the handler deactivates during that wait.
- Mattermost: a different-sender arrival waits on an already-flushing
  batch's admission the same way.

Validation (Node 24.21.0, ASDF_NODEJS_VERSION=24.21.0):
  pnpm tsgo:extensions                                            clean
  pnpm lint:extensions (oxlint)                                   0 warnings, 0 errors
  extensions/discord/src/monitor/    109 files, 1382 tests        passed
  extensions/mattermost/src/mattermost/monitor  14 files, 334 tests  passed

Co-authored-by: Ken (Nexus) <[email protected]>
… wait

A different-sender post awaiting the earlier batch's admission resumed after monitor shutdown and still tracked the lane and enqueued. Recheck abortSignal after the wait and cancel the ingress lifecycle, matching the Discord recheck. Adds a deactivate-during-cross-key-wait regression test.

Co-authored-by: Ken (Nexus) <[email protected]>
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Sep 30, 2026
@abacha
abacha force-pushed the fix/119382-ingress-lane-release branch from 3b235d7 to fc008d5 Compare September 30, 2026 14:30
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 30, 2026
@abacha

abacha commented Sep 30, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@abacha

abacha commented Oct 1, 2026

Copy link
Copy Markdown
Author

Closing without merge. The defect stays on record as #162714, which carries the mechanism, the WhatsApp before/after measurement and the Discord branch proof.

Why close rather than keep iterating: the remaining blocker is real-instance proof for Mattermost, and I have no Mattermost deployment to produce it from. The WhatsApp half this PR started from shipped via #112001, and we no longer carry a local patch on this path.

The branch abacha:fix/119382-ingress-lane-release stays on the fork as a reference implementation: "release" on both monitors plus a cross-sender admission guard, with interleaved-order and cancellation tests. If a maintainer wants it reopened or narrowed to Discord only, say so and I'll rebase it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp durable ingress lane hold starves inbound debounce — same-chat bursts never merge and each message pays the full window

1 participant