Skip to content

fix(agents): dir_fetch attachments are dropped while the tool says they were sent - #144609

Closed
igs-rogenlo wants to merge 1 commit into
openclaw:mainfrom
igs-rogenlo:fix/dir-fetch-trusted-local-media
Closed

igs-rogenlo wants to merge 1 commit into
openclaw:mainfrom
igs-rogenlo:fix/dir-fetch-trusted-local-media

Conversation

@igs-rogenlo

Copy link
Copy Markdown
Contributor

Fixes #138383.

What Problem This Solves

dir_fetch builds details.media.mediaUrls from local gateway paths, caps the list at 25, and returns a summary saying the channel attaches the first 25. Nothing attaches them.

filterToolResultMediaUrls reduces an untrusted tool's media to http(s) entries. dir_fetch emits filesystem paths, so the list empties on every call and embedded-agent-subscribe.handlers.tools.results.ts returns before queuePendingToolMedia. The tool text has already been emitted by then, so the model is handed a false statement and relays it. No warning, nothing logged, attachment count 0.

Why This Change Was Made

The mechanism for this already exists on both ends, and nothing connects them.

  • setManifestPluginToolMeta (src/plugins/tools.ts) marks a bundled plugin tool trustedLocalMedia when the manifest's contracts.tools declares it. extensions/file-transfer/openclaw.plugin.json declares dir_fetch.
  • filterToolResultMediaUrls already accepts a run-local trustedLocalMediaToolNames set, and a name in it is trusted for local media.

No production caller populates that set — only embedded-agent-subscribe.e2e-harness.ts does. The metadata is computed, the consumer is wired, and the value in between is permanently undefined.

This collects the set where the run's tool surface is already assembled (attempt-client-tools.ts, next to coreBuiltinToolNames) and threads it through attempt-execution-phase → attempt-stream-prepare → the subscription, which already forwards params.trustedLocalMediaToolNames.

collectTrustedLocalMediaToolNames takes names from two sources and no others:

  1. The core allowlist, matched exactly as isCoreToolResultMediaTrustedName matches it today — so every tool trusted before this change is still trusted, and this half is not a widening.
  2. Tools whose plugin metadata carries the bundled contract's trustedLocalMedia mark.

Forwarding the whole builtin set — what the e2e harness does as its fallback — would have granted local-media trust to every registered tool including MCP tools, which is the boundary the set exists to hold.

TRUSTED_TOOL_RESULT_MEDIA is untouched. #101434 moved this project away from widening that Set, and #120718 ruled on the delivery mechanism. Neither is reopened here, and the issue explicitly asked for neither.

Alias behaviour is deliberately unchanged. Supplying a defined set activates filterToolResultMediaUrls's exact-raw-name branch, and the set is built so every name trusted today passes it. Tightening that gate for core names would change behaviour for bash, cron and apply-patch — a separate decision that does not belong in a delivery fix.

User Impact

An agent that runs dir_fetch to bring back a directory of images, logs or exported reports for a person to look at now has those files attached, which is what the tool already told the model would happen. file_fetch, dir_list and file_write are declared in the same manifest contract and are covered by the same collection.

Nothing changes for any other tool: unmarked plugin tools and MCP tools keep being filtered to http(s), and core tools behave exactly as before.

Evidence

The defect and the fix are both pinned at the two boundaries the report names.

At the filter (embedded-agent-subscribe.tools.media.test.ts) — this is repro A from the issue, which needs neither node pairing nor a policy grant:

filterToolResultMediaUrls("dir_fetch", ["/tmp/run/report.png"], undefined, undefined) -> []
filterToolResultMediaUrls("dir_fetch", ["/tmp/run/report.png"], undefined, collected)  -> ["/tmp/run/report.png"]

At the delivery boundary (embedded-agent-subscribe.handlers.tools.media.test.ts), driving handleToolExecutionEnd with a dir_fetch result carrying two local paths:

run's trusted set state.pendingToolMediaUrls tool text emitted
absent [] yes — including the "channel attaches first 25" claim
{dir_fetch} ["/tmp/run/a.png", "/tmp/run/b.png"] yes

The second row is the contradiction closing: the summary and the attachments finally agree.

The collector is covered directly: both sources included, unmarked plugin tools excluded, dir_list without the mark excluded, unnamed tools ignored, and core tools (exec, read) still trusted once a run supplies its exact set — that last one is the regression guard for turning the set on at all.

The wiring is pinned in attempt-client-tools.test.ts: a run holding a marked dir_fetch, an unmarked MCP tool and exec exposes exactly {dir_fetch, exec}, so dropping the call site fails a test rather than silently restoring the bug.

Checks

  • branched from d331583bbf0
  • the four suites named as acceptance criteria on the issue: attempt-client-tools 16, attempt-stream-prepare + dir-fetch-tool 43, handlers.tools.media 32, tools.media 46 — all passing
  • tsgo -p tsconfig.json: no errors in src/agents; the pre-existing scripts/** and extensions/qa-lab/** errors on that project are untouched by this branch
  • oxlint and oxfmt --check: clean on all seven changed files

Open questions

  • The issue offered three consistent end states and I took a fourth, the one ClawSweeper's review pointed at: thread the metadata that already exists rather than reword the string or add a direct send. If you would rather have option (i) — make the summary say only what is true and drop the dead MEDIA_URL_CAP slicing — that is a much smaller diff and I am happy to send it instead.
  • mediaNote is only appended when the directory holds more than 25 files, but details.media.mediaUrls is populated regardless. This fix covers both; the false sentence and the dropped attachments had different trigger conditions.

`dir_fetch` builds `details.media.mediaUrls` from local gateway paths and
returns a summary telling the model the channel attaches the first 25. Nothing
attaches them. `filterToolResultMediaUrls` reduces an untrusted tool's media to
`http(s)` entries, `dir_fetch` emits filesystem paths, so the list empties on
every call and the handler returns before `queuePendingToolMedia`. The tool
text has already been emitted by then, so the model relays a statement that is
never true, with no warning and nothing logged.

The mechanism for this already exists on both ends and nothing connects them.
`setManifestPluginToolMeta` marks a bundled plugin tool `trustedLocalMedia`
when the manifest's `contracts.tools` declares it — file-transfer declares
`dir_fetch` — and `filterToolResultMediaUrls` already accepts a run-local
`trustedLocalMediaToolNames` set that grants exactly this. No production caller
ever populates it; only the e2e harness does. So the metadata is computed,
the consumer is wired, and the value in between is always `undefined`.

Collect the set where the run's tool surface is already assembled and thread it
alongside `coreBuiltinToolNames` to the subscription.

`collectTrustedLocalMediaToolNames` takes names from two sources and no others:
the core allowlist, matched exactly as `isCoreToolResultMediaTrustedName`
matches it today, so every tool trusted before this change is still trusted;
and tools whose plugin metadata carries the bundled contract's
`trustedLocalMedia` mark. Forwarding the whole builtin set would have granted
local-media trust to every registered tool, including MCP tools, which is the
boundary this set exists to hold.

`TRUSTED_TOOL_RESULT_MEDIA` is untouched. openclaw#101434 moved this project away from
widening that Set and openclaw#120718 ruled on the delivery mechanism; neither is
reopened here.

Alias behaviour is deliberately unchanged. Supplying the set activates
`filterToolResultMediaUrls`'s exact-raw-name branch, and the set is built so
that every name trusted today passes it. Tightening that gate for core names
would change behaviour for `bash`, `cron` and `apply-patch` and belongs in its
own change.

Tests: the collector's two sources and its exclusion of unmarked plugin tools;
the defect itself at the filter (`dir_fetch` local paths are dropped with no
set, kept with one) and at the delivery boundary (`pendingToolMediaUrls` empty
versus queued, with the tool text emitted either way); the run surface exposing
the set from contract metadata; and core tools staying trusted once a run
supplies its exact set.

Fixes openclaw#138383
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 10, 2026, 11:11 PM ET / September 11, 2026, 03:11 UTC.

ClawSweeper review

What this changes

The PR carries bundled tools’ local-media trust metadata into the embedded agent’s reply pipeline so fetched files can become channel attachments.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: the attachment-filtering defect remains on current main and v2026.9.3. The patch is focused, but delivery proof is still limited to tests; the overlapping open repair is not yet a proven replacement.

Priority: P2
Reviewed head: 1b3981a6046f0370437029eb4aa32225a3d69cc3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and has useful unit coverage, but real attachment-delivery proof remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied proof exercises the new collector and mocked tool-result handling through the pending-media queue, but does not demonstrate a real embedded dir_fetch run delivering attachments through a channel. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The supplied proof exercises the new collector and mocked tool-result handling through the pending-media queue, but does not demonstrate a real embedded dir_fetch run delivering attachments through a channel. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Pinned change ownership: The host verified the complete merge-base-to-head patch and a test merge whose parents are the pinned main followed by this PR head. The introduced change is the media-trust collector, its propagation, and focused tests; unrelated endpoint drift is not attributed to this PR.
Current main and latest release retain the gap: Both inspected versions of the tool-surface builder omit trustedLocalMediaToolNames. The release filter rejects dir_fetch local paths without that set, and current main retains the same filtering mechanism.
Existing trust contract and propagation: The plugin loader marks bundled manifest-declared tools as trustedLocalMedia. The PR reads that existing metadata, retains core-name behavior, refreshes the set in place, and forwards it through session preparation and stream setup to the existing filter. MCP-provenance rejection and explicitly private media remain intact.
Findings None None.
Security None None.

How this fits together

The embedded agent collects results from tools, filters their attachment paths, and queues permitted media for the assistant’s reply. File Transfer supplies files fetched from paired nodes to this pipeline.

flowchart LR
  A[Paired node files] --> B[File Transfer tools]
  C[Registered tool metadata] --> D[Run-local trusted names]
  B --> E[Tool-result media filter]
  D --> E
  E --> F[Pending reply attachments]
  F --> G[Channel delivery]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied proof exercises the new collector and mocked tool-result handling through the pending-media queue, but does not demonstrate a real embedded dir_fetch run delivering attachments through a channel. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - Provide redacted after-fix channel-delivery evidence and update the PR description to reflect the current tool output.
Agent review details

Security

None.

PR surface

Source +46, Tests +137. Total +183 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 46 0 +46
Tests 3 137 0 +137
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 183 0 +183

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138383
Summary: This PR is one of two open implementations of the attachment-trust repair; the summary-only work addresses a narrower symptom.

Members:

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

Technical review

Best possible solution:

Use the existing metadata-driven reply queue for bundled-tool attachments while preserving private-media rejection and the host’s channel and filesystem policies.

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

Yes, at source level: dir_fetch returns local media paths, but current main supplies no trusted-name set and filters those paths out before queuing. A failing real channel run was not executed.

Is this the best way to solve the issue?

Yes, for the embedded runtime: connecting the existing producer metadata to its existing consumer is a narrow repair and preserves normal reply selection and delivery ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e62272f04a3e.

Labels

Label justifications:

  • P2: This repairs silent attachment filtering in the bounded paired-node File Transfer workflow.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied proof exercises the new collector and mocked tool-result handling through the pending-media queue, but does not demonstrate a real embedded dir_fetch run delivering attachments through a channel. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. For Telegram, the repaired shared path changes visible file attachments and can be demonstrated through the Test Server userbot with a paired-node setup.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • wangmiao0668000666: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Add after-fix evidence from a real paired-node dir_fetch run showing files arriving in the channel; screenshots or recordings are preferred when useful, and terminal output or logs also count. Redact private paths, endpoints, IP addresses, keys, and other personal data.
  • Refresh the PR body to distinguish the remaining attachment defect from the already-removed summary text. Updating the body should trigger review; if it does not, ask a maintainer to comment @clawsweeper re-review.

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.

@obviyus obviyus self-assigned this Sep 11, 2026
@igs-rogenlo

Copy link
Copy Markdown
Contributor Author

Closing this in favour of #138427, which is the same repair, a week older, and broader.

I opened this without checking for an existing PR against #138383 — the issue's automatic implementation had stopped before completion and I took that to mean the fix was unowned. It was not. The review's root-cause cluster is what surfaced #138427, and reading it through, the overlap is essentially total:

  • same collection point (attempt-client-tools), same propagation (attempt-execution-phase → attempt-stream-prepare → the existing filter), same source for the set (core-trusted names ∪ plugin trustedLocalMedia metadata)
  • fix: attach fetched directories to replies #138427 additionally covers the Codex dynamic-tools bridge, a runtime path this PR does not touch
  • 15 files there against 7 here — this branch is a strict subset

Both are blocked on the same thing, which is the real bottleneck rather than the code: delivery proof through a final reply. Splitting reviewer attention across two implementations of one fix does not help that.

One correction to this PR's description, for the record. It quotes dir_fetch telling the model "channel attaches first 25". That string is gone on current main — #138542 removed mediaNote. What remains is the half that matters: details.media.mediaUrls is still populated (dir-fetch-tool.ts:257) and still filtered to nothing before delivery. So the defect is silently dropped attachments, not a false statement, and #138542 explicitly left delivery unchanged.

Offered to whoever carries #138427 forward, if useful — the tests on this branch are MIT-licensed to the project like any contribution here and can be lifted verbatim:

  • embedded-agent-subscribe.handlers.tools.media.test.ts — dir_fetch at the delivery boundary, before and after: state.pendingToolMediaUrls empty with no run-local set, populated with one, tool text emitted either way. Closest thing here to the delivery evidence the review is asking for, though still handler-level rather than a real channel.
  • embedded-agent-subscribe.tools.media.test.ts — collector cases: both sources included, unmarked plugin tools excluded, unnamed tools ignored, and a regression guard that core tools (exec, read) stay trusted once a run supplies its exact set. That last one is the one I would most want in place before turning the set on, since supplying it activates the exact-raw-name branch for every tool.

Happy to help produce the end-to-end proof if the author or a maintainer wants a hand; it needs a paired node and a channel on a clean build, which is the part neither PR has supplied yet.

obviyus added a commit that referenced this pull request Sep 11, 2026
…138427)

Fixes #138383.

## What Problem This Solves

`dir_fetch` saved files fetched from a paired node, but the embedded runner and Codex bridge discarded their local attachment paths. The final reply contained no files. The earlier misleading directory summary was already removed by #138542.

## Why This Change Was Made

Carry the existing concrete tool metadata into both reply pipelines. Keep core tool behavior, exact registered names, filesystem grants, private-media rejection, and MCP filtering. An unmarked plugin cannot gain trust by reusing a core name or setting a public result flag; the special TTS path uses the existing private core result provenance and its original URLs.

Complete delivery through the existing host-selected path: suppress final text already sent as the same assistant message's file caption, append UI media supplements without recreating runtime-owned text, and read image downloads through the existing authenticated media route without relaxing the browser policy.

## User Impact

Permitted files arrive with the final reply, up to the existing 25-file selection limit. The complete saved inventory remains available. No schema, configuration option, protocol, dependency, or direct adapter-send path is added.

## Evidence

- Real embedded Control UI and Telegram Test Server baseline: successful paired-node fetch, zero final attachments.
- Real Codex app-server baseline: 26 fetched files, zero final attachments.
- Repaired native Codex flow: one caption and 25 final attachments from 26 files; image and document downloads match the source bytes, and attachments survive history refresh.
- Real unmarked plugin calls succeed while local attachments remain blocked. An ungranted directory returns `POLICY_DENIED`. Core aliases, HTTP media, MCP provenance, private results, and TTS provenance also have focused owner-boundary coverage.
- Telegram delivers one captioned photo and one document; the document matches the original bytes. Owned test messages and credential leases were cleaned up.
- Focused integration, delivery, trust, and browser-policy checks plus the matching runtime/UI build passed on an isolated native runner.

Independent source-blind acceptance passed both native and embedded public flows: final attachments, 25-file selection, all 26 saved-file hashes, image/document downloads, history refresh, and actual unmarked-plugin rejection. Baseline and Telegram results above are separate retained proof. Exact-head hosted checks and final review are required before landing.

This preserves the implementation from @NianJiuZst and includes useful regression coverage offered by @igs-rogenlo in #144609. The two-runtime scope is retained; the older wording-only alternative is not reopened.

Co-authored-by: igs-rogenlo <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
…penclaw#138427)

Fixes openclaw#138383.

## What Problem This Solves

`dir_fetch` saved files fetched from a paired node, but the embedded runner and Codex bridge discarded their local attachment paths. The final reply contained no files. The earlier misleading directory summary was already removed by openclaw#138542.

## Why This Change Was Made

Carry the existing concrete tool metadata into both reply pipelines. Keep core tool behavior, exact registered names, filesystem grants, private-media rejection, and MCP filtering. An unmarked plugin cannot gain trust by reusing a core name or setting a public result flag; the special TTS path uses the existing private core result provenance and its original URLs.

Complete delivery through the existing host-selected path: suppress final text already sent as the same assistant message's file caption, append UI media supplements without recreating runtime-owned text, and read image downloads through the existing authenticated media route without relaxing the browser policy.

## User Impact

Permitted files arrive with the final reply, up to the existing 25-file selection limit. The complete saved inventory remains available. No schema, configuration option, protocol, dependency, or direct adapter-send path is added.

## Evidence

- Real embedded Control UI and Telegram Test Server baseline: successful paired-node fetch, zero final attachments.
- Real Codex app-server baseline: 26 fetched files, zero final attachments.
- Repaired native Codex flow: one caption and 25 final attachments from 26 files; image and document downloads match the source bytes, and attachments survive history refresh.
- Real unmarked plugin calls succeed while local attachments remain blocked. An ungranted directory returns `POLICY_DENIED`. Core aliases, HTTP media, MCP provenance, private results, and TTS provenance also have focused owner-boundary coverage.
- Telegram delivers one captioned photo and one document; the document matches the original bytes. Owned test messages and credential leases were cleaned up.
- Focused integration, delivery, trust, and browser-policy checks plus the matching runtime/UI build passed on an isolated native runner.

Independent source-blind acceptance passed both native and embedded public flows: final attachments, 25-file selection, all 26 saved-file hashes, image/document downloads, history refresh, and actual unmarked-plugin rejection. Baseline and Telegram results above are separate retained proof. Exact-head hosted checks and final review are required before landing.

This preserves the implementation from @NianJiuZst and includes useful regression coverage offered by @igs-rogenlo in openclaw#144609. The two-runtime scope is retained; the older wording-only alternative is not reopened.

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

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

2 participants