# Control authority

> How Arc resolves conflicts when multiple writers target the same channels

When multiple writers target the same channel (two Arc programs, an Arc program and a Python script, or an Arc program and a schematic control), authority determines whose values take effect. Without it, writers would overwrite each other unpredictably.

## Declaring authority

The [`authority` declaration](https://docs.synnaxlabs.com/reference/control/arc/reference/standard-library/control#authority) sets the level a program writes at. The reference page lists every form it accepts.

## Default authority

Default `authority` for a task when not declared is `255`

A task at `255` cannot be overridden, which suits a single writer but leaves no room to escalate or to hand control to an operator. Declare a lower value, such as `200`, to keep both options open.

## Changing authority at runtime

Declare a top-level [`authority`](https://docs.synnaxlabs.com/reference/control/arc/reference/standard-library/control#authority) to set the task default. Use [`control.set_authority`](https://docs.synnaxlabs.com/reference/control/arc/reference/standard-library/control#set_authority) inside stages to change it during execution:

```arc
import control
import time

authority 100

sequence main {
    stage monitor {
        sensor -> filter{} -> output
        sensor > THRESHOLD => escalate
    }

    stage escalate {
        control.set_authority{value=200}
        true -> press_vlv_cmd
        time.wait{duration=5s} => done
    }

    stage done {
        false -> press_vlv_cmd
    }
}

start_cmd => main
```

Authority changes apply before channel writes in the same execution cycle of a stage, so `control.set_authority` and channel writes can safely coexist.

## How multiple writers interact

The authority system follows three rules:

**Higher authority wins.** A writer at authority 200 takes precedence over one at 100. The lower-authority writer’s values are silently dropped for that channel.

**Equal authority: first in wins.** When two writers have the same authority, the one that acquired the channel first keeps control. The second writer’s values are dropped.

**Auto-resume on release.** When a higher-authority writer releases a channel (by stopping or lowering its authority), the next highest writer automatically regains effective control. No restart or re-acquisition is needed.

These rules apply uniformly across all writer types. Arc programs, Python scripts, and schematic controls all participate in the same authority system.

## Emergency escalation

A common pattern is starting at moderate authority and escalating when an emergency is detected:

```arc
import control

authority 100

sequence main {
    stage normal {
        sensor -> controller{} -> output
        emergency_condition => emergency
    }

    stage emergency {
        control.set_authority{value=255}
        false -> press_vlv_cmd
        true -> vent_vlv_cmd
    }
}

start_cmd => main
```

At authority 100, the program runs alongside other writers. When the emergency stage activates, it jumps to 255 and overrides everything, including other Arc programs, Python scripts, and schematic controls.

## Releasing control

Setting authority to 0 gives a program the lowest possible priority. Any other writer takes precedence:

```arc
import control

authority 200

sequence main {
    stage active {
        true -> press_vlv_cmd
        done_condition => yield
    }

    stage yield {
        control.set_authority{value=0}
        false -> press_vlv_cmd
    }
}

start_cmd => main
```

This is useful when two Arc programs coordinate over the same channels. A high-priority program lowers its authority when it finishes, allowing a lower-priority program to resume without restarting.

> Setting authority to 0 does not disconnect the writer. The program keeps the channel at the lowest priority. An empty stage does not lower authority either. To yield, call:
>
> ```arc
> control.set_authority{value=0}
> ```
