Skip to content

fix(channels): attachment filenames disappear from model context - #129140

Merged
steipete merged 4 commits into
mainfrom
codex/issue-128956
Aug 25, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/issue-128956

Conversation

@steipete

@steipete steipete commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #128956

What Problem This Solves

Fixes an issue where users sending documents through Discord, Mattermost, Slack, or Telegram would find that their agent could not identify the original attachment filename when inbound files were saved under opaque local names. A related Telegram cache boundary also unintentionally allowed a downloaded file's local host path to enter its stored cache payload.

Why This Change Was Made

Preserve authoritative filenames only after attachment download succeeds, carry that fact through the shared inbound-media boundary and all relevant Telegram message/reply relays, and render a bounded, sanitized basename in the existing model-visible attachment note. At the Telegram cache owner, project away only the transient filename and previously leaked local host path before storage; preserve all historically accepted partial attachment shapes and retain the existing strict parser exclusively at durable hydration, without changing schemas, history projections, template variables, or persisted canonical fields.

User Impact

Agents can refer to a successfully received attachment by its real name across all four affected messaging channels. Rejected or failed attachments still disclose no untrusted filename; malicious filenames cannot inject prompt lines, expose path components, or grow the bounded attachment note. Telegram's durable cache keeps only its existing canonical metadata.

Evidence

Before the fix, the original operator scenario supplied filename jj.txt but produced only [media attached: /tmp/opaque (application/octet-stream)]. After the fix, the actual shared owner produces [media attached: /tmp/opaque (application/octet-stream) "jj.txt"].

The shared prompt-renderer, inbound-media owner, primary and referenced-reply Discord transport owners, Telegram album and persisted-media owners, retained Telegram reply hydration, and Discord preflight owner pass: 187 tests across eight files.

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/auto-reply/media-note.test.ts src/channels/inbound-event/media.test.ts --maxWorkers=1
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/discord/src/monitor/message-media.test.ts --maxWorkers=1
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/discord/src/monitor/message-media.references.test.ts --maxWorkers=1
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/telegram/src/message-cache.test.ts --maxWorkers=1 -t 'persists resolved media with its source message'
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/telegram/src/bot.create-telegram-bot.channel-post-media.test.ts --maxWorkers=1
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/telegram/src/bot.test.ts --maxWorkers=1 -t 'hydrates allowlisted group reply'
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs extensions/discord/src/monitor/message-handler.preflight.test.ts --maxWorkers=1 -t 'downloads attachments during preflight'

A direct source-import scenario exercised the real createTelegramMessageCache owner and its actual persistentStore.register payload, then verified prompt rendering and hydration:

{"verdict":"PASS","storedKeys":["id","fileUniqueId","size","savedAt","kind","contentType"],"storedLeaksPath":false,"storedLeaksFileName":false,"prompt":"[media attached: media://inbound/saved-report.pdf (application/pdf) \"quarterly-report.pdf\"]","hydratedId":"saved-report.pdf"}

Additional regression coverage spans original-name propagation in Discord, Mattermost, Slack, and Telegram; Telegram's direct, album, and reply paths; failed-download suppression; prompt basename sanitization, control-character removal, attachment numbering, and bounded length; and the exact raw persisted Telegram payload. The entire Telegram album-owner suite passes 42/42; the real allowlisted retained-reply case verifies canonical media://inbound/ hydration, not a private local host path; the exact Telegram persistent-row owner regression passes 1/1; and the successful Discord preflight filename case passes 1/1. An earlier broader Telegram invocation was externally terminated under unrelated host pressure before assertions; all affected named owner paths have since passed genuinely. Exact-head hosted CI must cover the broader affected suites before landing. Live external-channel roundtrips across all four services were infeasible without preconfigured authenticated test-channel sessions; the changed transport-owner and persisted-store boundaries were exercised directly instead.

Production delta: +56/-26, net +30 across four channel producer boundaries and the canonical privacy-preserving cache projection. Tests: +114/-13. Scope: 24 coherent source/test files. No new dependency, config, breaking public API, template surface, or persistent-store schema.

@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.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost channel: slack Channel integration: slack channel: telegram Channel integration: telegram size: M maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 08:03
@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 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 25, 2026, 4:40 AM ET / 08:40 UTC.

ClawSweeper review

What this changes

The PR carries original inbound attachment filenames through shared media facts and channel adapters so agent prompts can identify attachments by name.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the branch fixes current-turn filename rendering but still drops a hydrated Telegram reply attachment filename before the reply-chain context reaches the model.

Priority: P2
Reviewed head: 767950932363e206bdcbfa968bf31f2315d55a43

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch covers the primary current-turn flow but misses a claimed retained-reply path and needs Telegram behavior evidence.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 4 items Reply hydration has a filename: The new retained-media helper derives a Telegram document/audio/video/animation filename and adds it to the transient media reference.
Reply-chain projection drops it: The reply-chain entry copies path, kind, and content type but no fileName, then reply context is rebuilt from that projection.
Current main still lacks the underlying renderer: Current main renders media notes from path, URL, and type only; it has not already solved the requested filename behavior.
Findings 1 actionable finding [P1] Carry filenames into the Telegram reply-chain projection
Security None None.

How this fits together

Channel attachments are downloaded and normalized into media facts before being rendered into model context. Telegram also rehydrates retained media for replies through a separate transient reply-chain projection.

flowchart LR
A[Channel attachment] --> B[Download and media metadata]
B --> C[Inbound media fact]
C --> D[Current-turn prompt note]
B --> E[Telegram retained reply hydration]
E --> F[Reply-chain projection]
F --> G[Reply context for model]
Loading

Before merge

  • Carry filenames into the Telegram reply-chain projection (P1) - resolveRetainedTelegramMedia now supplies fileName, but toReplyChainEntry only projects path, kind, and type. Because reply context prefers visibleReplyChain, a successfully hydrated reply to a document still reaches the model without its original name. Preserve the transient filename in that projection and add a retained-reply assertion; keep the durable cache exclusion intact.
  • Resolve merge risk (P1) - The claimed Telegram reply-to-document behavior lacks redacted real Telegram proof required by the applicable Telegram policy.
  • Complete next step (P2) - The remaining reply-chain omission is a focused repair with a clear owner boundary and regression target; contributor proof remains required before merge.

Findings

  • [P1] Carry filenames into the Telegram reply-chain projection — extensions/telegram/src/bot-handlers.message-pipeline.ts:162
Agent review details

Security

None.

PR surface

Source +30, Tests +101. Total +131 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 13 56 26 +30
Tests 11 114 13 +101
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 170 39 +131

Review metrics

Metric Value Why it matters
Production versus tests production +56/-26 (net +30), tests +114/-13 The positive production growth is justified by cross-channel filename propagation, but the retained Telegram reply projection remains incomplete.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/telegram/src/bot/delivery.resolve-media.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128956
Summary: This PR is the candidate fix for the canonical inbound attachment filename issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Mantis proof suggestion

Telegram Desktop evidence would materially demonstrate the user-visible named-document reply behavior. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis verify via Telegram Desktop that replying to a named document preserves the filename in the agent's resulting context or response, and return redacted proof.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Carry the already-hydrated filename through Telegram’s transient reply-chain projection without persisting it in the message cache, then demonstrate a named-document reply end to end.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Carry the already-hydrated filename through Telegram’s transient reply-chain projection without persisting it in the message cache, then demonstrate a named-document reply end to end.

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

Yes from source: a retained Telegram reply carries fileName into mediaRef, but the reply-chain projection omits it before model context is built.

Is this the best way to solve the issue?

No: the current branch preserves the filename during hydration but loses it at the reply-chain owner boundary.

Full review comments:

  • [P1] Carry filenames into the Telegram reply-chain projection — extensions/telegram/src/bot-handlers.message-pipeline.ts:162
    resolveRetainedTelegramMedia now supplies fileName, but toReplyChainEntry only projects path, kind, and type. Because reply context prefers visibleReplyChain, a successfully hydrated reply to a document still reaches the model without its original name. Preserve the transient filename in that projection and add a retained-reply assertion; keep the durable cache exclusion intact.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 15e8a6098468.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • add mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The change affects whether agents can identify documents in Telegram conversations, which is directly demonstrable in chat.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: A bounded attachment-identification bug remains on a claimed Telegram reply path.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The change affects whether agents can identify documents in Telegram conversations, which is directly demonstrable in chat.

Evidence

Acceptance criteria:

  • [P1] pnpm test extensions/telegram/src/bot-message-context.media-carriers.test.ts.
  • [P1] pnpm test extensions/telegram/src/message-cache.test.ts.
  • [P1] pnpm test src/auto-reply/media-note.test.ts.

What I checked:

Likely related people:

  • steipete: Available blame attributes the current main media-note formatter to Peter Steinberger; this PR also works in that area. (role: recent area contributor; confidence: medium; commits: 8c5a12c112e6; files: src/auto-reply/media-note.ts)

Rank-up moves

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

  • Preserve filename through the retained Telegram reply-chain projection and add a model-context regression assertion.
  • Provide redacted Telegram proof for replying to a named document, including the observed post-fix context or response.

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-25T08:09:23.168Z sha e8eec5c :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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
@openclaw-mantis

openclaw-mantis Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Mantis Telegram proof — PASS

Summary: A real Telegram user uploaded mantis-quarterly-report-2026.txt and asked for its exact original filename on both exact revisions. Main sent only a generated staged filename to the provider; the candidate additionally sent the bounded authoritative filename "mantis-quarterly-report-2026.txt". Telegram Desktop recorded the baseline inability and candidate success. The candidate cache row's resolvedMedia projection contained id, size, contentType, kind, fileUniqueId, and savedAt, with no transient path or fileName.

  • Scenario: Start each exact SUT with a deterministic mock provider, upload the same 114-byte text document as the real leased Telegram user with the caption 'What is the exact original filename of the attached document? Answer with the filename only.', inspect the provider-bound user context, inspect Telegram Desktop, and on the candidate inspect the persisted Telegram message-cache row before finalizing both recordings.
  • Trigger: clawsweeper_label
  • Run: https://github.com/openclaw/openclaw/actions/runs/32827966608
  • Artifact: https://github.com/openclaw/openclaw/actions/runs/32827966608/artifacts/9556491121
  • Baseline: pass at e5cc19185ba356bdff0c7ff9d9c66b19b05abe49 — The upload and question were delivered as Telegram document message 50850. The provider request rendered only the generated staged name mantis-quarterly-report-2026---.txt in the media note and file payload, without a separate exact original filename. Telegram message 50851 visibly reported that the original filename could not be identified.
  • Candidate (PR merged onto main): pass at 3334528a922dd2fa4cf1a929e2ba3793a8fd8083 — The identical upload and question were delivered as Telegram document message 50852. The provider request's attachment note ended with the explicit authoritative suffix "mantis-quarterly-report-2026.txt". Telegram message 50853 visibly identified that exact filename. The live SQLite cache row retained normal source-message metadata, while resolvedMedia omitted both path and fileName.
  • Differential (trusted facts): The same real-user document and caption on attested main e5cc191 lacked the exact original-name fact, while attested candidate 3334528a922dd2fa4cf1a929e2ba3793a8fd8083 added it to the provider-bound attachment note and produced the intended visible answer. The persisted candidate projection also demonstrates that propagating the runtime filename did not retain the transient local path/name in resolvedMedia.
  • Overall: pass
Before — current main After — this PR
baseline previewGifCropped candidate previewGifCropped

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-visible/pr-129140/run-32827966608-1/index.json

@steipete
steipete merged commit c5d1cb3 into main Aug 25, 2026
429 of 431 checks passed
@steipete
steipete deleted the codex/issue-128956 branch August 25, 2026 09:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…nclaw#129140)

* fix(channels): preserve inbound attachment filenames

Fixes openclaw#128956

* test(discord): verify names on successfully downloaded media

* test(discord): verify referenced attachment filenames

* fix(telegram): preserve accepted resolved-media shapes
steipete added a commit that referenced this pull request Aug 26, 2026
* fix(mattermost): keep server file name when the download fails

#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]>
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: discord Channel integration: discord channel: mattermost Channel integration: mattermost channel: slack Channel integration: slack channel: telegram Channel integration: telegram maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inbound attachment prompt note never includes the file name — MediaFact.fileName exists but is not rendered, and the Mattermost plugin never sets it

1 participant