Repository navigation
fix(discord): preserve gateway messages across dispatch crashes - #110274
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fc9954874
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!channelId) { | ||
| throw new DiscordIngressPayloadError("Discord MESSAGE_CREATE payload is missing channel_id"); | ||
| } | ||
| return { eventId, laneKey: `channel:${channelId}` }; |
There was a problem hiding this comment.
Preserve Discord debounce across durable ingress
When messages.inbound.debounceMs (or the Discord override) is nonzero, using the channel id as the durable ingress lane keeps the first claimed message active until its debounce flush reaches adoption; createChannelIngressDrain blocks later pending rows with the same lane while that claim is deferred, so a second same-channel/same-author message arriving inside the debounce window cannot be claimed and added to the same debounce buffer. The new dispatcher has logic to fan adoption across merged entries, but the gateway durable path never lets those entries reach the debouncer together, regressing configured Discord batching into one turn per message.
Useful? React with 👍 / 👎.
4fc9954 to
39d7f85
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39d7f85271
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await adoptAll(); | ||
| } | ||
| }, | ||
| abandon: async () => { |
There was a problem hiding this comment.
Preserve deferred flush failures for ingress disposition
When inbound debounce is enabled, dispatchMessage returns deferred before the later debounce flush runs; if that later preflight/flush fails, the catch path calls ingress.abandon(error), but this implementation drops the error and only calls onAbandoned(). That means permanent failures the drain can classify via resolveNonRetryableFailure (for example a Discord 401 raised during preflight) are recorded as generic turn-abandoned retries until the retry limit instead of being dead-lettered immediately.
Useful? React with 👍 / 👎.
Gateway MESSAGE_CREATE events dispatched with only an in-memory/persistent 5-minute dedupe; a crash between receive and dispatch lost the message (live sessions replay via RESUME, but session state is memory-only so a cold restart re-IDENTIFYs — stated platform limitation: the drain closes the receive->dispatch window, not cold downtime). Raw API messages now journal durably (event_id = message snowflake, lane per channel/thread) before normalization; dispatch runs through the core drain with deferred claims, fan-out adoption, gated settlement, and 30d/5k tombstones. The persistent guard is deleted after its RESUME duplicate-delivery parity test. Edits stay outside the queue: only MessageCreateListener is registered, MESSAGE_UPDATE never dispatches, so snowflake tombstones cannot swallow edit turns; a future edit dispatcher must namespace its event ids. Autoreview blocked by codex sandbox network in the build stage; full manual review performed. Part of the #109657 fleet adoption program (wave 2).
Landing autoreview reproduced a real loss race: a dispatch entering after dispatcher shutdown (or with an aborted signal) returned completed, so the drain tombstoned a message that never ran and a restarted gateway skipped it forever. Aborted-before-dispatch now returns failed-retryable so the claim releases for replay. Test type imports of drain-internal types converted to factory-derived types so the dead-export gate and typecheck agree.
39d7f85 to
347dfb6
Compare
|
Merged via squash.
|
|
Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 8:55 PM ET / July 18, 2026, 00:55 UTC. Summary PR surface: Source +413, Tests +350. Total +763 across 26 files. Reproducibility: yes. source review provides a high-confidence path for the two regressions: enable Discord inbound debounce and send two eligible messages in one channel, then force a non-retryable failure during the later debounce flush. A real Discord restart replay was not demonstrated in the supplied PR evidence. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Preserve durable-before-dispatch admission while allowing messages eligible for the same Discord debounce batch to reach the debouncer together, and propagate the actual deferred-flush error into the drain so retryability and dead-letter policy remain canonical. Do we have a high-confidence way to reproduce the issue? Yes, source review provides a high-confidence path for the two regressions: enable Discord inbound debounce and send two eligible messages in one channel, then force a non-retryable failure during the later debounce flush. A real Discord restart replay was not demonstrated in the supplied PR evidence. Is this the best way to solve the issue? No. Durable admission is the appropriate direction, but the patch must preserve existing debounce batching and carry deferred errors into the shared drain’s existing failure classifier rather than introducing Discord-specific weaker outcomes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 3a4e2ef65f41. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +413, Tests +350. Total +763 across 26 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
…claw#110274) * fix(discord): adopt durable ingress drain for gateway messages Gateway MESSAGE_CREATE events dispatched with only an in-memory/persistent 5-minute dedupe; a crash between receive and dispatch lost the message (live sessions replay via RESUME, but session state is memory-only so a cold restart re-IDENTIFYs — stated platform limitation: the drain closes the receive->dispatch window, not cold downtime). Raw API messages now journal durably (event_id = message snowflake, lane per channel/thread) before normalization; dispatch runs through the core drain with deferred claims, fan-out adoption, gated settlement, and 30d/5k tombstones. The persistent guard is deleted after its RESUME duplicate-delivery parity test. Edits stay outside the queue: only MessageCreateListener is registered, MESSAGE_UPDATE never dispatches, so snowflake tombstones cannot swallow edit turns; a future edit dispatcher must namespace its event ids. Autoreview blocked by codex sandbox network in the build stage; full manual review performed. Part of the openclaw#109657 fleet adoption program (wave 2). * style(discord): keep drain-internal types and dispatcher unexported * refactor(discord): move message dispatcher to its own module for the dead-export gate * fix(discord): shutdown dispatch releases claims instead of tombstoning Landing autoreview reproduced a real loss race: a dispatch entering after dispatcher shutdown (or with an aborted signal) returned completed, so the drain tombstoned a message that never ran and a restarted gateway skipped it forever. Aborted-before-dispatch now returns failed-retryable so the claim releases for replay. Test type imports of drain-internal types converted to factory-derived types so the dead-export gate and typecheck agree.
Matrix advances the /sync token before inbound events finish dispatching (matrix-js-sdk doSync sets the token first, then the plugin's SQLite sync store persists it), while room messages were dispatched into a memory-only detached queue for the full agent-turn duration. A gateway crash or restart in that window permanently lost the user message: the next /sync told the homeserver the batch was consumed. Journal every dispatchable inbound event into the shared channel ingress queue (channel_ingress_events, no schema change) synchronously inside the sync event listener — before the debounced token persist can land — and dispatch through the core durable ingress drain with per-room lanes, complete-at-adoption via the canonical turnAdoptionLifecycle reply-options seam, bounded retry/dead-letter, and restart replay. The existing persistent inbound deduper keeps redelivered events exactly-once. Events without an event id keep the previous live-dispatch path. Mirrors the durable-ingress fleet adoption (openclaw#109657): telegram openclaw#108924, discord openclaw#110274, whatsapp openclaw#110418, mattermost openclaw#110386, msteams openclaw#110357. Co-Authored-By: Claude <[email protected]>
Related: #109657
What Problem This Solves
Fixes an issue where Discord gateway messages could be lost when the gateway crashed after receiving an event but before dispatch adopted the turn. The old path detached dispatch behind a five-minute persistent replay guard. Discord RESUME can cover brief live-session interruptions, but session state is memory-only; a cold restart re-IDENTIFYs and cannot recover downtime from the platform. This change closes the receive-to-dispatch crash window without claiming to solve that platform limitation.
Why This Change Was Made
Discord now writes the raw
APIMessagepayload to the shared durable ingress drain before dispatch, using the message snowflake as the event id and channel/thread-derived lanes for ordering. Debounced turns keep claims deferred and fan adoption out to every constituent message; terminal outcomes settle through the shared drain. The old replay guard is removed after a RESUME duplicate-delivery parity test, with completed tombstones retained for 30 days and capped at 5,000 entries.The transport boundary remains narrow: only
MessageCreateListeneris registered. Message updates still do not dispatch, so snowflake tombstones cannot suppress edit turns. The feature commit records this boundary explicitly; any future edit dispatcher must namespace its event ids.User Impact
Discord messages received before an in-process gateway crash now replay after restart instead of disappearing between receive and turn adoption. Duplicate gateway deliveries remain suppressed after completion. Cold-restart downtime remains subject to Discord's re-IDENTIFY behavior and is not recovered by this change.
Evidence
extensions/discordsuite after rebase: 2,266 tests green.node scripts/check-deadcode-exports.mjsandnode scripts/check-deadcode-unused-files.mjs, both green with 0 entries.git diff --checkand changed-file conflict-marker scan: clean.AI-assisted implementation and review; maintainer understands and owns the change.