Skip to content

fix(pool): preserve capacity across replenishment races - #181

Merged
tisonkun merged 3 commits into
mainfrom
codex/pool-followup-review
Aug 23, 2026
Merged

fix(pool): preserve capacity across replenishment races#181
tisonkun merged 3 commits into
mainfrom
codex/pool-followup-review

Conversation

@tisonkun

@tisonkun tisonkun commented Aug 23, 2026

Copy link
Copy Markdown
Member

Summary

  • normalize pool-internal visibility and reexport organization
  • keep replenishment reservations inside the bounded pool instead of adding pool-gated methods to Semaphore
  • prevent concurrent replenishment, active objects, and in-flight creation from exceeding the pool maximum
  • restore reserved capacity when replenishment fails or is cancelled
  • document that targets above the maximum are clamped

Design Notes

replenish_to atomically drains only immediately available permits through the existing public Semaphore API. Because idle objects occupy pool slots without holding permits, it derives creation capacity from available permits plus its own reservation, minus the current idle count. Permits held by checkouts, in-flight creations, and concurrent replenishments therefore remain committed without serializing maintenance calls.

A private borrowed guard returns unused permits on success, error, or cancellation. Semaphore has no API surface conditioned on the unrelated pool feature.

@tisonkun tisonkun changed the title refactor(pool): isolate replenishment capacity tracking fix(pool): preserve capacity across replenishment races Aug 23, 2026
@tisonkun
tisonkun merged commit 48e746f into main Aug 23, 2026
9 checks passed
@tisonkun
tisonkun deleted the codex/pool-followup-review branch August 23, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant