Class LeaseRenewer
ConversationLock.LockHandle's lease (design §7.4) on a manager-owned
ScheduledExecutorService.
The renewer is intentionally separate from the turn-execution thread: when a turn blocks on an LLM call or a tool,
the lease must still be renewed by an unrelated scheduler tick or the lock will silently expire and another node may
race ahead. The recommended interval is lease/3.
When ConversationLock.extend(LockHandle, Duration) returns false — the fencing token no longer
matches because the lease already expired — the onExtendFailed hook is invoked exactly once. The hook is the
manager's signal to interrupt the turn with InterruptReason.LEASE_LOST. Subsequent ticks become no-ops
because the lostLease flag latches.
If an idempotency entry is associated with this turn, the optional IdempotencyStore.touch(String, String)
call piggybacks the secondary-TTL refresh on each successful extend so the holder-loss sweeper does not pick the
entry as stale while the holder is alive (design §9.2 stale cleanup).
-
Constructor Summary
ConstructorsConstructorDescriptionLeaseRenewer(ConversationLock lock, ScheduledExecutorService scheduler, Duration interval, Duration lease) LeaseRenewer(ConversationLock lock, ScheduledExecutorService scheduler, Duration interval, Duration lease, SessionMetrics metrics) -
Method Summary
Modifier and TypeMethodDescriptionstart(ConversationLock.LockHandle handle, IdempotencyStore store, String idempotencyKey, Runnable onExtendFailed) Variant ofstart(LockHandle, Runnable)that also touches an idempotency entry on each successful extend.start(ConversationLock.LockHandle handle, Runnable onExtendFailed) Schedule periodicextendcalls forhandle.
-
Constructor Details
-
LeaseRenewer
public LeaseRenewer(ConversationLock lock, ScheduledExecutorService scheduler, Duration interval, Duration lease) -
LeaseRenewer
public LeaseRenewer(ConversationLock lock, ScheduledExecutorService scheduler, Duration interval, Duration lease, SessionMetrics metrics)
-
-
Method Details
-
start
Schedule periodicextendcalls forhandle. Cancel the returned future at turn end.- Parameters:
handle- the held lock (must not be null)onExtendFailed- invoked at most once whenextendreturnsfalse; typically tells the manager to interrupt the turn (must not be null)- Returns:
- the
ScheduledFuturethe manager cancels at turn end (never null)
-
start
public ScheduledFuture<?> start(ConversationLock.LockHandle handle, IdempotencyStore store, String idempotencyKey, Runnable onExtendFailed) Variant ofstart(LockHandle, Runnable)that also touches an idempotency entry on each successful extend.- Parameters:
handle- the held lock (must not be null)store- the idempotency store, ornullto disable touchidempotencyKey- the key to touch, ornullto disable touchonExtendFailed- invoked at most once whenextendreturnsfalse(must not be null)- Returns:
- the scheduled task handle (never null)
-