Dev notes / 03
A cancel button is harder than it looks
Clicking cancel doesn't stop anything by itself. Here's what your API and UI should say while the stop is in flight.
You add a cancel button, wire it to an endpoint, flip the status to cancelled, and ship it. A week later a user reports that their “cancelled” job sent the email anyway.
The problem is that you recorded a wish and showed it as a fact.
✋ “Asked to stop” isn’t “stopped”
A running job can take a while to notice a stop request, or miss it entirely. So give the in-between moment its own name. Something like:
cancel_requested: we got your requestcancelled: the work actually stoppedcompleted: too late, it finished first
Your UI can now show “Stopping…” instead of lying, and you can alert on jobs that sit in cancel_requested for too long.
🚦 Decide which states can be cancelled
Not every job can be cancelled the same way:
- Queued: easy, just don’t start it.
- Running: you have to send a signal and wait.
- Already done: reject the request and say why.
Return a clear error for the last case instead of a silent 200. A 409 with a message like execution already completed saves someone an hour of confusion.
🧾 Keep a record of who cancelled what
Store who asked, when, and what state the job was in at the time. When someone asks “why didn’t my job finish?”, you’ll be able to tell a user cancellation apart from a timeout or a crash.
🧪 Trying it with mPaka
You can request cancellation with POST /v1/executions/{id}/cancel and see the status change on the record. The local executor is mock_no_code_execution, so there’s no real process to kill yet. Use it to build and test your client’s cancel flow, not to rely on stop guarantees.