fix(message-tool): use agent-scoped media roots for path validation#36219
fix(message-tool): use agent-scoped media roots for path validation#36219Sid-Qin wants to merge 1 commit into
Conversation
The message tool resolved agentId only from agentSessionKey, leaving it undefined for cron/hook sessions that lack a session key. This caused getAgentScopedMediaLocalRoots to fall back to default roots, rejecting files under the agent's configured workspace directory. Thread the requesterAgentIdOverride (already available) into MessageToolOptions.agentId so runMessageAction receives a valid agentId and includes the agent workspace in the allowed media roots. Closes openclaw#36185
Greptile SummaryThis PR fixes a bug where the message tool would fail to access files under an agent's configured workspace directory (e.g. The fix is minimal and surgical: it adds an Key points:
Confidence Score: 5/5
Last reviewed commit: f451373 |
Summary
agentIdonly fromagentSessionKey, leaving itundefinedfor cron/hook sessions that lack a session key. This causedgetAgentScopedMediaLocalRoots(cfg, undefined)to return only default roots (e.g.~/.openclaw/media), rejecting files under the agent's configured workspace directory withLocalMediaAccessError: path-not-allowed.~/.openclaw/media/outbound/.agentIdfield toMessageToolOptionsand threadedrequesterAgentIdOverride(already available increateOpenClawTools) into the message tool creation. WhenagentSessionKeyis unavailable, this explicitagentIdis forwarded torunMessageAction, which passes it togetAgentScopedMediaLocalRootsto include the agent's workspace in the allowed media roots.getAgentScopedMediaLocalRootsfunction, therunMessageActionfunction, or any media path validation logic. The fix only ensures the existing agent-scoped path is reachable.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
/home/user/clawd/) are now accepted by the message tool's media path validation, instead of being rejected withpath-not-allowed.Security Impact (required)
No— the agent workspace was already an allowed root ingetAgentScopedMediaLocalRoots; this fix just ensures it's actually used.NoNoNoNoRepro + Verification
Environment
Steps
agents.defaults.workspaceto a custom path (e.g./home/user/clawd)Expected
Actual
LocalMediaAccessError: path-not-allowedEvidence
Two files changed:
src/agents/tools/message-tool.ts: AddedagentId?: stringtoMessageToolOptionsand used it as fallback whenagentSessionKeyis unavailable.src/agents/openclaw-tools.ts: PassedrequesterAgentIdOverrideasagentIdwhen creating the message tool.TypeScript check passes (
npx tsc --noEmit— only pre-existing errors inextensions/diffsandextensions/tlon).Human Verification (required)
runMessageActionresolution chainagentSessionKeypresent (uses session-based resolution as before), bothagentSessionKeyandagentIdabsent (falls through to undefined as before),requesterAgentIdOverrideset (used as fallback)Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
src/agents/tools/message-tool.ts,src/agents/openclaw-tools.tsagentIdonly widens the allowed media roots to include the agent's own workspaceRisks and Mitigations
None — this aligns the message tool with the existing behavior of other code paths that already use
getAgentScopedMediaLocalRootswith a resolvedagentId.