Skip to content

fix(mattermost): keep server file name when the download fails - #129556

Merged
steipete merged 3 commits into
openclaw:mainfrom
goffern:fix/mattermost-file-info-name
Aug 26, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
goffern:fix/mattermost-file-info-name

Conversation

@goffern

@goffern goffern commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

#129140 made attachment file names reach the model context, but only on the successful-download path. The failed-download fallback in extensions/mattermost/src/mattermost/monitor-resources.ts already calls GET /files/{id}/info and keeps mime_type while discarding the name the same response carries. On exactly the branch where the model gets no local file, the server-side file name is the only context available about the attachment — and it was dropped, reproducing the symptom #129140 fixed.

Why This Change Was Made

Read name from the /files/{id}/info response that is already being fetched (zero additional requests) and forward it the same way the success path forwards saved.fileName; blank names stay omitted rather than becoming empty strings. The success path is untouched: it gets the name from the download response, which the server populates from the same stored FileInfo.

Production LOC is +7/−2, confined to the existing fallback block.

User Impact

When a Mattermost attachment cannot be downloaded (size cap, transient failure), the model now still sees the attachment's real file name alongside its type, instead of an anonymous [attachment unavailable] fact.

Evidence

Environment: real Mattermost (mattermost/mattermost-preview Docker) on a throwaway EC2; checkout c94b0bd92d; runs via node scripts/run-vitest.mjs.

1. Regression test fails on pre-fix code — the existing "keeps partial download failures aligned with native media metadata" test already mocked /files/{id}/info returning a name; asserting the name is now forwarded fails on stock main:

FAIL  mattermost monitor resources > keeps partial download failures aligned with native media metadata
Tests  1 failed | 17 passed (18)

2. Branch: monitor-resources.test.ts 18/18 green.

3. Live BEFORE/AFTER — real upload, real failed download, real /files/{id}/info: uploaded quarterly report final.pdf to a real channel, forced the download to fail with mediaMaxBytes: 1 (the real saveRemoteMedia starts the download and rejects on size), letting the real fallback branch hit the live server:

BEFORE (stock main):
{"proof":"file-info-name-live","phase":"before","uploadedName":"quarterly report final.pdf",
 "downloadFailed":true,"fact":{"contentType":"application/pdf","kind":"document"}}

AFTER (this branch):
{"proof":"file-info-name-live","phase":"after","uploadedName":"quarterly report final.pdf",
 "downloadFailed":true,"fact":{"contentType":"application/pdf","fileName":"quarterly report final.pdf","kind":"document"}}

Stock main returns the fact without a name; the branch returns fileName: "quarterly report final.pdf" from the live server metadata.

openclaw#129140 propagates the attachment file name into the model context, but
only on the successful-download path. The failed-download fallback
already calls /files/{id}/info and reads mime_type while discarding the
name the same response carries — and on that branch the name is the only
context the model gets about the attachment, since there is no local
file. Read it and forward it like the success path does; blank names
stay omitted.
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@goffern
goffern marked this pull request as ready for review August 25, 2026 19:02
@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: XS labels Aug 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 12:15 AM ET / 04:15 UTC.

ClawSweeper review

What this changes

The PR preserves sanitized server-provided filenames in Mattermost’s unavailable-attachment notice when a download fails.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking findings. This PR still addresses a current-main omission: Mattermost’s failed-download fallback obtains file metadata but drops its name before constructing the agent-visible unavailable-attachment notice.

Priority: P2
Reviewed head: 63908e49435dd685f92ff393103e366b17269737

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real-service evidence and owner-boundary coverage support a focused repair with no actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes a real Mattermost Docker before/after run showing a failed download now produces the server filename in the fallback fact.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes a real Mattermost Docker before/after run showing a failed download now produces the server filename in the fallback fact.
Evidence reviewed 7 items Current-main gap: Current main’s failed-download branch reads only mime_type and pushes a nameless fact, while its unavailable notice has no filename component.
Owner-boundary repair: The branch preserves name from the already-fetched file-info response and sanitizes plus bounds it before appending it to the unavailable notice.
Caller and dispatch boundary: The post handler passes resolved media through the formatter for BodyForAgent and separately emits the same ordered media facts into the finalized inbound context.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/monitor-resources.test.ts extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/monitor-resources.test.ts extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/monitor-resources.test.ts extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts"

[test] starting test/vitest/vitest.extension-mattermost.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129556-s1PMeQ/target

 ✓  extension-mattermost  extensions/mattermost/src/mattermost/monitor-resources.test.ts (21 tests) 27922ms
     ✓ times out inbound media downloads when response headers never arrive  565ms

Assertions:

  • FAIL expect_output: Test Files

How this fits together

Mattermost inbound posts resolve attachments before dispatching an agent turn. A failed download falls back to the Mattermost file-info response, then the plugin renders a bounded notice into the agent body and structured media context.

flowchart LR
  A[Mattermost post] --> B[Attachment resolver]
  B --> C{Download succeeds?}
  C -->|Yes| D[Saved media metadata]
  C -->|No| E[Server file metadata]
  D --> F[Inbound agent context]
  E --> G[Sanitized unavailable notice]
  G --> F
  F --> H[Agent turn]
Loading

Before merge

  • Resolve merge risk (P2) - Production code grows by 12 net lines to sanitize and bound newly model-visible fallback metadata; that growth is justified by the owner-boundary repair and focused boundary coverage.
  • Resolve merge risk (P1) - DNS prevented an independent upstream Mattermost API-document lookup; the PR’s real-server before/after proof supports the observed name field, but exact-head CI should still finish before merge.
  • Complete next step (P2) - No discrete repair remains; this is a normal maintainer merge decision after the exact-head checks complete.
Agent review details

Security

None.

PR surface

Source +12, Tests +72. Total +84 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 5 +12
Tests 2 125 53 +72
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 142 58 +84

Review metrics

Metric Value Why it matters
Production versus test LOC production +17/-5 (net +12); tests +125/-53 (net +72) The added production code is confined to existing fallback metadata and bounded prompt rendering; tests cover both the producer and posted-event dispatch boundary.

Stored data model

Persistent data-model change detected: serialized state: extensions/mattermost/src/mattermost/monitor-resources.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the bounded owner-plugin repair once the exact head is green; retain the existing no-extra-request fallback and its sanitization and dispatch-boundary coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the bounded owner-plugin repair once the exact head is green; retain the existing no-extra-request fallback and its sanitization and dispatch-boundary coverage.

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

Yes. The PR provides a concrete current-main failure path using a real Mattermost upload plus forced size-cap download failure, and current-main source confirms the fallback discards the returned name.

Is this the best way to solve the issue?

Yes. The repair keeps the existing metadata request, records the name at the fallback producer, and renders it only through the established bounded unavailable-media notice.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3e0d9a6fd2df.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: The PR fixes bounded Mattermost attachment context loss when a download fails, without evidence of broader delivery or availability impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes a real Mattermost Docker before/after run showing a failed download now produces the server filename in the fallback fact.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a real Mattermost Docker before/after run showing a failed download now produces the server filename in the fallback fact.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the earlier unavailable-media failure path and is the current-main blame owner for the omitted-name branch; also refreshed the reviewed branch. (role: feature owner and recent area contributor; confidence: high; commits: 73fc0f5c5fa3, 1c1eeedb9685; files: extensions/mattermost/src/mattermost/monitor-resources.ts, extensions/mattermost/src/mattermost/monitor-posts.ts)

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 (2 earlier review cycles)
  • reviewed 2026-08-25T19:08:38.808Z sha b1626b9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-26T03:16:49.077Z sha 2894d55 :: needs maintainer review before merge. :: none

Preserve server-provided attachment names through the Mattermost-owned unavailable-media notice, safely bound model-visible metadata, and cover the actual posted-event dispatch boundary.

Co-authored-by: goffern <[email protected]>
Inherit the maintainer-repaired Control UI startup baseline while preserving the reviewed Mattermost attachment filename repair and end-to-end regression coverage unchanged.

Co-authored-by: goffern <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification for exact signed head 63908e4: the complete Mattermost failed-download path now reaches the actual model. Existing authenticated file-info metadata flows through the Mattermost-owned, sanitized, JSON-quoted, 512-unit-bounded unavailable notice into BodyForAgent; unavailable facts remain non-hydratable. Anonymous, plural, mixed, blank, malicious, and actual posted-websocket cases are covered. Original contributor @goffern remains credited.

Proof: real Mattermost Docker upload plus forced size-cap failure and authenticated file-info request; isolated owner suite passed 21/21 twice; exact CI 32929115262 succeeded; exact Workflow Sanity 32929115225 succeeded; trusted formatting/lint and separate full-branch plus independent final reviews clean. Production net +12 provides genuinely model-visible context and bounded untrusted-input handling. An initial unrelated UI gzip failure was just three bytes over its prior limit; the signed branch refresh inherited the already-merged canonical baseline repair without adding UI changes. Ready for native maintainer merge.

@steipete
steipete merged commit 632343e into openclaw:main Aug 26, 2026
106 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…law#129556)

* fix(mattermost): keep server file name when the download fails

openclaw#129140 propagates the attachment file name into the model context, but
only on the successful-download path. The failed-download fallback
already calls /files/{id}/info and reads mime_type while discarding the
name the same response carries — and on that branch the name is the only
context the model gets about the attachment, since there is no local
file. Read it and forward it like the success path does; blank names
stay omitted.

* fix(mattermost): surface unavailable attachment filenames to agents

Preserve server-provided attachment names through the Mattermost-owned unavailable-media notice, safely bound model-visible metadata, and cover the actual posted-event dispatch boundary.

Co-authored-by: goffern <[email protected]>

---------

Co-authored-by: goffern <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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