Skip to content

fix(discord): dedupe inbound message deliveries#51950

Merged
Takhoffman merged 2 commits intomainfrom
codex/discord-inbound-dedupe
Mar 22, 2026
Merged

fix(discord): dedupe inbound message deliveries#51950
Takhoffman merged 2 commits intomainfrom
codex/discord-inbound-dedupe

Conversation

@Takhoffman
Copy link
Copy Markdown
Contributor

@Takhoffman Takhoffman commented Mar 22, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: duplicate Discord deliveries were being marked as seen before preflight and queued worker execution, so a transient failure could suppress retries for the same message for the full dedupe TTL.
  • Why it matters: that creates at-most-once behavior for inbound Discord handling and can drop legitimate redeliveries after preflight or worker errors.
  • What changed: added a scoped inbound dedupe guard keyed by accountId:channelId:messageId, and now release the dedupe claim when preflight fails or when the queued inbound worker errors; added focused queue regressions for duplicate suppression and both retry-after-failure paths.
  • What did NOT change (scope boundary): this does not change Discord routing, debounce grouping semantics, or outbound reply behavior.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

Discord inbound message handling now suppresses duplicate deliveries earlier in the pipeline, but retries the same delivery after transient preflight or queued-worker failures instead of dropping it for the dedupe TTL.

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 + pnpm
  • Model/provider: N/A
  • Integration/channel (if any): Discord
  • Relevant config (redacted): default test config with Discord inbound debounce disabled in handler tests

Steps

  1. Send the same Discord message delivery twice.
  2. Fail either preflight or the queued inbound worker on the first attempt.
  3. Redeliver the same message and observe whether it is retried or suppressed.

Expected

  • Duplicate deliveries are suppressed when the first delivery is accepted successfully.
  • The same delivery can retry after a transient preflight or queued-worker failure.

Actual

  • This PR makes the handler release the dedupe claim on those failure paths, and the focused queue regressions now cover both cases.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: pnpm exec vitest run extensions/discord/src/monitor/message-handler.queue.test.ts
  • Edge cases checked: duplicate suppression for identical deliveries, retry after preflight failure, and retry after queued inbound worker failure.
  • What you did not verify: live end-to-end Discord delivery behavior outside the focused queue tests.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR or remove the new dedupe-claim release paths in the Discord handler and inbound worker callback wiring.
  • Files/config to restore: extensions/discord/src/monitor/message-handler.ts, extensions/discord/src/monitor/inbound-worker.ts, extensions/discord/src/monitor/message-handler.queue.test.ts
  • Known bad symptoms reviewers should watch for: duplicate Discord inbound processing returning, or legitimate redeliveries being suppressed after transient failures.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: releasing the dedupe claim on worker failure could let a real duplicate retry while the failing delivery is being retried externally.
    • Mitigation: the release only happens on explicit preflight or worker failure paths; successful accepted deliveries still retain the short-TTL dedupe guard.

@openclaw-barnacle openclaw-barnacle bot added channel: discord Channel integration: discord size: XS maintainer Maintainer-authored PR labels Mar 22, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 22, 2026

Greptile Summary

This PR adds a narrow inbound deduplication guard for Discord message deliveries, keyed by accountId:channelId:messageId. The guard drops duplicate deliveries before they reach the debounce queue or preflight processing, preventing wasteful re-queuing of the same message. A new focused test verifies the duplicate-suppression behavior.

Key changes:

  • Adds buildDiscordInboundDedupeKey that constructs a scoped key from account, channel, and message ID, returning null for events where either field is unresolvable (graceful bypass).
  • Instantiates a createDedupeCache (5 min TTL, 5000-entry cap) per handler — scoped correctly per account.
  • The deduplication check is placed after the existing bot-self-filter and before the debouncer enqueue, matching the stated goal of dropping duplicates before debounce and preflight.
  • Adds a test asserting that two identical deliveries result in exactly one preflight and one process call.

Confidence Score: 5/5

  • This PR is safe to merge. The deduplication logic is correct, well-scoped, and has no impact on the happy path for unique messages.
  • The check method of createDedupeCache atomically checks-and-registers a key (first call → adds to cache, returns false; subsequent calls → returns true), so the guard in message-handler.ts works correctly. The key is correctly scoped to accountId:channelId:messageId, the cache is per-handler (no cross-account bleed), and the null-return path for unresolvable keys is a safe bypass. The TTL (5 min) and cap (5000) are reasonable for active Discord servers. The new test cleanly validates the dedupe contract against the preflight and process mocks.
  • No files require special attention.

Last reviewed commit: "fix(discord): dedupe..."

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: 0383420823

ℹ️ 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".

@Takhoffman Takhoffman force-pushed the codex/discord-inbound-dedupe branch from 0383420 to 6253f95 Compare March 22, 2026 01:00
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: df276e6ddc

ℹ️ 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".

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: fee7b58416

ℹ️ 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".

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: c1886d60c3

ℹ️ 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".

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: cd61a62753

ℹ️ 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".

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: 2c0fa2d93f

ℹ️ 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".

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: 0ea070a3a0

ℹ️ 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".

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: a9c6b6b7d5

ℹ️ 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".

@Takhoffman Takhoffman force-pushed the codex/discord-inbound-dedupe branch from a9c6b6b to d7129cb Compare March 22, 2026 03:55
@Takhoffman Takhoffman merged commit 432e894 into main Mar 22, 2026
42 checks passed
@Takhoffman Takhoffman deleted the codex/discord-inbound-dedupe branch March 22, 2026 04:55
aquaright1 pushed a commit to aquaright1/openclaw that referenced this pull request Mar 22, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
JohnJAS pushed a commit to JohnJAS/openclaw that referenced this pull request Mar 22, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
pholpaphankorn pushed a commit to pholpaphankorn/openclaw that referenced this pull request Mar 22, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
MaheshBhushan pushed a commit to MaheshBhushan/openclaw that referenced this pull request Mar 22, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
frankekn pushed a commit to artwalker/openclaw that referenced this pull request Mar 23, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
Erprabhat8423 added a commit to Erprabhat8423/openclaw that referenced this pull request Mar 23, 2026
The dedupe fix in openclaw#51950 introduced recentInboundMessages.check() in
the Discord message handler. This called prune() on every single
message, which did a full linear scan of up to 5000 cache entries on
each invocation.

On active Discord servers, this blocked the event loop for tens of
milliseconds per message, stacking up to the 33-122s delays reported
in openclaw#4453.

Also fixed map-size.ts which had corrupted duplicate code.

Changes:
- dedupe.ts: only call prune() when cache.size exceeds maxSize
- map-size.ts: rewrite pruneMapToMaxSize to delete in a single pass
  instead of calling map.keys().next() in a while loop

Fixes openclaw#4453
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 23, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec

(cherry picked from commit 432e894)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 23, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec

(cherry picked from commit 432e894)
Interstellar-code pushed a commit to Interstellar-code/operator1 that referenced this pull request Mar 24, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec

(cherry picked from commit 432e894)
furaul pushed a commit to furaul/openclaw that referenced this pull request Mar 24, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 28, 2026
* fix(discord): dedupe inbound message deliveries

* test(discord): disable debounce in tool-result dispatch spec

(cherry picked from commit 432e894)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant