Make the docker_start_app throttle per-app instead of global#176
Open
ClaydeCode wants to merge 3 commits into
Open
Make the docker_start_app throttle per-app instead of global#176ClaydeCode wants to merge 3 commits into
ClaydeCode wants to merge 3 commits into
Conversation
The throttle decorator kept a single last_call timestamp shared across all invocations, so the window was global per decorated function. Add an optional key function so each key gets its own window; key=None preserves the old global behaviour. Store windows in a dict and expose wrapper.reset() to clear them (used by tests that would otherwise inherit a stale window across cases). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Throttle(5) on docker_start_app was global, so a request to start app B within 5s of app A starting was silently dropped and B stayed on its splash until the next request or lifecycle tick. Key the throttle on the app name so each app has its own 5s dedupe window. Update the reset fixture to the new reset() hook and fix the now-stale "global" wording in app_lifecycle. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review panel follow-ups: document the throttle key/reset contract; drop the unreachable *args/**kwargs from the app-name key lambda (both callers pass name positionally); and in the repeat-start test reset the app to a startable status between calls so the throttle, not status gating, is the sole reason the second start is dropped. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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 #132.
Problem
docker_start_appwas decorated@throttle(5). The throttle kept a single shared timestamp, so the 5s window was global across all apps, not per-app. Starting app B within 5s of app A silently returnedNone— B stayed on its splash screen until the next request or the nextcontrol_appstick (which only startsalways_onapps).Change
throttlegains an optionalkeyfunction. Windows are stored in a dict keyed bykey(*args);key=None(default) preserves the old single global window, so the only other behaviour is byte-for-byte unchanged.docker_start_appis now@throttle(5, key=lambda name: name)— each app has its own 5s dedupe window.wrapper.reset()(clears all windows) as a test hook, replacing the old closure-cell-poking fixture.app_lifecycle.py.Same-app silent-drop semantics within one window are kept — that is the intended dedupe.
Tests
test_throttle_per_key_windows_are_independent,test_throttle_reset_clears_all_windows(unit).test_docker_start_app_starts_each_app_despite_throttle— two different apps back-to-back both invoke docker (fails on the old global throttle).test_docker_start_app_throttles_repeated_start_of_same_app— same app twice within 5s invokes docker once; the app is reset to a startable status between calls so the throttle, not status gating, is the sole reason the second start drops.All throttle + compose-pinning tests pass; the app-lifecycle / last-access / traefik-dyn blast-radius suites pass locally.
Review panel
Ran adversarial (always), test adversary (logic + tests changed), DevEx/readability (non-trivial decorator + tests). No specialist for security/DB/API/UX — the diff touches none of those surfaces.
No blocking findings from any reviewer. Both new integration tests were mutation-verified to fail on the pre-change (global) throttle.
Advisories addressed:
RUNNINGbeing in the startable set (sincedocker_start_appflips status toRUNNING). Fixed in 2f45a37 — reset the app toSTOPPEDbetween calls so the throttle is the unambiguous gate.throttlelacked a docstring for the newkey/resetcontract, and the key lambda carried unreachable*args/**kwargs. Fixed in 2f45a37 — added docstring, simplified tolambda name: name(both callers passnamepositionally).Advisories noted, not acted on:
last_calldict retains one entry per distinct key for the process lifetime — bounded here by installed-app count, only a concern ifthrottleis later reused with an unbounded key (documented in the new docstring caveat). Missingfunctools.wrapson the wrapper is pre-existing and out of scope.Recommended reading order
shard_core/util/misc.py— the decorator changeshard_core/service/app_tools.py— apply per-app keyshard_core/service/app_lifecycle.py— stale-comment fixtests/test_throttle.py,tests/test_app_compose_pinning.py— tests🤖 Generated with Claude Code