Repository navigation
Conversation
Every worker launch took the installation-wide `workers` licence lock and kept it
until the handler returned, across the launcher HTTP call (up to 20 s), even when
the licence sets no worker limit. Launches were serialised behind one slow launcher
and other API replicas answered `409 license limit is busy`.
- `worker_limit_guard` returns `None` without touching the database when the
licence sets no worker limit, and the launch handler drops the guard once the
pending launch row exists (it already counts) and before calling the launcher.
- `Store::license_limit_guard` bounds the in-process mutex wait by the same 10 s
deadline as the advisory lock.
- New `AppState::license_limit_lock` takes the lock without counting, so callers
decide under the lock whether a slot is needed:
- activating an agent reads its status under the lock (an agent archived after
the access check is still counted);
- `create_execution_with_limit` looks the idempotency key up again under the
lock, so a concurrent duplicate at the exact limit gets the first execution
instead of 402;
- a first OIDC login checks for a pre-provisioned user with that email under
the seat lock and only counts seats when it would insert a new user.
- `seat_limit_guard` is removed (its only caller now uses the lock directly).
Tests: launch with a slow launcher stub (the limit check does not wait for it),
no lock without a limit, two concurrent launches at limit+1, idempotent duplicate
at a zero execution limit, activate racing an archive. The launch and activate
tests fail with the fix reverted. Count-sensitive licence tests now serialise
with the tests that lower those counts. The OIDC seat change has no test: the
API tests have no OIDC login harness.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #396.
Summary
Every worker launch took the installation-wide
workerslicence lock and kept ituntil the handler returned, across the launcher HTTP call (up to 20 s), even when
the licence sets no worker limit. Launches were serialised behind one slow launcher
and other API replicas answered
409 license limit is busy.worker_limit_guardreturnsNonewithout touching the database when thelicence sets no worker limit, and the launch handler drops the guard once the
pending launch row exists (it already counts) and before calling the launcher.
Store::license_limit_guardbounds the in-process mutex wait by the same 10 sdeadline as the advisory lock.
AppState::license_limit_locktakes the lock without counting, so callersdecide under the lock whether a slot is needed:
the access check is still counted);
create_execution_with_limitlooks the idempotency key up again under thelock, so a concurrent duplicate at the exact limit gets the first execution
instead of 402;
the seat lock and only counts seats when it would insert a new user.
seat_limit_guardis removed (its only caller now uses the lock directly).Tests: launch with a slow launcher stub (the limit check does not wait for it),
no lock without a limit, two concurrent launches at limit+1, idempotent duplicate
at a zero execution limit, activate racing an archive. The launch and activate
tests fail with the fix reverted. Count-sensitive licence tests now serialise
with the tests that lower those counts. The OIDC seat change has no test: the
API tests have no OIDC login harness.
Testing
cargo fmt --check,clippy -D warnings: cleancargo test --workspaceon its own database: 766 passed, 0 failedpnpm docs:check: passedThe OIDC first-login seat change has no test (no OIDC login harness in the API tests).
🤖 Generated with Claude Code