# `Minga.Extension.CodeLease`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/extension/code_lease.ex#L1)

Tracks short-lived leases for extension callback modules.

Extension reload and disable may purge path, git, and generated plugin modules. Agent-facing callbacks can outlive the extension process that registered them, so callers lease the callback module while a provider, tool worker, hook, MCP config builder, or UI action may still call it. Purge paths consult this service and reject unsafe unloads with a clear error instead of racing `:code.purge/1` against active work.

# `reason`

```elixir
@type reason() :: :provider | :tool | :hook | :mcp | :ui_action | atom()
```

Why the module is still callable.

# `summary`

```elixir
@type summary() :: %{
  source: Minga.Extension.ContributionCleanup.contribution_source(),
  module: module(),
  owner: pid(),
  reason: reason()
}
```

Public lease summary safe to include in errors and logs.

# `t`

```elixir
@type t() :: %Minga.Extension.CodeLease{
  id: reference(),
  module: module(),
  owner: pid(),
  reason: reason(),
  server: GenServer.server(),
  source: Minga.Extension.ContributionCleanup.contribution_source(),
  started_at: integer()
}
```

A process-owned extension code lease.

# `active_leases`

```elixir
@spec active_leases(keyword()) :: [summary()]
```

Returns active leases matching a module, source, or both.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `ensure_purge_allowed`

```elixir
@spec ensure_purge_allowed(
  Minga.Extension.ContributionCleanup.contribution_source() | nil,
  module(),
  keyword()
) :: :ok | {:error, term()}
```

Returns `:ok` when a module can be purged safely.

# `lease`

```elixir
@spec lease(
  Minga.Extension.ContributionCleanup.contribution_source(),
  module(),
  reason(),
  keyword()
) ::
  {:ok, t()} | {:error, term()}
```

Leases an extension callback module for the owner process.

# `purge_module`

```elixir
@spec purge_module(
  Minga.Extension.ContributionCleanup.contribution_source() | nil,
  module(),
  keyword()
) ::
  :ok | {:error, term()}
```

Purges and deletes a module atomically with the lease check.

# `release`

```elixir
@spec release(
  t() | reference(),
  keyword()
) :: :ok
```

Releases a previously acquired lease.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the code lease service.

---

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