# ISingletonLeaseStore

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.isingletonleasestore/
> Summary: ISingletonLeaseStore: The lease store that keeps a named job running on a single instance across the cluster.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The lease store that keeps a named job running on a single instance across the
cluster.

```csharp
public interface ISingletonLeaseStore
```

## Remarks

Single-executor election uses it to coordinate background jobs such as MCP
discovery and model health probing, which must not repeat on several replicas. The
lease is a table, not a session lock: it behaves the same way on all three SQL
providers (PostgreSQL, SQL Server, SQLite), and SQLite has no session lock
equivalent.

While [SingletonExecutionOptions.Enabled](/api/tracon.singletonexecutionoptions/#Tracon_SingletonExecutionOptions_Enabled) is [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) (the
default) this store is never called — a single-instance setup pays no extra database
round trip.

**DI lifetime — singleton.** Registered as a singleton with
`TryAdd`; a consumer's own registration wins.

**Tenant behavior — TENANT-INDEPENDENT.** A lease name identifies a
protected JOB (`"mcp-discovery"`, a health-probe job id), not a tenant; leases
are not scoped by tenant at all.

**Guarantee limit: this lease is eventually correct, not strictly
exclusive.** It gives no hard mutual-exclusion guarantee the way a
database advisory lock or session lock would — this is deliberate (SQLite has no
session-lock equivalent, so the lease had to be a plain table row instead). A lease
owner that freezes past its own `duration` without releasing it — a GC pause,
thread starvation, or a network partition that cuts it off from the store — leaves a
narrow split-brain window: [ISingletonLeaseStore.TryAcquireAsync](/api/tracon.isingletonleasestore/#Tracon_ISingletonLeaseStore_TryAcquireAsync_System_String_System_String_System_TimeSpan_System_Threading_CancellationToken_) lets a SECOND instance take
the same lease once it expires, while the frozen first owner may resume and believe
it still holds it, until its own next [ISingletonLeaseStore.RenewAsync](/api/tracon.isingletonleasestore/#Tracon_ISingletonLeaseStore_RenewAsync_System_String_System_String_System_TimeSpan_System_Threading_CancellationToken_) call (correctly)
reports it lost the lease. A consumer whose protected job is not idempotent under a
brief overlap must not rely on this store alone.

## Methods

### <a id="Tracon_ISingletonLeaseStore_ReleaseAsync_System_String_System_String_System_Threading_CancellationToken_"></a> ReleaseAsync\(string, string, CancellationToken\)

Releases the lease. It does nothing when the caller is not the owner.

```csharp
ValueTask ReleaseAsync(string name, string ownerId, CancellationToken cancellationToken = default)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name of the lease.

`ownerId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The id of the instance that claims to hold the lease.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

A task that completes when the work is done.

### <a id="Tracon_ISingletonLeaseStore_RenewAsync_System_String_System_String_System_TimeSpan_System_Threading_CancellationToken_"></a> RenewAsync\(string, string, TimeSpan, CancellationToken\)

Extends the lease that is held. It returns [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when the lease
has moved to someone else — the caller MUST then drop the job.

```csharp
ValueTask<bool> RenewAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name of the lease.

`ownerId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The id of the instance that claims to hold the lease.

`duration` [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan)

The new lease duration.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when the renewal succeeded.

### <a id="Tracon_ISingletonLeaseStore_TryAcquireAsync_System_String_System_String_System_TimeSpan_System_Threading_CancellationToken_"></a> TryAcquireAsync\(string, string, TimeSpan, CancellationToken\)

Tries to take the lease. It returns [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when someone else
holds the lease and it has not expired.

```csharp
ValueTask<bool> TryAcquireAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name of the lease (the id of the protected job).

`ownerId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The id of this instance.

`duration` [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan)

How long the lease stays valid.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when the lease was taken.
