Skip to content

test(gateway): a module's ordinary pool runs 8, holds 24 and refuses the 33rd at once through the real ASGI path (ANYM-393) - #1066

Merged
egerev merged 2 commits into
mainfrom
bb/gateway-backend-pool-bounds-thr_h748zsv2mq
Nov 18, 2026
Merged

egerev merged 2 commits into
mainfrom
bb/gateway-backend-pool-bounds-thr_h748zsv2mq

Conversation

@egerev

@egerev egerev commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Problem (DK-85, group B audit): ANYM-393 criterion 1 says each module's ordinary pool runs 8 requests at once with up to 24 waiting, and refuses a new request at once with backend_busy (503) when 32 are pending. The audit was right that this exact shape was not asserted.

The existing test_backend_isolation.py::test_saturated_module_and_file_pool_do_not_block_other_metadata:

  • calls Clients.call directly;
  • starts 32 calls, sleeps 20 ms, and checks that one more is refused;
  • checks that other modules and the file pool stay usable.

It does not show 8 running vs 24 waiting, that waiters stay out of the backend, that the refusal is immediate rather than the 0.25 s queue timeout, or what happens after release. Cross-module isolation and the 0.25 s timeout and cancellation are covered there and in test_queue_timeout_and_cancellation_release_capacity, and are not repeated.

What the code does (verified, no defect):

  • Budget(8, 24) (http_clients.py:83) refuses when pending >= 32 before any await. Otherwise it counts the request as pending and waits up to 0.25 s for one of 8 semaphore slots.
  • Dispatch first reads the backend's /v1/capabilities through the same ordinary pool, then runs the operation.

Change: one new test file only, services/gateway/tests/test_backend_pool_bounds.py (1 test). No production, CI or existing-test change.

  • Path: requests go through the ASGI app (its own lifespan, the REST route, dispatch, Clients) into an in-memory calendar backend that holds each operation on an event.
  • 8 running, 24 waiting:
    • 8 operations run.
    • 24 more hold a place in the pool (pending == 32) but reach neither the operation nor the capabilities read.
  • The 33rd:
    • It is answered 503 {"error": "backend_busy"} and never reaches the backend.
    • The 24 are still pending at that moment. A waiter is refused after 0.25 s, so a 33rd that had waited would have been answered only after those 24 timed out. This proves an immediate refusal without measuring time.
  • After the release: all 32 answer 200. Each reached the backend exactly once (32 operations, 32 capabilities reads). The pool is empty and accepts another request.
  • Bounds and timing: 8/24/32 are written out from the spec. Waits are event-driven under a bounded 5 s supervision; there are no sleeps.

Proof:

  • The behaviour already exists, so the test passes on main by design.
  • Nine in-memory mutants of Budget/Clients are all killed: active 7, active 9, waiting 23, waiting 25, capacity of active only, refusal at > (33 pending), slot never released, pending never returned, ordinary and file pools swapped.
  • Locally, once: the whole gateway suite (956 passed). Ruff clean.

Not claimed: live or production performance (ANYM-212). The stale 1024-credential text of criterion 8 stays with root.

Signal grep: no path hit. The text hit is only the word "permissions" in the synthetic capabilities reply.

Spec: ANYM-393
Change path: AUTO (test-only)
Review record: none (owner 11-11: no reviews)

🤖 Generated with Claude Code

…the 33rd at once through the real ASGI path (ANYM-393)

One new test file. Requests go through the gateway's ASGI app (lifespan, REST route, dispatch, Clients) into an
in-memory calendar backend that holds each operation on an event:
- 8 operations run; the next 24 hold a pool place without reaching the backend (they queue at the capabilities read,
  which uses the same ordinary pool);
- with 32 pending, the 33rd is answered 503 backend_busy while the 24 are still pending, so it was refused at once,
  not after the 0.25 s queue wait, and it never reached the backend;
- after the release all 32 answer 200, each reached the backend exactly once, the pool is empty and accepts more.
Bounds are the spec's, written out; event-driven with bounded supervision, no sleeps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: egerev <egor@gosync.ai>
Brings in #1071 (the accepted Android test ordering fix for the CI 44354309423 failure that stopped this PR's
previous head 8a4e0af). The branch's own change is unchanged: one new gateway test file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: egerev <egor@gosync.ai>
@egerev egerev added the ship Small-fix rule: orchestrator Diff read at head; merge-keeper may enqueue label Nov 18, 2026
@egerev
egerev added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 5fe5f6a Nov 18, 2026
41 checks passed
@egerev
egerev deleted the bb/gateway-backend-pool-bounds-thr_h748zsv2mq branch November 18, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ship Small-fix rule: orchestrator Diff read at head; merge-keeper may enqueue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant