Repository navigation
fix(mattermost): preserve websocket posts across restarts - #110386
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 1:34 AM ET / 05:34 UTC. Summary PR surface: Source +368, Tests +494. Total +862 across 7 files. Reproducibility: yes. at source level: receive a Mattermost Review metrics: none identified. Stored data model 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
Security Review detailsBest possible solution: Retain the shared ingress-drain design, add redacted real Mattermost evidence showing receipt, process restart, recovery, and single dispatch, then have the Mattermost owner review the intentional fail-loud storage-failure behavior before merge. Do we have a high-confidence way to reproduce the issue? Yes at source level: receive a Mattermost Is this the best way to solve the issue? Unclear: the shared durable-ingress adapter is the right architectural direction, but direct Mattermost restart/recovery proof and owner review are needed before concluding this large lifecycle replacement is the best safe implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c1e5c1d4fa35. Label changesLabel justifications:
Evidence reviewedPR surface: Source +368, Tests +494. Total +862 across 7 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
Review history (1 earlier review cycle)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d98b23e99
ℹ️ 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".
| const chatId = message?.chat_id; | ||
| if (typeof chatId !== "number" || !Number.isSafeInteger(chatId)) { | ||
| throw new IMessageIngressPayloadError("iMessage ingress row is missing its chat id."); | ||
| } |
There was a problem hiding this comment.
Do not reject chat_id-less iMessages
When imsg emits a sender-only or otherwise anchorless payload without a numeric chat_id, this new durable admission gate throws before the existing parser and repairIMessageConversationAnchor path can run. That shape is explicitly supported by the current iMessage code (for example sender-only messages and GUID-based anchor repair), so these inbound messages now fail ingress.receive, are logged as durable admission failures, and are never queued or delivered. Derive the lane from chat_id only when present, falling back to the existing conversation identifiers or GUID/sender so repair can still recover the message.
Useful? React with 👍 / 👎.
Posted events processed detached from the websocket receive with only a 5-minute in-memory guard; a crash lost the post and reconnect never replays it. Raw posted envelopes now journal durably (event_id = post.id per the upstream Post model, lane per channel_id, one row per post) before handler scheduling; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, and 30d/20k tombstones covering the old 5min/2k guard, which is deleted after its parity test. post_edited stays excluded and cannot be swallowed by posted tombstones. Cold-gap limitation stated: Mattermost cannot replay posts missed while disconnected. Autoreview blocked by codex sandbox network in the build stage; full manual review performed (updated one websocket test asserting the pre-adoption parsed-post contract to the raw-envelope contract). Part of #109657 wave 2.
Landing autoreview caught a real loss path: a durable enqueue failure at the websocket chokepoint was logged and swallowed — the raw envelope discarded, the connection kept running against a broken store, and reconnect never replays, so a transient SQLite failure silently lost the post. The append now retries with short backoff for transient blips; a persistent failure propagates and the websocket terminates loudly so the outage is operator-visible instead of silently dropping every subsequent post. Regression test covers both the absorbed-transient and escalation paths.
…rune stop() disposing before the startup pump finished pruning let the pump lazily create a fresh undisposed drain and dispatch after shutdown. The pump now re-checks running after the prune, and stop() disposes again after awaiting the pump so a drain created mid-race is torn down. Regression test blocks the prune across stop and asserts no dispatch.
Concurrent websocket callbacks let a post in append-retry backoff be overtaken by its successor, inverting same-channel arrival order in the queue. Admissions now chain (order over latency, mirroring the iMessage admission tail); regression proves a retried post still lands ahead of a concurrently received one.
…ector Posts can carry their channel id on the post, the event data, or the broadcast envelope — the monitor dispatch honors all three, but the ingress inspector and claim-side validator required the nested field, rejecting valid posts as permanent and (via the storage-failure escalation) tearing down the socket for a failure that never happened, losing posts reconnect cannot replay. Both sites accept the three shapes; regression proves an envelope-level post dispatches.
8d98b23 to
177ae09
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 177ae096e7
ℹ️ 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 debouncer.enqueue({ post, payload, turnAdoptionLifecycle }); | ||
| return { kind: "deferred" }; |
There was a problem hiding this comment.
Do not block Mattermost debounce behind the first claim
When Mattermost inbound debouncing is enabled (messages.inbound.debounceMs or a per-channel override), this returns deferred after only the first same-channel post reaches the debouncer. The durable drain keeps that channel lane active until the claim is adopted, so later posts in the same debounce window stay pending and cannot join onFlush; rapid text messages that previously merged into one agent turn now dispatch as separate turns, each after its own debounce delay. Let the durable layer coalesce pending same-lane posts before holding the lane, or otherwise arrange for the debouncer to see all same-key posts in the window.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…10386) * fix(mattermost): adopt durable ingress drain at the websocket chokepoint Posted events processed detached from the websocket receive with only a 5-minute in-memory guard; a crash lost the post and reconnect never replays it. Raw posted envelopes now journal durably (event_id = post.id per the upstream Post model, lane per channel_id, one row per post) before handler scheduling; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, and 30d/20k tombstones covering the old 5min/2k guard, which is deleted after its parity test. post_edited stays excluded and cannot be swallowed by posted tombstones. Cold-gap limitation stated: Mattermost cannot replay posts missed while disconnected. Autoreview blocked by codex sandbox network in the build stage; full manual review performed (updated one websocket test asserting the pre-adoption parsed-post contract to the raw-envelope contract). Part of openclaw#109657 wave 2. * style(mattermost): keep ingress monitor type internal * fix(mattermost): retry then loudly escalate a failed durable append Landing autoreview caught a real loss path: a durable enqueue failure at the websocket chokepoint was logged and swallowed — the raw envelope discarded, the connection kept running against a broken store, and reconnect never replays, so a transient SQLite failure silently lost the post. The append now retries with short backoff for transient blips; a persistent failure propagates and the websocket terminates loudly so the outage is operator-visible instead of silently dropping every subsequent post. Regression test covers both the absorbed-transient and escalation paths. * style(mattermost): format rebased ingress handler * docs(mattermost): document bounded auth-failure retries under deferred claims * fix(mattermost): guard the drain pump against stop racing the async prune stop() disposing before the startup pump finished pruning let the pump lazily create a fresh undisposed drain and dispatch after shutdown. The pump now re-checks running after the prune, and stop() disposes again after awaiting the pump so a drain created mid-race is torn down. Regression test blocks the prune across stop and asserts no dispatch. * fix(mattermost): serialize durable admissions to preserve lane order Concurrent websocket callbacks let a post in append-retry backoff be overtaken by its successor, inverting same-channel arrival order in the queue. Admissions now chain (order over latency, mirroring the iMessage admission tail); regression proves a retried post still lands ahead of a concurrently received one. * test(mattermost): assert lane order via dispatch sequence * fix(mattermost): stop() awaits in-flight admissions before disposal * fix(mattermost): satisfy ingress lint checks * fix(mattermost): honor envelope-level channel ids in the durable inspector Posts can carry their channel id on the post, the event data, or the broadcast envelope — the monitor dispatch honors all three, but the ingress inspector and claim-side validator required the nested field, rejecting valid posts as permanent and (via the storage-failure escalation) tearing down the socket for a failure that never happened, losing posts reconnect cannot replay. Both sites accept the three shapes; regression proves an envelope-level post dispatches.
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]>
…10386) * fix(mattermost): adopt durable ingress drain at the websocket chokepoint Posted events processed detached from the websocket receive with only a 5-minute in-memory guard; a crash lost the post and reconnect never replays it. Raw posted envelopes now journal durably (event_id = post.id per the upstream Post model, lane per channel_id, one row per post) before handler scheduling; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, and 30d/20k tombstones covering the old 5min/2k guard, which is deleted after its parity test. post_edited stays excluded and cannot be swallowed by posted tombstones. Cold-gap limitation stated: Mattermost cannot replay posts missed while disconnected. Autoreview blocked by codex sandbox network in the build stage; full manual review performed (updated one websocket test asserting the pre-adoption parsed-post contract to the raw-envelope contract). Part of openclaw#109657 wave 2. * style(mattermost): keep ingress monitor type internal * fix(mattermost): retry then loudly escalate a failed durable append Landing autoreview caught a real loss path: a durable enqueue failure at the websocket chokepoint was logged and swallowed — the raw envelope discarded, the connection kept running against a broken store, and reconnect never replays, so a transient SQLite failure silently lost the post. The append now retries with short backoff for transient blips; a persistent failure propagates and the websocket terminates loudly so the outage is operator-visible instead of silently dropping every subsequent post. Regression test covers both the absorbed-transient and escalation paths. * style(mattermost): format rebased ingress handler * docs(mattermost): document bounded auth-failure retries under deferred claims * fix(mattermost): guard the drain pump against stop racing the async prune stop() disposing before the startup pump finished pruning let the pump lazily create a fresh undisposed drain and dispatch after shutdown. The pump now re-checks running after the prune, and stop() disposes again after awaiting the pump so a drain created mid-race is torn down. Regression test blocks the prune across stop and asserts no dispatch. * fix(mattermost): serialize durable admissions to preserve lane order Concurrent websocket callbacks let a post in append-retry backoff be overtaken by its successor, inverting same-channel arrival order in the queue. Admissions now chain (order over latency, mirroring the iMessage admission tail); regression proves a retried post still lands ahead of a concurrently received one. * test(mattermost): assert lane order via dispatch sequence * fix(mattermost): stop() awaits in-flight admissions before disposal * fix(mattermost): satisfy ingress lint checks * fix(mattermost): honor envelope-level channel ids in the durable inspector Posts can carry their channel id on the post, the event data, or the broadcast envelope — the monitor dispatch honors all three, but the ingress inspector and claim-side validator required the nested field, rejecting valid posts as permanent and (via the storage-failure escalation) tearing down the socket for a failure that never happened, losing posts reconnect cannot replay. Both sites accept the three shapes; regression proves an envelope-level post dispatches.
Related: #109657
What Problem This Solves
Mattermost WebSocket
postedevents were detached from the socket and protected only by a five-minute in-memory replay guard. If OpenClaw restarted after receiving a frame but before adopting its turn, the post was lost because Mattermost reconnects do not replay already-received posts.Why This Change Was Made
The Mattermost plugin now durably admits every raw
postedenvelope before scheduling its handler, usingpost.idas the event identity. Channel lanes honor channel IDs frompost.channel_id, envelopedata.channel_id, and broadcast metadata so inspection and claiming preserve ordering for every supported event shape.The shared ingress drain owns restart recovery, per-lane ordering, bounded retry/dead-letter behavior, deferred debounce claims, and merged-turn adoption fan-out. The five-minute replay guard is deleted after parity through 30-day, 20,000-entry completion tombstones. Admissions are serialized so append retries cannot invert same-channel order; shutdown waits for admitted work and closes the prune/pump race.
Cold-gap limitation: Mattermost does not replay posts missed while OpenClaw is disconnected. This change protects frames OpenClaw received and durably admitted; it does not fill that platform-level gap. Persistent admission failures terminate the WebSocket loudly instead of silently losing later posts.
User Impact
Mattermost posts accepted by OpenClaw now survive process restarts and dispatch once after recovery. Operators also get durable duplicate rejection within the bounded retention window and loud failure when the ingress store cannot accept new posts.
Evidence
8d98b23e99addeb84d4144fba60cb3ffd6698f2b.AI-assisted; maintainer-reviewed and understood.