# The no-mistakes Lifecycle Guard That Blocks Daemon Stop/Restart During Active Pipeline Runs

> Discover the no-mistakes Lifecycle Guard, a safety feature that prevents daemon stop or restart during active pipeline runs. Ensure uninterrupted operations with this essential tool.

- Repository: [Kun Chen/no-mistakes](https://github.com/kunchenguid/no-mistakes)
- Tags: deep-dive
- Published: 2026-07-18

---

**The Destructive Daemon Lifecycle Guard is a safety mechanism in [`internal/lifecycle/guard.go`](https://github.com/kunchenguid/no-mistakes/blob/main/internal/lifecycle/guard.go) that blocks `no-mistakes daemon stop`, `restart`, and update operations whenever active pipeline runs are detected, requiring an explicit `--force` flag to proceed.**

The kunchenguid/no-mistakes repository implements a robust concurrency control system to prevent accidental data loss. This **lifecycle guard** ensures that the daemon cannot be terminated or upgraded while it is actively managing pipeline executions, protecting worktrees from undefined states.

## How the Guard Intercepts Destructive Commands

When you invoke a destructive daemon operation—such as `stop`, `restart`, or an in-place `update`—the guard first queries the current execution state. It utilizes the `lifecycle.ActiveRuns` and `lifecycle.RunList` helpers defined in the codebase to enumerate all runs currently in **pending** or **running** status.

If any active runs exist, the command aborts immediately and surfaces a human-readable list of the blocking executions. The operation only proceeds if the caller explicitly acknowledges the risk by appending the `--force` flag. This design prevents silent daemon terminations that could orphan running processes or corrupt pipeline worktrees.

## CLI Behavior and the Force Override

In standard operation, the guard presents a clear error message identifying the active runs preventing the action:

```sh
$ no-mistakes daemon stop
Daemon stop blocked – active runs detected:
  • run 42 (pending) – branch feature/foo
  • run 57 (running) – branch fix/bar
Use --force to override.

```

To bypass the protection and stop the daemon despite active work, you must supply the override flag:

```sh
$ no-mistakes daemon stop --force
Daemon stopped successfully (force‑override).

```

The same behavior applies to updates:

```sh
$ no-mistakes update
Update aborted – the daemon has active runs.
Use --force to proceed anyway.

```

## Audit Logging and Forensic Attribution

Every invocation of a guarded command—whether blocked or permitted—is recorded in `<NM_HOME>/logs/cli.log`. The guard captures detailed caller attribution, including the **PID**, **PPID**, and the full command line arguments. This audit trail is essential for forensic analysis, allowing administrators to determine who attempted to terminate the daemon and whether they used the `--force` override.

## Key Source Files and Implementation