fix: tighten request controller release semantics#682
Conversation
|
Red-teamed this together with PR #681 and found one concurrency edge case around repeated If two leases are both acquired when Could we gate the multiplicative decrease on the lease limit, for example only decrease when |
Greptile SummaryThis PR tightens the release semantics of
|
| Filename | Overview |
|---|---|
| packages/data-designer-engine/src/data_designer/engine/models/request_admission/controller.py | Three targeted fixes: stale lease detection via exact equality check, one-shot rate_limit_ceiling capture, and outcome-first reason_or_outcome in release events — all logically consistent with the PR's stated contracts. |
| packages/data-designer-engine/tests/engine/models/request_admission/test_controller.py | Test updates cover the ceiling fix (assert 8 instead of 4), stale-lease detection with explicit construction, and a new test asserting that request_lease_released events carry the terminal outcome kind. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["release(lease, outcome)"] --> B{controller_generation\nmatches?}
B -- No --> D1["diagnostic: wrong_controller_generation"]
B -- Yes --> C{active_leases\nhas lease_id?}
C -- No --> D2["diagnostic: duplicate / unknown_lease"]
C -- Yes, pop active --> E{active == lease?}
E -- No --> D3["put active back\ndiagnostic: stale_lease"]
E -- Yes --> F["decrement counters\n_apply_outcome()"]
F --> G{outcome.kind ==\n'rate_limited'?}
G -- Yes --> H["emit request_rate_limited\nusing active lease"]
G -- No --> I
H --> I["emit request_lease_released\nwith outcome.kind as reason_or_outcome"]
I --> J["admit_waiters / notify"]
subgraph _apply_outcome ["_apply_outcome (rate_limited path)"]
direction TB
P["multiplicative decrease\ncurrent_limit x factor"] --> Q{rate_limit_ceiling == 0?}
Q -- Yes --> R["set ceiling = admitted_adaptive_limit\n(captured once per cascade)"]
Q -- No --> S["ceiling unchanged"]
end
F -.-> _apply_outcome
Reviews (4): Last reviewed commit: "test: restore waiter deadline time impor..." | Re-trigger Greptile
4a838c1 to
8f0255c
Compare
c19a078 to
cb9097d
Compare
Summary
request_lease_releasedevents instead of the generic release result.Why
The request-admission plan describes rate-limited outcomes as applying multiplicative decrease, release events as carrying the release outcome, and stale leases as diagnostic-only. This keeps controller accounting and telemetry aligned with those contracts.
Validation
.venv/bin/ruff check --fix ..venv/bin/ruff format ..venv/bin/pytest packages/data-designer-engine/tests/engine/models/request_admission/test_controller.py.venv/bin/pytest packages/data-designer-engine/tests/engine/dataset_builders/scheduling/test_resolver.py packages/data-designer-engine/tests/engine/dataset_builders/test_async_scheduler.py packages/data-designer-engine/tests/engine/models/request_admission/test_controller.py packages/data-designer-engine/tests/engine/models/clients/test_model_request_executor.py