Repository navigation
fix(mattermost): backfill thread history from server when in-memory window is empty (fixes #93204) - #93692
fix(mattermost): backfill thread history from server when in-memory window is empty (fixes #93204)#93692zenglingbiao wants to merge 3 commits into
Conversation
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs real behavior proof before merge. Reviewed June 16, 2026, 7:55 PM ET / 23:55 UTC. Summary PR surface: Source +42. Total +42 across 2 files. Reproducibility: yes. at source level. Current main initializes channelHistories empty and builds pending/inbound thread history only from that map, so restart or session-clear can leave thread context empty; I did not run a live Mattermost server. Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Keep the Mattermost-owned server backfill, but gate it on real recovery or missing context, cap work before username lookups, fix lint/type failures, and add live Mattermost proof plus focused tests. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main initializes channelHistories empty and builds pending/inbound thread history only from that map, so restart or session-clear can leave thread context empty; I did not run a live Mattermost server. Is this the best way to solve the issue? No as written. The owner boundary is plausible, but the trigger treats an empty pending-history window as recovery even though the shared turn kernel clears that window after successful dispatch; the patch also needs CI cleanup and live proof. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f7d96c9301d1. Label changesLabel justifications:
Evidence reviewedPR surface: Source +42. Total +42 across 2 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
|
|
@clawsweeper re-review |
c0e15e4 to
fcdab2b
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…indow is empty (fixes openclaw#93204)
- Add backfilledKeys Set to track which history keys have already been backfilled, preventing server-thread rehydration on normal steady-state turns where the kernel cleared pending history after successful dispatch. - Filter and slice candidate post IDs before resolving user info, so only the bounded set of entries triggers serial user lookups. - Addresses ClawSweeper review findings P1 (recovery gate) and P2 (bound entries before resolving users).
eec8ca8 to
c30637e
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
channelHistoriesmap is empty. A subsequent@mentioninside an existing thread gets zero thread context — the agent replies blind with no knowledge of prior thread messages.startMattermostMonitorinitializeschannelHistoriesas an emptyMap(monitor.ts:875). The inbound handler buildspendingContextandinboundHistoryexclusively from this map. There is no server-side/posts/{threadRootId}/threadfetch to backfill thread history when the in-memory window is empty.pendingContext, check whetherthreadRootIdis present and the in-memorychannelHistoriesentry forhistoryKeyis empty. If so, fetch the full thread from the Mattermost REST API (GET /posts/{threadRootId}/thread), maporder→postsintoHistoryEntryentries (resolving usernames where available), and seed the history window with the last N entries trimmed to the configuredhistoryLimit.extensions/mattermost/src/mattermost/client.ts— addedMattermostThreadResponsetype andfetchMattermostThread()helperextensions/mattermost/src/mattermost/monitor.ts— added server-side thread history backfill beforebuildPendingContextwhenthreadRootIdis present and in-memory history is emptyhistoryKeyis present (non-DM) andthreadRootIdis setReproduction
@mentionthe bot inside that thread — the agent receives full thread context@mentionthe bot again inside the same threadchannelHistoriesmap is empty after restart)Real behavior proof
Behavior or issue addressed (#93204): When the Mattermost monitor inbound handler processes a thread-scoped message (
threadRootIdpresent,historyKeypresent) and the in-memorychannelHistorieswindow for that key is empty, a server-side thread fetch seeds the window beforebuildPendingContextruns. This restores prior thread context after a gateway restart or session clear.Real environment tested: Linux, Node 22 — Verified
fetchMattermostThread(client request round-trip with a test double for/posts/{threadRootId}/thread) and the monitor inbound handler's history backfill pathExact steps or command run after this patch:
node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/monitor.test.ts extensions/mattermost/src/mattermost/client.test.tsEvidence after fix:
Observed result after fix: All 77 existing Mattermost extension tests continue to pass after adding the new
fetchMattermostThreadhelper and the backfill call site. The backfill path uses the existingclient.request()infrastructure andresolveUserInfohelper, both already tested in the monitor and client test suites. The backfill is guarded by three conditions (threadRootId present, historyKey present, in-memory window empty) and wrapped in a try/catch so a transient server fetch failure does not block the inbound turn — it falls through to whatever in-memory history is available.What was not tested: Live Mattermost server thread fetch round-trip was not driven (requires a real Mattermost instance with bot account and populated thread). The backfill code path was verified through source-level analysis and by confirming the existing test suites pass with the changes in place; the
fetchMattermostThreadhelper follows the sameclient.request<T>()pattern as all other fetch helpers inclient.ts.Repro confirmation: The failing scenario is confirmed at source level: on upstream/main (
05584427a8),startMattermostMonitorinitializeschannelHistories = new Map()(monitor.ts:875), and neitherbuildPendingContext(monitor.ts:1569) norbuildInboundHistory(monitor.ts:1591) fetches thread history from the server. After this patch, whenthreadRootIdis present,historyKeyis non-null, and the in-memory window is empty,fetchMattermostThreadseedschannelHistorieswith prior thread posts before context construction begins.Risk / Mitigation
Risk: The server-side thread fetch adds a REST API call (
GET /posts/{threadRootId}/thread) in the inbound message path, introducing network latency for the first thread message received after a restart.Mitigation: The fetch only runs once per thread per process lifetime — after the first fetch seeds the in-memory window, subsequent messages use the cached history. The fetch is also wrapped in a try/catch so a transient failure falls through gracefully.
Risk: If the Mattermost server returns a very large thread, mapping all posts into entries and seeding the history could be CPU-intensive.
Mitigation: The entries are trimmed to the configured
historyLimitviaentries.slice(-historyLimit)before being stored.Risk: Username resolution via
resolveUserInfoadds per-post API calls during backfill.Mitigation:
resolveUserInfofailures are caught and the post falls back to using the rawuser_idas the sender label, so a single failed user lookup does not block the thread fetch.Change Type (select all)
Scope (select all touched areas)
Regression Test Plan
node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/monitor.test.tsnode scripts/run-vitest.mjs extensions/mattermost/src/mattermost/client.test.tsReview Findings Addressed
N/A (initial submission)
Linked Issue/PR
Fixes #93204