Skip to content

ISingletonLeaseStore

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

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

public interface ISingletonLeaseStore

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 is false (the default) this store is never called — a single-instance setup pays no extra database round trip.

ReleaseAsync(string, string, CancellationToken)

Section titled “ ReleaseAsync(string, string, CancellationToken)”

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

ValueTask ReleaseAsync(string name, string ownerId, CancellationToken cancellationToken = default)

name string

The name of the lease.

ownerId string

The id of the instance that claims to hold the lease.

cancellationToken CancellationToken

The cancellation token.

ValueTask

A task that completes when the work is done.

RenewAsync(string, string, TimeSpan, CancellationToken)

Section titled “ RenewAsync(string, string, TimeSpan, CancellationToken)”

Extends the lease that is held. It returns false when the lease has moved to someone else — the caller MUST then drop the job.

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

name string

The name of the lease.

ownerId string

The id of the instance that claims to hold the lease.

duration TimeSpan

The new lease duration.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when the renewal succeeded.

TryAcquireAsync(string, string, TimeSpan, CancellationToken)

Section titled “ TryAcquireAsync(string, string, TimeSpan, CancellationToken)”

Tries to take the lease. It returns false when someone else holds the lease and it has not expired.

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

name string

The name of the lease (the id of the protected job).

ownerId string

The id of this instance.

duration TimeSpan

How long the lease stays valid.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when the lease was taken.