Skip to content

[API] Transfer cancel never reaches the agent — cancel_transfer has no server-side sender #2396

Description

@ToddHebebrand

Description

POST /remote/transfers/:id/cancel only flips the DB row and writes an audit event — nothing is sent to the device. The agent keeps transferring after a "successful" cancel, so server/UI state (failed, "Cancelled by user") diverges from device reality until the transfer runs to completion.

Root Cause

apps/api/src/routes/remote/transfers.ts:360-415 — the cancel route does db.update(fileTransfers).set({ status: 'failed', errorMessage: 'Cancelled by user', ... }) + logSessionAudit, and returns. No device command is queued, no WS/relay message is sent.

The agent side is fully built and waiting: CmdCancelTransfer = "cancel_transfer" (agent/internal/remote/tools/types.go:74), handler registered (agent/internal/heartbeat/handlers_desktop.go:135), and filetransfer.Manager.CancelTransfer correctly flags in-flight transfers (loop checks at transfer.go:166-171, 277-282). But grep -rn "cancel_transfer" apps/api/src finds only a docsIndex.json mention — zero senders.

Note for whoever fixes this: the transfer create route (transfers.ts:37) doesn't queue a file_transfer command either — trace how file_transfer commands actually reach the agent today (likely the remote-session relay / viewer path, remoteTools capability) and wire cancel through the same channel. Also apps/web/src/components/remote/FileManager.tsx:552cancelTransfer only removes the item from local React state and never calls the API cancel route at all.

Proposed Fix

  1. Make the API cancel route deliver cancel_transfer to the device via the same channel file_transfer uses.
  2. Wire the web FileManager cancel button to the API route.
  3. Only mark the row cancelled/failed after (or alongside) dispatch, and consider a distinct cancelled status vs failed.

Affected Files

  • apps/api/src/routes/remote/transfers.ts (primary)
  • apps/web/src/components/remote/FileManager.tsx
  • agent/internal/heartbeat/handlers_desktop.go (receiver — already works)

Found during the macOS agent memory audit follow-ups (PR #2391 review, #2388).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions