Skip to content

improve(mattermost): speed up inbound direct-message replies - #128431

Merged
steipete merged 2 commits into
mainfrom
codex/perf-mattermost-inbound-channel-current
Aug 24, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-mattermost-inbound-channel-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where inbound Mattermost direct-message replies would rediscover a channel already identified by the inbound event, adding GET /users/me and POST /channels/direct before every cold reply.

Why This Change Was Made

Inbound reply delivery now uses the authoritative provider channel ID carried by Mattermost post, interaction, model-picker, pairing, and slash-command events. Semantic DM routing remains user-based for sessions and last-route storage, while generic proactive user: sends retain their existing DM resolution, cache, and retry behavior.

The reply-only DM-resolution observer and extended admission barrier are removed because inbound delivery no longer performs that resolution.

User Impact

Mattermost DM replies avoid two unnecessary provider requests on a cold route, reducing latency and server work without changing reply text, media, threading, receipts, routing identity, or retry semantics.

Evidence

  • Provider-loopback regression: inbound DM reply makes only POST /api/v4/posts with the prepared channel ID and unchanged message payload.
  • Focused owner/sibling proof: 7 files / 89 tests passed; final send/client/loopback rerun: 3 files / 69 tests passed.
  • Full Mattermost extension: 51 files / 751 tests passed.
  • node scripts/check-changed.mjs: passed (extensions, extensionTests), including format, production/test typechecks, type-aware Oxlint (0 warnings/errors), dead exports, plugin boundaries, guards, and import cycles.
  • Structured autoreview: TruffleHog clean; Codex gpt-5.6-sol / high reported no findings and patch is correct (0.98 confidence).
  • git diff --check: clean.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: M maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 00:57
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 9:25 PM ET / August 24, 2026, 01:25 UTC.

ClawSweeper review

What this changes

The PR sends Mattermost inbound replies to the channel ID already present in each inbound event, avoiding cold direct-message channel lookup requests.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding: the PR carries the inbound Mattermost channel ID to reply delivery while preserving user-based session routing. It remains open for protected maintainer handling and exact-head refresh because GitHub reports the branch behind current main.

Priority: P2
Reviewed head: ec85633aa0e984e170b8c4d77d389e4668ae9bd5
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative owner-boundary simplification with a direct client-loopback regression; only exact-head integration remains.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless reports a post-fix Mattermost-client loopback regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless reports a post-fix Mattermost-client loopback regression.
Evidence reviewed 6 items Current-main inefficiency: Current main keeps a direct event's semantic target as user:<sender>, and cold user targets resolve the bot user then create a direct channel before posting.
Prepared-target repair: The PR's reply-delivery owner now always emits channel:<channelId>, and the inbound-turn caller supplies the event-plan channel ID.
Existing proactive behavior retained: Explicit channel targets return immediately, while only user targets perform bot-user and direct-channel resolution, so generic proactive user sends retain their prior path.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128431-NnzKJq/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 118.68 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 14.6s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4023ms (slowest: built plugin control-plane loads 3350ms)

OpenClaw 2026.8.1 (ec85633) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Mattermost events are authorized and routed into an OpenClaw reply turn, then the plugin posts the resulting reply through Mattermost. Session routing retains the sender-based direct-message identity, while reply delivery uses the physical inbound channel ID.

flowchart LR
  A[Mattermost inbound event] --> B[Authorization and event plan]
  B --> C[Session route from sender]
  B --> D[Prepared channel ID]
  C --> E[Reply turn]
  D --> F[Reply delivery]
  E --> F
  F --> G[Mattermost post API]
Loading

Decision needed

Question Recommendation
Should this protected maintainer PR merge the prepared inbound-channel reply path after its exact-head rebase and required checks complete? Merge after exact-head refresh: Rebase or refresh the branch and merge once the required checks validate the prepared-channel delivery path on the resulting head.

Why: The change is technically coherent, but the maintainer label requires an explicit human merge decision after the current-main integration refresh.

Before merge

  • Resolve merge risk (P1) - GitHub reports this branch behind current main, so the three-way merge result and required CI need refresh on the exact head before landing.
Agent review details

Security

None.

PR surface

Source -131, Tests -85. Total -216 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 9 51 182 -131
Tests 8 92 177 -85
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 143 359 -216

Review metrics

Metric Value Why it matters
Production versus test LOC production +51/-182 (net -131); tests +92/-177 (net -85) The change removes direct-channel resolution and its settlement machinery while retaining focused endpoint and caller coverage.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/mattermost/src/mattermost/send.test.ts, serialized state: extensions/mattermost/src/channel.send-loopback.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase or refresh against current main, then land the single prepared-channel reply path once exact-head checks confirm the current merge result.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase or refresh against current main, then land the single prepared-channel reply path once exact-head checks confirm the current merge result.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: direct inbound events retain user:<sender> for routing, and a cold user send takes the bot-user/direct-channel-resolution branch before posting.

Is this the best way to solve the issue?

Yes: carrying the already-prepared inbound channel ID to the reply-delivery owner removes duplicate lookup without changing session identity or generic proactive user sends.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 19d44d3f38bf.

Labels

Label justifications:

  • P2: This is a bounded Mattermost direct-message latency regression on current main without evidence of data loss, security bypass, or availability loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nonetheless reports a post-fix Mattermost-client loopback regression.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the direct event-plan target and related send path to his August 23 work; he also led the Mattermost event-plan refactor. (role: current feature owner; confidence: high; commits: a3e69b2ba082, 4301ca983168; files: extensions/mattermost/src/mattermost/monitor-event-plan.ts, extensions/mattermost/src/mattermost/send.ts)
  • Josh Avant: His July 29 Mattermost settlement repair introduced the closely related reply-delivery barrier being removed once direct-channel resolution no longer occurs on inbound replies. (role: recent delivery-lifecycle contributor; confidence: medium; commits: 545350488a07; files: extensions/mattermost/src/mattermost/reply-delivery.ts, extensions/mattermost/src/mattermost/monitor-turn.ts)
  • Vincent Koc: The supplemental interaction-route conflict change aligns with his HTTP route conflict handling work. (role: adjacent route-ownership contributor; confidence: medium; commits: 21a767639fa0; files: src/plugins/http-registry.ts, extensions/mattermost/src/mattermost/monitor-interactions.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase or refresh the exact merge head and let its required CI finish green.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-24T01:03:33.255Z sha 98b3e55 :: needs maintainer review before merge. :: none

Copy link
Copy Markdown
Contributor Author

Exact-head land-ready disposition for ec85633aa0e984e170b8c4d77d389e4668ae9bd5:

  • Exact-head CI is green in run 32679419777, including the extension-package boundary and all required checks.
  • The earlier precise-path scan failure was resolved by removing replaceExisting from the account-scoped interaction route. Exact-head Opengrep is green; duplicate or canonical-alias route conflicts still fail before websocket startup through the retained throwOnFailure behavior.
  • ClawSweeper exact-head review run 32679428289 completed with no correctness or security findings. Its live CLI proof passed and observed Usage: from pnpm openclaw --help.
  • GitHub's “behind” status is not itself a conflict. Native prepare intentionally did not rebase, verified the remote PR head against the local prep head, and passed exact-head hosted gates in hosted_exact_or_recent_parent mode. The native merge gate remains responsible for enforcing current mergeability.
  • ClawSweeper's stored-data-model classification is a filename-based false positive from touched test files. This patch changes no persisted schema, serialized state, storage behavior, or migration surface.
  • No credentialed Mattermost mutation was performed. The provider gap is covered by a real-client loopback regression proving that inbound direct replies issue only POST /api/v4/posts with the prepared inbound channel, plus the full Mattermost extension suite (51 files / 751 tests).
  • Exact-head Codex autoreview (gpt-5.6-sol, high reasoning) is clean: no findings, patch correct at 0.97 confidence. TruffleHog preflight was also clean.
  • Representative cold-DM proof: 40 replies reduced provider requests from 120 to 40 (−66.7%) and elapsed time from 580.0 ms to 287.7 ms (−50.4%), while preserving sender-based session identity and generic proactive user: resolution.

Review recommendation: READY FOR /prepare-pr

Issue status: valid

@steipete
steipete merged commit 24c4637 into main Aug 24, 2026
102 checks passed
@steipete
steipete deleted the codex/perf-mattermost-inbound-channel-current branch August 24, 2026 01:39

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants