You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[REMOTE-1820] Handle cancellation requests from dispatch server (#83)
## Summary
This is the worker-side half of REMOTE-1820: self-hosted worker cancellation support.
The companion `warp-server` change now forwards `task_cancellation` control messages to the worker. This PR makes `oz-agent-worker` consume those messages, cancel the matching active task context, and report the task back as terminal `CANCELLED` rather than as a normal failure.
End to end:
- Adds the `task_cancellation` WebSocket message and a shared `TaskStateCancelled` wire value.
- Tracks each active task's context and cancel function so the worker can cancel only the requested task.
- Cancels matching active tasks when a `task_cancellation` control message arrives; cancellations for inactive tasks are logged and ignored.
- Reports cancelled tasks through the existing `task_completed` message shape with `task_state=CANCELLED`, so server-side lifecycle reconciliation can distinguish cancellation from failure.
- Preserves the normal success/failure paths for non-cancelled tasks.
- Records cancellation lifecycle events and marks cancelled executions separately from failed executions.
- Handles context cancellation cleanly in the direct backend and uses bounded Docker cleanup so worker shutdown does not block indefinitely.
## Code overview
- `internal/types/messages.go` — adds `task_cancellation`, `TaskState`, and optional `task_state` fields on terminal worker messages.
- `internal/worker/worker.go` — handles cancellation messages, tracks active task contexts, emits terminal `CANCELLED`, and keeps shutdown cancellation on the same lifecycle path.
- `internal/worker/direct.go` — classifies context cancellation as task cancellation instead of a generic backend failure.
- `internal/worker/docker.go` — bounds container cleanup during cancellation/shutdown.
- `internal/worker/worker_test.go` — covers cancellation message handling, terminal `CANCELLED` reporting, and shutdown behavior.
## Validation
- `go test ./internal/metrics ./internal/worker`
- `go test ./...`
- `helm template oz-agent-worker charts/oz-agent-worker --set image.tag=test --set worker.workerId=test-worker --set warp.apiKeySecret.create=true --set warp.apiKeySecret.value=dummy --set metrics.enabled=true`
- `git diff --check`
Co-Authored-By: Oz <oz-agent@warp.dev>
0 commit comments