Repository navigation
fix: stop answering old Matrix messages again 30 days after they were handled - #208571
Merged
Merged
Conversation
Cached sync is admitted before its cursor is saved, so bind-time replay only finds existing ingress rows. Once the 30-day replay tombstone is pruned, the replay re-admitted month-old events as new turns on every Gateway or channel restart. Classify cached replay as history.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Collaborator
Author
|
Observed proof lines (isolated Gateway, built checkout, local tuwunel homeserver, deterministic model fixture; only the Gateway process clock shifted): |
Collaborator
Author
|
Landed in d692ddc. Thanks @hartmark for the dated reports that made this traceable. After a Gateway restart or a Matrix channel restart (for example from a room join), the plugin no longer answers cached Matrix messages again once their handled-message records have expired after 30 days: cached replay is treated as history. Messages that were mid-turn during a crash and messages sent while the Gateway was down are still answered exactly once. |
tideclaw-bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
… handled (#208571) Root cause: `extensions/matrix/src/matrix/client/file-sync-store.ts:118-120` replays the whole saved Matrix sync cache into ingress on every client start (Gateway restart, or the Matrix channel restart that a room join's config write triggers); `extensions/matrix/src/matrix/monitor/ingress.ts:136-142` only marks first-login events as history, so cached events are admitted as deliverable; their only guard is the event-ID replay tombstone (`src/channels/message/ingress-queue.ts:358-376`), which shared retention prunes after 30 days (`src/channels/message/ingress-monitor-owner.ts:16-17`), so the next restart answers month-old messages as new turns. Fixes #191476 (the replay of old inbound reported on 2026.11.12). The closed-consumer failure from the original report was fixed by #201554. ## What Problem This Solves After a Gateway restart or a Matrix room join, OpenClaw answered Matrix messages that were 30 to 60 days old as if they had just arrived. It only happened in quiet rooms whose last message was at least 30 days old. In the report, 32 replies went to stale messages over two days, the same two images were answered four times over two months, and a month-old instruction rewrote a spreadsheet. ## User Impact Restarts and room joins no longer revive Matrix messages that were already handled. Messages that arrived but were not yet answered when the Gateway stopped are still answered once after restart, and messages that arrive while the Gateway is down are still answered. No action or migration is needed. ## Why This Change Was Made Matrix stores each sync batch in durable ingress before saving its cursor, so everything in the saved sync cache was already admitted. Replaying the cache on startup is meant to find those existing rows (pending ones keep their delivery). Once a completed row's 30-day replay guard is pruned, the replay was creating a brand-new deliverable row instead. The plugin now classifies cached replay the way it already classifies first-login history: an existing row is left as is, and an event without a row is recorded as intentionally not delivered. Shared retention, storage and the ingress queue are unchanged. ## Evidence Isolated Gateway from a built checkout, local tuwunel homeserver, deterministic OpenAI-compatible model fixture. The Gateway answers a message in two rooms, then restarts with only its own clock moved forward 31 days (so the hourly prune removes the replay guards), then gets a `channels.matrix.groups` config change, which restarts the Matrix channel like a room join does. | Run | After the channel restart | |---|---| | main, +31 days | both 31-day-old events dispatched again (`message processed ... messageId=<old event>`), and the bot posted a new message in each quiet room | | main, no clock change | nothing dispatched | | this PR, +31 days | channel restarted, nothing dispatched, no new bot messages | On main the replayed turn in this setup ends with `Input completion retry conflicts with the committed input`, because the same session still holds the original input, and the room gets "⚠️ OpenClaw couldn't finish this request". The reporter's month-old sessions produced full fresh replies instead. Safety checks, same result on main and this PR: - A message queued behind a running turn when the Gateway was killed with SIGKILL (its ingress row was `claimed`) is answered exactly once after restart. - A message sent while the Gateway was down is answered exactly once after restart. Regression test `handler.restart.test.ts` "does not answer a cached message again after its replay tombstone expires" (real sync store, SQLite ingress queue) fails on main with `$unadopted` dispatched twice and passes here. Thanks @hartmark for the report, and @7s9ffcyjq5-lgtm for the detailed 2026.11.12 replay timeline. Merge danger: two-way door. A revert restores the old classification; no stored state, schema or config changes. Blast radius: Matrix inbound only, at client start. Observed proof lines: #208571 (comment) Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit d692ddc) Follow-up audit: No later same-path, PR-number or SHA references through be407a4. Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot
pushed a commit
that referenced
this pull request
Nov 30, 2026
… handled (#208571) Root cause: `extensions/matrix/src/matrix/client/file-sync-store.ts:118-120` replays the whole saved Matrix sync cache into ingress on every client start (Gateway restart, or the Matrix channel restart that a room join's config write triggers); `extensions/matrix/src/matrix/monitor/ingress.ts:136-142` only marks first-login events as history, so cached events are admitted as deliverable; their only guard is the event-ID replay tombstone (`src/channels/message/ingress-queue.ts:358-376`), which shared retention prunes after 30 days (`src/channels/message/ingress-monitor-owner.ts:16-17`), so the next restart answers month-old messages as new turns. Fixes #191476 (the replay of old inbound reported on 2026.11.12). The closed-consumer failure from the original report was fixed by #201554. ## What Problem This Solves After a Gateway restart or a Matrix room join, OpenClaw answered Matrix messages that were 30 to 60 days old as if they had just arrived. It only happened in quiet rooms whose last message was at least 30 days old. In the report, 32 replies went to stale messages over two days, the same two images were answered four times over two months, and a month-old instruction rewrote a spreadsheet. ## User Impact Restarts and room joins no longer revive Matrix messages that were already handled. Messages that arrived but were not yet answered when the Gateway stopped are still answered once after restart, and messages that arrive while the Gateway is down are still answered. No action or migration is needed. ## Why This Change Was Made Matrix stores each sync batch in durable ingress before saving its cursor, so everything in the saved sync cache was already admitted. Replaying the cache on startup is meant to find those existing rows (pending ones keep their delivery). Once a completed row's 30-day replay guard is pruned, the replay was creating a brand-new deliverable row instead. The plugin now classifies cached replay the way it already classifies first-login history: an existing row is left as is, and an event without a row is recorded as intentionally not delivered. Shared retention, storage and the ingress queue are unchanged. ## Evidence Isolated Gateway from a built checkout, local tuwunel homeserver, deterministic OpenAI-compatible model fixture. The Gateway answers a message in two rooms, then restarts with only its own clock moved forward 31 days (so the hourly prune removes the replay guards), then gets a `channels.matrix.groups` config change, which restarts the Matrix channel like a room join does. | Run | After the channel restart | |---|---| | main, +31 days | both 31-day-old events dispatched again (`message processed ... messageId=<old event>`), and the bot posted a new message in each quiet room | | main, no clock change | nothing dispatched | | this PR, +31 days | channel restarted, nothing dispatched, no new bot messages | On main the replayed turn in this setup ends with `Input completion retry conflicts with the committed input`, because the same session still holds the original input, and the room gets "⚠️ OpenClaw couldn't finish this request". The reporter's month-old sessions produced full fresh replies instead. Safety checks, same result on main and this PR: - A message queued behind a running turn when the Gateway was killed with SIGKILL (its ingress row was `claimed`) is answered exactly once after restart. - A message sent while the Gateway was down is answered exactly once after restart. Regression test `handler.restart.test.ts` "does not answer a cached message again after its replay tombstone expires" (real sync store, SQLite ingress queue) fails on main with `$unadopted` dispatched twice and passes here. Thanks @hartmark for the report, and @7s9ffcyjq5-lgtm for the detailed 2026.11.12 replay timeline. Merge danger: two-way door. A revert restores the old classification; no stored state, schema or config changes. Blast radius: Matrix inbound only, at client start. Observed proof lines: #208571 (comment) Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit d692ddc) Co-authored-by: RomneyDa <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 30, 2026
… handled (openclaw#208571) Root cause: `extensions/matrix/src/matrix/client/file-sync-store.ts:118-120` replays the whole saved Matrix sync cache into ingress on every client start (Gateway restart, or the Matrix channel restart that a room join's config write triggers); `extensions/matrix/src/matrix/monitor/ingress.ts:136-142` only marks first-login events as history, so cached events are admitted as deliverable; their only guard is the event-ID replay tombstone (`src/channels/message/ingress-queue.ts:358-376`), which shared retention prunes after 30 days (`src/channels/message/ingress-monitor-owner.ts:16-17`), so the next restart answers month-old messages as new turns. Fixes openclaw#191476 (the replay of old inbound reported on 2026.11.12). The closed-consumer failure from the original report was fixed by openclaw#201554. ## What Problem This Solves After a Gateway restart or a Matrix room join, OpenClaw answered Matrix messages that were 30 to 60 days old as if they had just arrived. It only happened in quiet rooms whose last message was at least 30 days old. In the report, 32 replies went to stale messages over two days, the same two images were answered four times over two months, and a month-old instruction rewrote a spreadsheet. ## User Impact Restarts and room joins no longer revive Matrix messages that were already handled. Messages that arrived but were not yet answered when the Gateway stopped are still answered once after restart, and messages that arrive while the Gateway is down are still answered. No action or migration is needed. ## Why This Change Was Made Matrix stores each sync batch in durable ingress before saving its cursor, so everything in the saved sync cache was already admitted. Replaying the cache on startup is meant to find those existing rows (pending ones keep their delivery). Once a completed row's 30-day replay guard is pruned, the replay was creating a brand-new deliverable row instead. The plugin now classifies cached replay the way it already classifies first-login history: an existing row is left as is, and an event without a row is recorded as intentionally not delivered. Shared retention, storage and the ingress queue are unchanged. ## Evidence Isolated Gateway from a built checkout, local tuwunel homeserver, deterministic OpenAI-compatible model fixture. The Gateway answers a message in two rooms, then restarts with only its own clock moved forward 31 days (so the hourly prune removes the replay guards), then gets a `channels.matrix.groups` config change, which restarts the Matrix channel like a room join does. | Run | After the channel restart | |---|---| | main, +31 days | both 31-day-old events dispatched again (`message processed ... messageId=<old event>`), and the bot posted a new message in each quiet room | | main, no clock change | nothing dispatched | | this PR, +31 days | channel restarted, nothing dispatched, no new bot messages | On main the replayed turn in this setup ends with `Input completion retry conflicts with the committed input`, because the same session still holds the original input, and the room gets "⚠️ OpenClaw couldn't finish this request". The reporter's month-old sessions produced full fresh replies instead. Safety checks, same result on main and this PR: - A message queued behind a running turn when the Gateway was killed with SIGKILL (its ingress row was `claimed`) is answered exactly once after restart. - A message sent while the Gateway was down is answered exactly once after restart. Regression test `handler.restart.test.ts` "does not answer a cached message again after its replay tombstone expires" (real sync store, SQLite ingress queue) fails on main with `$unadopted` dispatched twice and passes here. Thanks @hartmark for the report, and @7s9ffcyjq5-lgtm for the detailed 2026.11.12 replay timeline. Merge danger: two-way door. A revert restores the old classification; no stored state, schema or config changes. Blast radius: Matrix inbound only, at client start. Observed proof lines: openclaw#208571 (comment) Co-authored-by: Ayaan Zaidi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause:
extensions/matrix/src/matrix/client/file-sync-store.ts:118-120replays the whole saved Matrix sync cache into ingress on every client start (Gateway restart, or the Matrix channel restart that a room join's config write triggers);extensions/matrix/src/matrix/monitor/ingress.ts:136-142only marks first-login events as history, so cached events are admitted as deliverable; their only guard is the event-ID replay tombstone (src/channels/message/ingress-queue.ts:358-376), which shared retention prunes after 30 days (src/channels/message/ingress-monitor-owner.ts:16-17), so the next restart answers month-old messages as new turns.Fixes #191476 (the replay of old inbound reported on 2026.11.12). The closed-consumer failure from the original report was fixed by #201554.
What Problem This Solves
After a Gateway restart or a Matrix room join, OpenClaw answered Matrix messages that were 30 to 60 days old as if they had just arrived. It only happened in quiet rooms whose last message was at least 30 days old. In the report, 32 replies went to stale messages over two days, the same two images were answered four times over two months, and a month-old instruction rewrote a spreadsheet.
User Impact
Restarts and room joins no longer revive Matrix messages that were already handled. Messages that arrived but were not yet answered when the Gateway stopped are still answered once after restart, and messages that arrive while the Gateway is down are still answered. No action or migration is needed.
Why This Change Was Made
Matrix stores each sync batch in durable ingress before saving its cursor, so everything in the saved sync cache was already admitted. Replaying the cache on startup is meant to find those existing rows (pending ones keep their delivery). Once a completed row's 30-day replay guard is pruned, the replay was creating a brand-new deliverable row instead. The plugin now classifies cached replay the way it already classifies first-login history: an existing row is left as is, and an event without a row is recorded as intentionally not delivered. Shared retention, storage and the ingress queue are unchanged.
Evidence
Isolated Gateway from a built checkout, local tuwunel homeserver, deterministic OpenAI-compatible model fixture. The Gateway answers a message in two rooms, then restarts with only its own clock moved forward 31 days (so the hourly prune removes the replay guards), then gets a
channels.matrix.groupsconfig change, which restarts the Matrix channel like a room join does.message processed ... messageId=<old event>), and the bot posted a new message in each quiet roomOn main the replayed turn in this setup ends with⚠️ OpenClaw couldn't finish this request". The reporter's month-old sessions produced full fresh replies instead.
Input completion retry conflicts with the committed input, because the same session still holds the original input, and the room gets "Safety checks, same result on main and this PR:
claimed) is answered exactly once after restart.Regression test
handler.restart.test.ts"does not answer a cached message again after its replay tombstone expires" (real sync store, SQLite ingress queue) fails on main with$unadopteddispatched twice and passes here.Thanks @hartmark for the report, and @7s9ffcyjq5-lgtm for the detailed 2026.11.12 replay timeline.
Merge danger: two-way door. A revert restores the old classification; no stored state, schema or config changes. Blast radius: Matrix inbound only, at client start.
Observed proof lines: #208571 (comment)