Signal Handling and Clean Shutdown
367 words2 min read5 subsectionsFrom the README at ft 0.15.21
ft watch attempts a bounded clean shutdown for catchable signals and
reports an unclean result when task acknowledgement or storage flush does not
finish. SIGKILL, blocking OS work, and independently delegated work remain
outside that guarantee.
SIGINT (Ctrl-C)
- The signal handler cancels the root
Cx. - Owned tasks receive the cancellation context and observe it at their operation-specific checkpoints or races.
- Top-level runtime handles are asked to settle within the shutdown budget.
- The storage writer is asked to flush queued segments and commit the WAL within its bounded cleanup phase.
- On complete settlement, resources are released and the clean-shutdown state can be recorded; otherwise the shutdown result stays explicitly unclean.
SIGTERM
Identical to SIGINT in steady state. The shutdown deadline is configurable; if
the deadline passes before flush completes, the process exits with a non-zero
code and the persisted unclean authority remains available to the explicit
session-inspection commands. Production ft watch startup runs the session
detector and logs its verdict; it does not offer a recovery prompt or restore.
SIGKILL
There's no clean path. The watcher is killed mid-flush. On the next start:
- The file lock is detected as stale (PID no longer exists).
- The clean-shutdown marker is absent.
- The persisted unclean marker remains available to the session inspection
commands.
ft watchstartup detects and logs the unclean session but does not prompt; inspection and any manual reconstruction are explicit operator actions. - The DB is opened in WAL recovery mode; SQLite reconstructs consistent state from the WAL.
Cancel-correctness in long ops
Long operations are cancellation-responsive only when their implementation
uses the operation-specific Cx contract: checkpoints at bounded progress
boundaries, cancellation-aware I/O, or an explicit race against a cancellation
signal. The pinned sleep_with_cx and timeout_with_cx helpers honor budget
deadlines but do not themselves register a direct-cancellation wake, so callers
must not rely on a bare long sleep/timeout for prompt shutdown.
What Ctrl-C won't do
- It won't roll back a tx that already entered the commit phase; that's the compensation engine's job, not the shutdown path.
- It won't kill child mux/pty processes that aren't owned by the watcher; those are owned by the mux server.
- It won't fire workflow handlers' rollback methods; handlers are responsible for their own cleanup-on-cancel logic.