Skip to content

fix(queue): dedupe queued message IDs across drain restarts#33168

Closed
rylena wants to merge 1 commit intoopenclaw:mainfrom
rylena:fix/33150-signal-queued-message-redelivery-dedupe
Closed

fix(queue): dedupe queued message IDs across drain restarts#33168
rylena wants to merge 1 commit intoopenclaw:mainfrom
rylena:fix/33150-signal-queued-message-redelivery-dedupe

Conversation

@rylena
Copy link
Copy Markdown
Contributor

@rylena rylena commented Mar 3, 2026

Summary

Fixes duplicate queued-message delivery when a channel re-emits the same provider message_id while the agent is busy.

Root cause

Followup queue dedupe only compared against items currently in the in-memory queue. Once a drain completed and the queue was deleted/recreated, a redelivery of the same message_id was accepted as a brand-new queued item.

Changes

  • Added a short-lived dedupe cache for queued message_id values keyed by queue + routing target.
  • Check this cache before enqueueing followup runs.
  • Record queued IDs after successful enqueue.
  • Exported a test reset helper for deterministic queue dedupe tests.
  • Added regression test covering duplicate redelivery after a queue drain restart.

Tests

  • pnpm exec vitest run src/auto-reply/reply/reply-flow.test.ts

Fixes #33150

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR fixes a duplicate-message delivery bug in the followup queue by introducing a short-lived, module-level dedupe cache (RECENT_QUEUE_MESSAGE_IDS) that persists message IDs across queue drain cycles. Previously, deduplification only compared against items currently in memory; once a drain completed and the queue was torn down, a redelivered message bypassed the check entirely. The fix is targeted and the regression test covers the exact scenario described in the root-cause analysis.

The peek-before-enqueue / check-after-push pattern is used correctly against the DedupeCache API, and items dropped by applyQueueDropPolicy are intentionally not recorded in the cross-drain cache to remain eligible for redelivery once capacity is available — consistent with existing in-memory deduplication behaviour. The resetRecentQueuedMessageIdDedupe test helper is correctly scoped and guarded.

Confidence Score: 4/5

  • Safe to merge — the fix is correct, logically sound, and well-tested. The cross-drain dedupe cache is checked before any other path and is populated only on confirmed successful enqueue.
  • The root-cause fix is sound: the cross-drain dedupe cache correctly prevents duplicate messages across drain restarts, and the regression test directly validates the described failure scenario. The implementation correctly uses the DedupeCache API (peek for read, check for write after push), and the behavior regarding dropped items is intentional and consistent with existing deduplication logic.
  • No files require special attention

Last reviewed commit: b86b4d9

@benBeideman
Copy link
Copy Markdown

This PR should be pushed independently of #33455.

#33455 fixes a different issue (duplicate outbound agent), but this bug and PR address the root cause of duplicate incoming messages. It was referenced as fixing #33150, but it's not a real fix for that issue. It might reduce the visible impact, but duplicates would still be delivered to the agent, still burn tokens, and the agent would still need to process them — the outbound dedup just catches duplicate responses.

@steipete
Copy link
Copy Markdown
Contributor

steipete commented Mar 8, 2026

Landed on 5edcab2 from source commit b86b4d9.

What was done:

  • rebased/landed on latest 'main' via temp branch
  • kept the queue redelivery dedupe fix and regression test
  • added changelog entry with contributor + PR attribution
  • ran full gate before commit: 'pnpm lint && pnpm build && pnpm test'

Thanks @rylena for the fix and repro detail.

@steipete steipete closed this Mar 8, 2026
vincentkoc pushed a commit to BryanTegomoh/openclaw-fork that referenced this pull request Mar 8, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
ziomancer pushed a commit to ziomancer/openclaw that referenced this pull request Mar 8, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
openperf pushed a commit to openperf/moltbot that referenced this pull request Mar 8, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 8, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
(cherry picked from commit 5edcab2)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
Landed from contributor PR openclaw#33168 by @rylena.

Co-authored-by: Rylen Anil <[email protected]>
(cherry picked from commit 5edcab2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Signal: duplicate message delivery when processing queued messages (same as #25192)

3 participants