Fix inbound media handling, file-receive race, and add shared-directory support#24
Closed
lundog wants to merge 1 commit into
Closed
Fix inbound media handling, file-receive race, and add shared-directory support#24lundog wants to merge 1 commit into
lundog wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix inbound media handling, file-receive race, and add shared-directory support
Summary
Inbound files were not fully usable by the agent: received media never reached OpenClaw's shared media store, the initial
/freceiveraced the XFTP file description and caused messages to dispatch without their attachment, andmedia://references produced by the agent couldn't be sent back out. This PR fixes those, and adds an opt-in pair of config keys for deployments where OpenClaw andsimplex-chatdon't share a filesystem.1. Comply with OpenClaw media requirements
Stage inbound files into the shared media store. The plugin passed the raw path from the SimpleX runtime directly into the inbound context as
MediaPath/MediaUrl. Files outside~/.openclaw/media/are rejected by theimagetool and invisible to sandboxed workspaces, so attachments failed with errors like:finalizePendingFile()now reads the received file and stages it viacore.channel.media.saveMediaBuffer(buffer, mime, "inbound", maxBytes, fileName)— the same pattern as other bundled channels — and passes the saved store path into the context. If staging fails, it logs and falls back to the raw path.Resolve relative paths from the WS API.
rcvFileCompletereportsfileSource.filePathrelative to the runtime's--files-folder(typically just the bare file name, e.g."IMG_x.jpg"). The plugin now resolves relative paths against the newfiles.inboundDirsetting, defaulting to/tmp— wheresimplex-chatsaves files when started without--files-folder.Follow the inbound context envelope. Added
MediaPaths(array form) alongsideMediaPath, and the originalfileNamefrom the chat item is now used when saving (MIME/extension fallback).Resolve
media://references on send. When the agent echoes an attachment back (e.g. "send me that file"), it passesmedia://inbound/<id>asmediaUrl. The plugin treated this as a literal filesystem path:resolveMediaPath()now resolvesmedia://<subdir>/<id>to its physical path via the SDK'sresolveMediaBufferPath()(the documented read-side counterpart tosaveMediaBuffer, with built-in path-traversal protection) before the normal local-path flow.2. Fix the inbound file receive race
The plugin issued
/freceiveimmediately onnewChatItems, but for XFTP transfers the file description usually isn't ready yet, so the accept fails (SimpleX receive file failed: Error: IMG_x.jpg). Because the pending file was only queued after a successful accept, this had two compounding effects: the message dispatched immediately with no media, and when the retry onrcvFileDescrReadydid download the file, thercvFileCompletepath was dropped because nothing was queued.Now:
rcvFileDescrReadyretries the accept, but only for queued files not yet accepted (shouldRetryFileAccept/markFileAccepted) — previously it accepted unconditionally, including files skipped as oversize.rcvFileCompletewith the actual downloaded path. The existing 90s pending-file timeout still dispatches without media (and cancels the transfer) if the download never completes.3. Optional shared-directory support (cross-container deployments)
When OpenClaw and
simplex-chatrun in separate containers (or otherwise don't share a filesystem), local paths on one side are meaningless on the other. Two new optional keys under the channel (or per-account) config make file exchange work across a shared directory/volume:inboundDir— the runtime's--files-folder; used to resolve the relative paths from §1 (defaults to/tmp).outboundDir— when set, outbound media (fetched remote URLs,media://references, and local files simplex-chat can't read) is staged into this directory with UUID-prefixed names before the send command is issued, so thefileSource.filePathpassed to simplex-chat is readable by it. Staged files are tracked and deleted after the send completes; only files this plugin staged are ever deleted.With both keys unset, behavior is unchanged apart from the bug fixes above — single-filesystem deployments need no configuration.
Testing
pnpm typecheck,pnpm check(biome), andpnpm vitest run(151 tests, including a new test for the accept-retry tracking) all pass.openclaw.plugin.jsonregenerated viapnpm manifest:sync.simplex-chatin a separate container sharing a mounted volume: image receive → agentimagetool reads the staged store file; agent echo round-trip (media://inbound/<id>→ staged to the shared dir → sent → cleaned up); plus outbound remote-URL media.