---
title: "U6007: The host stopped the run before it finished"
url: https://una-lang.org/en/docs/errors/U6007/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U6007.md
---

# U6007: The host stopped the run before it finished

`una run` and native executables end a run with this error when the hard stop of a host stop cancels it (`spec/26 §6`, ADR 0116 rule 16). The output so far stays printed, the trace is written, and the exit code is 1.

## Why Una rejects it

A host stop request is one of:

- SIGINT or SIGTERM,
- the end of `--deadline <seconds>`,
- a driver's shutdown, or
- the run's own stop after `--stop-after-iterations <n>`.

After the first request, every `for ever` ends at its next iteration start and runs its `on stop`, and the rest of the program runs on.

The hard stop comes at the end of the grace period, `--stop-grace <seconds>` (10 by default), or at a second request. It cancels the run at its next call or loop iteration, `on stop` blocks included.

A run that ends within the grace period ends normally, with exit code 0.

## How to fix it

- Keep the work after a stop short: an `on stop` that releases what the loop holds, and no long computation or wait there.
- A run that must not be cut gets a longer grace period.

## The repair at a glance

`src/demo.una`

```diff
  module demo

  pub main() -> Unit
    diverges
  =
    let edit n = 0
    for ever
      n = n + 1
    on stop
-     for i in 0..<1000000000
+     for i in 0..<10
        n = n + 1
    unit
```

## Failing example

Run it with `una run --deadline 1 --stop-grace 1`: the `on stop` block counts far past the grace period.

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4

run
  entry demo
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub main() -> Unit
  diverges
=
  let edit n = 0
  for ever
    n = n + 1
  on stop
    for i in 0..<1000000000
      n = n + 1
  unit
```

## Fixed example

Run it with `una run --deadline 1 --stop-grace 1`: the `on stop` block ends well within the grace period.

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4

run
  entry demo
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

pub main() -> Unit
  diverges
=
  let edit n = 0
  for ever
    n = n + 1
  on stop
    for i in 0..<10
      n = n + 1
  unit
```
