# `Minga.Extension.Instance.State`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/extension/instance/state.ex#L1)

Pure lifecycle state and phase transitions for one extension Instance.

# `phase`

```elixir
@type phase() ::
  :stopped
  | {:stub, Minga.Extension.Instance.Artifact.t()}
  | {:starting, Minga.Extension.Instance.StartContext.t()}
  | {:running, Minga.Extension.Instance.Runtime.t()}
  | {:stopping, Minga.Extension.Instance.StopContext.t()}
  | {:crashed, Minga.Extension.Instance.PhaseFailure.t()}
  | {:load_error, Minga.Extension.Instance.PhaseFailure.t()}
  | {:cleanup_failed, Minga.Extension.Instance.CleanupFailure.t()}
```

# `queued_start`

```elixir
@type queued_start() ::
  {:current, GenServer.from()}
  | {:deferred, GenServer.from(), Minga.Extension.Entry.t()}
```

# `t`

```elixir
@type t() :: %Minga.Extension.Instance.State{
  artifact: :unprepared | {:prepared, Minga.Extension.Instance.Artifact.t()},
  collaborators: keyword(),
  declaration: Minga.Extension.Entry.t(),
  instance_registry: atom(),
  name: atom(),
  phase: phase(),
  registry: GenServer.server(),
  restart_count: non_neg_integer()
}
```

# `artifact`

```elixir
@spec artifact(t()) :: {:ok, Minga.Extension.Instance.Artifact.t()} | :error
```

Returns the prepared artifact when available.

# `cleanup_failed`

```elixir
@spec cleanup_failed(t(), term(), Minga.Extension.Instance.StopContext.t()) :: t()
```

Moves the authority to cleanup-failed with a resumable stop context.

# `configure`

```elixir
@spec configure(
  t(),
  keyword()
) :: t()
```

Replaces per-request lifecycle collaborators while retaining stable injections.

# `crashed`

```elixir
@spec crashed(t(), term()) :: t()
```

Moves the authority to a terminal crash phase.

# `declaration_only`

```elixir
@spec declaration_only(Minga.Extension.Entry.t()) :: Minga.Extension.Entry.t()
```

Removes projection fields from a registry snapshot.

# `declare`

```elixir
@spec declare(t(), Minga.Extension.Entry.t(), GenServer.server(), keyword()) ::
  {:ok, t()} | {:error, term()}
```

Updates declaration identity and collaborators while no transition is active.

# `increment_restart`

```elixir
@spec increment_restart(t()) :: t()
```

Increments the authority-owned crash restart count.

# `join_stop`

```elixir
@spec join_stop(t(), GenServer.from()) :: t()
```

Adds a caller to a transition's stop waiter list.

# `load_error`

```elixir
@spec load_error(t(), term()) :: t()
```

Moves the authority to a terminal load-error phase.

# `new`

```elixir
@spec new(atom(), Minga.Extension.Entry.t(), GenServer.server(), atom(), keyword()) ::
  t()
```

Constructs a stopped lifecycle state from its declaration.

# `put_artifact`

```elixir
@spec put_artifact(t(), Minga.Extension.Instance.Artifact.t()) :: t()
```

Stores the immutable current-generation artifact.

# `queue_start`

```elixir
@spec queue_start(t(), queued_start()) :: t()
```

Queues a start intent behind a safe stop.

# `replace_terminal_failure`

```elixir
@spec replace_terminal_failure(t(), term()) :: t()
```

Replaces the reason of the current terminal failure phase.

# `running`

```elixir
@spec running(t(), Minga.Extension.Instance.Runtime.t()) :: t()
```

Moves the authority into the running phase.

# `runtime`

```elixir
@spec runtime(phase()) :: Minga.Extension.Instance.Runtime.t() | nil
```

Returns runtime identity only from phases that own it.

# `stable_collaborators`

```elixir
@spec stable_collaborators(keyword()) :: keyword()
```

Removes request-scoped callbacks and timeout overrides.

# `starting`

```elixir
@spec starting(t(), Minga.Extension.Instance.StartContext.t()) :: t()
```

Moves the authority into a start transition.

# `stopped`

```elixir
@spec stopped(t()) :: t()
```

Moves the authority to a terminal stopped phase.

# `stopping`

```elixir
@spec stopping(t(), Minga.Extension.Instance.StopContext.t()) :: t()
```

Moves the authority into a stop transition with an existing context.

# `stopping`

```elixir
@spec stopping(t(), GenServer.from() | nil, :explicit | :normal | :crash, term()) ::
  t()
```

Builds the initial asynchronous stop context.

# `stubbed`

```elixir
@spec stubbed(t(), Minga.Extension.Instance.Artifact.t()) :: t()
```

Moves the authority to the lazy stub phase.

# `terminal`

```elixir
@spec terminal(t(), Minga.Extension.Instance.StopContext.t()) :: t()
```

Applies the terminal phase implied by a completed stop context.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
