FIG_009 [ SEMAPHORE ]
FIG_009 // Interactive Cutaway durability/experimental/semaphore

DurabilitySemaphore

Bounded durable concurrency permits with dynamic pool limits, per-group caps, and high-water release.

FIG_009 [ DURABILITY_SEMAPHORE ] ROUND TX // HWM
1 Round Collect 2 1 TX Grant / Sweep 3 HWM Release Sync
1 / 6
CLEAR (4 / 8 IN USE): Click any running client siding on the right to finish a job & return its brass token, or test group caps, dynamic limits, and duplicate reports.
CLEAR CLIENT A GRP α QUEUED: 0 READY SemaphoreQueue CLIENT B GRP α QUEUED: 0 READY SemaphoreQueue CLIENT C GRP β QUEUED: 0 READY SemaphoreQueue ROUND COLLECTOR BRASS TOKEN VAULT LIM 8 LIMIT STOP-PIN: 8 / 8 OPEN ALARM IDLE SWEEP EXPIRED GROUP CAP (4) α: 3 / 4 β: 1 / 4 CLIENT A (α) FREE -1 2 OUT CLIENT B (α) FREE -1 1 OUT CLIENT C (β) FREE -1 1 OUT RELEASED HWM #12 • MONOTONIC SIGNAL BLADE CLEAR ╱ vs STOP ─ ROUND GATE OLDEST-FIRST BATCH CLIENT DOs REQUEST(DEMAND) EXPIRY SWEEP SET_ALARM() RECLAIM SEMAPHORE ARM SHARED LIMIT CAP TOKEN VAULT GRANTS + LEASES TX ADMITTED WORK CLICK ANY TO FREE GROUP CAP (4) FAIR ISOLATION HWM RATCHET NO DOUBLE-FREE
GUARANTEE: 1 SHARED BUDGET ACROSS DOs • MONOTONIC RELEASE HWM
SPEC // 09 [ ARCHITECTURE ]
01 // What it’s for

Why reach for DurabilitySemaphore

Use DurabilitySemaphore when many client Durable Objects or Workers compete for a shared account concurrency budget, external API rate slot, or bounded downstream resource—and permits must survive evictions, handle crashed holders via expiry, and support live limit reductions without revoking running work.


02 // How it works

Inside your Durable Object

  1. 01Durable token vault: Active permits, optional per-group caps (groupLimit), and unclaimed-grant expiries live in ctx.storage.sql inside a single coordinator DO per key.
  2. 02Dynamic limit tightening: Lowering limit() stops new grants immediately without killing already-running jobs; capacity drains cleanly as holders release.
  3. 03Unclaimed grant sweeper: Grants that are issued but never confirmed or renewed are automatically reclaimed on the shared DurabilityScheduler alarm.
  4. 04Monotonic high-water release: Client release messages carry monotonic sequence markers so duplicate or reordered release RPCs never double-free permits.
Storage
ctx.storage.sql
Alarm
Shared DurabilityScheduler
Import
durability/experimental/semaphore